You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@kafka.apache.org by Jan Filipiak <Ja...@trivago.com> on 2018/03/01 06:55:39 UTC

Re: [DISCUSS] KIP-253: Support in-order message delivery with partition expansion

Hi Dong,

I tried to focus on what the steps are one can currently perform to 
expand or shrink a keyed topic while maintaining a top notch semantics.
I can understand that there might be confusion about "stopping the 
consumer". It is exactly the same as proposed in the KIP. there needs to be
a time the producers agree on the new partitioning. The extra semantics 
I want to put in there is that we have a possibility to wait until all 
the existing data
is copied over into the new partitioning scheme. When I say stopping I 
think more of having a memory barrier that ensures the ordering. I am 
still aming for latencies  on the scale of leader failovers.

Consumers have to explicitly adapt the new partitioning scheme in the 
above scenario. The reason is that in these cases where you are 
dependent on a particular partitioning scheme, you also have other 
topics that have co-partition enforcements or the kind -frequently. 
Therefore all your other input topics might need to grow accordingly.


What I was suggesting was to streamline all these operations as best as 
possible to have "real" partition grow and shrinkage going on. Migrating 
the producers to a new partitioning scheme can be much more streamlined 
with proper broker support for this. Migrating consumer is a step that 
might be made completly unnecessary if - for example streams - takes the 
gcd as partitioning scheme instead of enforcing 1 to 1. Connect 
consumers and other consumers should be fine anyways.

I hope this makes more clear where I was aiming at. The rest needs to be 
figured out. The only danger i see is that when we are introducing this 
feature as supposed in the KIP, it wont help any people depending on  
log compaction.

The other thing I wanted to mention is that I believe the current 
suggestion (without copying data over) can be implemented in pure 
userland with a custom partitioner and a small feedbackloop from 
ProduceResponse => Partitionier in coorporation with a change management 
system.

Best Jan







On 28.02.2018 07:13, Dong Lin wrote:
> Hey Jan,
>
> I am not sure if it is acceptable for producer to be stopped for a while,
> particularly for online application which requires low latency. I am also
> not sure how consumers can switch to a new topic. Does user application
> needs to explicitly specify a different topic for producer/consumer to
> subscribe to? It will be helpful for discussion if you can provide more
> detail on the interface change for this solution.
>
> Thanks,
> Dong
>
> On Mon, Feb 26, 2018 at 12:48 AM, Jan Filipiak <Ja...@trivago.com>
> wrote:
>
>> Hi,
>>
>> just want to throw my though in. In general the functionality is very
>> usefull, we should though not try to find the architecture to hard while
>> implementing.
>>
>> The manual steps would be to
>>
>> create a new topic
>> the mirrormake from the new old topic to the new topic
>> wait for mirror making to catch up.
>> then put the consumers onto the new topic
>>      (having mirrormaker spit out a mapping from old offsets to new offsets:
>>          if topic is increased by factor X there is gonna be a clean
>> mapping from 1 offset in the old topic to X offsets in the new topic,
>>          if there is no factor then there is no chance to generate a
>> mapping that can be reasonable used for continuing)
>>      make consumers stop at appropriate points and continue consumption
>> with offsets from the mapping.
>> have the producers stop for a minimal time.
>> wait for mirrormaker to finish
>> let producer produce with the new metadata.
>>
>>
>> Instead of implementing the approach suggest in the KIP which will leave
>> log compacted topic completely crumbled and unusable.
>> I would much rather try to build infrastructure to support the mentioned
>> above operations more smoothly.
>> Especially having producers stop and use another topic is difficult and
>> it would be nice if one can trigger "invalid metadata" exceptions for them
>> and
>> if one could give topics aliases so that their produces with the old topic
>> will arrive in the new topic.
>>
>> The downsides are obvious I guess ( having the same data twice for the
>> transition period, but kafka tends to scale well with datasize). So its a
>> nicer fit into the architecture.
>>
>> I further want to argument that the functionality by the KIP can
>> completely be implementing in "userland" with a custom partitioner that
>> handles the transition as needed. I would appreciate if someone could point
>> out what a custom partitioner couldn't handle in this case?
>>
>> With the above approach, shrinking a topic becomes the same steps. Without
>> loosing keys in the discontinued partitions.
>>
>> Would love to hear what everyone thinks.
>>
>> Best Jan
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> On 11.02.2018 00:35, Dong Lin wrote:
>>
>>> Hi all,
>>>
>>> I have created KIP-253: Support in-order message delivery with partition
>>> expansion. See
>>> https://cwiki.apache.org/confluence/display/KAFKA/KIP-253%
>>> 3A+Support+in-order+message+delivery+with+partition+expansion
>>> .
>>>
>>> This KIP provides a way to allow messages of the same key from the same
>>> producer to be consumed in the same order they are produced even if we
>>> expand partition of the topic.
>>>
>>> Thanks,
>>> Dong
>>>
>>>


Re: [DISCUSS] KIP-253: Support in-order message delivery with partition expansion

Posted by Jay Kreps <ja...@confluent.io>.
Hey Jason,

I agree. Even apart from this proposal the partitioning strategy is really
an essential part of the metadata for a topic and had we been less lazy we
probably would have included it with the topic metadata.

I think in terms of grandfathering this in you could have existing topics
just be auto-assigned a "client" partitioning and add a "linear" strategy
(or whatever) that is that is checked server-side and supported in terms of
re-partitioning.

-Jay

On Mon, Mar 5, 2018 at 10:43 AM, Jason Gustafson <ja...@confluent.io> wrote:

> Great discussion. I think I'm wondering whether we can continue to leave
> Kafka agnostic to the partitioning strategy. The challenge is communicating
> the partitioning logic from producers to consumers so that the dependencies
> between each epoch can be determined. For the sake of discussion, imagine
> you did something like the following:
>
> 1. The name (and perhaps version) of a partitioning strategy is stored in
> topic configuration when a topic is created.
> 2. The producer looks up the partitioning strategy before writing to a
> topic and includes it in the produce request (for fencing). If it doesn't
> have an implementation for the configured strategy, it fails.
> 3. The consumer also looks up the partitioning strategy and uses it to
> determine dependencies when reading a new epoch. It could either fail or
> make the most conservative dependency assumptions if it doesn't know how to
> implement the partitioning strategy. For the consumer, the new interface
> might look something like this:
>
> // Return the partition dependencies following an epoch bump
> Map<Integer, List<Integer>> dependencies(int numPartitionsBeforeEpochBump,
> int numPartitionsAfterEpochBump)
>
> The unordered case then is just a particular implementation which never has
> any epoch dependencies. To implement this, we would need some way for the
> consumer to find out how many partitions there were in each epoch, but
> maybe that's not too unreasonable.
>
> Thanks,
> Jason
>
>
> On Mon, Mar 5, 2018 at 4:51 AM, Jan Filipiak <Ja...@trivago.com>
> wrote:
>
> > Hi Dong
> >
> > thank you very much for your questions.
> >
> > regarding the time spend copying data across:
> > It is correct that copying data from a topic with one partition mapping
> to
> > a topic with a different partition mapping takes way longer than we can
> > stop producers. Tens of minutes is a very optimistic estimate here. Many
> > people can not afford copy full steam and therefore will have some rate
> > limiting in place, this can bump the timespan into the day's. The good
> part
> > is that the vast majority of the data can be copied while the producers
> are
> > still going. One can then, piggyback the consumers ontop of this
> timeframe,
> > by the method mentioned (provide them an mapping from their old offsets
> to
> > new offsets in their repartitioned topics. In that way we separate
> > migration of consumers from migration of producers (decoupling these is
> > what kafka is strongest at). The time to actually swap over the producers
> > should be kept minimal by ensuring that when a swap attempt is started
> the
> > consumer copying over should be very close to the log end and is expected
> > to finish within the next fetch. The operation should have a time-out and
> > should be "reattemtable".
> >
> > Importance of logcompaction:
> > If a producer produces key A, to partiton 0, its forever gonna be there,
> > unless it gets deleted. The record might sit in there for years. A new
> > producer started with the new partitions will fail to delete the record
> in
> > the correct partition. Th record will be there forever and one can not
> > reliable bootstrap new consumers. I cannot see how linear hashing can
> solve
> > this.
> >
> > Regarding your skipping of userland copying:
> > 100%, copying the data across in userland is, as far as i can see, only a
> > usecase for log compacted topics. Even for logcompaction + retentions it
> > should only be opt-in. Why did I bring it up? I think log compaction is a
> > very important feature to really embrace kafka as a "data plattform". The
> > point I also want to make is that copying data this way is completely
> > inline with the kafka architecture. it only consists of reading and
> writing
> > to topics.
> >
> > I hope it clarifies more why I think we should aim for more than the
> > current KIP. I fear that once the KIP is done not much more effort will
> be
> > taken.
> >
> >
> >
> >
> > On 04.03.2018 02:28, Dong Lin wrote:
> >
> >> Hey Jan,
> >>
> >> In the current proposal, the consumer will be blocked on waiting for
> other
> >> consumers of the group to consume up to a given offset. In most cases,
> all
> >> consumers should be close to the LEO of the partitions when the
> partition
> >> expansion happens. Thus the time waiting should not be long e.g. on the
> >> order of seconds. On the other hand, it may take a long time to wait for
> >> the entire partition to be copied -- the amount of time is proportional
> to
> >> the amount of existing data in the partition, which can take tens of
> >> minutes. So the amount of time that we stop consumers may not be on the
> >> same order of magnitude.
> >>
> >> If we can implement this suggestion without copying data over in purse
> >> userland, it will be much more valuable. Do you have ideas on how this
> can
> >> be done?
> >>
> >> Not sure why the current KIP not help people who depend on log
> compaction.
> >> Could you elaborate more on this point?
> >>
> >> Thanks,
> >> Dong
> >>
> >> On Wed, Feb 28, 2018 at 10:55 PM, Jan Filipiak<Jan.Filipiak@trivago.com
> >
> >> wrote:
> >>
> >> Hi Dong,
> >>>
> >>> I tried to focus on what the steps are one can currently perform to
> >>> expand
> >>> or shrink a keyed topic while maintaining a top notch semantics.
> >>> I can understand that there might be confusion about "stopping the
> >>> consumer". It is exactly the same as proposed in the KIP. there needs
> to
> >>> be
> >>> a time the producers agree on the new partitioning. The extra
> semantics I
> >>> want to put in there is that we have a possibility to wait until all
> the
> >>> existing data
> >>> is copied over into the new partitioning scheme. When I say stopping I
> >>> think more of having a memory barrier that ensures the ordering. I am
> >>> still
> >>> aming for latencies  on the scale of leader failovers.
> >>>
> >>> Consumers have to explicitly adapt the new partitioning scheme in the
> >>> above scenario. The reason is that in these cases where you are
> dependent
> >>> on a particular partitioning scheme, you also have other topics that
> have
> >>> co-partition enforcements or the kind -frequently. Therefore all your
> >>> other
> >>> input topics might need to grow accordingly.
> >>>
> >>>
> >>> What I was suggesting was to streamline all these operations as best as
> >>> possible to have "real" partition grow and shrinkage going on.
> Migrating
> >>> the producers to a new partitioning scheme can be much more streamlined
> >>> with proper broker support for this. Migrating consumer is a step that
> >>> might be made completly unnecessary if - for example streams - takes
> the
> >>> gcd as partitioning scheme instead of enforcing 1 to 1. Connect
> consumers
> >>> and other consumers should be fine anyways.
> >>>
> >>> I hope this makes more clear where I was aiming at. The rest needs to
> be
> >>> figured out. The only danger i see is that when we are introducing this
> >>> feature as supposed in the KIP, it wont help any people depending on
> log
> >>> compaction.
> >>>
> >>> The other thing I wanted to mention is that I believe the current
> >>> suggestion (without copying data over) can be implemented in pure
> >>> userland
> >>> with a custom partitioner and a small feedbackloop from ProduceResponse
> >>> =>
> >>> Partitionier in coorporation with a change management system.
> >>>
> >>> Best Jan
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>
> >>> On 28.02.2018 07:13, Dong Lin wrote:
> >>>
> >>> Hey Jan,
> >>>>
> >>>> I am not sure if it is acceptable for producer to be stopped for a
> >>>> while,
> >>>> particularly for online application which requires low latency. I am
> >>>> also
> >>>> not sure how consumers can switch to a new topic. Does user
> application
> >>>> needs to explicitly specify a different topic for producer/consumer to
> >>>> subscribe to? It will be helpful for discussion if you can provide
> more
> >>>> detail on the interface change for this solution.
> >>>>
> >>>> Thanks,
> >>>> Dong
> >>>>
> >>>> On Mon, Feb 26, 2018 at 12:48 AM, Jan Filipiak<Jan.Filipiak@trivago.
> com
> >>>> >
> >>>> wrote:
> >>>>
> >>>> Hi,
> >>>>
> >>>>> just want to throw my though in. In general the functionality is very
> >>>>> usefull, we should though not try to find the architecture to hard
> >>>>> while
> >>>>> implementing.
> >>>>>
> >>>>> The manual steps would be to
> >>>>>
> >>>>> create a new topic
> >>>>> the mirrormake from the new old topic to the new topic
> >>>>> wait for mirror making to catch up.
> >>>>> then put the consumers onto the new topic
> >>>>>       (having mirrormaker spit out a mapping from old offsets to new
> >>>>> offsets:
> >>>>>           if topic is increased by factor X there is gonna be a clean
> >>>>> mapping from 1 offset in the old topic to X offsets in the new topic,
> >>>>>           if there is no factor then there is no chance to generate a
> >>>>> mapping that can be reasonable used for continuing)
> >>>>>       make consumers stop at appropriate points and continue
> >>>>> consumption
> >>>>> with offsets from the mapping.
> >>>>> have the producers stop for a minimal time.
> >>>>> wait for mirrormaker to finish
> >>>>> let producer produce with the new metadata.
> >>>>>
> >>>>>
> >>>>> Instead of implementing the approach suggest in the KIP which will
> >>>>> leave
> >>>>> log compacted topic completely crumbled and unusable.
> >>>>> I would much rather try to build infrastructure to support the
> >>>>> mentioned
> >>>>> above operations more smoothly.
> >>>>> Especially having producers stop and use another topic is difficult
> and
> >>>>> it would be nice if one can trigger "invalid metadata" exceptions for
> >>>>> them
> >>>>> and
> >>>>> if one could give topics aliases so that their produces with the old
> >>>>> topic
> >>>>> will arrive in the new topic.
> >>>>>
> >>>>> The downsides are obvious I guess ( having the same data twice for
> the
> >>>>> transition period, but kafka tends to scale well with datasize). So
> >>>>> its a
> >>>>> nicer fit into the architecture.
> >>>>>
> >>>>> I further want to argument that the functionality by the KIP can
> >>>>> completely be implementing in "userland" with a custom partitioner
> that
> >>>>> handles the transition as needed. I would appreciate if someone could
> >>>>> point
> >>>>> out what a custom partitioner couldn't handle in this case?
> >>>>>
> >>>>> With the above approach, shrinking a topic becomes the same steps.
> >>>>> Without
> >>>>> loosing keys in the discontinued partitions.
> >>>>>
> >>>>> Would love to hear what everyone thinks.
> >>>>>
> >>>>> Best Jan
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>> On 11.02.2018 00:35, Dong Lin wrote:
> >>>>>
> >>>>> Hi all,
> >>>>>
> >>>>>> I have created KIP-253: Support in-order message delivery with
> >>>>>> partition
> >>>>>> expansion. See
> >>>>>> https://cwiki.apache.org/confluence/display/KAFKA/KIP-253%
> >>>>>> 3A+Support+in-order+message+delivery+with+partition+expansion
> >>>>>> .
> >>>>>>
> >>>>>> This KIP provides a way to allow messages of the same key from the
> >>>>>> same
> >>>>>> producer to be consumed in the same order they are produced even if
> we
> >>>>>> expand partition of the topic.
> >>>>>>
> >>>>>> Thanks,
> >>>>>> Dong
> >>>>>>
> >>>>>>
> >>>>>>
> >>>>>>
> >
>

Re: [DISCUSS] KIP-253: Support in-order message delivery with partition expansion

Posted by Jun Rao <ju...@confluent.io>.
Hi, Jan,

Thanks for the reply. A few more comments inlined below.

On Fri, Mar 23, 2018 at 7:15 AM, Jan Filipiak <Ja...@trivago.com>
wrote:

>
>> I agree that decoupling the number of tasks in a consumer group from the
>> number of partitions in the input topic is a good idea. This allows each
>> consumer group to change its degree of parallelism independently. There
>> are
>> different ways to achieve such decoupling. You suggested one approach,
>> which works when splitting partitions. Not sure if this works in general,
>> for example when merging partitions.
>>
> Merging is the same.
>
> topicOldMapping-0 : 25 => [0:50]
> topicOldMapping-1 : 25 => [1:50]
> topicOldMapping-2 : 15 => [0:50]
> topicOldMapping-3 : 45 => [1:50]
>
> generating this mapping is trivial again if we do not copy data. (end
> offsets point to start offsets)
> If we do copy data the consumer will create the mapping.


For merging partitions, I was thinking of the following case. Suppose that
the input topic has 4 partitions and the consumer has 4 instances and each
instance is assigned 1 partition. Now if we want to merge the 4 partitions
into 2 partitions, we can't assign the 2 partitions to 4 instances without
changing the key space that each instance covers. In order not to force the
consumers to rebuild the states immediately, one more general option is to
just let the consumer re-shuffle the input.


>
>
>
>> Once a consumer group decides to change its degree of parallelism, it
>> needs
>> to rebuild the local state for the new tasks. We can either rebuild the
>> states from the input topic or from the local state (through change
>> capture
>> topic). I think we agreed that rebuilding from the local state is more
>> efficient. It also seems that it's better to let the KStreams library do
>> the state rebuilding, instead of each application. Would you agree?
>>
> If you want todo by RPC, you are changing the running application without
> having a new good one. This
> is against the kappa achitecture I would not recommend that.
>
> If you replay the changelog and only poll records that are for your
> partition. You have the problem of knowing
> which offset from the input topic your current state relates to.
>
>
Hmm, my understanding is that the changelog data always reflects the state
up to committed offset in the input topic. So, when rebuilding the state,
you keep reading from the current changelog and pulling the key belonging
to the new state. When you almost catch up on the changelog topic, you stop
the consumption, drain the remaining data in the changelog, and resume the
consumption. At this point, the new local state should match the committed
offset in the input topic.



> If you rebuild you could leave the old running and just wait for the new
> to be _good_ then change who's output you
> show to the customers.
>
>
>> About the special consumer. I guess that's only needed if one wants to
>> recopy the existing data? However, if we can truly decouple the tasks in
>> the consumer group from the partitions in the input topic, it seems there
>> is no need for copying existing data? It's also not clear to me who will
>> start/stop this special consumer.
>>
> Who starts and stops it is also not very clear to me. I do not have strong
> opinions.
> The thing is that I am looking for an explanation how you can have a
> logcompacted topic working without copying.
> I agree that for running consumers its no problem as they are already past
> the history. But the whole purpose of Log compaction
> is to be able to bootstrap new consumers. They are completely lost with a
> topic expanded without repartitioning.
> The topic will be broken forever. and this is not acceptable.
>
>
Yes, one option here is to always reshuffle the compacted topic in the
consumer until the number of partition matches the number of tasks. One
still pays the copying overhead, but only when it's needed and doesn't
affect the brokers.



> This is why I am so intrigued to model the problem as described because it
> has no overhead for the no copy path while it allows
> to also perform a copy.
>
> State handling wise one has also all the options. Exactly the 3 you
> mentioned I guess. its just that this statestore RPC is a bad idea
> and it was only invented to allow for optimisations that are better not
> done.Not to say they are premature ;)
>
>
Hmm, could you elaborate that a bit? Recopying existing data needs RPCs
across consumers and brokers, which seems ok to you. To me, that's not any
different from RPC across consumer instances.


> I hope it makes it clear
>
> best jan


Thanks,

Jun

Re: [DISCUSS] KIP-253: Support in-order message delivery with partition expansion

Posted by Jun Rao <ju...@confluent.io>.
Hi, John,

Thanks for the comments.

For your thought 1, I agree that it's better to decouple the design of core
and Streams with respect to re-partitioning. From the state management
perspective, a streaming application can be (1) stateless, (2) stateful and
maintaining the states in a global data store, (3) stateful and maintaining
the states in a local store. If an application does (3), it probably will
be using a stream processing library such as KStreams since managing the
local state in the application can be tricky. When using KStreams to manage
local states, currently the main issue is that the number of tasks is
coupled with the number of partitions. Since each task has a separate local
state, if the number of input partitions changes, one needs to rebuild the
local state immediately, which affects latency. So, we need to solution in
KStreams to decouple the two somehow. From the core's perspective, it seems
that it first needs to support per-key ordering since it's required in all
3 use cases above. Next, it would be ideal for it to support some kind of
notification to the consumer when a key switches partitions. Then, for (2),
the application can use this opportunity to do things like flushing the
value for a given key to the global store.

The rest of your thoughts are mostly about the specific implementation of
backfilling existing data to new partitions. To me, backfilling existing
data mainly helps with new applications with case (3). So, if we want to do
that, it seems it's better done in KStreams, instead of core. We also need
a solution for the existing consumers. Then, we should also consider if new
applications can just use the same approach for existing consumers.

Jun


On Mon, Mar 26, 2018 at 11:16 AM, John Roesler <jo...@confluent.io> wrote:

> Hi all,
>
> I hope you don't mind if I throw some thoughts in...
>
> For some reason, Jan's proposal wasn't really clear to me until this last
> message, and now that (I think) I understand it, I actually like it quite a
> lot.
>
> Thought 1:
> As much as I like Streams, I don't think it should become a requirement to
> pull off something like partition expansion. It would be a bummer if folks
> who otherwise have no use case for Streams have to run an trivial app
> *just* to get partition expansion.
>
> Assuming we get a nice partition-expansion design out of this conversation,
> It may or may not be the case that Streams will still decide to
> re-partition its inputs, but I'd like to keep those two designs (Core and
> Streams) independent (personal opinion, fwiw). It also may or may not be
> the case that we would try to split the local state versus re-building the
> affected operators from the new (post-split) topics. It would be nice to be
> able to optimize the process of scaling Streams independently of Core.
>
> Thought 2:
> Regarding who might manage this special backfill consumer, I wonder if the
> answer might actually be that that logic should be in the producer.
>
> Consider that only the producer knows the partition function, so locating
> backfill anywhere else requires sharing that logic, which would be a
> bummer.
>
> Also, if you think about the "producer" in the broader sense, as the
> organization that produces the data in a particular topic, that "producer"
> controls everything about the topic: the name, the number of partitions,
> the schema, and all of the configs including compaction and retention. This
> "producer" will be the person responsible for splitting/merging partitions
> anyway, so introducing a new component is asking that "producer" to own and
> operate more pieces, whereas placing inside the KafkaProducer keeps their
> operational burden the same.
>
> Thought 3:
> I don't think we want to think about actually creating a new topic, but
> instead something like a "generation" or "version" of a topic.
>
> Different generations of a topic can have different numbers of partitions,
> and also different offsets. Consumers can currently start with the earliest
> available offset. Similarly, with generations, consumers could start off
> with the earliest available in the earliest available generation. The
> retention policy still applies, so when the log cleaner deletes the last
> segment from a generation, that whole generation becomes unavailable, and
> new consumers start off on the next generation.
>
> This also makes the backfill job well defined: the range it's copying
> *from* has a start and an end; the range it's copying *to* is out of bounds
> for new writes. When backfill finishes copying all the records from
> generation 0 to the beginning of generation 1, it instructs the broker that
> generation 1, offset x is now the earliest available offset and all of
> generation 0's files can be deleted. The metadata tracking how to
> transition from gen0 to gen1 can also be deleted, as it's no longer
> meaningful.
>
> Note that for compacted topics, you really want to think of the number of
> partitions in the topic as the number of partitions in the first available
> partition. I.e., I think it's simplifying to assume that consumers may not
> be able to split their state. If I'm a consumer, and I don't have enough
> parallelism, I think I'd go to the producer and request an expansion. The
> producer would do the expansion and kick off the backfill. My existing
> consumers get assigned the new generations partitions such that each
> consumer gets the same set of records. When the backfill completes, *then*
> I can start up my new crop of more granular consumers. Being able to split
> and merge state when I hit topic generation barriers would obviously be
> nice, but I don't think it's universally available, so it's important to
> have a solid design around async backfill with notifications.
>
> Thought 4:
> I *think* Jan's approach works fine even if you want to split just one
> partition, instead of increasing the number of partitions by a factor.
> Plus, you could split the partition into any number of new partitions. It
> all depends on the partition function, which again comes back to it being
> nice to place the responsibility for all these decisions squarely with the
> producer. Maybe the default hash function requires them to double the
> partition count, but if they want to be able to split single partitions,
> they can use a hash function that makes that possible.
>
> We also need to remember that some topics don't use hashing at all to
> assign partitions, but round-robin instead. In this case, the partition
> assignment for a record is clearly arbitrary. In this case, I could see
> wanting to just increase the partition count, say from 2 to 3, and achieve
> a uniform re-distribution. This is the only use case that isn't well served
> by the "partition split" mentality. If you wanted a uniform re-distribution
> in this case, you would have to go from 2 to 4. Or, you could always create
> a truly new topic and get all your consumers to start consuming that one
> instead.
>
> Thought 5:
> This whole operation can be really straightforward if we're a little
> careful with the offsets. I think for expansion, you want to start the new
> generation off with the end offset of the old generation, and for merging,
> you want to add the end offsets of the two old-gen parent partitions. This
> way, you know that there will be enough room at the beginning of the
> partition for a potential backfill either way.
>
> In other words:
> Let's assume MyTopic has 3 partitions, and we're splitting partition 0 into
> two:
> MyTopic[gen=0,part=0,endOffset=50] -> (
> MyTopic[gen=1,part=0,endOffset=50], MyTopic[gen=1,part=3,endOffset=50]
> )
> MyTopic[gen=0,part=1,endOffset=41] -> ( MyTopic[gen=1,part=1,endOffset=41]
> )
> MyTopic[gen=0,part=2,endOffset=63] -> ( MyTopic[gen=1,part=2,endOffset=63]
> )
>
> *Maybe* the producer of MyTopic decides to backfill the split of part=0:
> 1) For each record, they run it though their partition function to decide
> between part=0 and part=3, instructing the broker to copy that record to
> the new generation's partition with the *same* offset.
> 2) When they reach the end of [gen=0,part=0], they instruct the broker that
> MyTopic[gen=1,part=1] now begins at offset=0 and MyTopic[gen=1,part=3] now
> begins at offset=1 (for example), and they also mark gen=0,part=0 as
> defunct.
>
> Assuming 4 Consumers: if they started reading during gen=0, they might have
> the following assignment:
> * consumer1: in gen=0, [part=0], transitioning to [part=0,part=3] at
> offset=50
> * consumer2: [part=1]
> * consumer3: [part=2]
> * consumer4: []
>
> Now, if they started reading during gen=1 after gen=0 becomes defunct, they
> might have this assignment:
> * consumer1: [part=0]
> * consumer2: [part=1]
> * consumer3: [part=2]
> * consumer4: [part=3]
>
> Just a quick note about the possibility of splitting without starting
> over... if consumer1 knows how to split its task, either because it's
> stateless or because it has splittable state, it certainly can and "send"
> part=3 to consumer4. So this avenue is still open.
>
> Thought 5.5:
> I think it's worth also sketching out the merge operation, as I'm picturing
> it.
> Let's assume we've got 4 partitions, and we want to merge part=1 and
> part=2:
> MyTopic[gen=0,part=0,endOffset=50] -> MyTopic[gen=1,part=0,endOffset=50]
> MyTopic[gen=0,part=1,endOffset=12] -> MyTopic[gen=1,part=1,endOffset=(12 +
> 23 = 35)]
> MyTopic[gen=0,part=2,endOffset=23] -> (see gen=1,part=1)
> MyTopic[gen=0,part=3,endOffset=41] -> MyTopic[gen=1,part=3,endOffset=41]
>
> Now, I think no matter how you cut it, this is going to be a tough
> transition for stateful consumers to handle. The good news is that the
> brokers can pull off a merge backfill very efficiently, by just copying
> part=2's segments into part=1 and using a little metadata to remember to
> add 12 to all the offsets it reads out of these segments. So, it might just
> have to be good enough to make merge super fast and then stateful consumers
> will have to rebuild their state for the affected partitions. Producers can
> be warned that while splitting is fine, merging may break their consumers.
>
> Thought 6:
> To pull off the split backfill, the broker will have to stream all the
> records to the producer's backfill worker, which is a bummer, but note that
> the backfill worker doesn't have to stream them back. It is sufficient just
> to send back the new partition assignment and offset for each (old
> partition,offset), since the records are going to keep their old timestamp,
> key, and value. The broker can then do its best to merge consecutive ranges
> and do efficient filesystem copies. Hopefully, the fact that backfill is
> async and producers and consumers can just continue working in the new
> generation while it happens, in combination with the fact that we only have
> to stream the data out and not back in to the broker makes this tolerable.
>
> Likewise, for partitions not undergoing a split can trivially backfill into
> the new generation by copying, moving, or hardlinking the segment files
> over, depending on the implementer's preference. The point is, it can be
> done without streaming that data back to the producer.
>
>
> All done!
> Now that (I think) I understand Jan's proposal, I agree it's a better way
> forward for the project than pulling Streams in to perform the repartition
> operation. Hopefully, my comments add a little to the conversation.
>
> Thanks,
> John
>
> On Fri, Mar 23, 2018 at 9:15 AM, Jan Filipiak <Ja...@trivago.com>
> wrote:
>
> > Hi Jun,
> >
> > thanks for your great reply, even though I only managed to throw a few
> > sentences in, because of time last time. I think you are starting to
> > understand me pretty well. There is still some minor things that need to
> be
> > flattened out. I already had these points previously but I try to
> rephrase
> > them into answers to your questions for clarity.
> >
> > On 23.03.2018 01:43, Jun Rao wrote:
> >
> >> Hi, Jan,
> >>
> >> Thanks for the reply.
> >>
> >> Ok. So your idea is to have a special consumer reshuffle the data to a
> new
> >> set of partitions. Each consumer group will not increase its tasks
> >> immediately. We just need to make sure that each consumer instance is
> >> assigned the set of new partitions covering the same set of keys. At
> some
> >> point later, each consumer group can decide independently when to
> increase
> >> the number of tasks. At that point, the consumer will need to rebuild
> the
> >> local state for the new tasks. Is that right?
> >>
> > This has multiple aspects. The middle part
> >
> >  We just need to make sure that each consumer instance is
> > assigned the set of new partitions covering the same set of keys
> >
> > is probably the most important one here. This is essentially what the
> > second part of my idea is about.
> > We need a protocol that allows consumers to switch from old topic (old
> > partiton count) to the new topic (new partion count). (If it really is a
> > new topic or not depends on the implementation -I like to model it as
> such
> > as its easier in my head). The protocol I envision is something like
> this:
> > Per partition there is information from the old offset to the new offset.
> >
> > topicOldMapping-0 : 50 => [0:25,2:25]
> > topicOldMapping-1 : 60 => [1:15,3:45]
> >
> > A consumer can get a hold on this information and stop at 50 and 60 and
> > continue at 25,25,15,45
> >
> > The same transition works when the data is not copied. a mapping would
> > look like
> >
> > topicOldMapping-0 : 50 => [0:0,2:0]
> > topicOldMapping-1 : 60 => [1:0,3:0]
> >
> > No data would have been copied and 50 and 60 are the endoffsets and we
> > would start at the very beginning of the new topic 0,0,0,0
> >
> >
> >> I agree that decoupling the number of tasks in a consumer group from the
> >> number of partitions in the input topic is a good idea. This allows each
> >> consumer group to change its degree of parallelism independently. There
> >> are
> >> different ways to achieve such decoupling. You suggested one approach,
> >> which works when splitting partitions. Not sure if this works in
> general,
> >> for example when merging partitions.
> >>
> > Merging is the same.
> >
> > topicOldMapping-0 : 25 => [0:50]
> > topicOldMapping-1 : 25 => [1:50]
> > topicOldMapping-2 : 15 => [0:50]
> > topicOldMapping-3 : 45 => [1:50]
> >
> > generating this mapping is trivial again if we do not copy data. (end
> > offsets point to start offsets)
> > If we do copy data the consumer will create the mapping.
> >
> >
> >> Once a consumer group decides to change its degree of parallelism, it
> >> needs
> >> to rebuild the local state for the new tasks. We can either rebuild the
> >> states from the input topic or from the local state (through change
> >> capture
> >> topic). I think we agreed that rebuilding from the local state is more
> >> efficient. It also seems that it's better to let the KStreams library do
> >> the state rebuilding, instead of each application. Would you agree?
> >>
> > If you want todo by RPC, you are changing the running application without
> > having a new good one. This
> > is against the kappa achitecture I would not recommend that.
> >
> > If you replay the changelog and only poll records that are for your
> > partition. You have the problem of knowing
> > which offset from the input topic your current state relates to.
> >
> > If you rebuild you could leave the old running and just wait for the new
> > to be _good_ then change who's output you
> > show to the customers.
> >
> >
> >> About the special consumer. I guess that's only needed if one wants to
> >> recopy the existing data? However, if we can truly decouple the tasks in
> >> the consumer group from the partitions in the input topic, it seems
> there
> >> is no need for copying existing data? It's also not clear to me who will
> >> start/stop this special consumer.
> >>
> > Who starts and stops it is also not very clear to me. I do not have
> strong
> > opinions.
> > The thing is that I am looking for an explanation how you can have a
> > logcompacted topic working without copying.
> > I agree that for running consumers its no problem as they are already
> past
> > the history. But the whole purpose of Log compaction
> > is to be able to bootstrap new consumers. They are completely lost with a
> > topic expanded without repartitioning.
> > The topic will be broken forever. and this is not acceptable.
> >
> > This is why I am so intrigued to model the problem as described because
> it
> > has no overhead for the no copy path while it allows
> > to also perform a copy.
> >
> > State handling wise one has also all the options. Exactly the 3 you
> > mentioned I guess. its just that this statestore RPC is a bad idea
> > and it was only invented to allow for optimisations that are better not
> > done.Not to say they are premature ;)
> >
> > I hope it makes it clear
> >
> > best jan
> >
> >
> >> Thanks,
> >>
> >> Jun
> >>
> >> On Wed, Mar 21, 2018 at 6:57 AM, Jan Filipiak <Jan.Filipiak@trivago.com
> >
> >> wrote:
> >>
> >> Hi Jun,
> >>>
> >>> I was really seeing progress in our conversation but your latest reply
> is
> >>> just devastating.
> >>> I though we were getting close being on the same page now it feels like
> >>> we
> >>> are in different libraries.
> >>>
> >>> I just quickly slam my answers in here. If they are to brief I am sorry
> >>> give me a ping and try to go into details more.
> >>> Just want to show that your pro/cons listing is broken.
> >>>
> >>> Best Jan
> >>>
> >>> and want to get rid of this horrible compromise
> >>>
> >>>
> >>> On 19.03.2018 05:48, Jun Rao wrote:
> >>>
> >>> Hi, Jan,
> >>>>
> >>>> Thanks for the discussion. Great points.
> >>>>
> >>>> Let me try to summarize the approach that you are proposing. On the
> >>>> broker
> >>>> side, we reshuffle the existing data in a topic from current
> partitions
> >>>> to
> >>>> the new partitions. Once the reshuffle fully catches up, switch the
> >>>> consumers to start consuming from the new partitions. If a consumer
> >>>> needs
> >>>> to rebuild its local state (due to partition changes), let the
> consumer
> >>>> rebuild its state by reading all existing data from the new
> partitions.
> >>>> Once all consumers have switches over, cut over the producer to the
> new
> >>>> partitions.
> >>>>
> >>>> The pros for this approach are that :
> >>>> 1. There is just one way to rebuild the local state, which is simpler.
> >>>>
> >>>> true thanks
> >>>
> >>> The cons for this approach are:
> >>>> 1. Need to copy existing data.
> >>>>
> >>>> Very unfair and not correct. It does not require you to copy over
> >>> existing
> >>> data. It _allows_ you to copy all existing data.
> >>>
> >>> 2. The cutover of the producer is a bit complicated since it needs to
> >>>
> >>>> coordinate with all consumer groups.
> >>>>
> >>>> Also not true. I explicitly tried to make clear that there is only one
> >>> special consumer (in the case of actually copying data) coordination is
> >>> required.
> >>>
> >>> 3. The rebuilding of the state in the consumer is from the input topic,
> >>>> which can be more expensive than rebuilding from the existing state.
> >>>>
> >>>> true, but rebuilding state is only required if you want to increase
> >>> processing power, so we assume this is at hand.
> >>>
> >>> 4. The broker potentially has to know the partitioning function. If
> this
> >>>> needs to be customized at the topic level, it can be a bit messy.
> >>>>
> >>>> I would argue against having the operation being performed by the
> >>> broker.
> >>> This was not discussed yet but if you see my original email i suggested
> >>> otherwise from the beginning.
> >>>
> >>> Here is an alternative approach by applying your idea not in the
> broker,
> >>>> but in the consumer. When new partitions are added, we don't move
> >>>> existing
> >>>> data. In KStreams, we first reshuffle the new input data to a new
> topic
> >>>> T1
> >>>> with the old number of partitions and feed T1's data to the rest of
> the
> >>>> pipeline. In the meantime, KStreams reshuffles all existing data of
> the
> >>>> change capture topic to another topic C1 with the new number of
> >>>> partitions.
> >>>> We can then build the state of the new tasks from C1. Once the new
> >>>> states
> >>>> have been fully built, we can cut over the consumption to the input
> >>>> topic
> >>>> and delete T1. This approach works with compacted topic too. If an
> >>>> application reads from the beginning of a compacted topic, the
> consumer
> >>>> will reshuffle the portion of the input when the number of partitions
> >>>> doesn't match the number of tasks.
> >>>>
> >>>> We all wipe this idea from our heads instantly. Mixing Ideas from an
> >>> argument is not a resolution strategy
> >>> just leads to horrible horrible software.
> >>>
> >>>
> >>> The pros of this approach are:
> >>>> 1. No need to copy existing data.
> >>>> 2. Each consumer group can cut over to the new partitions
> independently.
> >>>> 3. The state is rebuilt from the change capture topic, which is
> cheaper
> >>>> than rebuilding from the input topic.
> >>>> 4. Only the KStreams job needs to know the partitioning function.
> >>>>
> >>>> The cons of this approach are:
> >>>> 1. Potentially the same input topic needs to be reshuffled more than
> >>>> once
> >>>> in different consumer groups during the transition phase.
> >>>>
> >>>> What do you think?
> >>>>
> >>>> Thanks,
> >>>>
> >>>> Jun
> >>>>
> >>>>
> >>>>
> >>>> On Thu, Mar 15, 2018 at 1:04 AM, Jan Filipiak <
> Jan.Filipiak@trivago.com
> >>>> >
> >>>> wrote:
> >>>>
> >>>> Hi Jun,
> >>>>
> >>>>> thank you for following me on these thoughts. It was important to me
> to
> >>>>> feel that kind of understanding for my arguments.
> >>>>>
> >>>>> What I was hoping for (I mentioned this earlier) is that we can model
> >>>>> the
> >>>>> case where we do not want to copy the data the exact same way as the
> >>>>> case
> >>>>> when we do copy the data. Maybe you can peek into the mails before to
> >>>>> see
> >>>>> more details for this.
> >>>>>
> >>>>> This means we have the same mechanism to transfer consumer groups to
> >>>>> switch topic. The offset mapping that would be generated would even
> be
> >>>>> simpler End Offset of the Old topic => offset 0 off all the
> partitions
> >>>>> of
> >>>>> the new topic. Then we could model the transition of a non-copy
> >>>>> expansion
> >>>>> the exact same way as a copy-expansion.
> >>>>>
> >>>>> I know this only works when topic growth by a factor. But the
> benefits
> >>>>> of
> >>>>> only growing by a factor are to strong anyways. See Clemens's hint
> and
> >>>>> remember that state reshuffling is entirely not needed if one doesn't
> >>>>> want
> >>>>> to grow processing power.
> >>>>>
> >>>>> I think these benefits should be clear, and that there is basically
> no
> >>>>> downside to what is currently at hand but just makes everything easy.
> >>>>>
> >>>>> One thing you need to know is. that if you do not offer rebuilding a
> >>>>> log
> >>>>> compacted topic like i suggest that even if you have consumer state
> >>>>> reshuffling. The topic is broken and can not be used to bootstrap new
> >>>>> consumers. They don't know if they need to apply a key from and old
> >>>>> partition or not. This is a horrible downside I haven't seen a
> solution
> >>>>> for
> >>>>> in the email conversation.
> >>>>>
> >>>>> I argue to:
> >>>>>
> >>>>> Only grow topic by a factor always.
> >>>>> Have the "no copy consumer" transition as the trivial case of the
> "copy
> >>>>> consumer transition".
> >>>>> If processors needs to be scaled, let them rebuild from the new topic
> >>>>> and
> >>>>> leave the old running in the mean time.
> >>>>> Do not implement key shuffling in streams.
> >>>>>
> >>>>> I hope I can convince you especially with the fact how I want to
> handle
> >>>>> consumer transition. I think
> >>>>> you didn't quite understood me there before. I think the term "new
> >>>>> topic"
> >>>>> intimidated you a little.
> >>>>> How we solve this on disc doesn't really matter, If the data goes
> into
> >>>>> the
> >>>>> same Dir or a different Dir or anything. I do think that it needs to
> >>>>> involve at least rolling a new segment for the existing partitions.
> >>>>> But most of the transitions should work without restarting consumers.
> >>>>> (newer consumers with support for this). But with new topic i just
> >>>>> meant
> >>>>> the topic that now has a different partition count. Plenty of ways to
> >>>>> handle that (versions, aliases)
> >>>>>
> >>>>> Hope I can further get my idea across.
> >>>>>
> >>>>> Best Jan
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>> On 14.03.2018 02:45, Jun Rao wrote:
> >>>>>
> >>>>> Hi, Jan,
> >>>>>
> >>>>>> Thanks for sharing your view.
> >>>>>>
> >>>>>> I agree with you that recopying the data potentially makes the state
> >>>>>> management easier since the consumer can just rebuild its state from
> >>>>>> scratch (i.e., no need for state reshuffling).
> >>>>>>
> >>>>>> On the flip slide, I saw a few disadvantages of the approach that
> you
> >>>>>> suggested. (1) Building the state from the input topic from scratch
> is
> >>>>>> in
> >>>>>> general less efficient than state reshuffling. Let's say one
> computes
> >>>>>> a
> >>>>>> count per key from an input topic. The former requires reading all
> >>>>>> existing
> >>>>>> records in the input topic whereas the latter only requires reading
> >>>>>> data
> >>>>>> proportional to the number of unique keys. (2) The switching of the
> >>>>>> topic
> >>>>>> needs modification to the application. If there are many
> applications
> >>>>>> on a
> >>>>>> topic, coordinating such an effort may not be easy. Also, it's not
> >>>>>> clear
> >>>>>> how to enforce exactly-once semantic during the switch. (3) If a
> topic
> >>>>>> doesn't need any state management, recopying the data seems
> wasteful.
> >>>>>> In
> >>>>>> that case, in place partition expansion seems more desirable.
> >>>>>>
> >>>>>> I understand your concern about adding complexity in KStreams. But,
> >>>>>> perhaps
> >>>>>> we could iterate on that a bit more to see if it can be simplified.
> >>>>>>
> >>>>>> Jun
> >>>>>>
> >>>>>>
> >>>>>> On Mon, Mar 12, 2018 at 11:21 PM, Jan Filipiak <
> >>>>>> Jan.Filipiak@trivago.com>
> >>>>>> wrote:
> >>>>>>
> >>>>>> Hi Jun,
> >>>>>>
> >>>>>> I will focus on point 61 as I think its _the_ fundamental part that
> I
> >>>>>>> cant
> >>>>>>> get across at the moment.
> >>>>>>>
> >>>>>>> Kafka is the platform to have state materialized multiple times
> from
> >>>>>>> one
> >>>>>>> input. I emphasize this: It is the building block in architectures
> >>>>>>> that
> >>>>>>> allow you to
> >>>>>>> have your state maintained multiple times. You put a message in
> once,
> >>>>>>> and
> >>>>>>> you have it pop out as often as you like. I believe you understand
> >>>>>>> this.
> >>>>>>>
> >>>>>>> Now! The path of thinking goes the following: I am using apache
> kafka
> >>>>>>> and
> >>>>>>> I _want_ my state multiple times. What am I going todo?
> >>>>>>>
> >>>>>>> A) Am I going to take my state that I build up, plunge some sort of
> >>>>>>> RPC
> >>>>>>> layer ontop of it, use that RPC layer to throw my records across
> >>>>>>> instances?
> >>>>>>> B) Am I just going to read the damn message twice?
> >>>>>>>
> >>>>>>> Approach A is fundamentally flawed and a violation of all that is
> >>>>>>> good
> >>>>>>> and
> >>>>>>> holy in kafka deployments. I can not understand how this Idea can
> >>>>>>> come
> >>>>>>> in
> >>>>>>> the first place.
> >>>>>>> (I do understand: IQ in streams, they polluted the kafka streams
> >>>>>>> codebase
> >>>>>>> really bad already. It is not funny! I think they are equally
> flawed
> >>>>>>> as
> >>>>>>> A)
> >>>>>>>
> >>>>>>> I say, we do what Kafka is good at. We repartition the topic once.
> We
> >>>>>>> switch the consumers.
> >>>>>>> (Those that need more partitions are going to rebuild their state
> in
> >>>>>>> multiple partitions by reading the new topic, those that don't just
> >>>>>>> assign
> >>>>>>> the new partitions properly)
> >>>>>>> We switch producers. Done!
> >>>>>>>
> >>>>>>> The best thing! It is trivial, hipster stream processor will have
> an
> >>>>>>> easy
> >>>>>>> time with that aswell. Its so super simple. And simple IS good!
> >>>>>>> It is what kafka was build todo. It is how we do it today. All I am
> >>>>>>> saying
> >>>>>>> is that a little broker help doing the producer swap is super
> useful.
> >>>>>>>
> >>>>>>> For everyone interested in why kafka is so powerful with approach
> B,
> >>>>>>> please watch https://youtu.be/bEbeZPVo98c?t=1633
> >>>>>>> I already looked up a good point in time, I think after 5 minutes
> the
> >>>>>>> "state" topic is handled and you should be able to understand me
> >>>>>>> and inch better.
> >>>>>>>
> >>>>>>> Please do not do A to the project, it deserves better!
> >>>>>>>
> >>>>>>> Best Jan
> >>>>>>>
> >>>>>>>
> >>>>>>>
> >>>>>>> On 13.03.2018 02:40, Jun Rao wrote:
> >>>>>>>
> >>>>>>> Hi, Jan,
> >>>>>>>
> >>>>>>> Thanks for the reply. A few more comments below.
> >>>>>>>>
> >>>>>>>> 50. Ok, we can think a bit harder for supporting compacted topics.
> >>>>>>>>
> >>>>>>>> 51. This is a fundamental design question. In the more common
> case,
> >>>>>>>> the
> >>>>>>>> reason why someone wants to increase the number of partitions is
> >>>>>>>> that
> >>>>>>>> the
> >>>>>>>> consumer application is slow and one wants to run more consumer
> >>>>>>>> instances
> >>>>>>>> to increase the degree of parallelism. So, fixing the number of
> >>>>>>>> running
> >>>>>>>> consumer instances when expanding the partitions won't help this
> >>>>>>>> case.
> >>>>>>>> If
> >>>>>>>> we do need to increase the number of consumer instances, we need
> to
> >>>>>>>> somehow
> >>>>>>>> reshuffle the state of the consumer across instances. What we have
> >>>>>>>> been
> >>>>>>>> discussing in this KIP is whether we can do this more effectively
> >>>>>>>> through
> >>>>>>>> the KStream library (e.g. through a 2-phase partition expansion).
> >>>>>>>> This
> >>>>>>>> will
> >>>>>>>> add some complexity, but it's probably better than everyone doing
> >>>>>>>> this
> >>>>>>>> in
> >>>>>>>> the application space. The recopying approach that you mentioned
> >>>>>>>> doesn't
> >>>>>>>> seem to address the consumer state management issue when the
> >>>>>>>> consumer
> >>>>>>>> switches from an old to a new topic.
> >>>>>>>>
> >>>>>>>> 52. As for your example, it depends on whether the join key is the
> >>>>>>>> same
> >>>>>>>> between (A,B) and (B,C). If the join key is the same, we can do a
> >>>>>>>> 2-phase
> >>>>>>>> partition expansion of A, B, and C together. If the join keys are
> >>>>>>>> different, one would need to repartition the data on a different
> key
> >>>>>>>> for
> >>>>>>>> the second join, then the partition expansion can be done
> >>>>>>>> independently
> >>>>>>>> between (A,B) and (B,C).
> >>>>>>>>
> >>>>>>>> 53. If you always fix the number of consumer instances, we you
> >>>>>>>> described
> >>>>>>>> works. However, as I mentioned in #51, I am not sure how your
> >>>>>>>> proposal
> >>>>>>>> deals with consumer states when the number of consumer instances
> >>>>>>>> grows.
> >>>>>>>> Also, it just seems that it's better to avoid re-copying the
> >>>>>>>> existing
> >>>>>>>> data.
> >>>>>>>>
> >>>>>>>> 60. "just want to throw in my question from the longer email in
> the
> >>>>>>>> other
> >>>>>>>> Thread here. How will the bloom filter help a new consumer to
> decide
> >>>>>>>> to
> >>>>>>>> apply the key or not?" Not sure that I fully understood your
> >>>>>>>> question.
> >>>>>>>> The
> >>>>>>>> consumer just reads whatever key is in the log. The bloom filter
> >>>>>>>> just
> >>>>>>>> helps
> >>>>>>>> clean up the old keys.
> >>>>>>>>
> >>>>>>>> 61. "Why can we afford having a topic where its apparently not
> >>>>>>>> possible
> >>>>>>>> to
> >>>>>>>> start a new application on? I think this is an overall flaw of the
> >>>>>>>> discussed idea here. Not playing attention to the overall
> >>>>>>>> architecture."
> >>>>>>>> Could you explain a bit more when one can't start a new
> application?
> >>>>>>>>
> >>>>>>>> Jun
> >>>>>>>>
> >>>>>>>>
> >>>>>>>>
> >>>>>>>> On Sat, Mar 10, 2018 at 1:40 AM, Jan Filipiak <
> >>>>>>>> Jan.Filipiak@trivago.com
> >>>>>>>> wrote:
> >>>>>>>>
> >>>>>>>> Hi Jun, thanks for your mail.
> >>>>>>>>
> >>>>>>>> Thank you for your questions!
> >>>>>>>>
> >>>>>>>>> I think they are really good and tackle the core of the problem I
> >>>>>>>>> see.
> >>>>>>>>>
> >>>>>>>>> I will answer inline, mostly but still want to set the tone here.
> >>>>>>>>>
> >>>>>>>>> The core strength of kafka is what Martin once called the
> >>>>>>>>> kappa-Architecture. How does this work?
> >>>>>>>>> You have everything as a log as in kafka. When you need to change
> >>>>>>>>> something.
> >>>>>>>>> You create the new version of your application and leave it
> running
> >>>>>>>>> in
> >>>>>>>>> parallel.
> >>>>>>>>> Once the new version is good you switch your users to use the new
> >>>>>>>>> application.
> >>>>>>>>>
> >>>>>>>>> The online reshuffling effectively breaks this architecture and I
> >>>>>>>>> think
> >>>>>>>>> the switch in thinking here is more harmful
> >>>>>>>>> than any details about the partitioning function to allow such a
> >>>>>>>>> change.
> >>>>>>>>> I
> >>>>>>>>> feel with my suggestion we are the closest to
> >>>>>>>>> the original and battle proven architecture and I can only warn
> to
> >>>>>>>>> move
> >>>>>>>>> away from it.
> >>>>>>>>>
> >>>>>>>>> I might have forgotten something, sometimes its hard for me to
> >>>>>>>>> getting
> >>>>>>>>> all
> >>>>>>>>> the thoughts captured in a mail, but I hope the comments inline
> >>>>>>>>> will
> >>>>>>>>> further make my concern clear, and put some emphasis on why I
> >>>>>>>>> prefer
> >>>>>>>>> my
> >>>>>>>>> solution ;)
> >>>>>>>>>
> >>>>>>>>> One thing we should all be aware of when discussing this, and I
> >>>>>>>>> think
> >>>>>>>>> Dong
> >>>>>>>>> should have mentioned it (maybe he did).
> >>>>>>>>> We are not discussing all of this out of thin air but there is an
> >>>>>>>>> effort
> >>>>>>>>> in the Samza project.
> >>>>>>>>>
> >>>>>>>>> https://cwiki.apache.org/confluence/display/SAMZA/SEP-5%3A+
> >>>>>>>>> Enable+partition+expansion+of+input+streams
> >>>>>>>>> https://issues.apache.org/jira/browse/SAMZA-1293
> >>>>>>>>>
> >>>>>>>>> To be clear. I think SEP-5 (state of last week, dont know if it
> >>>>>>>>> adapted
> >>>>>>>>> to
> >>>>>>>>> this discussion) is on a way better path than KIP-253, and I
> can't
> >>>>>>>>> really
> >>>>>>>>> explain why.
> >>>>>>>>>
> >>>>>>>>> Best Jan,
> >>>>>>>>>
> >>>>>>>>> nice weekend everyone
> >>>>>>>>>
> >>>>>>>>>
> >>>>>>>>> On 09.03.2018 03:36, Jun Rao wrote:
> >>>>>>>>>
> >>>>>>>>> Hi, Jan,
> >>>>>>>>>
> >>>>>>>>> Thanks for the feedback. Just some comments on the earlier points
> >>>>>>>>>
> >>>>>>>>>> that
> >>>>>>>>>> you
> >>>>>>>>>> mentioned.
> >>>>>>>>>>
> >>>>>>>>>> 50. You brought up the question of whether existing data needs
> to
> >>>>>>>>>> be
> >>>>>>>>>> copied
> >>>>>>>>>> during partition expansion. My understand of your view is that
> >>>>>>>>>> avoid
> >>>>>>>>>> copying existing data will be more efficient, but it doesn't
> work
> >>>>>>>>>> well
> >>>>>>>>>> with
> >>>>>>>>>> compacted topics since some keys in the original partitions will
> >>>>>>>>>> never
> >>>>>>>>>> be
> >>>>>>>>>> cleaned. It would be useful to understand your use case of
> >>>>>>>>>> compacted
> >>>>>>>>>> topics
> >>>>>>>>>> a bit more. In the common use case, the data volume in a
> compacted
> >>>>>>>>>> topic
> >>>>>>>>>> may not be large. So, I am not sure if there is a strong need to
> >>>>>>>>>> expand
> >>>>>>>>>> partitions in a compacted topic, at least initially.
> >>>>>>>>>>
> >>>>>>>>>> I do agree. State is usually smaller. Update rates might be also
> >>>>>>>>>>
> >>>>>>>>>> competitively high.
> >>>>>>>>>>
> >>>>>>>>> Doing Log-compaction (even beeing very efficient and
> configurable)
> >>>>>>>>> is
> >>>>>>>>> also
> >>>>>>>>> a more expensive operation than
> >>>>>>>>> just discarding old segments. Further if you want to use more
> >>>>>>>>> consumers
> >>>>>>>>> processing the events
> >>>>>>>>> you also have to grow the number of partitions. Especially for
> >>>>>>>>> use-cases
> >>>>>>>>> we do (KIP-213) a tiny state full
> >>>>>>>>> table might be very expensive to process if it joins against a
> huge
> >>>>>>>>> table.
> >>>>>>>>>
> >>>>>>>>> I can just say we have been in the spot of needing to grow log
> >>>>>>>>> compacted
> >>>>>>>>> topics. Mainly for processing power we can bring to the table.
> >>>>>>>>>
> >>>>>>>>> Further i am not at all concerned about the extra spaced used by
> >>>>>>>>> "garbage
> >>>>>>>>> keys". I am more concerned about the correctness of innocent
> >>>>>>>>> consumers.
> >>>>>>>>> The
> >>>>>>>>> logic becomes complicated. Say for streams one would need to load
> >>>>>>>>> the
> >>>>>>>>> record into state but not forward it the topology ( to have it
> >>>>>>>>> available
> >>>>>>>>> for shuffeling). I rather have it simple and a topic clean
> >>>>>>>>> regardless
> >>>>>>>>> if
> >>>>>>>>> it
> >>>>>>>>> still has its old partition count. Especially with multiple
> >>>>>>>>> partitions
> >>>>>>>>> growth's I think it becomes insanely hard to to this shuffle
> >>>>>>>>> correct.
> >>>>>>>>> Maybe
> >>>>>>>>> Streams and Samza can do it. Especially if you do "hipster stream
> >>>>>>>>> processing" <https://www.confluent.io/blog
> >>>>>>>>> /introducing-kafka-streams-
> >>>>>>>>> stream-processing-made-simple/>. This makes kafka way to
> >>>>>>>>> complicated.
> >>>>>>>>> With my approach I think its way simpler because the topic has no
> >>>>>>>>> "history"
> >>>>>>>>> in terms of partitioning but is always clean.
> >>>>>>>>>
> >>>>>>>>>
> >>>>>>>>> 51. "Growing the topic by an integer factor does not require any
> >>>>>>>>> state
> >>>>>>>>>
> >>>>>>>>> redistribution at all." Could you clarify this a bit more? Let's
> >>>>>>>>> say
> >>>>>>>>>
> >>>>>>>>>> you
> >>>>>>>>>> have a consumer app that computes the windowed count per key. If
> >>>>>>>>>> you
> >>>>>>>>>> double
> >>>>>>>>>> the number of partitions from 1 to 2 and grow the consumer
> >>>>>>>>>> instances
> >>>>>>>>>> from
> >>>>>>>>>> 1
> >>>>>>>>>> to 2, we would need to redistribute some of the counts to the
> new
> >>>>>>>>>> consumer
> >>>>>>>>>> instance. Regarding to linear hashing, it's true that it won't
> >>>>>>>>>> solve
> >>>>>>>>>> the
> >>>>>>>>>> problem with compacted topics. The main benefit is that it
> >>>>>>>>>> redistributes
> >>>>>>>>>> the keys in one partition to no more than two partitions, which
> >>>>>>>>>> could
> >>>>>>>>>> help
> >>>>>>>>>> redistribute the state.
> >>>>>>>>>>
> >>>>>>>>>> You don't need to spin up a new consumer in this case. every
> >>>>>>>>>> consumer
> >>>>>>>>>>
> >>>>>>>>>> would just read every partition with the (partition % num_task)
> >>>>>>>>>>
> >>>>>>>>> task.
> >>>>>>>>> it
> >>>>>>>>> will still have the previous data right there and can go on.
> >>>>>>>>>
> >>>>>>>>> This sounds contradictory to what I said before, but please bear
> >>>>>>>>> with
> >>>>>>>>> me.
> >>>>>>>>>
> >>>>>>>>> 52. Good point on coordinating the expansion of 2 topics that
> need
> >>>>>>>>> to
> >>>>>>>>> be
> >>>>>>>>>
> >>>>>>>>> joined together. This is where the 2-phase partition expansion
> >>>>>>>>> could
> >>>>>>>>>
> >>>>>>>>>> potentially help. In the first phase, we could add new
> partitions
> >>>>>>>>>> to
> >>>>>>>>>> the 2
> >>>>>>>>>> topics one at a time but without publishing to the new
> patitions.
> >>>>>>>>>> Then,
> >>>>>>>>>> we
> >>>>>>>>>> can add new consumer instances to pick up the new partitions. In
> >>>>>>>>>> this
> >>>>>>>>>> transition phase, no reshuffling is needed since no data is
> coming
> >>>>>>>>>> from
> >>>>>>>>>> the
> >>>>>>>>>> new partitions. Finally, we can enable the publishing to the new
> >>>>>>>>>> partitions.
> >>>>>>>>>>
> >>>>>>>>>> I think its even worse than you think. I would like to introduce
> >>>>>>>>>> the
> >>>>>>>>>>
> >>>>>>>>>> Term
> >>>>>>>>>>
> >>>>>>>>> transitive copartitioning. Imagine
> >>>>>>>>> 2 streams application. One joins (A,B) the other (B,C) then there
> >>>>>>>>> is
> >>>>>>>>> a
> >>>>>>>>> transitive copartition requirement for
> >>>>>>>>> (A,C) to be copartitioned aswell. This can spread significantly
> and
> >>>>>>>>> require many consumers to adapt at the same time.
> >>>>>>>>>
> >>>>>>>>> It is also not entirely clear to me how you not need reshuffling
> in
> >>>>>>>>> this
> >>>>>>>>> case. If A has a record that never gets updated after the
> expansion
> >>>>>>>>> and
> >>>>>>>>> the
> >>>>>>>>> coresponding B record moves to a new partition. How shall they
> meet
> >>>>>>>>> w/o
> >>>>>>>>> shuffle?
> >>>>>>>>>
> >>>>>>>>> 53. "Migrating consumer is a step that might be made completly
> >>>>>>>>>
> >>>>>>>>> unnecessary
> >>>>>>>>>
> >>>>>>>>>> if - for example streams - takes the gcd as partitioning scheme
> >>>>>>>>>> instead
> >>>>>>>>>> of
> >>>>>>>>>> enforcing 1 to 1." Not sure that I fully understand this. I
> think
> >>>>>>>>>> you
> >>>>>>>>>> mean
> >>>>>>>>>> that a consumer application can run more instances than the
> number
> >>>>>>>>>> of
> >>>>>>>>>> partitions. In that case, the consumer can just repartitioning
> the
> >>>>>>>>>> input
> >>>>>>>>>> data according to the number of instances. This is possible, but
> >>>>>>>>>> just
> >>>>>>>>>> has
> >>>>>>>>>> the overhead of reshuffling the data.
> >>>>>>>>>>
> >>>>>>>>>> No what I meant is ( that is also your question i think Mathias)
> >>>>>>>>>> that
> >>>>>>>>>> if
> >>>>>>>>>>
> >>>>>>>>>> you grow a topic by a factor.
> >>>>>>>>>>
> >>>>>>>>> Even if your processor is statefull you can can just assign all
> the
> >>>>>>>>> multiples of the previous partition to
> >>>>>>>>> this consumer and the state to keep processing correctly will be
> >>>>>>>>> present
> >>>>>>>>> w/o any shuffling.
> >>>>>>>>>
> >>>>>>>>> Say you have an assignment
> >>>>>>>>> Statefull consumer => partition
> >>>>>>>>> 0 => 0
> >>>>>>>>> 1 => 1
> >>>>>>>>> 2 => 2
> >>>>>>>>>
> >>>>>>>>> and you grow you topic by 4 you get,
> >>>>>>>>>
> >>>>>>>>> 0 => 0,3,6,9
> >>>>>>>>> 1 => 1,4,7,10
> >>>>>>>>> 2 => 2,5,8,11
> >>>>>>>>>
> >>>>>>>>> Say your hashcode is 8. 8%3 => 2  before so consumer for
> partition
> >>>>>>>>> 2
> >>>>>>>>> has
> >>>>>>>>> it.
> >>>>>>>>> Now you you have 12 partitions so 8%12 => 8, so it goes into
> >>>>>>>>> partition
> >>>>>>>>> 8
> >>>>>>>>> which is assigned to the same consumer
> >>>>>>>>> who had 2 before and therefore knows the key.
> >>>>>>>>>
> >>>>>>>>> Userland reshuffeling is there as an options. And it does exactly
> >>>>>>>>> what
> >>>>>>>>> I
> >>>>>>>>> suggest. And I think its the perfect strategie. All I am
> suggestion
> >>>>>>>>> is
> >>>>>>>>> broker side support to switch the producers to the newly
> >>>>>>>>> partitioned
> >>>>>>>>> topic.
> >>>>>>>>> Then the old (to few partition topic) can go away.  Remember the
> >>>>>>>>> list
> >>>>>>>>> of
> >>>>>>>>> steps in the beginning of this thread. If one has broker support
> >>>>>>>>> for
> >>>>>>>>> all
> >>>>>>>>> where its required and streams support for those that aren’t
> >>>>>>>>> necessarily.
> >>>>>>>>> Then one has solved the problem.
> >>>>>>>>> I repeat it because I think its important. I am really happy that
> >>>>>>>>> you
> >>>>>>>>> brought that up! because its 100% what I want just with the
> >>>>>>>>> differences
> >>>>>>>>> to
> >>>>>>>>> have an option to discard the to small topic later (after all
> >>>>>>>>> consumers
> >>>>>>>>> adapted). And to have order correct there. I need broker support
> >>>>>>>>> managing
> >>>>>>>>> the copy process + the produces and fence them against each
> other.
> >>>>>>>>> I
> >>>>>>>>> also
> >>>>>>>>> repeat. the copy process can run for weeks in the worst case.
> >>>>>>>>> Copying
> >>>>>>>>> the
> >>>>>>>>> data is not the longest task migrating consumers might very well
> >>>>>>>>> be.
> >>>>>>>>> Once all consumers switched and copying is really up to date
> (think
> >>>>>>>>> ISR
> >>>>>>>>> like up to date) only then we stop the producer, wait for the
> copy
> >>>>>>>>> to
> >>>>>>>>> finish and use the new topic for producing.
> >>>>>>>>>
> >>>>>>>>> After this the topic is perfect in shape. and no one needs to
> worry
> >>>>>>>>> about
> >>>>>>>>> complicated stuff. (old keys hanging around might arrive in some
> >>>>>>>>> other
> >>>>>>>>> topic later.....). can only imagine how many tricky bugs gonna
> >>>>>>>>> arrive
> >>>>>>>>> after
> >>>>>>>>> someone had grown and shrunken is topic 10 times.
> >>>>>>>>>
> >>>>>>>>>
> >>>>>>>>>
> >>>>>>>>>
> >>>>>>>>>
> >>>>>>>>>
> >>>>>>>>> 54. "The other thing I wanted to mention is that I believe the
> >>>>>>>>> current
> >>>>>>>>>
> >>>>>>>>> suggestion (without copying data over) can be implemented in pure
> >>>>>>>>>
> >>>>>>>>>> userland
> >>>>>>>>>> with a custom partitioner and a small feedbackloop from
> >>>>>>>>>> ProduceResponse
> >>>>>>>>>> =>
> >>>>>>>>>> Partitionier in coorporation with a change management system." I
> >>>>>>>>>> am
> >>>>>>>>>> not
> >>>>>>>>>> sure a customized partitioner itself solves the problem. We
> >>>>>>>>>> probably
> >>>>>>>>>> need
> >>>>>>>>>> some broker side support to enforce when the new partitions can
> be
> >>>>>>>>>> used.
> >>>>>>>>>> We
> >>>>>>>>>> also need some support on the consumer/kstream side to preserve
> >>>>>>>>>> the
> >>>>>>>>>> per
> >>>>>>>>>> key
> >>>>>>>>>> ordering and potentially migrate the processing state. This is
> not
> >>>>>>>>>> trivial
> >>>>>>>>>> and I am not sure if it's ideal to fully push to the application
> >>>>>>>>>> space.
> >>>>>>>>>>
> >>>>>>>>>> Broker support is defenitly the preferred way here. I have
> nothing
> >>>>>>>>>>
> >>>>>>>>>> against
> >>>>>>>>>>
> >>>>>>>>> broker support.
> >>>>>>>>> I tried to say that for what I would preffer - copying the data
> >>>>>>>>> over,
> >>>>>>>>> at
> >>>>>>>>> least for log compacted topics -
> >>>>>>>>> I would require more broker support than the KIP currently
> offers.
> >>>>>>>>>
> >>>>>>>>>
> >>>>>>>>>
> >>>>>>>>> Jun
> >>>>>>>>>
> >>>>>>>>> On Tue, Mar 6, 2018 at 10:33 PM, Jan Filipiak <
> >>>>>>>>>
> >>>>>>>>>> Jan.Filipiak@trivago.com
> >>>>>>>>>> wrote:
> >>>>>>>>>>
> >>>>>>>>>> Hi Dong,
> >>>>>>>>>>
> >>>>>>>>>> are you actually reading my emails, or are you just using the
> >>>>>>>>>> thread I
> >>>>>>>>>>
> >>>>>>>>>> started for general announcements regarding the KIP?
> >>>>>>>>>>>
> >>>>>>>>>>> I tried to argue really hard against linear hashing. Growing
> the
> >>>>>>>>>>> topic
> >>>>>>>>>>> by
> >>>>>>>>>>> an integer factor does not require any state redistribution at
> >>>>>>>>>>> all. I
> >>>>>>>>>>> fail
> >>>>>>>>>>> to see completely where linear hashing helps on log compacted
> >>>>>>>>>>> topics.
> >>>>>>>>>>>
> >>>>>>>>>>> If you are not willing to explain to me what I might be
> >>>>>>>>>>> overlooking:
> >>>>>>>>>>> that
> >>>>>>>>>>> is fine.
> >>>>>>>>>>> But I ask you to not reply to my emails then. Please understand
> >>>>>>>>>>> my
> >>>>>>>>>>> frustration with this.
> >>>>>>>>>>>
> >>>>>>>>>>> Best Jan
> >>>>>>>>>>>
> >>>>>>>>>>>
> >>>>>>>>>>>
> >>>>>>>>>>> On 06.03.2018 19:38, Dong Lin wrote:
> >>>>>>>>>>>
> >>>>>>>>>>> Hi everyone,
> >>>>>>>>>>>
> >>>>>>>>>>> Thanks for all the comments! It appears that everyone prefers
> >>>>>>>>>>> linear
> >>>>>>>>>>>
> >>>>>>>>>>> hashing because it reduces the amount of state that needs to be
> >>>>>>>>>>>> moved
> >>>>>>>>>>>> between consumers (for stream processing). The KIP has been
> >>>>>>>>>>>> updated
> >>>>>>>>>>>> to
> >>>>>>>>>>>> use
> >>>>>>>>>>>> linear hashing.
> >>>>>>>>>>>>
> >>>>>>>>>>>> Regarding the migration endeavor: it seems that migrating
> >>>>>>>>>>>> producer
> >>>>>>>>>>>> library
> >>>>>>>>>>>> to use linear hashing should be pretty straightforward without
> >>>>>>>>>>>> much operational endeavor. If we don't upgrade client library
> to
> >>>>>>>>>>>> use
> >>>>>>>>>>>> this
> >>>>>>>>>>>> KIP, we can not support in-order delivery after partition is
> >>>>>>>>>>>> changed
> >>>>>>>>>>>> anyway. Suppose we upgrade client library to use this KIP, if
> >>>>>>>>>>>> partition
> >>>>>>>>>>>> number is not changed, the key -> partition mapping will be
> >>>>>>>>>>>> exactly
> >>>>>>>>>>>> the
> >>>>>>>>>>>> same as it is now because it is still determined using
> >>>>>>>>>>>> murmur_hash(key)
> >>>>>>>>>>>> %
> >>>>>>>>>>>> original_partition_num. In other words, this change is
> backward
> >>>>>>>>>>>> compatible.
> >>>>>>>>>>>>
> >>>>>>>>>>>> Regarding the load distribution: if we use linear hashing, the
> >>>>>>>>>>>> load
> >>>>>>>>>>>> may
> >>>>>>>>>>>> be
> >>>>>>>>>>>> unevenly distributed because those partitions which are not
> >>>>>>>>>>>> split
> >>>>>>>>>>>> may
> >>>>>>>>>>>> receive twice as much traffic as other partitions that are
> >>>>>>>>>>>> split.
> >>>>>>>>>>>> This
> >>>>>>>>>>>> issue can be mitigated by creating topic with partitions that
> >>>>>>>>>>>> are
> >>>>>>>>>>>> several
> >>>>>>>>>>>> times the number of consumers. And there will be no imbalance
> if
> >>>>>>>>>>>> the
> >>>>>>>>>>>> partition number is always doubled. So this imbalance seems
> >>>>>>>>>>>> acceptable.
> >>>>>>>>>>>>
> >>>>>>>>>>>> Regarding storing the partition strategy as per-topic config:
> It
> >>>>>>>>>>>> seems
> >>>>>>>>>>>> not
> >>>>>>>>>>>> necessary since we can still use murmur_hash as the default
> hash
> >>>>>>>>>>>> function
> >>>>>>>>>>>> and additionally apply the linear hashing algorithm if the
> >>>>>>>>>>>> partition
> >>>>>>>>>>>> number
> >>>>>>>>>>>> has increased. Not sure if there is any use-case for producer
> to
> >>>>>>>>>>>> use a
> >>>>>>>>>>>> different hash function. Jason, can you check if there is some
> >>>>>>>>>>>> use-case
> >>>>>>>>>>>> that I missed for using the per-topic partition strategy?
> >>>>>>>>>>>>
> >>>>>>>>>>>> Regarding how to reduce latency (due to state store/load) in
> >>>>>>>>>>>> stream
> >>>>>>>>>>>> processing consumer when partition number changes: I need to
> >>>>>>>>>>>> read
> >>>>>>>>>>>> the
> >>>>>>>>>>>> Kafka
> >>>>>>>>>>>> Stream code to understand how Kafka Stream currently migrate
> >>>>>>>>>>>> state
> >>>>>>>>>>>> between
> >>>>>>>>>>>> consumers when the application is added/removed for a given
> >>>>>>>>>>>> job. I
> >>>>>>>>>>>> will
> >>>>>>>>>>>> reply after I finish reading the documentation and code.
> >>>>>>>>>>>>
> >>>>>>>>>>>>
> >>>>>>>>>>>> Thanks,
> >>>>>>>>>>>> Dong
> >>>>>>>>>>>>
> >>>>>>>>>>>>
> >>>>>>>>>>>> On Mon, Mar 5, 2018 at 10:43 AM, Jason Gustafson <
> >>>>>>>>>>>> jason@confluent.io>
> >>>>>>>>>>>> wrote:
> >>>>>>>>>>>>
> >>>>>>>>>>>> Great discussion. I think I'm wondering whether we can
> continue
> >>>>>>>>>>>> to
> >>>>>>>>>>>> leave
> >>>>>>>>>>>>
> >>>>>>>>>>>> Kafka agnostic to the partitioning strategy. The challenge is
> >>>>>>>>>>>>
> >>>>>>>>>>>> communicating
> >>>>>>>>>>>>
> >>>>>>>>>>>>> the partitioning logic from producers to consumers so that
> the
> >>>>>>>>>>>>> dependencies
> >>>>>>>>>>>>> between each epoch can be determined. For the sake of
> >>>>>>>>>>>>> discussion,
> >>>>>>>>>>>>> imagine
> >>>>>>>>>>>>> you did something like the following:
> >>>>>>>>>>>>>
> >>>>>>>>>>>>> 1. The name (and perhaps version) of a partitioning strategy
> is
> >>>>>>>>>>>>> stored
> >>>>>>>>>>>>> in
> >>>>>>>>>>>>> topic configuration when a topic is created.
> >>>>>>>>>>>>> 2. The producer looks up the partitioning strategy before
> >>>>>>>>>>>>> writing
> >>>>>>>>>>>>> to
> >>>>>>>>>>>>> a
> >>>>>>>>>>>>> topic and includes it in the produce request (for fencing).
> If
> >>>>>>>>>>>>> it
> >>>>>>>>>>>>> doesn't
> >>>>>>>>>>>>> have an implementation for the configured strategy, it fails.
> >>>>>>>>>>>>> 3. The consumer also looks up the partitioning strategy and
> >>>>>>>>>>>>> uses
> >>>>>>>>>>>>> it
> >>>>>>>>>>>>> to
> >>>>>>>>>>>>> determine dependencies when reading a new epoch. It could
> >>>>>>>>>>>>> either
> >>>>>>>>>>>>> fail
> >>>>>>>>>>>>> or
> >>>>>>>>>>>>> make the most conservative dependency assumptions if it
> doesn't
> >>>>>>>>>>>>> know
> >>>>>>>>>>>>> how
> >>>>>>>>>>>>> to
> >>>>>>>>>>>>> implement the partitioning strategy. For the consumer, the
> new
> >>>>>>>>>>>>> interface
> >>>>>>>>>>>>> might look something like this:
> >>>>>>>>>>>>>
> >>>>>>>>>>>>> // Return the partition dependencies following an epoch bump
> >>>>>>>>>>>>> Map<Integer, List<Integer>> dependencies(int
> >>>>>>>>>>>>> numPartitionsBeforeEpochBump,
> >>>>>>>>>>>>> int numPartitionsAfterEpochBump)
> >>>>>>>>>>>>>
> >>>>>>>>>>>>> The unordered case then is just a particular implementation
> >>>>>>>>>>>>> which
> >>>>>>>>>>>>> never
> >>>>>>>>>>>>> has
> >>>>>>>>>>>>> any epoch dependencies. To implement this, we would need some
> >>>>>>>>>>>>> way
> >>>>>>>>>>>>> for
> >>>>>>>>>>>>> the
> >>>>>>>>>>>>> consumer to find out how many partitions there were in each
> >>>>>>>>>>>>> epoch,
> >>>>>>>>>>>>> but
> >>>>>>>>>>>>> maybe that's not too unreasonable.
> >>>>>>>>>>>>>
> >>>>>>>>>>>>> Thanks,
> >>>>>>>>>>>>> Jason
> >>>>>>>>>>>>>
> >>>>>>>>>>>>>
> >>>>>>>>>>>>> On Mon, Mar 5, 2018 at 4:51 AM, Jan Filipiak <
> >>>>>>>>>>>>> Jan.Filipiak@trivago.com
> >>>>>>>>>>>>> wrote:
> >>>>>>>>>>>>>
> >>>>>>>>>>>>> Hi Dong
> >>>>>>>>>>>>>
> >>>>>>>>>>>>> thank you very much for your questions.
> >>>>>>>>>>>>>
> >>>>>>>>>>>>> regarding the time spend copying data across:
> >>>>>>>>>>>>>
> >>>>>>>>>>>>>> It is correct that copying data from a topic with one
> >>>>>>>>>>>>>> partition
> >>>>>>>>>>>>>> mapping
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>> to
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>> a topic with a different partition mapping takes way longer
> >>>>>>>>>>>>>> than
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>> we
> >>>>>>>>>>>>> can
> >>>>>>>>>>>>>
> >>>>>>>>>>>>> stop producers. Tens of minutes is a very optimistic estimate
> >>>>>>>>>>>>> here.
> >>>>>>>>>>>>>
> >>>>>>>>>>>>> Many
> >>>>>>>>>>>>>> people can not afford copy full steam and therefore will
> have
> >>>>>>>>>>>>>> some
> >>>>>>>>>>>>>> rate
> >>>>>>>>>>>>>> limiting in place, this can bump the timespan into the
> day's.
> >>>>>>>>>>>>>> The
> >>>>>>>>>>>>>> good
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>> part
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>> is that the vast majority of the data can be copied while
> the
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>> producers
> >>>>>>>>>>>>>
> >>>>>>>>>>>>> are
> >>>>>>>>>>>>>
> >>>>>>>>>>>>> still going. One can then, piggyback the consumers ontop of
> >>>>>>>>>>>>>> this
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>> timeframe,
> >>>>>>>>>>>>>
> >>>>>>>>>>>>> by the method mentioned (provide them an mapping from their
> old
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>> offsets
> >>>>>>>>>>>>>
> >>>>>>>>>>>>> to
> >>>>>>>>>>>>>
> >>>>>>>>>>>>> new offsets in their repartitioned topics. In that way we
> >>>>>>>>>>>>>> separate
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>> migration of consumers from migration of producers
> (decoupling
> >>>>>>>>>>>>>
> >>>>>>>>>>>>> these
> >>>>>>>>>>>>>> is
> >>>>>>>>>>>>>> what kafka is strongest at). The time to actually swap over
> >>>>>>>>>>>>>> the
> >>>>>>>>>>>>>> producers
> >>>>>>>>>>>>>> should be kept minimal by ensuring that when a swap attempt
> is
> >>>>>>>>>>>>>> started
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>> the
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>> consumer copying over should be very close to the log end
> and
> >>>>>>>>>>>>>> is
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>> expected
> >>>>>>>>>>>>>
> >>>>>>>>>>>>> to finish within the next fetch. The operation should have a
> >>>>>>>>>>>>>> time-out
> >>>>>>>>>>>>>> and
> >>>>>>>>>>>>>> should be "reattemtable".
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>> Importance of logcompaction:
> >>>>>>>>>>>>>> If a producer produces key A, to partiton 0, its forever
> gonna
> >>>>>>>>>>>>>> be
> >>>>>>>>>>>>>> there,
> >>>>>>>>>>>>>> unless it gets deleted. The record might sit in there for
> >>>>>>>>>>>>>> years. A
> >>>>>>>>>>>>>> new
> >>>>>>>>>>>>>> producer started with the new partitions will fail to delete
> >>>>>>>>>>>>>> the
> >>>>>>>>>>>>>> record
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>> in
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>> the correct partition. Th record will be there forever and
> one
> >>>>>>>>>>>>>> can
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>> not
> >>>>>>>>>>>>>
> >>>>>>>>>>>>> reliable bootstrap new consumers. I cannot see how linear
> >>>>>>>>>>>>> hashing
> >>>>>>>>>>>>>
> >>>>>>>>>>>>> can
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>> solve
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>> this.
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>> Regarding your skipping of userland copying:
> >>>>>>>>>>>>>
> >>>>>>>>>>>>> 100%, copying the data across in userland is, as far as i can
> >>>>>>>>>>>>>> see,
> >>>>>>>>>>>>>> only
> >>>>>>>>>>>>>> a
> >>>>>>>>>>>>>> usecase for log compacted topics. Even for logcompaction +
> >>>>>>>>>>>>>> retentions
> >>>>>>>>>>>>>> it
> >>>>>>>>>>>>>> should only be opt-in. Why did I bring it up? I think log
> >>>>>>>>>>>>>> compaction
> >>>>>>>>>>>>>> is
> >>>>>>>>>>>>>> a
> >>>>>>>>>>>>>> very important feature to really embrace kafka as a "data
> >>>>>>>>>>>>>> plattform".
> >>>>>>>>>>>>>> The
> >>>>>>>>>>>>>> point I also want to make is that copying data this way is
> >>>>>>>>>>>>>> completely
> >>>>>>>>>>>>>> inline with the kafka architecture. it only consists of
> >>>>>>>>>>>>>> reading
> >>>>>>>>>>>>>> and
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>> writing
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>> to topics.
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>> I hope it clarifies more why I think we should aim for more
> >>>>>>>>>>>>> than
> >>>>>>>>>>>>>
> >>>>>>>>>>>>> the
> >>>>>>>>>>>>>> current KIP. I fear that once the KIP is done not much more
> >>>>>>>>>>>>>> effort
> >>>>>>>>>>>>>> will
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>> be
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>> taken.
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>> On 04.03.2018 02:28, Dong Lin wrote:
> >>>>>>>>>>>>>
> >>>>>>>>>>>>>> Hey Jan,
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>> In the current proposal, the consumer will be blocked on
> >>>>>>>>>>>>>> waiting
> >>>>>>>>>>>>>> for
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>> other
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>>> consumers of the group to consume up to a given offset. In
> >>>>>>>>>>>>>>> most
> >>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>> cases,
> >>>>>>>>>>>>>> all
> >>>>>>>>>>>>>> consumers should be close to the LEO of the partitions when
> >>>>>>>>>>>>>> the
> >>>>>>>>>>>>>> partition
> >>>>>>>>>>>>>> expansion happens. Thus the time waiting should not be long
> >>>>>>>>>>>>>> e.g.
> >>>>>>>>>>>>>> on
> >>>>>>>>>>>>>> the
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>> order of seconds. On the other hand, it may take a long time
> >>>>>>>>>>>>>> to
> >>>>>>>>>>>>>> wait
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>> for
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>>> the entire partition to be copied -- the amount of time is
> >>>>>>>>>>>>>>> proportional
> >>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>> to
> >>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>> the amount of existing data in the partition, which can
> take
> >>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>> tens of
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>> minutes. So the amount of time that we stop consumers may
> not
> >>>>>>>>>>>>>> be
> >>>>>>>>>>>>>> on
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>> the
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>>> same order of magnitude.
> >>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>> If we can implement this suggestion without copying data
> over
> >>>>>>>>>>>>>>> in
> >>>>>>>>>>>>>>> purse
> >>>>>>>>>>>>>>> userland, it will be much more valuable. Do you have ideas
> on
> >>>>>>>>>>>>>>> how
> >>>>>>>>>>>>>>> this
> >>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>> can
> >>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>> be done?
> >>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>> Not sure why the current KIP not help people who depend on
> >>>>>>>>>>>>>> log
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>> compaction.
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>>> Could you elaborate more on this point?
> >>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>> Thanks,
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>> Dong
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>>> On Wed, Feb 28, 2018 at 10:55 PM, Jan
> >>>>>>>>>>>>>>> Filipiak<Jan.Filipiak@trivago.
> >>>>>>>>>>>>>>> com
> >>>>>>>>>>>>>>> wrote:
> >>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>> Hi Dong,
> >>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>> I tried to focus on what the steps are one can currently
> >>>>>>>>>>>>>>> perform
> >>>>>>>>>>>>>>> to
> >>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>> expand
> >>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>> or shrink a keyed topic while maintaining a top notch
> >>>>>>>>>>>>>>>> semantics.
> >>>>>>>>>>>>>>>> I can understand that there might be confusion about
> >>>>>>>>>>>>>>>> "stopping
> >>>>>>>>>>>>>>>> the
> >>>>>>>>>>>>>>>> consumer". It is exactly the same as proposed in the KIP.
> >>>>>>>>>>>>>>>> there
> >>>>>>>>>>>>>>>> needs
> >>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>> to
> >>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>> be
> >>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>> a time the producers agree on the new partitioning. The
> >>>>>>>>>>>>>>> extra
> >>>>>>>>>>>>>>>
> >>>>>>>>>>>>>> semantics I
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>>> want to put in there is that we have a possibility to wait
> >>>>>>>>>>>>>>>> until
> >>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>> all
> >>>>>>>>>>>>>>>
> >>>>>>>>>>>>>> the
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>> existing data
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>>> is copied over into the new partitioning scheme. When I say
> >>>>>>>>>>>>>>>
> >>>>>>>>>>>>>> stopping
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>> I
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>>> think more of having a memory barrier that ensures the
> >>>>>>>>>>>>>>>> ordering. I
> >>>>>>>>>>>>>>>> am
> >>>>>>>>>>>>>>>> still
> >>>>>>>>>>>>>>>> aming for latencies  on the scale of leader failovers.
> >>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>> Consumers have to explicitly adapt the new partitioning
> >>>>>>>>>>>>>>>> scheme
> >>>>>>>>>>>>>>>> in
> >>>>>>>>>>>>>>>> the
> >>>>>>>>>>>>>>>> above scenario. The reason is that in these cases where
> you
> >>>>>>>>>>>>>>>> are
> >>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>> dependent
> >>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>> on a particular partitioning scheme, you also have other
> >>>>>>>>>>>>>>>> topics
> >>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>> that
> >>>>>>>>>>>>>>>
> >>>>>>>>>>>>>> have
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>> co-partition enforcements or the kind -frequently. Therefore
> >>>>>>>>>>>>>> all
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>>> your
> >>>>>>>>>>>>>>>
> >>>>>>>>>>>>>> other
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>> input topics might need to grow accordingly.
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>>> What I was suggesting was to streamline all these
> operations
> >>>>>>>>>>>>>>>> as
> >>>>>>>>>>>>>>>> best
> >>>>>>>>>>>>>>>> as
> >>>>>>>>>>>>>>>> possible to have "real" partition grow and shrinkage going
> >>>>>>>>>>>>>>>> on.
> >>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>> Migrating
> >>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>> the producers to a new partitioning scheme can be much
> more
> >>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>> streamlined
> >>>>>>>>>>>>>>>
> >>>>>>>>>>>>>> with proper broker support for this. Migrating consumer is a
> >>>>>>>>>>>>>> step
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>> that
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>>> might be made completly unnecessary if - for example
> streams
> >>>>>>>>>>>>>>>> -
> >>>>>>>>>>>>>>>> takes
> >>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>> the
> >>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>> gcd as partitioning scheme instead of enforcing 1 to 1.
> >>>>>>>>>>>>>>>> Connect
> >>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>> consumers
> >>>>>>>>>>>>>>>
> >>>>>>>>>>>>>> and other consumers should be fine anyways.
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>>> I hope this makes more clear where I was aiming at. The
> rest
> >>>>>>>>>>>>>>>
> >>>>>>>>>>>>>> needs
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>> to
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>>> be
> >>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>> figured out. The only danger i see is that when we are
> >>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>> introducing
> >>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>> this
> >>>>>>>>>>>>>>>
> >>>>>>>>>>>>>> feature as supposed in the KIP, it wont help any people
> >>>>>>>>>>>>>> depending
> >>>>>>>>>>>>>> on
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>> log
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>>> compaction.
> >>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>> The other thing I wanted to mention is that I believe the
> >>>>>>>>>>>>>>>
> >>>>>>>>>>>>>> current
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>> suggestion (without copying data over) can be implemented in
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>>> pure
> >>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>> userland
> >>>>>>>>>>>>>>>> with a custom partitioner and a small feedbackloop from
> >>>>>>>>>>>>>>>> ProduceResponse
> >>>>>>>>>>>>>>>> =>
> >>>>>>>>>>>>>>>> Partitionier in coorporation with a change management
> >>>>>>>>>>>>>>>> system.
> >>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>> Best Jan
> >>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>> On 28.02.2018 07:13, Dong Lin wrote:
> >>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>> Hey Jan,
> >>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>> I am not sure if it is acceptable for producer to be
> stopped
> >>>>>>>>>>>>>>>> for a
> >>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>> while,
> >>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>> particularly for online application which requires low
> >>>>>>>>>>>>>>>>> latency. I
> >>>>>>>>>>>>>>>>> am
> >>>>>>>>>>>>>>>>> also
> >>>>>>>>>>>>>>>>> not sure how consumers can switch to a new topic. Does
> user
> >>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>> application
> >>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>> needs to explicitly specify a different topic for
> >>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>> producer/consumer
> >>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>> to
> >>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>> subscribe to? It will be helpful for discussion if you can
> >>>>>>>>>>>>>> provide
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>> more
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>>> detail on the interface change for this solution.
> >>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>> Thanks,
> >>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>> Dong
> >>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>> On Mon, Feb 26, 2018 at 12:48 AM, Jan
> >>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>> Filipiak<Jan.Filipiak@trivago.
> >>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>> com
> >>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>> wrote:
> >>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>> Hi,
> >>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>> just want to throw my though in. In general the
> functionality
> >>>>>>>>>>>>>>> is
> >>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>> very
> >>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>> usefull, we should though not try to find the
> architecture
> >>>>>>>>>>>>>>>>> to
> >>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>> hard
> >>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>>> while
> >>>>>>>>>>>>>>>>>> implementing.
> >>>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>>> The manual steps would be to
> >>>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>>> create a new topic
> >>>>>>>>>>>>>>>>>> the mirrormake from the new old topic to the new topic
> >>>>>>>>>>>>>>>>>> wait for mirror making to catch up.
> >>>>>>>>>>>>>>>>>> then put the consumers onto the new topic
> >>>>>>>>>>>>>>>>>>             (having mirrormaker spit out a mapping from
> >>>>>>>>>>>>>>>>>> old
> >>>>>>>>>>>>>>>>>> offsets to
> >>>>>>>>>>>>>>>>>> new
> >>>>>>>>>>>>>>>>>> offsets:
> >>>>>>>>>>>>>>>>>>                 if topic is increased by factor X there
> is
> >>>>>>>>>>>>>>>>>> gonna
> >>>>>>>>>>>>>>>>>> be a
> >>>>>>>>>>>>>>>>>> clean
> >>>>>>>>>>>>>>>>>> mapping from 1 offset in the old topic to X offsets in
> the
> >>>>>>>>>>>>>>>>>> new
> >>>>>>>>>>>>>>>>>> topic,
> >>>>>>>>>>>>>>>>>>                 if there is no factor then there is no
> >>>>>>>>>>>>>>>>>> chance to
> >>>>>>>>>>>>>>>>>> generate a
> >>>>>>>>>>>>>>>>>> mapping that can be reasonable used for continuing)
> >>>>>>>>>>>>>>>>>>             make consumers stop at appropriate points
> and
> >>>>>>>>>>>>>>>>>> continue
> >>>>>>>>>>>>>>>>>> consumption
> >>>>>>>>>>>>>>>>>> with offsets from the mapping.
> >>>>>>>>>>>>>>>>>> have the producers stop for a minimal time.
> >>>>>>>>>>>>>>>>>> wait for mirrormaker to finish
> >>>>>>>>>>>>>>>>>> let producer produce with the new metadata.
> >>>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>>> Instead of implementing the approach suggest in the KIP
> >>>>>>>>>>>>>>>>>> which
> >>>>>>>>>>>>>>>>>> will
> >>>>>>>>>>>>>>>>>> leave
> >>>>>>>>>>>>>>>>>> log compacted topic completely crumbled and unusable.
> >>>>>>>>>>>>>>>>>> I would much rather try to build infrastructure to
> support
> >>>>>>>>>>>>>>>>>> the
> >>>>>>>>>>>>>>>>>> mentioned
> >>>>>>>>>>>>>>>>>> above operations more smoothly.
> >>>>>>>>>>>>>>>>>> Especially having producers stop and use another topic
> is
> >>>>>>>>>>>>>>>>>> difficult
> >>>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>>> and
> >>>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>>> it would be nice if one can trigger "invalid metadata"
> >>>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>>> exceptions
> >>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>> for
> >>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>> them
> >>>>>>>>>>>>>>>
> >>>>>>>>>>>>>> and
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>>> if one could give topics aliases so that their produces
> with
> >>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>> the
> >>>>>>>>>>>>>>>>>> old
> >>>>>>>>>>>>>>>>>> topic
> >>>>>>>>>>>>>>>>>> will arrive in the new topic.
> >>>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>>> The downsides are obvious I guess ( having the same data
> >>>>>>>>>>>>>>>>>> twice
> >>>>>>>>>>>>>>>>>> for
> >>>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>>> the
> >>>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>>> transition period, but kafka tends to scale well with
> >>>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>>> datasize).
> >>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>> So
> >>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>> its a
> >>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>> nicer fit into the architecture.
> >>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>> I further want to argument that the functionality by the
> KIP
> >>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>> can
> >>>>>>>>>>>>>>>>>> completely be implementing in "userland" with a custom
> >>>>>>>>>>>>>>>>>> partitioner
> >>>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>>> that
> >>>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>>> handles the transition as needed. I would appreciate if
> >>>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>>> someone
> >>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>> could
> >>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>> point
> >>>>>>>>>>>>>>>
> >>>>>>>>>>>>>> out what a custom partitioner couldn't handle in this case?
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>>> With the above approach, shrinking a topic becomes the same
> >>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>> steps.
> >>>>>>>>>>>>>>>>>> Without
> >>>>>>>>>>>>>>>>>> loosing keys in the discontinued partitions.
> >>>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>>> Would love to hear what everyone thinks.
> >>>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>>> Best Jan
> >>>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>>> On 11.02.2018 00:35, Dong Lin wrote:
> >>>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>>> Hi all,
> >>>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>>> I have created KIP-253: Support in-order message
> delivery
> >>>>>>>>>>>>>>>>>> with
> >>>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>>> partition
> >>>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>>> expansion. See
> >>>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>>>> https://cwiki.apache.org/confl
> >>>>>>>>>>>>>>>>>>> uence/display/KAFKA/KIP-253%
> >>>>>>>>>>>>>>>>>>> 3A+Support+in-order+message+de
> >>>>>>>>>>>>>>>>>>> livery+with+partition+expansio
> >>>>>>>>>>>>>>>>>>> n
> >>>>>>>>>>>>>>>>>>> .
> >>>>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>>>> This KIP provides a way to allow messages of the same
> key
> >>>>>>>>>>>>>>>>>>> from
> >>>>>>>>>>>>>>>>>>> the
> >>>>>>>>>>>>>>>>>>> same
> >>>>>>>>>>>>>>>>>>> producer to be consumed in the same order they are
> >>>>>>>>>>>>>>>>>>> produced
> >>>>>>>>>>>>>>>>>>> even
> >>>>>>>>>>>>>>>>>>> if
> >>>>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>>>> we
> >>>>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>>>> expand partition of the topic.
> >>>>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>>>> Thanks,
> >>>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>> Dong
> >>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>>>>
> >>>
> >
>

Re: [DISCUSS] KIP-253: Support in-order message delivery with partition expansion

Posted by Dong Lin <li...@gmail.com>.
Hey John,

Thanks much for the detailed comment. Here is my thought:

Regarding thought 1: I agree. The current proposal seems to have addressed
core problem. It has also provided the extra interface to support the
stream use-case. I have yet to come up with the solution to do the 2-phase
partition expansion to optimize the performance for stream use-case. But it
is not required for correctness. Do you think the current KIP meets the
requirement for thought 1?

Regarding thought 2: If we don't care about the stream use-case, then the
current KIP probably has already addressed problem without requiring
consumer to know the partition function. If we care about the stream
use-case, we already need coordination across producers of different
topics, i.e. the same partition function needs to be used by producers of
topics A and B in order to join topics A and B. Thus, it might be
reasonable to extend coordination a bit and say we need coordination across
clients (i.e. producer and consumer), such that consumer knows the
partition function used by producer. If we do so, then we can let consumer
re-copy data for the change log topic using the same partition function as
producer. This approach has lower overhead as compared to having producer
re-copy data of the input topic.

Also, producer currently does not need to know the data already produced to
the topic. If we let producer split/merge partition, it would require
producer to consume the existing data, which intuitively is the task of
consumer.

Regarding thought 3/4/5: Yeah we probably can figure out solution for
offset management etc. if we take the approach of copying input topic. But
after reading through the discussion between Jun and Jan, I am still not
sure why copying the input topic is better than copying the change log
topic. Maybe you could help summarize it? For core Kafka use-case, and for
the stream use-case that does not need to increase consumers, the current
KIP already supports in-order delivery without the overhead of copying the
data. For stream use-case that needs to increase consumer number, the
existing consumer can backfill the existing data in the change log topic to
the same change log topic with the new partition number, before the new set
of consumers bootstrap state from the new partitions of the change log
topic, right?

Regarding thought 6: The main concern with copying the input topic is the
performance overhead, i.e. the time-to-completion and the bandwidth
consumption of the brokers. Today the data copy between brokers is
essentially consume and produce. Copying data between brokers may be better
but still has the same performance concern. I guess the main question is
whether the performance overhead is worthwhile in comparison to copying the
change log topic for streaming use-case.

Regards,
Dong


On Mon, Mar 26, 2018 at 11:16 AM, John Roesler <jo...@confluent.io> wrote:

> Hi all,
>
> I hope you don't mind if I throw some thoughts in...
>
> For some reason, Jan's proposal wasn't really clear to me until this last
> message, and now that (I think) I understand it, I actually like it quite a
> lot.
>
> Thought 1:
> As much as I like Streams, I don't think it should become a requirement to
> pull off something like partition expansion. It would be a bummer if folks
> who otherwise have no use case for Streams have to run an trivial app
> *just* to get partition expansion.
>
> Assuming we get a nice partition-expansion design out of this conversation,
> It may or may not be the case that Streams will still decide to
> re-partition its inputs, but I'd like to keep those two designs (Core and
> Streams) independent (personal opinion, fwiw). It also may or may not be
> the case that we would try to split the local state versus re-building the
> affected operators from the new (post-split) topics. It would be nice to be
> able to optimize the process of scaling Streams independently of Core.
>
> Thought 2:
> Regarding who might manage this special backfill consumer, I wonder if the
> answer might actually be that that logic should be in the producer.
>
> Consider that only the producer knows the partition function, so locating
> backfill anywhere else requires sharing that logic, which would be a
> bummer.
>
> Also, if you think about the "producer" in the broader sense, as the
> organization that produces the data in a particular topic, that "producer"
> controls everything about the topic: the name, the number of partitions,
> the schema, and all of the configs including compaction and retention. This
> "producer" will be the person responsible for splitting/merging partitions
> anyway, so introducing a new component is asking that "producer" to own and
> operate more pieces, whereas placing inside the KafkaProducer keeps their
> operational burden the same.
>
> Thought 3:
> I don't think we want to think about actually creating a new topic, but
> instead something like a "generation" or "version" of a topic.
>
> Different generations of a topic can have different numbers of partitions,
> and also different offsets. Consumers can currently start with the earliest
> available offset. Similarly, with generations, consumers could start off
> with the earliest available in the earliest available generation. The
> retention policy still applies, so when the log cleaner deletes the last
> segment from a generation, that whole generation becomes unavailable, and
> new consumers start off on the next generation.
>
> This also makes the backfill job well defined: the range it's copying
> *from* has a start and an end; the range it's copying *to* is out of bounds
> for new writes. When backfill finishes copying all the records from
> generation 0 to the beginning of generation 1, it instructs the broker that
> generation 1, offset x is now the earliest available offset and all of
> generation 0's files can be deleted. The metadata tracking how to
> transition from gen0 to gen1 can also be deleted, as it's no longer
> meaningful.
>
> Note that for compacted topics, you really want to think of the number of
> partitions in the topic as the number of partitions in the first available
> partition. I.e., I think it's simplifying to assume that consumers may not
> be able to split their state. If I'm a consumer, and I don't have enough
> parallelism, I think I'd go to the producer and request an expansion. The
> producer would do the expansion and kick off the backfill. My existing
> consumers get assigned the new generations partitions such that each
> consumer gets the same set of records. When the backfill completes, *then*
> I can start up my new crop of more granular consumers. Being able to split
> and merge state when I hit topic generation barriers would obviously be
> nice, but I don't think it's universally available, so it's important to
> have a solid design around async backfill with notifications.
>
> Thought 4:
> I *think* Jan's approach works fine even if you want to split just one
> partition, instead of increasing the number of partitions by a factor.
> Plus, you could split the partition into any number of new partitions. It
> all depends on the partition function, which again comes back to it being
> nice to place the responsibility for all these decisions squarely with the
> producer. Maybe the default hash function requires them to double the
> partition count, but if they want to be able to split single partitions,
> they can use a hash function that makes that possible.
>
> We also need to remember that some topics don't use hashing at all to
> assign partitions, but round-robin instead. In this case, the partition
> assignment for a record is clearly arbitrary. In this case, I could see
> wanting to just increase the partition count, say from 2 to 3, and achieve
> a uniform re-distribution. This is the only use case that isn't well served
> by the "partition split" mentality. If you wanted a uniform re-distribution
> in this case, you would have to go from 2 to 4. Or, you could always create
> a truly new topic and get all your consumers to start consuming that one
> instead.
>
> Thought 5:
> This whole operation can be really straightforward if we're a little
> careful with the offsets. I think for expansion, you want to start the new
> generation off with the end offset of the old generation, and for merging,
> you want to add the end offsets of the two old-gen parent partitions. This
> way, you know that there will be enough room at the beginning of the
> partition for a potential backfill either way.
>
> In other words:
> Let's assume MyTopic has 3 partitions, and we're splitting partition 0 into
> two:
> MyTopic[gen=0,part=0,endOffset=50] -> (
> MyTopic[gen=1,part=0,endOffset=50], MyTopic[gen=1,part=3,endOffset=50]
> )
> MyTopic[gen=0,part=1,endOffset=41] -> ( MyTopic[gen=1,part=1,endOffset=41]
> )
> MyTopic[gen=0,part=2,endOffset=63] -> ( MyTopic[gen=1,part=2,endOffset=63]
> )
>
> *Maybe* the producer of MyTopic decides to backfill the split of part=0:
> 1) For each record, they run it though their partition function to decide
> between part=0 and part=3, instructing the broker to copy that record to
> the new generation's partition with the *same* offset.
> 2) When they reach the end of [gen=0,part=0], they instruct the broker that
> MyTopic[gen=1,part=1] now begins at offset=0 and MyTopic[gen=1,part=3] now
> begins at offset=1 (for example), and they also mark gen=0,part=0 as
> defunct.
>
> Assuming 4 Consumers: if they started reading during gen=0, they might have
> the following assignment:
> * consumer1: in gen=0, [part=0], transitioning to [part=0,part=3] at
> offset=50
> * consumer2: [part=1]
> * consumer3: [part=2]
> * consumer4: []
>
> Now, if they started reading during gen=1 after gen=0 becomes defunct, they
> might have this assignment:
> * consumer1: [part=0]
> * consumer2: [part=1]
> * consumer3: [part=2]
> * consumer4: [part=3]
>
> Just a quick note about the possibility of splitting without starting
> over... if consumer1 knows how to split its task, either because it's
> stateless or because it has splittable state, it certainly can and "send"
> part=3 to consumer4. So this avenue is still open.
>
> Thought 5.5:
> I think it's worth also sketching out the merge operation, as I'm picturing
> it.
> Let's assume we've got 4 partitions, and we want to merge part=1 and
> part=2:
> MyTopic[gen=0,part=0,endOffset=50] -> MyTopic[gen=1,part=0,endOffset=50]
> MyTopic[gen=0,part=1,endOffset=12] -> MyTopic[gen=1,part=1,endOffset=(12 +
> 23 = 35)]
> MyTopic[gen=0,part=2,endOffset=23] -> (see gen=1,part=1)
> MyTopic[gen=0,part=3,endOffset=41] -> MyTopic[gen=1,part=3,endOffset=41]
>
> Now, I think no matter how you cut it, this is going to be a tough
> transition for stateful consumers to handle. The good news is that the
> brokers can pull off a merge backfill very efficiently, by just copying
> part=2's segments into part=1 and using a little metadata to remember to
> add 12 to all the offsets it reads out of these segments. So, it might just
> have to be good enough to make merge super fast and then stateful consumers
> will have to rebuild their state for the affected partitions. Producers can
> be warned that while splitting is fine, merging may break their consumers.
>
> Thought 6:
> To pull off the split backfill, the broker will have to stream all the
> records to the producer's backfill worker, which is a bummer, but note that
> the backfill worker doesn't have to stream them back. It is sufficient just
> to send back the new partition assignment and offset for each (old
> partition,offset), since the records are going to keep their old timestamp,
> key, and value. The broker can then do its best to merge consecutive ranges
> and do efficient filesystem copies. Hopefully, the fact that backfill is
> async and producers and consumers can just continue working in the new
> generation while it happens, in combination with the fact that we only have
> to stream the data out and not back in to the broker makes this tolerable.
>
> Likewise, for partitions not undergoing a split can trivially backfill into
> the new generation by copying, moving, or hardlinking the segment files
> over, depending on the implementer's preference. The point is, it can be
> done without streaming that data back to the producer.
>
>
> All done!
> Now that (I think) I understand Jan's proposal, I agree it's a better way
> forward for the project than pulling Streams in to perform the repartition
> operation. Hopefully, my comments add a little to the conversation.
>
> Thanks,
> John
>
> On Fri, Mar 23, 2018 at 9:15 AM, Jan Filipiak <Ja...@trivago.com>
> wrote:
>
> > Hi Jun,
> >
> > thanks for your great reply, even though I only managed to throw a few
> > sentences in, because of time last time. I think you are starting to
> > understand me pretty well. There is still some minor things that need to
> be
> > flattened out. I already had these points previously but I try to
> rephrase
> > them into answers to your questions for clarity.
> >
> > On 23.03.2018 01:43, Jun Rao wrote:
> >
> >> Hi, Jan,
> >>
> >> Thanks for the reply.
> >>
> >> Ok. So your idea is to have a special consumer reshuffle the data to a
> new
> >> set of partitions. Each consumer group will not increase its tasks
> >> immediately. We just need to make sure that each consumer instance is
> >> assigned the set of new partitions covering the same set of keys. At
> some
> >> point later, each consumer group can decide independently when to
> increase
> >> the number of tasks. At that point, the consumer will need to rebuild
> the
> >> local state for the new tasks. Is that right?
> >>
> > This has multiple aspects. The middle part
> >
> >  We just need to make sure that each consumer instance is
> > assigned the set of new partitions covering the same set of keys
> >
> > is probably the most important one here. This is essentially what the
> > second part of my idea is about.
> > We need a protocol that allows consumers to switch from old topic (old
> > partiton count) to the new topic (new partion count). (If it really is a
> > new topic or not depends on the implementation -I like to model it as
> such
> > as its easier in my head). The protocol I envision is something like
> this:
> > Per partition there is information from the old offset to the new offset.
> >
> > topicOldMapping-0 : 50 => [0:25,2:25]
> > topicOldMapping-1 : 60 => [1:15,3:45]
> >
> > A consumer can get a hold on this information and stop at 50 and 60 and
> > continue at 25,25,15,45
> >
> > The same transition works when the data is not copied. a mapping would
> > look like
> >
> > topicOldMapping-0 : 50 => [0:0,2:0]
> > topicOldMapping-1 : 60 => [1:0,3:0]
> >
> > No data would have been copied and 50 and 60 are the endoffsets and we
> > would start at the very beginning of the new topic 0,0,0,0
> >
> >
> >> I agree that decoupling the number of tasks in a consumer group from the
> >> number of partitions in the input topic is a good idea. This allows each
> >> consumer group to change its degree of parallelism independently. There
> >> are
> >> different ways to achieve such decoupling. You suggested one approach,
> >> which works when splitting partitions. Not sure if this works in
> general,
> >> for example when merging partitions.
> >>
> > Merging is the same.
> >
> > topicOldMapping-0 : 25 => [0:50]
> > topicOldMapping-1 : 25 => [1:50]
> > topicOldMapping-2 : 15 => [0:50]
> > topicOldMapping-3 : 45 => [1:50]
> >
> > generating this mapping is trivial again if we do not copy data. (end
> > offsets point to start offsets)
> > If we do copy data the consumer will create the mapping.
> >
> >
> >> Once a consumer group decides to change its degree of parallelism, it
> >> needs
> >> to rebuild the local state for the new tasks. We can either rebuild the
> >> states from the input topic or from the local state (through change
> >> capture
> >> topic). I think we agreed that rebuilding from the local state is more
> >> efficient. It also seems that it's better to let the KStreams library do
> >> the state rebuilding, instead of each application. Would you agree?
> >>
> > If you want todo by RPC, you are changing the running application without
> > having a new good one. This
> > is against the kappa achitecture I would not recommend that.
> >
> > If you replay the changelog and only poll records that are for your
> > partition. You have the problem of knowing
> > which offset from the input topic your current state relates to.
> >
> > If you rebuild you could leave the old running and just wait for the new
> > to be _good_ then change who's output you
> > show to the customers.
> >
> >
> >> About the special consumer. I guess that's only needed if one wants to
> >> recopy the existing data? However, if we can truly decouple the tasks in
> >> the consumer group from the partitions in the input topic, it seems
> there
> >> is no need for copying existing data? It's also not clear to me who will
> >> start/stop this special consumer.
> >>
> > Who starts and stops it is also not very clear to me. I do not have
> strong
> > opinions.
> > The thing is that I am looking for an explanation how you can have a
> > logcompacted topic working without copying.
> > I agree that for running consumers its no problem as they are already
> past
> > the history. But the whole purpose of Log compaction
> > is to be able to bootstrap new consumers. They are completely lost with a
> > topic expanded without repartitioning.
> > The topic will be broken forever. and this is not acceptable.
> >
> > This is why I am so intrigued to model the problem as described because
> it
> > has no overhead for the no copy path while it allows
> > to also perform a copy.
> >
> > State handling wise one has also all the options. Exactly the 3 you
> > mentioned I guess. its just that this statestore RPC is a bad idea
> > and it was only invented to allow for optimisations that are better not
> > done.Not to say they are premature ;)
> >
> > I hope it makes it clear
> >
> > best jan
> >
> >
> >> Thanks,
> >>
> >> Jun
> >>
> >> On Wed, Mar 21, 2018 at 6:57 AM, Jan Filipiak <Jan.Filipiak@trivago.com
> >
> >> wrote:
> >>
> >> Hi Jun,
> >>>
> >>> I was really seeing progress in our conversation but your latest reply
> is
> >>> just devastating.
> >>> I though we were getting close being on the same page now it feels like
> >>> we
> >>> are in different libraries.
> >>>
> >>> I just quickly slam my answers in here. If they are to brief I am sorry
> >>> give me a ping and try to go into details more.
> >>> Just want to show that your pro/cons listing is broken.
> >>>
> >>> Best Jan
> >>>
> >>> and want to get rid of this horrible compromise
> >>>
> >>>
> >>> On 19.03.2018 05:48, Jun Rao wrote:
> >>>
> >>> Hi, Jan,
> >>>>
> >>>> Thanks for the discussion. Great points.
> >>>>
> >>>> Let me try to summarize the approach that you are proposing. On the
> >>>> broker
> >>>> side, we reshuffle the existing data in a topic from current
> partitions
> >>>> to
> >>>> the new partitions. Once the reshuffle fully catches up, switch the
> >>>> consumers to start consuming from the new partitions. If a consumer
> >>>> needs
> >>>> to rebuild its local state (due to partition changes), let the
> consumer
> >>>> rebuild its state by reading all existing data from the new
> partitions.
> >>>> Once all consumers have switches over, cut over the producer to the
> new
> >>>> partitions.
> >>>>
> >>>> The pros for this approach are that :
> >>>> 1. There is just one way to rebuild the local state, which is simpler.
> >>>>
> >>>> true thanks
> >>>
> >>> The cons for this approach are:
> >>>> 1. Need to copy existing data.
> >>>>
> >>>> Very unfair and not correct. It does not require you to copy over
> >>> existing
> >>> data. It _allows_ you to copy all existing data.
> >>>
> >>> 2. The cutover of the producer is a bit complicated since it needs to
> >>>
> >>>> coordinate with all consumer groups.
> >>>>
> >>>> Also not true. I explicitly tried to make clear that there is only one
> >>> special consumer (in the case of actually copying data) coordination is
> >>> required.
> >>>
> >>> 3. The rebuilding of the state in the consumer is from the input topic,
> >>>> which can be more expensive than rebuilding from the existing state.
> >>>>
> >>>> true, but rebuilding state is only required if you want to increase
> >>> processing power, so we assume this is at hand.
> >>>
> >>> 4. The broker potentially has to know the partitioning function. If
> this
> >>>> needs to be customized at the topic level, it can be a bit messy.
> >>>>
> >>>> I would argue against having the operation being performed by the
> >>> broker.
> >>> This was not discussed yet but if you see my original email i suggested
> >>> otherwise from the beginning.
> >>>
> >>> Here is an alternative approach by applying your idea not in the
> broker,
> >>>> but in the consumer. When new partitions are added, we don't move
> >>>> existing
> >>>> data. In KStreams, we first reshuffle the new input data to a new
> topic
> >>>> T1
> >>>> with the old number of partitions and feed T1's data to the rest of
> the
> >>>> pipeline. In the meantime, KStreams reshuffles all existing data of
> the
> >>>> change capture topic to another topic C1 with the new number of
> >>>> partitions.
> >>>> We can then build the state of the new tasks from C1. Once the new
> >>>> states
> >>>> have been fully built, we can cut over the consumption to the input
> >>>> topic
> >>>> and delete T1. This approach works with compacted topic too. If an
> >>>> application reads from the beginning of a compacted topic, the
> consumer
> >>>> will reshuffle the portion of the input when the number of partitions
> >>>> doesn't match the number of tasks.
> >>>>
> >>>> We all wipe this idea from our heads instantly. Mixing Ideas from an
> >>> argument is not a resolution strategy
> >>> just leads to horrible horrible software.
> >>>
> >>>
> >>> The pros of this approach are:
> >>>> 1. No need to copy existing data.
> >>>> 2. Each consumer group can cut over to the new partitions
> independently.
> >>>> 3. The state is rebuilt from the change capture topic, which is
> cheaper
> >>>> than rebuilding from the input topic.
> >>>> 4. Only the KStreams job needs to know the partitioning function.
> >>>>
> >>>> The cons of this approach are:
> >>>> 1. Potentially the same input topic needs to be reshuffled more than
> >>>> once
> >>>> in different consumer groups during the transition phase.
> >>>>
> >>>> What do you think?
> >>>>
> >>>> Thanks,
> >>>>
> >>>> Jun
> >>>>
> >>>>
> >>>>
> >>>> On Thu, Mar 15, 2018 at 1:04 AM, Jan Filipiak <
> Jan.Filipiak@trivago.com
> >>>> >
> >>>> wrote:
> >>>>
> >>>> Hi Jun,
> >>>>
> >>>>> thank you for following me on these thoughts. It was important to me
> to
> >>>>> feel that kind of understanding for my arguments.
> >>>>>
> >>>>> What I was hoping for (I mentioned this earlier) is that we can model
> >>>>> the
> >>>>> case where we do not want to copy the data the exact same way as the
> >>>>> case
> >>>>> when we do copy the data. Maybe you can peek into the mails before to
> >>>>> see
> >>>>> more details for this.
> >>>>>
> >>>>> This means we have the same mechanism to transfer consumer groups to
> >>>>> switch topic. The offset mapping that would be generated would even
> be
> >>>>> simpler End Offset of the Old topic => offset 0 off all the
> partitions
> >>>>> of
> >>>>> the new topic. Then we could model the transition of a non-copy
> >>>>> expansion
> >>>>> the exact same way as a copy-expansion.
> >>>>>
> >>>>> I know this only works when topic growth by a factor. But the
> benefits
> >>>>> of
> >>>>> only growing by a factor are to strong anyways. See Clemens's hint
> and
> >>>>> remember that state reshuffling is entirely not needed if one doesn't
> >>>>> want
> >>>>> to grow processing power.
> >>>>>
> >>>>> I think these benefits should be clear, and that there is basically
> no
> >>>>> downside to what is currently at hand but just makes everything easy.
> >>>>>
> >>>>> One thing you need to know is. that if you do not offer rebuilding a
> >>>>> log
> >>>>> compacted topic like i suggest that even if you have consumer state
> >>>>> reshuffling. The topic is broken and can not be used to bootstrap new
> >>>>> consumers. They don't know if they need to apply a key from and old
> >>>>> partition or not. This is a horrible downside I haven't seen a
> solution
> >>>>> for
> >>>>> in the email conversation.
> >>>>>
> >>>>> I argue to:
> >>>>>
> >>>>> Only grow topic by a factor always.
> >>>>> Have the "no copy consumer" transition as the trivial case of the
> "copy
> >>>>> consumer transition".
> >>>>> If processors needs to be scaled, let them rebuild from the new topic
> >>>>> and
> >>>>> leave the old running in the mean time.
> >>>>> Do not implement key shuffling in streams.
> >>>>>
> >>>>> I hope I can convince you especially with the fact how I want to
> handle
> >>>>> consumer transition. I think
> >>>>> you didn't quite understood me there before. I think the term "new
> >>>>> topic"
> >>>>> intimidated you a little.
> >>>>> How we solve this on disc doesn't really matter, If the data goes
> into
> >>>>> the
> >>>>> same Dir or a different Dir or anything. I do think that it needs to
> >>>>> involve at least rolling a new segment for the existing partitions.
> >>>>> But most of the transitions should work without restarting consumers.
> >>>>> (newer consumers with support for this). But with new topic i just
> >>>>> meant
> >>>>> the topic that now has a different partition count. Plenty of ways to
> >>>>> handle that (versions, aliases)
> >>>>>
> >>>>> Hope I can further get my idea across.
> >>>>>
> >>>>> Best Jan
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>> On 14.03.2018 02:45, Jun Rao wrote:
> >>>>>
> >>>>> Hi, Jan,
> >>>>>
> >>>>>> Thanks for sharing your view.
> >>>>>>
> >>>>>> I agree with you that recopying the data potentially makes the state
> >>>>>> management easier since the consumer can just rebuild its state from
> >>>>>> scratch (i.e., no need for state reshuffling).
> >>>>>>
> >>>>>> On the flip slide, I saw a few disadvantages of the approach that
> you
> >>>>>> suggested. (1) Building the state from the input topic from scratch
> is
> >>>>>> in
> >>>>>> general less efficient than state reshuffling. Let's say one
> computes
> >>>>>> a
> >>>>>> count per key from an input topic. The former requires reading all
> >>>>>> existing
> >>>>>> records in the input topic whereas the latter only requires reading
> >>>>>> data
> >>>>>> proportional to the number of unique keys. (2) The switching of the
> >>>>>> topic
> >>>>>> needs modification to the application. If there are many
> applications
> >>>>>> on a
> >>>>>> topic, coordinating such an effort may not be easy. Also, it's not
> >>>>>> clear
> >>>>>> how to enforce exactly-once semantic during the switch. (3) If a
> topic
> >>>>>> doesn't need any state management, recopying the data seems
> wasteful.
> >>>>>> In
> >>>>>> that case, in place partition expansion seems more desirable.
> >>>>>>
> >>>>>> I understand your concern about adding complexity in KStreams. But,
> >>>>>> perhaps
> >>>>>> we could iterate on that a bit more to see if it can be simplified.
> >>>>>>
> >>>>>> Jun
> >>>>>>
> >>>>>>
> >>>>>> On Mon, Mar 12, 2018 at 11:21 PM, Jan Filipiak <
> >>>>>> Jan.Filipiak@trivago.com>
> >>>>>> wrote:
> >>>>>>
> >>>>>> Hi Jun,
> >>>>>>
> >>>>>> I will focus on point 61 as I think its _the_ fundamental part that
> I
> >>>>>>> cant
> >>>>>>> get across at the moment.
> >>>>>>>
> >>>>>>> Kafka is the platform to have state materialized multiple times
> from
> >>>>>>> one
> >>>>>>> input. I emphasize this: It is the building block in architectures
> >>>>>>> that
> >>>>>>> allow you to
> >>>>>>> have your state maintained multiple times. You put a message in
> once,
> >>>>>>> and
> >>>>>>> you have it pop out as often as you like. I believe you understand
> >>>>>>> this.
> >>>>>>>
> >>>>>>> Now! The path of thinking goes the following: I am using apache
> kafka
> >>>>>>> and
> >>>>>>> I _want_ my state multiple times. What am I going todo?
> >>>>>>>
> >>>>>>> A) Am I going to take my state that I build up, plunge some sort of
> >>>>>>> RPC
> >>>>>>> layer ontop of it, use that RPC layer to throw my records across
> >>>>>>> instances?
> >>>>>>> B) Am I just going to read the damn message twice?
> >>>>>>>
> >>>>>>> Approach A is fundamentally flawed and a violation of all that is
> >>>>>>> good
> >>>>>>> and
> >>>>>>> holy in kafka deployments. I can not understand how this Idea can
> >>>>>>> come
> >>>>>>> in
> >>>>>>> the first place.
> >>>>>>> (I do understand: IQ in streams, they polluted the kafka streams
> >>>>>>> codebase
> >>>>>>> really bad already. It is not funny! I think they are equally
> flawed
> >>>>>>> as
> >>>>>>> A)
> >>>>>>>
> >>>>>>> I say, we do what Kafka is good at. We repartition the topic once.
> We
> >>>>>>> switch the consumers.
> >>>>>>> (Those that need more partitions are going to rebuild their state
> in
> >>>>>>> multiple partitions by reading the new topic, those that don't just
> >>>>>>> assign
> >>>>>>> the new partitions properly)
> >>>>>>> We switch producers. Done!
> >>>>>>>
> >>>>>>> The best thing! It is trivial, hipster stream processor will have
> an
> >>>>>>> easy
> >>>>>>> time with that aswell. Its so super simple. And simple IS good!
> >>>>>>> It is what kafka was build todo. It is how we do it today. All I am
> >>>>>>> saying
> >>>>>>> is that a little broker help doing the producer swap is super
> useful.
> >>>>>>>
> >>>>>>> For everyone interested in why kafka is so powerful with approach
> B,
> >>>>>>> please watch https://youtu.be/bEbeZPVo98c?t=1633
> >>>>>>> I already looked up a good point in time, I think after 5 minutes
> the
> >>>>>>> "state" topic is handled and you should be able to understand me
> >>>>>>> and inch better.
> >>>>>>>
> >>>>>>> Please do not do A to the project, it deserves better!
> >>>>>>>
> >>>>>>> Best Jan
> >>>>>>>
> >>>>>>>
> >>>>>>>
> >>>>>>> On 13.03.2018 02:40, Jun Rao wrote:
> >>>>>>>
> >>>>>>> Hi, Jan,
> >>>>>>>
> >>>>>>> Thanks for the reply. A few more comments below.
> >>>>>>>>
> >>>>>>>> 50. Ok, we can think a bit harder for supporting compacted topics.
> >>>>>>>>
> >>>>>>>> 51. This is a fundamental design question. In the more common
> case,
> >>>>>>>> the
> >>>>>>>> reason why someone wants to increase the number of partitions is
> >>>>>>>> that
> >>>>>>>> the
> >>>>>>>> consumer application is slow and one wants to run more consumer
> >>>>>>>> instances
> >>>>>>>> to increase the degree of parallelism. So, fixing the number of
> >>>>>>>> running
> >>>>>>>> consumer instances when expanding the partitions won't help this
> >>>>>>>> case.
> >>>>>>>> If
> >>>>>>>> we do need to increase the number of consumer instances, we need
> to
> >>>>>>>> somehow
> >>>>>>>> reshuffle the state of the consumer across instances. What we have
> >>>>>>>> been
> >>>>>>>> discussing in this KIP is whether we can do this more effectively
> >>>>>>>> through
> >>>>>>>> the KStream library (e.g. through a 2-phase partition expansion).
> >>>>>>>> This
> >>>>>>>> will
> >>>>>>>> add some complexity, but it's probably better than everyone doing
> >>>>>>>> this
> >>>>>>>> in
> >>>>>>>> the application space. The recopying approach that you mentioned
> >>>>>>>> doesn't
> >>>>>>>> seem to address the consumer state management issue when the
> >>>>>>>> consumer
> >>>>>>>> switches from an old to a new topic.
> >>>>>>>>
> >>>>>>>> 52. As for your example, it depends on whether the join key is the
> >>>>>>>> same
> >>>>>>>> between (A,B) and (B,C). If the join key is the same, we can do a
> >>>>>>>> 2-phase
> >>>>>>>> partition expansion of A, B, and C together. If the join keys are
> >>>>>>>> different, one would need to repartition the data on a different
> key
> >>>>>>>> for
> >>>>>>>> the second join, then the partition expansion can be done
> >>>>>>>> independently
> >>>>>>>> between (A,B) and (B,C).
> >>>>>>>>
> >>>>>>>> 53. If you always fix the number of consumer instances, we you
> >>>>>>>> described
> >>>>>>>> works. However, as I mentioned in #51, I am not sure how your
> >>>>>>>> proposal
> >>>>>>>> deals with consumer states when the number of consumer instances
> >>>>>>>> grows.
> >>>>>>>> Also, it just seems that it's better to avoid re-copying the
> >>>>>>>> existing
> >>>>>>>> data.
> >>>>>>>>
> >>>>>>>> 60. "just want to throw in my question from the longer email in
> the
> >>>>>>>> other
> >>>>>>>> Thread here. How will the bloom filter help a new consumer to
> decide
> >>>>>>>> to
> >>>>>>>> apply the key or not?" Not sure that I fully understood your
> >>>>>>>> question.
> >>>>>>>> The
> >>>>>>>> consumer just reads whatever key is in the log. The bloom filter
> >>>>>>>> just
> >>>>>>>> helps
> >>>>>>>> clean up the old keys.
> >>>>>>>>
> >>>>>>>> 61. "Why can we afford having a topic where its apparently not
> >>>>>>>> possible
> >>>>>>>> to
> >>>>>>>> start a new application on? I think this is an overall flaw of the
> >>>>>>>> discussed idea here. Not playing attention to the overall
> >>>>>>>> architecture."
> >>>>>>>> Could you explain a bit more when one can't start a new
> application?
> >>>>>>>>
> >>>>>>>> Jun
> >>>>>>>>
> >>>>>>>>
> >>>>>>>>
> >>>>>>>> On Sat, Mar 10, 2018 at 1:40 AM, Jan Filipiak <
> >>>>>>>> Jan.Filipiak@trivago.com
> >>>>>>>> wrote:
> >>>>>>>>
> >>>>>>>> Hi Jun, thanks for your mail.
> >>>>>>>>
> >>>>>>>> Thank you for your questions!
> >>>>>>>>
> >>>>>>>>> I think they are really good and tackle the core of the problem I
> >>>>>>>>> see.
> >>>>>>>>>
> >>>>>>>>> I will answer inline, mostly but still want to set the tone here.
> >>>>>>>>>
> >>>>>>>>> The core strength of kafka is what Martin once called the
> >>>>>>>>> kappa-Architecture. How does this work?
> >>>>>>>>> You have everything as a log as in kafka. When you need to change
> >>>>>>>>> something.
> >>>>>>>>> You create the new version of your application and leave it
> running
> >>>>>>>>> in
> >>>>>>>>> parallel.
> >>>>>>>>> Once the new version is good you switch your users to use the new
> >>>>>>>>> application.
> >>>>>>>>>
> >>>>>>>>> The online reshuffling effectively breaks this architecture and I
> >>>>>>>>> think
> >>>>>>>>> the switch in thinking here is more harmful
> >>>>>>>>> than any details about the partitioning function to allow such a
> >>>>>>>>> change.
> >>>>>>>>> I
> >>>>>>>>> feel with my suggestion we are the closest to
> >>>>>>>>> the original and battle proven architecture and I can only warn
> to
> >>>>>>>>> move
> >>>>>>>>> away from it.
> >>>>>>>>>
> >>>>>>>>> I might have forgotten something, sometimes its hard for me to
> >>>>>>>>> getting
> >>>>>>>>> all
> >>>>>>>>> the thoughts captured in a mail, but I hope the comments inline
> >>>>>>>>> will
> >>>>>>>>> further make my concern clear, and put some emphasis on why I
> >>>>>>>>> prefer
> >>>>>>>>> my
> >>>>>>>>> solution ;)
> >>>>>>>>>
> >>>>>>>>> One thing we should all be aware of when discussing this, and I
> >>>>>>>>> think
> >>>>>>>>> Dong
> >>>>>>>>> should have mentioned it (maybe he did).
> >>>>>>>>> We are not discussing all of this out of thin air but there is an
> >>>>>>>>> effort
> >>>>>>>>> in the Samza project.
> >>>>>>>>>
> >>>>>>>>> https://cwiki.apache.org/confluence/display/SAMZA/SEP-5%3A+
> >>>>>>>>> Enable+partition+expansion+of+input+streams
> >>>>>>>>> https://issues.apache.org/jira/browse/SAMZA-1293
> >>>>>>>>>
> >>>>>>>>> To be clear. I think SEP-5 (state of last week, dont know if it
> >>>>>>>>> adapted
> >>>>>>>>> to
> >>>>>>>>> this discussion) is on a way better path than KIP-253, and I
> can't
> >>>>>>>>> really
> >>>>>>>>> explain why.
> >>>>>>>>>
> >>>>>>>>> Best Jan,
> >>>>>>>>>
> >>>>>>>>> nice weekend everyone
> >>>>>>>>>
> >>>>>>>>>
> >>>>>>>>> On 09.03.2018 03:36, Jun Rao wrote:
> >>>>>>>>>
> >>>>>>>>> Hi, Jan,
> >>>>>>>>>
> >>>>>>>>> Thanks for the feedback. Just some comments on the earlier points
> >>>>>>>>>
> >>>>>>>>>> that
> >>>>>>>>>> you
> >>>>>>>>>> mentioned.
> >>>>>>>>>>
> >>>>>>>>>> 50. You brought up the question of whether existing data needs
> to
> >>>>>>>>>> be
> >>>>>>>>>> copied
> >>>>>>>>>> during partition expansion. My understand of your view is that
> >>>>>>>>>> avoid
> >>>>>>>>>> copying existing data will be more efficient, but it doesn't
> work
> >>>>>>>>>> well
> >>>>>>>>>> with
> >>>>>>>>>> compacted topics since some keys in the original partitions will
> >>>>>>>>>> never
> >>>>>>>>>> be
> >>>>>>>>>> cleaned. It would be useful to understand your use case of
> >>>>>>>>>> compacted
> >>>>>>>>>> topics
> >>>>>>>>>> a bit more. In the common use case, the data volume in a
> compacted
> >>>>>>>>>> topic
> >>>>>>>>>> may not be large. So, I am not sure if there is a strong need to
> >>>>>>>>>> expand
> >>>>>>>>>> partitions in a compacted topic, at least initially.
> >>>>>>>>>>
> >>>>>>>>>> I do agree. State is usually smaller. Update rates might be also
> >>>>>>>>>>
> >>>>>>>>>> competitively high.
> >>>>>>>>>>
> >>>>>>>>> Doing Log-compaction (even beeing very efficient and
> configurable)
> >>>>>>>>> is
> >>>>>>>>> also
> >>>>>>>>> a more expensive operation than
> >>>>>>>>> just discarding old segments. Further if you want to use more
> >>>>>>>>> consumers
> >>>>>>>>> processing the events
> >>>>>>>>> you also have to grow the number of partitions. Especially for
> >>>>>>>>> use-cases
> >>>>>>>>> we do (KIP-213) a tiny state full
> >>>>>>>>> table might be very expensive to process if it joins against a
> huge
> >>>>>>>>> table.
> >>>>>>>>>
> >>>>>>>>> I can just say we have been in the spot of needing to grow log
> >>>>>>>>> compacted
> >>>>>>>>> topics. Mainly for processing power we can bring to the table.
> >>>>>>>>>
> >>>>>>>>> Further i am not at all concerned about the extra spaced used by
> >>>>>>>>> "garbage
> >>>>>>>>> keys". I am more concerned about the correctness of innocent
> >>>>>>>>> consumers.
> >>>>>>>>> The
> >>>>>>>>> logic becomes complicated. Say for streams one would need to load
> >>>>>>>>> the
> >>>>>>>>> record into state but not forward it the topology ( to have it
> >>>>>>>>> available
> >>>>>>>>> for shuffeling). I rather have it simple and a topic clean
> >>>>>>>>> regardless
> >>>>>>>>> if
> >>>>>>>>> it
> >>>>>>>>> still has its old partition count. Especially with multiple
> >>>>>>>>> partitions
> >>>>>>>>> growth's I think it becomes insanely hard to to this shuffle
> >>>>>>>>> correct.
> >>>>>>>>> Maybe
> >>>>>>>>> Streams and Samza can do it. Especially if you do "hipster stream
> >>>>>>>>> processing" <https://www.confluent.io/blog
> >>>>>>>>> /introducing-kafka-streams-
> >>>>>>>>> stream-processing-made-simple/>. This makes kafka way to
> >>>>>>>>> complicated.
> >>>>>>>>> With my approach I think its way simpler because the topic has no
> >>>>>>>>> "history"
> >>>>>>>>> in terms of partitioning but is always clean.
> >>>>>>>>>
> >>>>>>>>>
> >>>>>>>>> 51. "Growing the topic by an integer factor does not require any
> >>>>>>>>> state
> >>>>>>>>>
> >>>>>>>>> redistribution at all." Could you clarify this a bit more? Let's
> >>>>>>>>> say
> >>>>>>>>>
> >>>>>>>>>> you
> >>>>>>>>>> have a consumer app that computes the windowed count per key. If
> >>>>>>>>>> you
> >>>>>>>>>> double
> >>>>>>>>>> the number of partitions from 1 to 2 and grow the consumer
> >>>>>>>>>> instances
> >>>>>>>>>> from
> >>>>>>>>>> 1
> >>>>>>>>>> to 2, we would need to redistribute some of the counts to the
> new
> >>>>>>>>>> consumer
> >>>>>>>>>> instance. Regarding to linear hashing, it's true that it won't
> >>>>>>>>>> solve
> >>>>>>>>>> the
> >>>>>>>>>> problem with compacted topics. The main benefit is that it
> >>>>>>>>>> redistributes
> >>>>>>>>>> the keys in one partition to no more than two partitions, which
> >>>>>>>>>> could
> >>>>>>>>>> help
> >>>>>>>>>> redistribute the state.
> >>>>>>>>>>
> >>>>>>>>>> You don't need to spin up a new consumer in this case. every
> >>>>>>>>>> consumer
> >>>>>>>>>>
> >>>>>>>>>> would just read every partition with the (partition % num_task)
> >>>>>>>>>>
> >>>>>>>>> task.
> >>>>>>>>> it
> >>>>>>>>> will still have the previous data right there and can go on.
> >>>>>>>>>
> >>>>>>>>> This sounds contradictory to what I said before, but please bear
> >>>>>>>>> with
> >>>>>>>>> me.
> >>>>>>>>>
> >>>>>>>>> 52. Good point on coordinating the expansion of 2 topics that
> need
> >>>>>>>>> to
> >>>>>>>>> be
> >>>>>>>>>
> >>>>>>>>> joined together. This is where the 2-phase partition expansion
> >>>>>>>>> could
> >>>>>>>>>
> >>>>>>>>>> potentially help. In the first phase, we could add new
> partitions
> >>>>>>>>>> to
> >>>>>>>>>> the 2
> >>>>>>>>>> topics one at a time but without publishing to the new
> patitions.
> >>>>>>>>>> Then,
> >>>>>>>>>> we
> >>>>>>>>>> can add new consumer instances to pick up the new partitions. In
> >>>>>>>>>> this
> >>>>>>>>>> transition phase, no reshuffling is needed since no data is
> coming
> >>>>>>>>>> from
> >>>>>>>>>> the
> >>>>>>>>>> new partitions. Finally, we can enable the publishing to the new
> >>>>>>>>>> partitions.
> >>>>>>>>>>
> >>>>>>>>>> I think its even worse than you think. I would like to introduce
> >>>>>>>>>> the
> >>>>>>>>>>
> >>>>>>>>>> Term
> >>>>>>>>>>
> >>>>>>>>> transitive copartitioning. Imagine
> >>>>>>>>> 2 streams application. One joins (A,B) the other (B,C) then there
> >>>>>>>>> is
> >>>>>>>>> a
> >>>>>>>>> transitive copartition requirement for
> >>>>>>>>> (A,C) to be copartitioned aswell. This can spread significantly
> and
> >>>>>>>>> require many consumers to adapt at the same time.
> >>>>>>>>>
> >>>>>>>>> It is also not entirely clear to me how you not need reshuffling
> in
> >>>>>>>>> this
> >>>>>>>>> case. If A has a record that never gets updated after the
> expansion
> >>>>>>>>> and
> >>>>>>>>> the
> >>>>>>>>> coresponding B record moves to a new partition. How shall they
> meet
> >>>>>>>>> w/o
> >>>>>>>>> shuffle?
> >>>>>>>>>
> >>>>>>>>> 53. "Migrating consumer is a step that might be made completly
> >>>>>>>>>
> >>>>>>>>> unnecessary
> >>>>>>>>>
> >>>>>>>>>> if - for example streams - takes the gcd as partitioning scheme
> >>>>>>>>>> instead
> >>>>>>>>>> of
> >>>>>>>>>> enforcing 1 to 1." Not sure that I fully understand this. I
> think
> >>>>>>>>>> you
> >>>>>>>>>> mean
> >>>>>>>>>> that a consumer application can run more instances than the
> number
> >>>>>>>>>> of
> >>>>>>>>>> partitions. In that case, the consumer can just repartitioning
> the
> >>>>>>>>>> input
> >>>>>>>>>> data according to the number of instances. This is possible, but
> >>>>>>>>>> just
> >>>>>>>>>> has
> >>>>>>>>>> the overhead of reshuffling the data.
> >>>>>>>>>>
> >>>>>>>>>> No what I meant is ( that is also your question i think Mathias)
> >>>>>>>>>> that
> >>>>>>>>>> if
> >>>>>>>>>>
> >>>>>>>>>> you grow a topic by a factor.
> >>>>>>>>>>
> >>>>>>>>> Even if your processor is statefull you can can just assign all
> the
> >>>>>>>>> multiples of the previous partition to
> >>>>>>>>> this consumer and the state to keep processing correctly will be
> >>>>>>>>> present
> >>>>>>>>> w/o any shuffling.
> >>>>>>>>>
> >>>>>>>>> Say you have an assignment
> >>>>>>>>> Statefull consumer => partition
> >>>>>>>>> 0 => 0
> >>>>>>>>> 1 => 1
> >>>>>>>>> 2 => 2
> >>>>>>>>>
> >>>>>>>>> and you grow you topic by 4 you get,
> >>>>>>>>>
> >>>>>>>>> 0 => 0,3,6,9
> >>>>>>>>> 1 => 1,4,7,10
> >>>>>>>>> 2 => 2,5,8,11
> >>>>>>>>>
> >>>>>>>>> Say your hashcode is 8. 8%3 => 2  before so consumer for
> partition
> >>>>>>>>> 2
> >>>>>>>>> has
> >>>>>>>>> it.
> >>>>>>>>> Now you you have 12 partitions so 8%12 => 8, so it goes into
> >>>>>>>>> partition
> >>>>>>>>> 8
> >>>>>>>>> which is assigned to the same consumer
> >>>>>>>>> who had 2 before and therefore knows the key.
> >>>>>>>>>
> >>>>>>>>> Userland reshuffeling is there as an options. And it does exactly
> >>>>>>>>> what
> >>>>>>>>> I
> >>>>>>>>> suggest. And I think its the perfect strategie. All I am
> suggestion
> >>>>>>>>> is
> >>>>>>>>> broker side support to switch the producers to the newly
> >>>>>>>>> partitioned
> >>>>>>>>> topic.
> >>>>>>>>> Then the old (to few partition topic) can go away.  Remember the
> >>>>>>>>> list
> >>>>>>>>> of
> >>>>>>>>> steps in the beginning of this thread. If one has broker support
> >>>>>>>>> for
> >>>>>>>>> all
> >>>>>>>>> where its required and streams support for those that aren’t
> >>>>>>>>> necessarily.
> >>>>>>>>> Then one has solved the problem.
> >>>>>>>>> I repeat it because I think its important. I am really happy that
> >>>>>>>>> you
> >>>>>>>>> brought that up! because its 100% what I want just with the
> >>>>>>>>> differences
> >>>>>>>>> to
> >>>>>>>>> have an option to discard the to small topic later (after all
> >>>>>>>>> consumers
> >>>>>>>>> adapted). And to have order correct there. I need broker support
> >>>>>>>>> managing
> >>>>>>>>> the copy process + the produces and fence them against each
> other.
> >>>>>>>>> I
> >>>>>>>>> also
> >>>>>>>>> repeat. the copy process can run for weeks in the worst case.
> >>>>>>>>> Copying
> >>>>>>>>> the
> >>>>>>>>> data is not the longest task migrating consumers might very well
> >>>>>>>>> be.
> >>>>>>>>> Once all consumers switched and copying is really up to date
> (think
> >>>>>>>>> ISR
> >>>>>>>>> like up to date) only then we stop the producer, wait for the
> copy
> >>>>>>>>> to
> >>>>>>>>> finish and use the new topic for producing.
> >>>>>>>>>
> >>>>>>>>> After this the topic is perfect in shape. and no one needs to
> worry
> >>>>>>>>> about
> >>>>>>>>> complicated stuff. (old keys hanging around might arrive in some
> >>>>>>>>> other
> >>>>>>>>> topic later.....). can only imagine how many tricky bugs gonna
> >>>>>>>>> arrive
> >>>>>>>>> after
> >>>>>>>>> someone had grown and shrunken is topic 10 times.
> >>>>>>>>>
> >>>>>>>>>
> >>>>>>>>>
> >>>>>>>>>
> >>>>>>>>>
> >>>>>>>>>
> >>>>>>>>> 54. "The other thing I wanted to mention is that I believe the
> >>>>>>>>> current
> >>>>>>>>>
> >>>>>>>>> suggestion (without copying data over) can be implemented in pure
> >>>>>>>>>
> >>>>>>>>>> userland
> >>>>>>>>>> with a custom partitioner and a small feedbackloop from
> >>>>>>>>>> ProduceResponse
> >>>>>>>>>> =>
> >>>>>>>>>> Partitionier in coorporation with a change management system." I
> >>>>>>>>>> am
> >>>>>>>>>> not
> >>>>>>>>>> sure a customized partitioner itself solves the problem. We
> >>>>>>>>>> probably
> >>>>>>>>>> need
> >>>>>>>>>> some broker side support to enforce when the new partitions can
> be
> >>>>>>>>>> used.
> >>>>>>>>>> We
> >>>>>>>>>> also need some support on the consumer/kstream side to preserve
> >>>>>>>>>> the
> >>>>>>>>>> per
> >>>>>>>>>> key
> >>>>>>>>>> ordering and potentially migrate the processing state. This is
> not
> >>>>>>>>>> trivial
> >>>>>>>>>> and I am not sure if it's ideal to fully push to the application
> >>>>>>>>>> space.
> >>>>>>>>>>
> >>>>>>>>>> Broker support is defenitly the preferred way here. I have
> nothing
> >>>>>>>>>>
> >>>>>>>>>> against
> >>>>>>>>>>
> >>>>>>>>> broker support.
> >>>>>>>>> I tried to say that for what I would preffer - copying the data
> >>>>>>>>> over,
> >>>>>>>>> at
> >>>>>>>>> least for log compacted topics -
> >>>>>>>>> I would require more broker support than the KIP currently
> offers.
> >>>>>>>>>
> >>>>>>>>>
> >>>>>>>>>
> >>>>>>>>> Jun
> >>>>>>>>>
> >>>>>>>>> On Tue, Mar 6, 2018 at 10:33 PM, Jan Filipiak <
> >>>>>>>>>
> >>>>>>>>>> Jan.Filipiak@trivago.com
> >>>>>>>>>> wrote:
> >>>>>>>>>>
> >>>>>>>>>> Hi Dong,
> >>>>>>>>>>
> >>>>>>>>>> are you actually reading my emails, or are you just using the
> >>>>>>>>>> thread I
> >>>>>>>>>>
> >>>>>>>>>> started for general announcements regarding the KIP?
> >>>>>>>>>>>
> >>>>>>>>>>> I tried to argue really hard against linear hashing. Growing
> the
> >>>>>>>>>>> topic
> >>>>>>>>>>> by
> >>>>>>>>>>> an integer factor does not require any state redistribution at
> >>>>>>>>>>> all. I
> >>>>>>>>>>> fail
> >>>>>>>>>>> to see completely where linear hashing helps on log compacted
> >>>>>>>>>>> topics.
> >>>>>>>>>>>
> >>>>>>>>>>> If you are not willing to explain to me what I might be
> >>>>>>>>>>> overlooking:
> >>>>>>>>>>> that
> >>>>>>>>>>> is fine.
> >>>>>>>>>>> But I ask you to not reply to my emails then. Please understand
> >>>>>>>>>>> my
> >>>>>>>>>>> frustration with this.
> >>>>>>>>>>>
> >>>>>>>>>>> Best Jan
> >>>>>>>>>>>
> >>>>>>>>>>>
> >>>>>>>>>>>
> >>>>>>>>>>> On 06.03.2018 19:38, Dong Lin wrote:
> >>>>>>>>>>>
> >>>>>>>>>>> Hi everyone,
> >>>>>>>>>>>
> >>>>>>>>>>> Thanks for all the comments! It appears that everyone prefers
> >>>>>>>>>>> linear
> >>>>>>>>>>>
> >>>>>>>>>>> hashing because it reduces the amount of state that needs to be
> >>>>>>>>>>>> moved
> >>>>>>>>>>>> between consumers (for stream processing). The KIP has been
> >>>>>>>>>>>> updated
> >>>>>>>>>>>> to
> >>>>>>>>>>>> use
> >>>>>>>>>>>> linear hashing.
> >>>>>>>>>>>>
> >>>>>>>>>>>> Regarding the migration endeavor: it seems that migrating
> >>>>>>>>>>>> producer
> >>>>>>>>>>>> library
> >>>>>>>>>>>> to use linear hashing should be pretty straightforward without
> >>>>>>>>>>>> much operational endeavor. If we don't upgrade client library
> to
> >>>>>>>>>>>> use
> >>>>>>>>>>>> this
> >>>>>>>>>>>> KIP, we can not support in-order delivery after partition is
> >>>>>>>>>>>> changed
> >>>>>>>>>>>> anyway. Suppose we upgrade client library to use this KIP, if
> >>>>>>>>>>>> partition
> >>>>>>>>>>>> number is not changed, the key -> partition mapping will be
> >>>>>>>>>>>> exactly
> >>>>>>>>>>>> the
> >>>>>>>>>>>> same as it is now because it is still determined using
> >>>>>>>>>>>> murmur_hash(key)
> >>>>>>>>>>>> %
> >>>>>>>>>>>> original_partition_num. In other words, this change is
> backward
> >>>>>>>>>>>> compatible.
> >>>>>>>>>>>>
> >>>>>>>>>>>> Regarding the load distribution: if we use linear hashing, the
> >>>>>>>>>>>> load
> >>>>>>>>>>>> may
> >>>>>>>>>>>> be
> >>>>>>>>>>>> unevenly distributed because those partitions which are not
> >>>>>>>>>>>> split
> >>>>>>>>>>>> may
> >>>>>>>>>>>> receive twice as much traffic as other partitions that are
> >>>>>>>>>>>> split.
> >>>>>>>>>>>> This
> >>>>>>>>>>>> issue can be mitigated by creating topic with partitions that
> >>>>>>>>>>>> are
> >>>>>>>>>>>> several
> >>>>>>>>>>>> times the number of consumers. And there will be no imbalance
> if
> >>>>>>>>>>>> the
> >>>>>>>>>>>> partition number is always doubled. So this imbalance seems
> >>>>>>>>>>>> acceptable.
> >>>>>>>>>>>>
> >>>>>>>>>>>> Regarding storing the partition strategy as per-topic config:
> It
> >>>>>>>>>>>> seems
> >>>>>>>>>>>> not
> >>>>>>>>>>>> necessary since we can still use murmur_hash as the default
> hash
> >>>>>>>>>>>> function
> >>>>>>>>>>>> and additionally apply the linear hashing algorithm if the
> >>>>>>>>>>>> partition
> >>>>>>>>>>>> number
> >>>>>>>>>>>> has increased. Not sure if there is any use-case for producer
> to
> >>>>>>>>>>>> use a
> >>>>>>>>>>>> different hash function. Jason, can you check if there is some
> >>>>>>>>>>>> use-case
> >>>>>>>>>>>> that I missed for using the per-topic partition strategy?
> >>>>>>>>>>>>
> >>>>>>>>>>>> Regarding how to reduce latency (due to state store/load) in
> >>>>>>>>>>>> stream
> >>>>>>>>>>>> processing consumer when partition number changes: I need to
> >>>>>>>>>>>> read
> >>>>>>>>>>>> the
> >>>>>>>>>>>> Kafka
> >>>>>>>>>>>> Stream code to understand how Kafka Stream currently migrate
> >>>>>>>>>>>> state
> >>>>>>>>>>>> between
> >>>>>>>>>>>> consumers when the application is added/removed for a given
> >>>>>>>>>>>> job. I
> >>>>>>>>>>>> will
> >>>>>>>>>>>> reply after I finish reading the documentation and code.
> >>>>>>>>>>>>
> >>>>>>>>>>>>
> >>>>>>>>>>>> Thanks,
> >>>>>>>>>>>> Dong
> >>>>>>>>>>>>
> >>>>>>>>>>>>
> >>>>>>>>>>>> On Mon, Mar 5, 2018 at 10:43 AM, Jason Gustafson <
> >>>>>>>>>>>> jason@confluent.io>
> >>>>>>>>>>>> wrote:
> >>>>>>>>>>>>
> >>>>>>>>>>>> Great discussion. I think I'm wondering whether we can
> continue
> >>>>>>>>>>>> to
> >>>>>>>>>>>> leave
> >>>>>>>>>>>>
> >>>>>>>>>>>> Kafka agnostic to the partitioning strategy. The challenge is
> >>>>>>>>>>>>
> >>>>>>>>>>>> communicating
> >>>>>>>>>>>>
> >>>>>>>>>>>>> the partitioning logic from producers to consumers so that
> the
> >>>>>>>>>>>>> dependencies
> >>>>>>>>>>>>> between each epoch can be determined. For the sake of
> >>>>>>>>>>>>> discussion,
> >>>>>>>>>>>>> imagine
> >>>>>>>>>>>>> you did something like the following:
> >>>>>>>>>>>>>
> >>>>>>>>>>>>> 1. The name (and perhaps version) of a partitioning strategy
> is
> >>>>>>>>>>>>> stored
> >>>>>>>>>>>>> in
> >>>>>>>>>>>>> topic configuration when a topic is created.
> >>>>>>>>>>>>> 2. The producer looks up the partitioning strategy before
> >>>>>>>>>>>>> writing
> >>>>>>>>>>>>> to
> >>>>>>>>>>>>> a
> >>>>>>>>>>>>> topic and includes it in the produce request (for fencing).
> If
> >>>>>>>>>>>>> it
> >>>>>>>>>>>>> doesn't
> >>>>>>>>>>>>> have an implementation for the configured strategy, it fails.
> >>>>>>>>>>>>> 3. The consumer also looks up the partitioning strategy and
> >>>>>>>>>>>>> uses
> >>>>>>>>>>>>> it
> >>>>>>>>>>>>> to
> >>>>>>>>>>>>> determine dependencies when reading a new epoch. It could
> >>>>>>>>>>>>> either
> >>>>>>>>>>>>> fail
> >>>>>>>>>>>>> or
> >>>>>>>>>>>>> make the most conservative dependency assumptions if it
> doesn't
> >>>>>>>>>>>>> know
> >>>>>>>>>>>>> how
> >>>>>>>>>>>>> to
> >>>>>>>>>>>>> implement the partitioning strategy. For the consumer, the
> new
> >>>>>>>>>>>>> interface
> >>>>>>>>>>>>> might look something like this:
> >>>>>>>>>>>>>
> >>>>>>>>>>>>> // Return the partition dependencies following an epoch bump
> >>>>>>>>>>>>> Map<Integer, List<Integer>> dependencies(int
> >>>>>>>>>>>>> numPartitionsBeforeEpochBump,
> >>>>>>>>>>>>> int numPartitionsAfterEpochBump)
> >>>>>>>>>>>>>
> >>>>>>>>>>>>> The unordered case then is just a particular implementation
> >>>>>>>>>>>>> which
> >>>>>>>>>>>>> never
> >>>>>>>>>>>>> has
> >>>>>>>>>>>>> any epoch dependencies. To implement this, we would need some
> >>>>>>>>>>>>> way
> >>>>>>>>>>>>> for
> >>>>>>>>>>>>> the
> >>>>>>>>>>>>> consumer to find out how many partitions there were in each
> >>>>>>>>>>>>> epoch,
> >>>>>>>>>>>>> but
> >>>>>>>>>>>>> maybe that's not too unreasonable.
> >>>>>>>>>>>>>
> >>>>>>>>>>>>> Thanks,
> >>>>>>>>>>>>> Jason
> >>>>>>>>>>>>>
> >>>>>>>>>>>>>
> >>>>>>>>>>>>> On Mon, Mar 5, 2018 at 4:51 AM, Jan Filipiak <
> >>>>>>>>>>>>> Jan.Filipiak@trivago.com
> >>>>>>>>>>>>> wrote:
> >>>>>>>>>>>>>
> >>>>>>>>>>>>> Hi Dong
> >>>>>>>>>>>>>
> >>>>>>>>>>>>> thank you very much for your questions.
> >>>>>>>>>>>>>
> >>>>>>>>>>>>> regarding the time spend copying data across:
> >>>>>>>>>>>>>
> >>>>>>>>>>>>>> It is correct that copying data from a topic with one
> >>>>>>>>>>>>>> partition
> >>>>>>>>>>>>>> mapping
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>> to
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>> a topic with a different partition mapping takes way longer
> >>>>>>>>>>>>>> than
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>> we
> >>>>>>>>>>>>> can
> >>>>>>>>>>>>>
> >>>>>>>>>>>>> stop producers. Tens of minutes is a very optimistic estimate
> >>>>>>>>>>>>> here.
> >>>>>>>>>>>>>
> >>>>>>>>>>>>> Many
> >>>>>>>>>>>>>> people can not afford copy full steam and therefore will
> have
> >>>>>>>>>>>>>> some
> >>>>>>>>>>>>>> rate
> >>>>>>>>>>>>>> limiting in place, this can bump the timespan into the
> day's.
> >>>>>>>>>>>>>> The
> >>>>>>>>>>>>>> good
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>> part
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>> is that the vast majority of the data can be copied while
> the
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>> producers
> >>>>>>>>>>>>>
> >>>>>>>>>>>>> are
> >>>>>>>>>>>>>
> >>>>>>>>>>>>> still going. One can then, piggyback the consumers ontop of
> >>>>>>>>>>>>>> this
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>> timeframe,
> >>>>>>>>>>>>>
> >>>>>>>>>>>>> by the method mentioned (provide them an mapping from their
> old
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>> offsets
> >>>>>>>>>>>>>
> >>>>>>>>>>>>> to
> >>>>>>>>>>>>>
> >>>>>>>>>>>>> new offsets in their repartitioned topics. In that way we
> >>>>>>>>>>>>>> separate
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>> migration of consumers from migration of producers
> (decoupling
> >>>>>>>>>>>>>
> >>>>>>>>>>>>> these
> >>>>>>>>>>>>>> is
> >>>>>>>>>>>>>> what kafka is strongest at). The time to actually swap over
> >>>>>>>>>>>>>> the
> >>>>>>>>>>>>>> producers
> >>>>>>>>>>>>>> should be kept minimal by ensuring that when a swap attempt
> is
> >>>>>>>>>>>>>> started
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>> the
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>> consumer copying over should be very close to the log end
> and
> >>>>>>>>>>>>>> is
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>> expected
> >>>>>>>>>>>>>
> >>>>>>>>>>>>> to finish within the next fetch. The operation should have a
> >>>>>>>>>>>>>> time-out
> >>>>>>>>>>>>>> and
> >>>>>>>>>>>>>> should be "reattemtable".
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>> Importance of logcompaction:
> >>>>>>>>>>>>>> If a producer produces key A, to partiton 0, its forever
> gonna
> >>>>>>>>>>>>>> be
> >>>>>>>>>>>>>> there,
> >>>>>>>>>>>>>> unless it gets deleted. The record might sit in there for
> >>>>>>>>>>>>>> years. A
> >>>>>>>>>>>>>> new
> >>>>>>>>>>>>>> producer started with the new partitions will fail to delete
> >>>>>>>>>>>>>> the
> >>>>>>>>>>>>>> record
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>> in
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>> the correct partition. Th record will be there forever and
> one
> >>>>>>>>>>>>>> can
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>> not
> >>>>>>>>>>>>>
> >>>>>>>>>>>>> reliable bootstrap new consumers. I cannot see how linear
> >>>>>>>>>>>>> hashing
> >>>>>>>>>>>>>
> >>>>>>>>>>>>> can
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>> solve
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>> this.
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>> Regarding your skipping of userland copying:
> >>>>>>>>>>>>>
> >>>>>>>>>>>>> 100%, copying the data across in userland is, as far as i can
> >>>>>>>>>>>>>> see,
> >>>>>>>>>>>>>> only
> >>>>>>>>>>>>>> a
> >>>>>>>>>>>>>> usecase for log compacted topics. Even for logcompaction +
> >>>>>>>>>>>>>> retentions
> >>>>>>>>>>>>>> it
> >>>>>>>>>>>>>> should only be opt-in. Why did I bring it up? I think log
> >>>>>>>>>>>>>> compaction
> >>>>>>>>>>>>>> is
> >>>>>>>>>>>>>> a
> >>>>>>>>>>>>>> very important feature to really embrace kafka as a "data
> >>>>>>>>>>>>>> plattform".
> >>>>>>>>>>>>>> The
> >>>>>>>>>>>>>> point I also want to make is that copying data this way is
> >>>>>>>>>>>>>> completely
> >>>>>>>>>>>>>> inline with the kafka architecture. it only consists of
> >>>>>>>>>>>>>> reading
> >>>>>>>>>>>>>> and
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>> writing
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>> to topics.
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>> I hope it clarifies more why I think we should aim for more
> >>>>>>>>>>>>> than
> >>>>>>>>>>>>>
> >>>>>>>>>>>>> the
> >>>>>>>>>>>>>> current KIP. I fear that once the KIP is done not much more
> >>>>>>>>>>>>>> effort
> >>>>>>>>>>>>>> will
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>> be
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>> taken.
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>> On 04.03.2018 02:28, Dong Lin wrote:
> >>>>>>>>>>>>>
> >>>>>>>>>>>>>> Hey Jan,
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>> In the current proposal, the consumer will be blocked on
> >>>>>>>>>>>>>> waiting
> >>>>>>>>>>>>>> for
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>> other
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>>> consumers of the group to consume up to a given offset. In
> >>>>>>>>>>>>>>> most
> >>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>> cases,
> >>>>>>>>>>>>>> all
> >>>>>>>>>>>>>> consumers should be close to the LEO of the partitions when
> >>>>>>>>>>>>>> the
> >>>>>>>>>>>>>> partition
> >>>>>>>>>>>>>> expansion happens. Thus the time waiting should not be long
> >>>>>>>>>>>>>> e.g.
> >>>>>>>>>>>>>> on
> >>>>>>>>>>>>>> the
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>> order of seconds. On the other hand, it may take a long time
> >>>>>>>>>>>>>> to
> >>>>>>>>>>>>>> wait
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>> for
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>>> the entire partition to be copied -- the amount of time is
> >>>>>>>>>>>>>>> proportional
> >>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>> to
> >>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>> the amount of existing data in the partition, which can
> take
> >>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>> tens of
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>> minutes. So the amount of time that we stop consumers may
> not
> >>>>>>>>>>>>>> be
> >>>>>>>>>>>>>> on
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>> the
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>>> same order of magnitude.
> >>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>> If we can implement this suggestion without copying data
> over
> >>>>>>>>>>>>>>> in
> >>>>>>>>>>>>>>> purse
> >>>>>>>>>>>>>>> userland, it will be much more valuable. Do you have ideas
> on
> >>>>>>>>>>>>>>> how
> >>>>>>>>>>>>>>> this
> >>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>> can
> >>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>> be done?
> >>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>> Not sure why the current KIP not help people who depend on
> >>>>>>>>>>>>>> log
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>> compaction.
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>>> Could you elaborate more on this point?
> >>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>> Thanks,
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>> Dong
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>>> On Wed, Feb 28, 2018 at 10:55 PM, Jan
> >>>>>>>>>>>>>>> Filipiak<Jan.Filipiak@trivago.
> >>>>>>>>>>>>>>> com
> >>>>>>>>>>>>>>> wrote:
> >>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>> Hi Dong,
> >>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>> I tried to focus on what the steps are one can currently
> >>>>>>>>>>>>>>> perform
> >>>>>>>>>>>>>>> to
> >>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>> expand
> >>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>> or shrink a keyed topic while maintaining a top notch
> >>>>>>>>>>>>>>>> semantics.
> >>>>>>>>>>>>>>>> I can understand that there might be confusion about
> >>>>>>>>>>>>>>>> "stopping
> >>>>>>>>>>>>>>>> the
> >>>>>>>>>>>>>>>> consumer". It is exactly the same as proposed in the KIP.
> >>>>>>>>>>>>>>>> there
> >>>>>>>>>>>>>>>> needs
> >>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>> to
> >>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>> be
> >>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>> a time the producers agree on the new partitioning. The
> >>>>>>>>>>>>>>> extra
> >>>>>>>>>>>>>>>
> >>>>>>>>>>>>>> semantics I
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>>> want to put in there is that we have a possibility to wait
> >>>>>>>>>>>>>>>> until
> >>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>> all
> >>>>>>>>>>>>>>>
> >>>>>>>>>>>>>> the
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>> existing data
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>>> is copied over into the new partitioning scheme. When I say
> >>>>>>>>>>>>>>>
> >>>>>>>>>>>>>> stopping
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>> I
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>>> think more of having a memory barrier that ensures the
> >>>>>>>>>>>>>>>> ordering. I
> >>>>>>>>>>>>>>>> am
> >>>>>>>>>>>>>>>> still
> >>>>>>>>>>>>>>>> aming for latencies  on the scale of leader failovers.
> >>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>> Consumers have to explicitly adapt the new partitioning
> >>>>>>>>>>>>>>>> scheme
> >>>>>>>>>>>>>>>> in
> >>>>>>>>>>>>>>>> the
> >>>>>>>>>>>>>>>> above scenario. The reason is that in these cases where
> you
> >>>>>>>>>>>>>>>> are
> >>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>> dependent
> >>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>> on a particular partitioning scheme, you also have other
> >>>>>>>>>>>>>>>> topics
> >>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>> that
> >>>>>>>>>>>>>>>
> >>>>>>>>>>>>>> have
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>> co-partition enforcements or the kind -frequently. Therefore
> >>>>>>>>>>>>>> all
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>>> your
> >>>>>>>>>>>>>>>
> >>>>>>>>>>>>>> other
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>> input topics might need to grow accordingly.
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>>> What I was suggesting was to streamline all these
> operations
> >>>>>>>>>>>>>>>> as
> >>>>>>>>>>>>>>>> best
> >>>>>>>>>>>>>>>> as
> >>>>>>>>>>>>>>>> possible to have "real" partition grow and shrinkage going
> >>>>>>>>>>>>>>>> on.
> >>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>> Migrating
> >>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>> the producers to a new partitioning scheme can be much
> more
> >>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>> streamlined
> >>>>>>>>>>>>>>>
> >>>>>>>>>>>>>> with proper broker support for this. Migrating consumer is a
> >>>>>>>>>>>>>> step
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>> that
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>>> might be made completly unnecessary if - for example
> streams
> >>>>>>>>>>>>>>>> -
> >>>>>>>>>>>>>>>> takes
> >>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>> the
> >>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>> gcd as partitioning scheme instead of enforcing 1 to 1.
> >>>>>>>>>>>>>>>> Connect
> >>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>> consumers
> >>>>>>>>>>>>>>>
> >>>>>>>>>>>>>> and other consumers should be fine anyways.
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>>> I hope this makes more clear where I was aiming at. The
> rest
> >>>>>>>>>>>>>>>
> >>>>>>>>>>>>>> needs
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>> to
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>>> be
> >>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>> figured out. The only danger i see is that when we are
> >>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>> introducing
> >>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>> this
> >>>>>>>>>>>>>>>
> >>>>>>>>>>>>>> feature as supposed in the KIP, it wont help any people
> >>>>>>>>>>>>>> depending
> >>>>>>>>>>>>>> on
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>> log
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>>> compaction.
> >>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>> The other thing I wanted to mention is that I believe the
> >>>>>>>>>>>>>>>
> >>>>>>>>>>>>>> current
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>> suggestion (without copying data over) can be implemented in
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>>> pure
> >>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>> userland
> >>>>>>>>>>>>>>>> with a custom partitioner and a small feedbackloop from
> >>>>>>>>>>>>>>>> ProduceResponse
> >>>>>>>>>>>>>>>> =>
> >>>>>>>>>>>>>>>> Partitionier in coorporation with a change management
> >>>>>>>>>>>>>>>> system.
> >>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>> Best Jan
> >>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>> On 28.02.2018 07:13, Dong Lin wrote:
> >>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>> Hey Jan,
> >>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>> I am not sure if it is acceptable for producer to be
> stopped
> >>>>>>>>>>>>>>>> for a
> >>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>> while,
> >>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>> particularly for online application which requires low
> >>>>>>>>>>>>>>>>> latency. I
> >>>>>>>>>>>>>>>>> am
> >>>>>>>>>>>>>>>>> also
> >>>>>>>>>>>>>>>>> not sure how consumers can switch to a new topic. Does
> user
> >>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>> application
> >>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>> needs to explicitly specify a different topic for
> >>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>> producer/consumer
> >>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>> to
> >>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>> subscribe to? It will be helpful for discussion if you can
> >>>>>>>>>>>>>> provide
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>> more
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>>> detail on the interface change for this solution.
> >>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>> Thanks,
> >>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>> Dong
> >>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>> On Mon, Feb 26, 2018 at 12:48 AM, Jan
> >>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>> Filipiak<Jan.Filipiak@trivago.
> >>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>> com
> >>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>> wrote:
> >>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>> Hi,
> >>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>> just want to throw my though in. In general the
> functionality
> >>>>>>>>>>>>>>> is
> >>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>> very
> >>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>> usefull, we should though not try to find the
> architecture
> >>>>>>>>>>>>>>>>> to
> >>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>> hard
> >>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>>> while
> >>>>>>>>>>>>>>>>>> implementing.
> >>>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>>> The manual steps would be to
> >>>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>>> create a new topic
> >>>>>>>>>>>>>>>>>> the mirrormake from the new old topic to the new topic
> >>>>>>>>>>>>>>>>>> wait for mirror making to catch up.
> >>>>>>>>>>>>>>>>>> then put the consumers onto the new topic
> >>>>>>>>>>>>>>>>>>             (having mirrormaker spit out a mapping from
> >>>>>>>>>>>>>>>>>> old
> >>>>>>>>>>>>>>>>>> offsets to
> >>>>>>>>>>>>>>>>>> new
> >>>>>>>>>>>>>>>>>> offsets:
> >>>>>>>>>>>>>>>>>>                 if topic is increased by factor X there
> is
> >>>>>>>>>>>>>>>>>> gonna
> >>>>>>>>>>>>>>>>>> be a
> >>>>>>>>>>>>>>>>>> clean
> >>>>>>>>>>>>>>>>>> mapping from 1 offset in the old topic to X offsets in
> the
> >>>>>>>>>>>>>>>>>> new
> >>>>>>>>>>>>>>>>>> topic,
> >>>>>>>>>>>>>>>>>>                 if there is no factor then there is no
> >>>>>>>>>>>>>>>>>> chance to
> >>>>>>>>>>>>>>>>>> generate a
> >>>>>>>>>>>>>>>>>> mapping that can be reasonable used for continuing)
> >>>>>>>>>>>>>>>>>>             make consumers stop at appropriate points
> and
> >>>>>>>>>>>>>>>>>> continue
> >>>>>>>>>>>>>>>>>> consumption
> >>>>>>>>>>>>>>>>>> with offsets from the mapping.
> >>>>>>>>>>>>>>>>>> have the producers stop for a minimal time.
> >>>>>>>>>>>>>>>>>> wait for mirrormaker to finish
> >>>>>>>>>>>>>>>>>> let producer produce with the new metadata.
> >>>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>>> Instead of implementing the approach suggest in the KIP
> >>>>>>>>>>>>>>>>>> which
> >>>>>>>>>>>>>>>>>> will
> >>>>>>>>>>>>>>>>>> leave
> >>>>>>>>>>>>>>>>>> log compacted topic completely crumbled and unusable.
> >>>>>>>>>>>>>>>>>> I would much rather try to build infrastructure to
> support
> >>>>>>>>>>>>>>>>>> the
> >>>>>>>>>>>>>>>>>> mentioned
> >>>>>>>>>>>>>>>>>> above operations more smoothly.
> >>>>>>>>>>>>>>>>>> Especially having producers stop and use another topic
> is
> >>>>>>>>>>>>>>>>>> difficult
> >>>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>>> and
> >>>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>>> it would be nice if one can trigger "invalid metadata"
> >>>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>>> exceptions
> >>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>> for
> >>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>> them
> >>>>>>>>>>>>>>>
> >>>>>>>>>>>>>> and
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>>> if one could give topics aliases so that their produces
> with
> >>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>> the
> >>>>>>>>>>>>>>>>>> old
> >>>>>>>>>>>>>>>>>> topic
> >>>>>>>>>>>>>>>>>> will arrive in the new topic.
> >>>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>>> The downsides are obvious I guess ( having the same data
> >>>>>>>>>>>>>>>>>> twice
> >>>>>>>>>>>>>>>>>> for
> >>>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>>> the
> >>>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>>> transition period, but kafka tends to scale well with
> >>>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>>> datasize).
> >>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>> So
> >>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>> its a
> >>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>> nicer fit into the architecture.
> >>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>> I further want to argument that the functionality by the
> KIP
> >>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>> can
> >>>>>>>>>>>>>>>>>> completely be implementing in "userland" with a custom
> >>>>>>>>>>>>>>>>>> partitioner
> >>>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>>> that
> >>>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>>> handles the transition as needed. I would appreciate if
> >>>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>>> someone
> >>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>> could
> >>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>> point
> >>>>>>>>>>>>>>>
> >>>>>>>>>>>>>> out what a custom partitioner couldn't handle in this case?
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>>> With the above approach, shrinking a topic becomes the same
> >>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>> steps.
> >>>>>>>>>>>>>>>>>> Without
> >>>>>>>>>>>>>>>>>> loosing keys in the discontinued partitions.
> >>>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>>> Would love to hear what everyone thinks.
> >>>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>>> Best Jan
> >>>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>>> On 11.02.2018 00:35, Dong Lin wrote:
> >>>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>>> Hi all,
> >>>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>>> I have created KIP-253: Support in-order message
> delivery
> >>>>>>>>>>>>>>>>>> with
> >>>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>>> partition
> >>>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>>> expansion. See
> >>>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>>>> https://cwiki.apache.org/confl
> >>>>>>>>>>>>>>>>>>> uence/display/KAFKA/KIP-253%
> >>>>>>>>>>>>>>>>>>> 3A+Support+in-order+message+de
> >>>>>>>>>>>>>>>>>>> livery+with+partition+expansio
> >>>>>>>>>>>>>>>>>>> n
> >>>>>>>>>>>>>>>>>>> .
> >>>>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>>>> This KIP provides a way to allow messages of the same
> key
> >>>>>>>>>>>>>>>>>>> from
> >>>>>>>>>>>>>>>>>>> the
> >>>>>>>>>>>>>>>>>>> same
> >>>>>>>>>>>>>>>>>>> producer to be consumed in the same order they are
> >>>>>>>>>>>>>>>>>>> produced
> >>>>>>>>>>>>>>>>>>> even
> >>>>>>>>>>>>>>>>>>> if
> >>>>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>>>> we
> >>>>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>>>> expand partition of the topic.
> >>>>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>>>> Thanks,
> >>>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>> Dong
> >>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>>>>
> >>>
> >
>

Re: [DISCUSS] KIP-253: Support in-order message delivery with partition expansion

Posted by John Roesler <jo...@confluent.io>.
Hi all,

I hope you don't mind if I throw some thoughts in...

For some reason, Jan's proposal wasn't really clear to me until this last
message, and now that (I think) I understand it, I actually like it quite a
lot.

Thought 1:
As much as I like Streams, I don't think it should become a requirement to
pull off something like partition expansion. It would be a bummer if folks
who otherwise have no use case for Streams have to run an trivial app
*just* to get partition expansion.

Assuming we get a nice partition-expansion design out of this conversation,
It may or may not be the case that Streams will still decide to
re-partition its inputs, but I'd like to keep those two designs (Core and
Streams) independent (personal opinion, fwiw). It also may or may not be
the case that we would try to split the local state versus re-building the
affected operators from the new (post-split) topics. It would be nice to be
able to optimize the process of scaling Streams independently of Core.

Thought 2:
Regarding who might manage this special backfill consumer, I wonder if the
answer might actually be that that logic should be in the producer.

Consider that only the producer knows the partition function, so locating
backfill anywhere else requires sharing that logic, which would be a bummer.

Also, if you think about the "producer" in the broader sense, as the
organization that produces the data in a particular topic, that "producer"
controls everything about the topic: the name, the number of partitions,
the schema, and all of the configs including compaction and retention. This
"producer" will be the person responsible for splitting/merging partitions
anyway, so introducing a new component is asking that "producer" to own and
operate more pieces, whereas placing inside the KafkaProducer keeps their
operational burden the same.

Thought 3:
I don't think we want to think about actually creating a new topic, but
instead something like a "generation" or "version" of a topic.

Different generations of a topic can have different numbers of partitions,
and also different offsets. Consumers can currently start with the earliest
available offset. Similarly, with generations, consumers could start off
with the earliest available in the earliest available generation. The
retention policy still applies, so when the log cleaner deletes the last
segment from a generation, that whole generation becomes unavailable, and
new consumers start off on the next generation.

This also makes the backfill job well defined: the range it's copying
*from* has a start and an end; the range it's copying *to* is out of bounds
for new writes. When backfill finishes copying all the records from
generation 0 to the beginning of generation 1, it instructs the broker that
generation 1, offset x is now the earliest available offset and all of
generation 0's files can be deleted. The metadata tracking how to
transition from gen0 to gen1 can also be deleted, as it's no longer
meaningful.

Note that for compacted topics, you really want to think of the number of
partitions in the topic as the number of partitions in the first available
partition. I.e., I think it's simplifying to assume that consumers may not
be able to split their state. If I'm a consumer, and I don't have enough
parallelism, I think I'd go to the producer and request an expansion. The
producer would do the expansion and kick off the backfill. My existing
consumers get assigned the new generations partitions such that each
consumer gets the same set of records. When the backfill completes, *then*
I can start up my new crop of more granular consumers. Being able to split
and merge state when I hit topic generation barriers would obviously be
nice, but I don't think it's universally available, so it's important to
have a solid design around async backfill with notifications.

Thought 4:
I *think* Jan's approach works fine even if you want to split just one
partition, instead of increasing the number of partitions by a factor.
Plus, you could split the partition into any number of new partitions. It
all depends on the partition function, which again comes back to it being
nice to place the responsibility for all these decisions squarely with the
producer. Maybe the default hash function requires them to double the
partition count, but if they want to be able to split single partitions,
they can use a hash function that makes that possible.

We also need to remember that some topics don't use hashing at all to
assign partitions, but round-robin instead. In this case, the partition
assignment for a record is clearly arbitrary. In this case, I could see
wanting to just increase the partition count, say from 2 to 3, and achieve
a uniform re-distribution. This is the only use case that isn't well served
by the "partition split" mentality. If you wanted a uniform re-distribution
in this case, you would have to go from 2 to 4. Or, you could always create
a truly new topic and get all your consumers to start consuming that one
instead.

Thought 5:
This whole operation can be really straightforward if we're a little
careful with the offsets. I think for expansion, you want to start the new
generation off with the end offset of the old generation, and for merging,
you want to add the end offsets of the two old-gen parent partitions. This
way, you know that there will be enough room at the beginning of the
partition for a potential backfill either way.

In other words:
Let's assume MyTopic has 3 partitions, and we're splitting partition 0 into
two:
MyTopic[gen=0,part=0,endOffset=50] -> (
MyTopic[gen=1,part=0,endOffset=50], MyTopic[gen=1,part=3,endOffset=50]
)
MyTopic[gen=0,part=1,endOffset=41] -> ( MyTopic[gen=1,part=1,endOffset=41] )
MyTopic[gen=0,part=2,endOffset=63] -> ( MyTopic[gen=1,part=2,endOffset=63] )

*Maybe* the producer of MyTopic decides to backfill the split of part=0:
1) For each record, they run it though their partition function to decide
between part=0 and part=3, instructing the broker to copy that record to
the new generation's partition with the *same* offset.
2) When they reach the end of [gen=0,part=0], they instruct the broker that
MyTopic[gen=1,part=1] now begins at offset=0 and MyTopic[gen=1,part=3] now
begins at offset=1 (for example), and they also mark gen=0,part=0 as
defunct.

Assuming 4 Consumers: if they started reading during gen=0, they might have
the following assignment:
* consumer1: in gen=0, [part=0], transitioning to [part=0,part=3] at
offset=50
* consumer2: [part=1]
* consumer3: [part=2]
* consumer4: []

Now, if they started reading during gen=1 after gen=0 becomes defunct, they
might have this assignment:
* consumer1: [part=0]
* consumer2: [part=1]
* consumer3: [part=2]
* consumer4: [part=3]

Just a quick note about the possibility of splitting without starting
over... if consumer1 knows how to split its task, either because it's
stateless or because it has splittable state, it certainly can and "send"
part=3 to consumer4. So this avenue is still open.

Thought 5.5:
I think it's worth also sketching out the merge operation, as I'm picturing
it.
Let's assume we've got 4 partitions, and we want to merge part=1 and part=2:
MyTopic[gen=0,part=0,endOffset=50] -> MyTopic[gen=1,part=0,endOffset=50]
MyTopic[gen=0,part=1,endOffset=12] -> MyTopic[gen=1,part=1,endOffset=(12 +
23 = 35)]
MyTopic[gen=0,part=2,endOffset=23] -> (see gen=1,part=1)
MyTopic[gen=0,part=3,endOffset=41] -> MyTopic[gen=1,part=3,endOffset=41]

Now, I think no matter how you cut it, this is going to be a tough
transition for stateful consumers to handle. The good news is that the
brokers can pull off a merge backfill very efficiently, by just copying
part=2's segments into part=1 and using a little metadata to remember to
add 12 to all the offsets it reads out of these segments. So, it might just
have to be good enough to make merge super fast and then stateful consumers
will have to rebuild their state for the affected partitions. Producers can
be warned that while splitting is fine, merging may break their consumers.

Thought 6:
To pull off the split backfill, the broker will have to stream all the
records to the producer's backfill worker, which is a bummer, but note that
the backfill worker doesn't have to stream them back. It is sufficient just
to send back the new partition assignment and offset for each (old
partition,offset), since the records are going to keep their old timestamp,
key, and value. The broker can then do its best to merge consecutive ranges
and do efficient filesystem copies. Hopefully, the fact that backfill is
async and producers and consumers can just continue working in the new
generation while it happens, in combination with the fact that we only have
to stream the data out and not back in to the broker makes this tolerable.

Likewise, for partitions not undergoing a split can trivially backfill into
the new generation by copying, moving, or hardlinking the segment files
over, depending on the implementer's preference. The point is, it can be
done without streaming that data back to the producer.


All done!
Now that (I think) I understand Jan's proposal, I agree it's a better way
forward for the project than pulling Streams in to perform the repartition
operation. Hopefully, my comments add a little to the conversation.

Thanks,
John

On Fri, Mar 23, 2018 at 9:15 AM, Jan Filipiak <Ja...@trivago.com>
wrote:

> Hi Jun,
>
> thanks for your great reply, even though I only managed to throw a few
> sentences in, because of time last time. I think you are starting to
> understand me pretty well. There is still some minor things that need to be
> flattened out. I already had these points previously but I try to rephrase
> them into answers to your questions for clarity.
>
> On 23.03.2018 01:43, Jun Rao wrote:
>
>> Hi, Jan,
>>
>> Thanks for the reply.
>>
>> Ok. So your idea is to have a special consumer reshuffle the data to a new
>> set of partitions. Each consumer group will not increase its tasks
>> immediately. We just need to make sure that each consumer instance is
>> assigned the set of new partitions covering the same set of keys. At some
>> point later, each consumer group can decide independently when to increase
>> the number of tasks. At that point, the consumer will need to rebuild the
>> local state for the new tasks. Is that right?
>>
> This has multiple aspects. The middle part
>
>  We just need to make sure that each consumer instance is
> assigned the set of new partitions covering the same set of keys
>
> is probably the most important one here. This is essentially what the
> second part of my idea is about.
> We need a protocol that allows consumers to switch from old topic (old
> partiton count) to the new topic (new partion count). (If it really is a
> new topic or not depends on the implementation -I like to model it as such
> as its easier in my head). The protocol I envision is something like this:
> Per partition there is information from the old offset to the new offset.
>
> topicOldMapping-0 : 50 => [0:25,2:25]
> topicOldMapping-1 : 60 => [1:15,3:45]
>
> A consumer can get a hold on this information and stop at 50 and 60 and
> continue at 25,25,15,45
>
> The same transition works when the data is not copied. a mapping would
> look like
>
> topicOldMapping-0 : 50 => [0:0,2:0]
> topicOldMapping-1 : 60 => [1:0,3:0]
>
> No data would have been copied and 50 and 60 are the endoffsets and we
> would start at the very beginning of the new topic 0,0,0,0
>
>
>> I agree that decoupling the number of tasks in a consumer group from the
>> number of partitions in the input topic is a good idea. This allows each
>> consumer group to change its degree of parallelism independently. There
>> are
>> different ways to achieve such decoupling. You suggested one approach,
>> which works when splitting partitions. Not sure if this works in general,
>> for example when merging partitions.
>>
> Merging is the same.
>
> topicOldMapping-0 : 25 => [0:50]
> topicOldMapping-1 : 25 => [1:50]
> topicOldMapping-2 : 15 => [0:50]
> topicOldMapping-3 : 45 => [1:50]
>
> generating this mapping is trivial again if we do not copy data. (end
> offsets point to start offsets)
> If we do copy data the consumer will create the mapping.
>
>
>> Once a consumer group decides to change its degree of parallelism, it
>> needs
>> to rebuild the local state for the new tasks. We can either rebuild the
>> states from the input topic or from the local state (through change
>> capture
>> topic). I think we agreed that rebuilding from the local state is more
>> efficient. It also seems that it's better to let the KStreams library do
>> the state rebuilding, instead of each application. Would you agree?
>>
> If you want todo by RPC, you are changing the running application without
> having a new good one. This
> is against the kappa achitecture I would not recommend that.
>
> If you replay the changelog and only poll records that are for your
> partition. You have the problem of knowing
> which offset from the input topic your current state relates to.
>
> If you rebuild you could leave the old running and just wait for the new
> to be _good_ then change who's output you
> show to the customers.
>
>
>> About the special consumer. I guess that's only needed if one wants to
>> recopy the existing data? However, if we can truly decouple the tasks in
>> the consumer group from the partitions in the input topic, it seems there
>> is no need for copying existing data? It's also not clear to me who will
>> start/stop this special consumer.
>>
> Who starts and stops it is also not very clear to me. I do not have strong
> opinions.
> The thing is that I am looking for an explanation how you can have a
> logcompacted topic working without copying.
> I agree that for running consumers its no problem as they are already past
> the history. But the whole purpose of Log compaction
> is to be able to bootstrap new consumers. They are completely lost with a
> topic expanded without repartitioning.
> The topic will be broken forever. and this is not acceptable.
>
> This is why I am so intrigued to model the problem as described because it
> has no overhead for the no copy path while it allows
> to also perform a copy.
>
> State handling wise one has also all the options. Exactly the 3 you
> mentioned I guess. its just that this statestore RPC is a bad idea
> and it was only invented to allow for optimisations that are better not
> done.Not to say they are premature ;)
>
> I hope it makes it clear
>
> best jan
>
>
>> Thanks,
>>
>> Jun
>>
>> On Wed, Mar 21, 2018 at 6:57 AM, Jan Filipiak <Ja...@trivago.com>
>> wrote:
>>
>> Hi Jun,
>>>
>>> I was really seeing progress in our conversation but your latest reply is
>>> just devastating.
>>> I though we were getting close being on the same page now it feels like
>>> we
>>> are in different libraries.
>>>
>>> I just quickly slam my answers in here. If they are to brief I am sorry
>>> give me a ping and try to go into details more.
>>> Just want to show that your pro/cons listing is broken.
>>>
>>> Best Jan
>>>
>>> and want to get rid of this horrible compromise
>>>
>>>
>>> On 19.03.2018 05:48, Jun Rao wrote:
>>>
>>> Hi, Jan,
>>>>
>>>> Thanks for the discussion. Great points.
>>>>
>>>> Let me try to summarize the approach that you are proposing. On the
>>>> broker
>>>> side, we reshuffle the existing data in a topic from current partitions
>>>> to
>>>> the new partitions. Once the reshuffle fully catches up, switch the
>>>> consumers to start consuming from the new partitions. If a consumer
>>>> needs
>>>> to rebuild its local state (due to partition changes), let the consumer
>>>> rebuild its state by reading all existing data from the new partitions.
>>>> Once all consumers have switches over, cut over the producer to the new
>>>> partitions.
>>>>
>>>> The pros for this approach are that :
>>>> 1. There is just one way to rebuild the local state, which is simpler.
>>>>
>>>> true thanks
>>>
>>> The cons for this approach are:
>>>> 1. Need to copy existing data.
>>>>
>>>> Very unfair and not correct. It does not require you to copy over
>>> existing
>>> data. It _allows_ you to copy all existing data.
>>>
>>> 2. The cutover of the producer is a bit complicated since it needs to
>>>
>>>> coordinate with all consumer groups.
>>>>
>>>> Also not true. I explicitly tried to make clear that there is only one
>>> special consumer (in the case of actually copying data) coordination is
>>> required.
>>>
>>> 3. The rebuilding of the state in the consumer is from the input topic,
>>>> which can be more expensive than rebuilding from the existing state.
>>>>
>>>> true, but rebuilding state is only required if you want to increase
>>> processing power, so we assume this is at hand.
>>>
>>> 4. The broker potentially has to know the partitioning function. If this
>>>> needs to be customized at the topic level, it can be a bit messy.
>>>>
>>>> I would argue against having the operation being performed by the
>>> broker.
>>> This was not discussed yet but if you see my original email i suggested
>>> otherwise from the beginning.
>>>
>>> Here is an alternative approach by applying your idea not in the broker,
>>>> but in the consumer. When new partitions are added, we don't move
>>>> existing
>>>> data. In KStreams, we first reshuffle the new input data to a new topic
>>>> T1
>>>> with the old number of partitions and feed T1's data to the rest of the
>>>> pipeline. In the meantime, KStreams reshuffles all existing data of the
>>>> change capture topic to another topic C1 with the new number of
>>>> partitions.
>>>> We can then build the state of the new tasks from C1. Once the new
>>>> states
>>>> have been fully built, we can cut over the consumption to the input
>>>> topic
>>>> and delete T1. This approach works with compacted topic too. If an
>>>> application reads from the beginning of a compacted topic, the consumer
>>>> will reshuffle the portion of the input when the number of partitions
>>>> doesn't match the number of tasks.
>>>>
>>>> We all wipe this idea from our heads instantly. Mixing Ideas from an
>>> argument is not a resolution strategy
>>> just leads to horrible horrible software.
>>>
>>>
>>> The pros of this approach are:
>>>> 1. No need to copy existing data.
>>>> 2. Each consumer group can cut over to the new partitions independently.
>>>> 3. The state is rebuilt from the change capture topic, which is cheaper
>>>> than rebuilding from the input topic.
>>>> 4. Only the KStreams job needs to know the partitioning function.
>>>>
>>>> The cons of this approach are:
>>>> 1. Potentially the same input topic needs to be reshuffled more than
>>>> once
>>>> in different consumer groups during the transition phase.
>>>>
>>>> What do you think?
>>>>
>>>> Thanks,
>>>>
>>>> Jun
>>>>
>>>>
>>>>
>>>> On Thu, Mar 15, 2018 at 1:04 AM, Jan Filipiak <Jan.Filipiak@trivago.com
>>>> >
>>>> wrote:
>>>>
>>>> Hi Jun,
>>>>
>>>>> thank you for following me on these thoughts. It was important to me to
>>>>> feel that kind of understanding for my arguments.
>>>>>
>>>>> What I was hoping for (I mentioned this earlier) is that we can model
>>>>> the
>>>>> case where we do not want to copy the data the exact same way as the
>>>>> case
>>>>> when we do copy the data. Maybe you can peek into the mails before to
>>>>> see
>>>>> more details for this.
>>>>>
>>>>> This means we have the same mechanism to transfer consumer groups to
>>>>> switch topic. The offset mapping that would be generated would even be
>>>>> simpler End Offset of the Old topic => offset 0 off all the partitions
>>>>> of
>>>>> the new topic. Then we could model the transition of a non-copy
>>>>> expansion
>>>>> the exact same way as a copy-expansion.
>>>>>
>>>>> I know this only works when topic growth by a factor. But the benefits
>>>>> of
>>>>> only growing by a factor are to strong anyways. See Clemens's hint and
>>>>> remember that state reshuffling is entirely not needed if one doesn't
>>>>> want
>>>>> to grow processing power.
>>>>>
>>>>> I think these benefits should be clear, and that there is basically no
>>>>> downside to what is currently at hand but just makes everything easy.
>>>>>
>>>>> One thing you need to know is. that if you do not offer rebuilding a
>>>>> log
>>>>> compacted topic like i suggest that even if you have consumer state
>>>>> reshuffling. The topic is broken and can not be used to bootstrap new
>>>>> consumers. They don't know if they need to apply a key from and old
>>>>> partition or not. This is a horrible downside I haven't seen a solution
>>>>> for
>>>>> in the email conversation.
>>>>>
>>>>> I argue to:
>>>>>
>>>>> Only grow topic by a factor always.
>>>>> Have the "no copy consumer" transition as the trivial case of the "copy
>>>>> consumer transition".
>>>>> If processors needs to be scaled, let them rebuild from the new topic
>>>>> and
>>>>> leave the old running in the mean time.
>>>>> Do not implement key shuffling in streams.
>>>>>
>>>>> I hope I can convince you especially with the fact how I want to handle
>>>>> consumer transition. I think
>>>>> you didn't quite understood me there before. I think the term "new
>>>>> topic"
>>>>> intimidated you a little.
>>>>> How we solve this on disc doesn't really matter, If the data goes into
>>>>> the
>>>>> same Dir or a different Dir or anything. I do think that it needs to
>>>>> involve at least rolling a new segment for the existing partitions.
>>>>> But most of the transitions should work without restarting consumers.
>>>>> (newer consumers with support for this). But with new topic i just
>>>>> meant
>>>>> the topic that now has a different partition count. Plenty of ways to
>>>>> handle that (versions, aliases)
>>>>>
>>>>> Hope I can further get my idea across.
>>>>>
>>>>> Best Jan
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> On 14.03.2018 02:45, Jun Rao wrote:
>>>>>
>>>>> Hi, Jan,
>>>>>
>>>>>> Thanks for sharing your view.
>>>>>>
>>>>>> I agree with you that recopying the data potentially makes the state
>>>>>> management easier since the consumer can just rebuild its state from
>>>>>> scratch (i.e., no need for state reshuffling).
>>>>>>
>>>>>> On the flip slide, I saw a few disadvantages of the approach that you
>>>>>> suggested. (1) Building the state from the input topic from scratch is
>>>>>> in
>>>>>> general less efficient than state reshuffling. Let's say one computes
>>>>>> a
>>>>>> count per key from an input topic. The former requires reading all
>>>>>> existing
>>>>>> records in the input topic whereas the latter only requires reading
>>>>>> data
>>>>>> proportional to the number of unique keys. (2) The switching of the
>>>>>> topic
>>>>>> needs modification to the application. If there are many applications
>>>>>> on a
>>>>>> topic, coordinating such an effort may not be easy. Also, it's not
>>>>>> clear
>>>>>> how to enforce exactly-once semantic during the switch. (3) If a topic
>>>>>> doesn't need any state management, recopying the data seems wasteful.
>>>>>> In
>>>>>> that case, in place partition expansion seems more desirable.
>>>>>>
>>>>>> I understand your concern about adding complexity in KStreams. But,
>>>>>> perhaps
>>>>>> we could iterate on that a bit more to see if it can be simplified.
>>>>>>
>>>>>> Jun
>>>>>>
>>>>>>
>>>>>> On Mon, Mar 12, 2018 at 11:21 PM, Jan Filipiak <
>>>>>> Jan.Filipiak@trivago.com>
>>>>>> wrote:
>>>>>>
>>>>>> Hi Jun,
>>>>>>
>>>>>> I will focus on point 61 as I think its _the_ fundamental part that I
>>>>>>> cant
>>>>>>> get across at the moment.
>>>>>>>
>>>>>>> Kafka is the platform to have state materialized multiple times from
>>>>>>> one
>>>>>>> input. I emphasize this: It is the building block in architectures
>>>>>>> that
>>>>>>> allow you to
>>>>>>> have your state maintained multiple times. You put a message in once,
>>>>>>> and
>>>>>>> you have it pop out as often as you like. I believe you understand
>>>>>>> this.
>>>>>>>
>>>>>>> Now! The path of thinking goes the following: I am using apache kafka
>>>>>>> and
>>>>>>> I _want_ my state multiple times. What am I going todo?
>>>>>>>
>>>>>>> A) Am I going to take my state that I build up, plunge some sort of
>>>>>>> RPC
>>>>>>> layer ontop of it, use that RPC layer to throw my records across
>>>>>>> instances?
>>>>>>> B) Am I just going to read the damn message twice?
>>>>>>>
>>>>>>> Approach A is fundamentally flawed and a violation of all that is
>>>>>>> good
>>>>>>> and
>>>>>>> holy in kafka deployments. I can not understand how this Idea can
>>>>>>> come
>>>>>>> in
>>>>>>> the first place.
>>>>>>> (I do understand: IQ in streams, they polluted the kafka streams
>>>>>>> codebase
>>>>>>> really bad already. It is not funny! I think they are equally flawed
>>>>>>> as
>>>>>>> A)
>>>>>>>
>>>>>>> I say, we do what Kafka is good at. We repartition the topic once. We
>>>>>>> switch the consumers.
>>>>>>> (Those that need more partitions are going to rebuild their state in
>>>>>>> multiple partitions by reading the new topic, those that don't just
>>>>>>> assign
>>>>>>> the new partitions properly)
>>>>>>> We switch producers. Done!
>>>>>>>
>>>>>>> The best thing! It is trivial, hipster stream processor will have an
>>>>>>> easy
>>>>>>> time with that aswell. Its so super simple. And simple IS good!
>>>>>>> It is what kafka was build todo. It is how we do it today. All I am
>>>>>>> saying
>>>>>>> is that a little broker help doing the producer swap is super useful.
>>>>>>>
>>>>>>> For everyone interested in why kafka is so powerful with approach B,
>>>>>>> please watch https://youtu.be/bEbeZPVo98c?t=1633
>>>>>>> I already looked up a good point in time, I think after 5 minutes the
>>>>>>> "state" topic is handled and you should be able to understand me
>>>>>>> and inch better.
>>>>>>>
>>>>>>> Please do not do A to the project, it deserves better!
>>>>>>>
>>>>>>> Best Jan
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> On 13.03.2018 02:40, Jun Rao wrote:
>>>>>>>
>>>>>>> Hi, Jan,
>>>>>>>
>>>>>>> Thanks for the reply. A few more comments below.
>>>>>>>>
>>>>>>>> 50. Ok, we can think a bit harder for supporting compacted topics.
>>>>>>>>
>>>>>>>> 51. This is a fundamental design question. In the more common case,
>>>>>>>> the
>>>>>>>> reason why someone wants to increase the number of partitions is
>>>>>>>> that
>>>>>>>> the
>>>>>>>> consumer application is slow and one wants to run more consumer
>>>>>>>> instances
>>>>>>>> to increase the degree of parallelism. So, fixing the number of
>>>>>>>> running
>>>>>>>> consumer instances when expanding the partitions won't help this
>>>>>>>> case.
>>>>>>>> If
>>>>>>>> we do need to increase the number of consumer instances, we need to
>>>>>>>> somehow
>>>>>>>> reshuffle the state of the consumer across instances. What we have
>>>>>>>> been
>>>>>>>> discussing in this KIP is whether we can do this more effectively
>>>>>>>> through
>>>>>>>> the KStream library (e.g. through a 2-phase partition expansion).
>>>>>>>> This
>>>>>>>> will
>>>>>>>> add some complexity, but it's probably better than everyone doing
>>>>>>>> this
>>>>>>>> in
>>>>>>>> the application space. The recopying approach that you mentioned
>>>>>>>> doesn't
>>>>>>>> seem to address the consumer state management issue when the
>>>>>>>> consumer
>>>>>>>> switches from an old to a new topic.
>>>>>>>>
>>>>>>>> 52. As for your example, it depends on whether the join key is the
>>>>>>>> same
>>>>>>>> between (A,B) and (B,C). If the join key is the same, we can do a
>>>>>>>> 2-phase
>>>>>>>> partition expansion of A, B, and C together. If the join keys are
>>>>>>>> different, one would need to repartition the data on a different key
>>>>>>>> for
>>>>>>>> the second join, then the partition expansion can be done
>>>>>>>> independently
>>>>>>>> between (A,B) and (B,C).
>>>>>>>>
>>>>>>>> 53. If you always fix the number of consumer instances, we you
>>>>>>>> described
>>>>>>>> works. However, as I mentioned in #51, I am not sure how your
>>>>>>>> proposal
>>>>>>>> deals with consumer states when the number of consumer instances
>>>>>>>> grows.
>>>>>>>> Also, it just seems that it's better to avoid re-copying the
>>>>>>>> existing
>>>>>>>> data.
>>>>>>>>
>>>>>>>> 60. "just want to throw in my question from the longer email in the
>>>>>>>> other
>>>>>>>> Thread here. How will the bloom filter help a new consumer to decide
>>>>>>>> to
>>>>>>>> apply the key or not?" Not sure that I fully understood your
>>>>>>>> question.
>>>>>>>> The
>>>>>>>> consumer just reads whatever key is in the log. The bloom filter
>>>>>>>> just
>>>>>>>> helps
>>>>>>>> clean up the old keys.
>>>>>>>>
>>>>>>>> 61. "Why can we afford having a topic where its apparently not
>>>>>>>> possible
>>>>>>>> to
>>>>>>>> start a new application on? I think this is an overall flaw of the
>>>>>>>> discussed idea here. Not playing attention to the overall
>>>>>>>> architecture."
>>>>>>>> Could you explain a bit more when one can't start a new application?
>>>>>>>>
>>>>>>>> Jun
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> On Sat, Mar 10, 2018 at 1:40 AM, Jan Filipiak <
>>>>>>>> Jan.Filipiak@trivago.com
>>>>>>>> wrote:
>>>>>>>>
>>>>>>>> Hi Jun, thanks for your mail.
>>>>>>>>
>>>>>>>> Thank you for your questions!
>>>>>>>>
>>>>>>>>> I think they are really good and tackle the core of the problem I
>>>>>>>>> see.
>>>>>>>>>
>>>>>>>>> I will answer inline, mostly but still want to set the tone here.
>>>>>>>>>
>>>>>>>>> The core strength of kafka is what Martin once called the
>>>>>>>>> kappa-Architecture. How does this work?
>>>>>>>>> You have everything as a log as in kafka. When you need to change
>>>>>>>>> something.
>>>>>>>>> You create the new version of your application and leave it running
>>>>>>>>> in
>>>>>>>>> parallel.
>>>>>>>>> Once the new version is good you switch your users to use the new
>>>>>>>>> application.
>>>>>>>>>
>>>>>>>>> The online reshuffling effectively breaks this architecture and I
>>>>>>>>> think
>>>>>>>>> the switch in thinking here is more harmful
>>>>>>>>> than any details about the partitioning function to allow such a
>>>>>>>>> change.
>>>>>>>>> I
>>>>>>>>> feel with my suggestion we are the closest to
>>>>>>>>> the original and battle proven architecture and I can only warn to
>>>>>>>>> move
>>>>>>>>> away from it.
>>>>>>>>>
>>>>>>>>> I might have forgotten something, sometimes its hard for me to
>>>>>>>>> getting
>>>>>>>>> all
>>>>>>>>> the thoughts captured in a mail, but I hope the comments inline
>>>>>>>>> will
>>>>>>>>> further make my concern clear, and put some emphasis on why I
>>>>>>>>> prefer
>>>>>>>>> my
>>>>>>>>> solution ;)
>>>>>>>>>
>>>>>>>>> One thing we should all be aware of when discussing this, and I
>>>>>>>>> think
>>>>>>>>> Dong
>>>>>>>>> should have mentioned it (maybe he did).
>>>>>>>>> We are not discussing all of this out of thin air but there is an
>>>>>>>>> effort
>>>>>>>>> in the Samza project.
>>>>>>>>>
>>>>>>>>> https://cwiki.apache.org/confluence/display/SAMZA/SEP-5%3A+
>>>>>>>>> Enable+partition+expansion+of+input+streams
>>>>>>>>> https://issues.apache.org/jira/browse/SAMZA-1293
>>>>>>>>>
>>>>>>>>> To be clear. I think SEP-5 (state of last week, dont know if it
>>>>>>>>> adapted
>>>>>>>>> to
>>>>>>>>> this discussion) is on a way better path than KIP-253, and I can't
>>>>>>>>> really
>>>>>>>>> explain why.
>>>>>>>>>
>>>>>>>>> Best Jan,
>>>>>>>>>
>>>>>>>>> nice weekend everyone
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> On 09.03.2018 03:36, Jun Rao wrote:
>>>>>>>>>
>>>>>>>>> Hi, Jan,
>>>>>>>>>
>>>>>>>>> Thanks for the feedback. Just some comments on the earlier points
>>>>>>>>>
>>>>>>>>>> that
>>>>>>>>>> you
>>>>>>>>>> mentioned.
>>>>>>>>>>
>>>>>>>>>> 50. You brought up the question of whether existing data needs to
>>>>>>>>>> be
>>>>>>>>>> copied
>>>>>>>>>> during partition expansion. My understand of your view is that
>>>>>>>>>> avoid
>>>>>>>>>> copying existing data will be more efficient, but it doesn't work
>>>>>>>>>> well
>>>>>>>>>> with
>>>>>>>>>> compacted topics since some keys in the original partitions will
>>>>>>>>>> never
>>>>>>>>>> be
>>>>>>>>>> cleaned. It would be useful to understand your use case of
>>>>>>>>>> compacted
>>>>>>>>>> topics
>>>>>>>>>> a bit more. In the common use case, the data volume in a compacted
>>>>>>>>>> topic
>>>>>>>>>> may not be large. So, I am not sure if there is a strong need to
>>>>>>>>>> expand
>>>>>>>>>> partitions in a compacted topic, at least initially.
>>>>>>>>>>
>>>>>>>>>> I do agree. State is usually smaller. Update rates might be also
>>>>>>>>>>
>>>>>>>>>> competitively high.
>>>>>>>>>>
>>>>>>>>> Doing Log-compaction (even beeing very efficient and configurable)
>>>>>>>>> is
>>>>>>>>> also
>>>>>>>>> a more expensive operation than
>>>>>>>>> just discarding old segments. Further if you want to use more
>>>>>>>>> consumers
>>>>>>>>> processing the events
>>>>>>>>> you also have to grow the number of partitions. Especially for
>>>>>>>>> use-cases
>>>>>>>>> we do (KIP-213) a tiny state full
>>>>>>>>> table might be very expensive to process if it joins against a huge
>>>>>>>>> table.
>>>>>>>>>
>>>>>>>>> I can just say we have been in the spot of needing to grow log
>>>>>>>>> compacted
>>>>>>>>> topics. Mainly for processing power we can bring to the table.
>>>>>>>>>
>>>>>>>>> Further i am not at all concerned about the extra spaced used by
>>>>>>>>> "garbage
>>>>>>>>> keys". I am more concerned about the correctness of innocent
>>>>>>>>> consumers.
>>>>>>>>> The
>>>>>>>>> logic becomes complicated. Say for streams one would need to load
>>>>>>>>> the
>>>>>>>>> record into state but not forward it the topology ( to have it
>>>>>>>>> available
>>>>>>>>> for shuffeling). I rather have it simple and a topic clean
>>>>>>>>> regardless
>>>>>>>>> if
>>>>>>>>> it
>>>>>>>>> still has its old partition count. Especially with multiple
>>>>>>>>> partitions
>>>>>>>>> growth's I think it becomes insanely hard to to this shuffle
>>>>>>>>> correct.
>>>>>>>>> Maybe
>>>>>>>>> Streams and Samza can do it. Especially if you do "hipster stream
>>>>>>>>> processing" <https://www.confluent.io/blog
>>>>>>>>> /introducing-kafka-streams-
>>>>>>>>> stream-processing-made-simple/>. This makes kafka way to
>>>>>>>>> complicated.
>>>>>>>>> With my approach I think its way simpler because the topic has no
>>>>>>>>> "history"
>>>>>>>>> in terms of partitioning but is always clean.
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> 51. "Growing the topic by an integer factor does not require any
>>>>>>>>> state
>>>>>>>>>
>>>>>>>>> redistribution at all." Could you clarify this a bit more? Let's
>>>>>>>>> say
>>>>>>>>>
>>>>>>>>>> you
>>>>>>>>>> have a consumer app that computes the windowed count per key. If
>>>>>>>>>> you
>>>>>>>>>> double
>>>>>>>>>> the number of partitions from 1 to 2 and grow the consumer
>>>>>>>>>> instances
>>>>>>>>>> from
>>>>>>>>>> 1
>>>>>>>>>> to 2, we would need to redistribute some of the counts to the new
>>>>>>>>>> consumer
>>>>>>>>>> instance. Regarding to linear hashing, it's true that it won't
>>>>>>>>>> solve
>>>>>>>>>> the
>>>>>>>>>> problem with compacted topics. The main benefit is that it
>>>>>>>>>> redistributes
>>>>>>>>>> the keys in one partition to no more than two partitions, which
>>>>>>>>>> could
>>>>>>>>>> help
>>>>>>>>>> redistribute the state.
>>>>>>>>>>
>>>>>>>>>> You don't need to spin up a new consumer in this case. every
>>>>>>>>>> consumer
>>>>>>>>>>
>>>>>>>>>> would just read every partition with the (partition % num_task)
>>>>>>>>>>
>>>>>>>>> task.
>>>>>>>>> it
>>>>>>>>> will still have the previous data right there and can go on.
>>>>>>>>>
>>>>>>>>> This sounds contradictory to what I said before, but please bear
>>>>>>>>> with
>>>>>>>>> me.
>>>>>>>>>
>>>>>>>>> 52. Good point on coordinating the expansion of 2 topics that need
>>>>>>>>> to
>>>>>>>>> be
>>>>>>>>>
>>>>>>>>> joined together. This is where the 2-phase partition expansion
>>>>>>>>> could
>>>>>>>>>
>>>>>>>>>> potentially help. In the first phase, we could add new partitions
>>>>>>>>>> to
>>>>>>>>>> the 2
>>>>>>>>>> topics one at a time but without publishing to the new patitions.
>>>>>>>>>> Then,
>>>>>>>>>> we
>>>>>>>>>> can add new consumer instances to pick up the new partitions. In
>>>>>>>>>> this
>>>>>>>>>> transition phase, no reshuffling is needed since no data is coming
>>>>>>>>>> from
>>>>>>>>>> the
>>>>>>>>>> new partitions. Finally, we can enable the publishing to the new
>>>>>>>>>> partitions.
>>>>>>>>>>
>>>>>>>>>> I think its even worse than you think. I would like to introduce
>>>>>>>>>> the
>>>>>>>>>>
>>>>>>>>>> Term
>>>>>>>>>>
>>>>>>>>> transitive copartitioning. Imagine
>>>>>>>>> 2 streams application. One joins (A,B) the other (B,C) then there
>>>>>>>>> is
>>>>>>>>> a
>>>>>>>>> transitive copartition requirement for
>>>>>>>>> (A,C) to be copartitioned aswell. This can spread significantly and
>>>>>>>>> require many consumers to adapt at the same time.
>>>>>>>>>
>>>>>>>>> It is also not entirely clear to me how you not need reshuffling in
>>>>>>>>> this
>>>>>>>>> case. If A has a record that never gets updated after the expansion
>>>>>>>>> and
>>>>>>>>> the
>>>>>>>>> coresponding B record moves to a new partition. How shall they meet
>>>>>>>>> w/o
>>>>>>>>> shuffle?
>>>>>>>>>
>>>>>>>>> 53. "Migrating consumer is a step that might be made completly
>>>>>>>>>
>>>>>>>>> unnecessary
>>>>>>>>>
>>>>>>>>>> if - for example streams - takes the gcd as partitioning scheme
>>>>>>>>>> instead
>>>>>>>>>> of
>>>>>>>>>> enforcing 1 to 1." Not sure that I fully understand this. I think
>>>>>>>>>> you
>>>>>>>>>> mean
>>>>>>>>>> that a consumer application can run more instances than the number
>>>>>>>>>> of
>>>>>>>>>> partitions. In that case, the consumer can just repartitioning the
>>>>>>>>>> input
>>>>>>>>>> data according to the number of instances. This is possible, but
>>>>>>>>>> just
>>>>>>>>>> has
>>>>>>>>>> the overhead of reshuffling the data.
>>>>>>>>>>
>>>>>>>>>> No what I meant is ( that is also your question i think Mathias)
>>>>>>>>>> that
>>>>>>>>>> if
>>>>>>>>>>
>>>>>>>>>> you grow a topic by a factor.
>>>>>>>>>>
>>>>>>>>> Even if your processor is statefull you can can just assign all the
>>>>>>>>> multiples of the previous partition to
>>>>>>>>> this consumer and the state to keep processing correctly will be
>>>>>>>>> present
>>>>>>>>> w/o any shuffling.
>>>>>>>>>
>>>>>>>>> Say you have an assignment
>>>>>>>>> Statefull consumer => partition
>>>>>>>>> 0 => 0
>>>>>>>>> 1 => 1
>>>>>>>>> 2 => 2
>>>>>>>>>
>>>>>>>>> and you grow you topic by 4 you get,
>>>>>>>>>
>>>>>>>>> 0 => 0,3,6,9
>>>>>>>>> 1 => 1,4,7,10
>>>>>>>>> 2 => 2,5,8,11
>>>>>>>>>
>>>>>>>>> Say your hashcode is 8. 8%3 => 2  before so consumer for partition
>>>>>>>>> 2
>>>>>>>>> has
>>>>>>>>> it.
>>>>>>>>> Now you you have 12 partitions so 8%12 => 8, so it goes into
>>>>>>>>> partition
>>>>>>>>> 8
>>>>>>>>> which is assigned to the same consumer
>>>>>>>>> who had 2 before and therefore knows the key.
>>>>>>>>>
>>>>>>>>> Userland reshuffeling is there as an options. And it does exactly
>>>>>>>>> what
>>>>>>>>> I
>>>>>>>>> suggest. And I think its the perfect strategie. All I am suggestion
>>>>>>>>> is
>>>>>>>>> broker side support to switch the producers to the newly
>>>>>>>>> partitioned
>>>>>>>>> topic.
>>>>>>>>> Then the old (to few partition topic) can go away.  Remember the
>>>>>>>>> list
>>>>>>>>> of
>>>>>>>>> steps in the beginning of this thread. If one has broker support
>>>>>>>>> for
>>>>>>>>> all
>>>>>>>>> where its required and streams support for those that aren’t
>>>>>>>>> necessarily.
>>>>>>>>> Then one has solved the problem.
>>>>>>>>> I repeat it because I think its important. I am really happy that
>>>>>>>>> you
>>>>>>>>> brought that up! because its 100% what I want just with the
>>>>>>>>> differences
>>>>>>>>> to
>>>>>>>>> have an option to discard the to small topic later (after all
>>>>>>>>> consumers
>>>>>>>>> adapted). And to have order correct there. I need broker support
>>>>>>>>> managing
>>>>>>>>> the copy process + the produces and fence them against each other.
>>>>>>>>> I
>>>>>>>>> also
>>>>>>>>> repeat. the copy process can run for weeks in the worst case.
>>>>>>>>> Copying
>>>>>>>>> the
>>>>>>>>> data is not the longest task migrating consumers might very well
>>>>>>>>> be.
>>>>>>>>> Once all consumers switched and copying is really up to date (think
>>>>>>>>> ISR
>>>>>>>>> like up to date) only then we stop the producer, wait for the copy
>>>>>>>>> to
>>>>>>>>> finish and use the new topic for producing.
>>>>>>>>>
>>>>>>>>> After this the topic is perfect in shape. and no one needs to worry
>>>>>>>>> about
>>>>>>>>> complicated stuff. (old keys hanging around might arrive in some
>>>>>>>>> other
>>>>>>>>> topic later.....). can only imagine how many tricky bugs gonna
>>>>>>>>> arrive
>>>>>>>>> after
>>>>>>>>> someone had grown and shrunken is topic 10 times.
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> 54. "The other thing I wanted to mention is that I believe the
>>>>>>>>> current
>>>>>>>>>
>>>>>>>>> suggestion (without copying data over) can be implemented in pure
>>>>>>>>>
>>>>>>>>>> userland
>>>>>>>>>> with a custom partitioner and a small feedbackloop from
>>>>>>>>>> ProduceResponse
>>>>>>>>>> =>
>>>>>>>>>> Partitionier in coorporation with a change management system." I
>>>>>>>>>> am
>>>>>>>>>> not
>>>>>>>>>> sure a customized partitioner itself solves the problem. We
>>>>>>>>>> probably
>>>>>>>>>> need
>>>>>>>>>> some broker side support to enforce when the new partitions can be
>>>>>>>>>> used.
>>>>>>>>>> We
>>>>>>>>>> also need some support on the consumer/kstream side to preserve
>>>>>>>>>> the
>>>>>>>>>> per
>>>>>>>>>> key
>>>>>>>>>> ordering and potentially migrate the processing state. This is not
>>>>>>>>>> trivial
>>>>>>>>>> and I am not sure if it's ideal to fully push to the application
>>>>>>>>>> space.
>>>>>>>>>>
>>>>>>>>>> Broker support is defenitly the preferred way here. I have nothing
>>>>>>>>>>
>>>>>>>>>> against
>>>>>>>>>>
>>>>>>>>> broker support.
>>>>>>>>> I tried to say that for what I would preffer - copying the data
>>>>>>>>> over,
>>>>>>>>> at
>>>>>>>>> least for log compacted topics -
>>>>>>>>> I would require more broker support than the KIP currently offers.
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> Jun
>>>>>>>>>
>>>>>>>>> On Tue, Mar 6, 2018 at 10:33 PM, Jan Filipiak <
>>>>>>>>>
>>>>>>>>>> Jan.Filipiak@trivago.com
>>>>>>>>>> wrote:
>>>>>>>>>>
>>>>>>>>>> Hi Dong,
>>>>>>>>>>
>>>>>>>>>> are you actually reading my emails, or are you just using the
>>>>>>>>>> thread I
>>>>>>>>>>
>>>>>>>>>> started for general announcements regarding the KIP?
>>>>>>>>>>>
>>>>>>>>>>> I tried to argue really hard against linear hashing. Growing the
>>>>>>>>>>> topic
>>>>>>>>>>> by
>>>>>>>>>>> an integer factor does not require any state redistribution at
>>>>>>>>>>> all. I
>>>>>>>>>>> fail
>>>>>>>>>>> to see completely where linear hashing helps on log compacted
>>>>>>>>>>> topics.
>>>>>>>>>>>
>>>>>>>>>>> If you are not willing to explain to me what I might be
>>>>>>>>>>> overlooking:
>>>>>>>>>>> that
>>>>>>>>>>> is fine.
>>>>>>>>>>> But I ask you to not reply to my emails then. Please understand
>>>>>>>>>>> my
>>>>>>>>>>> frustration with this.
>>>>>>>>>>>
>>>>>>>>>>> Best Jan
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> On 06.03.2018 19:38, Dong Lin wrote:
>>>>>>>>>>>
>>>>>>>>>>> Hi everyone,
>>>>>>>>>>>
>>>>>>>>>>> Thanks for all the comments! It appears that everyone prefers
>>>>>>>>>>> linear
>>>>>>>>>>>
>>>>>>>>>>> hashing because it reduces the amount of state that needs to be
>>>>>>>>>>>> moved
>>>>>>>>>>>> between consumers (for stream processing). The KIP has been
>>>>>>>>>>>> updated
>>>>>>>>>>>> to
>>>>>>>>>>>> use
>>>>>>>>>>>> linear hashing.
>>>>>>>>>>>>
>>>>>>>>>>>> Regarding the migration endeavor: it seems that migrating
>>>>>>>>>>>> producer
>>>>>>>>>>>> library
>>>>>>>>>>>> to use linear hashing should be pretty straightforward without
>>>>>>>>>>>> much operational endeavor. If we don't upgrade client library to
>>>>>>>>>>>> use
>>>>>>>>>>>> this
>>>>>>>>>>>> KIP, we can not support in-order delivery after partition is
>>>>>>>>>>>> changed
>>>>>>>>>>>> anyway. Suppose we upgrade client library to use this KIP, if
>>>>>>>>>>>> partition
>>>>>>>>>>>> number is not changed, the key -> partition mapping will be
>>>>>>>>>>>> exactly
>>>>>>>>>>>> the
>>>>>>>>>>>> same as it is now because it is still determined using
>>>>>>>>>>>> murmur_hash(key)
>>>>>>>>>>>> %
>>>>>>>>>>>> original_partition_num. In other words, this change is backward
>>>>>>>>>>>> compatible.
>>>>>>>>>>>>
>>>>>>>>>>>> Regarding the load distribution: if we use linear hashing, the
>>>>>>>>>>>> load
>>>>>>>>>>>> may
>>>>>>>>>>>> be
>>>>>>>>>>>> unevenly distributed because those partitions which are not
>>>>>>>>>>>> split
>>>>>>>>>>>> may
>>>>>>>>>>>> receive twice as much traffic as other partitions that are
>>>>>>>>>>>> split.
>>>>>>>>>>>> This
>>>>>>>>>>>> issue can be mitigated by creating topic with partitions that
>>>>>>>>>>>> are
>>>>>>>>>>>> several
>>>>>>>>>>>> times the number of consumers. And there will be no imbalance if
>>>>>>>>>>>> the
>>>>>>>>>>>> partition number is always doubled. So this imbalance seems
>>>>>>>>>>>> acceptable.
>>>>>>>>>>>>
>>>>>>>>>>>> Regarding storing the partition strategy as per-topic config: It
>>>>>>>>>>>> seems
>>>>>>>>>>>> not
>>>>>>>>>>>> necessary since we can still use murmur_hash as the default hash
>>>>>>>>>>>> function
>>>>>>>>>>>> and additionally apply the linear hashing algorithm if the
>>>>>>>>>>>> partition
>>>>>>>>>>>> number
>>>>>>>>>>>> has increased. Not sure if there is any use-case for producer to
>>>>>>>>>>>> use a
>>>>>>>>>>>> different hash function. Jason, can you check if there is some
>>>>>>>>>>>> use-case
>>>>>>>>>>>> that I missed for using the per-topic partition strategy?
>>>>>>>>>>>>
>>>>>>>>>>>> Regarding how to reduce latency (due to state store/load) in
>>>>>>>>>>>> stream
>>>>>>>>>>>> processing consumer when partition number changes: I need to
>>>>>>>>>>>> read
>>>>>>>>>>>> the
>>>>>>>>>>>> Kafka
>>>>>>>>>>>> Stream code to understand how Kafka Stream currently migrate
>>>>>>>>>>>> state
>>>>>>>>>>>> between
>>>>>>>>>>>> consumers when the application is added/removed for a given
>>>>>>>>>>>> job. I
>>>>>>>>>>>> will
>>>>>>>>>>>> reply after I finish reading the documentation and code.
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>> Thanks,
>>>>>>>>>>>> Dong
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>> On Mon, Mar 5, 2018 at 10:43 AM, Jason Gustafson <
>>>>>>>>>>>> jason@confluent.io>
>>>>>>>>>>>> wrote:
>>>>>>>>>>>>
>>>>>>>>>>>> Great discussion. I think I'm wondering whether we can continue
>>>>>>>>>>>> to
>>>>>>>>>>>> leave
>>>>>>>>>>>>
>>>>>>>>>>>> Kafka agnostic to the partitioning strategy. The challenge is
>>>>>>>>>>>>
>>>>>>>>>>>> communicating
>>>>>>>>>>>>
>>>>>>>>>>>>> the partitioning logic from producers to consumers so that the
>>>>>>>>>>>>> dependencies
>>>>>>>>>>>>> between each epoch can be determined. For the sake of
>>>>>>>>>>>>> discussion,
>>>>>>>>>>>>> imagine
>>>>>>>>>>>>> you did something like the following:
>>>>>>>>>>>>>
>>>>>>>>>>>>> 1. The name (and perhaps version) of a partitioning strategy is
>>>>>>>>>>>>> stored
>>>>>>>>>>>>> in
>>>>>>>>>>>>> topic configuration when a topic is created.
>>>>>>>>>>>>> 2. The producer looks up the partitioning strategy before
>>>>>>>>>>>>> writing
>>>>>>>>>>>>> to
>>>>>>>>>>>>> a
>>>>>>>>>>>>> topic and includes it in the produce request (for fencing). If
>>>>>>>>>>>>> it
>>>>>>>>>>>>> doesn't
>>>>>>>>>>>>> have an implementation for the configured strategy, it fails.
>>>>>>>>>>>>> 3. The consumer also looks up the partitioning strategy and
>>>>>>>>>>>>> uses
>>>>>>>>>>>>> it
>>>>>>>>>>>>> to
>>>>>>>>>>>>> determine dependencies when reading a new epoch. It could
>>>>>>>>>>>>> either
>>>>>>>>>>>>> fail
>>>>>>>>>>>>> or
>>>>>>>>>>>>> make the most conservative dependency assumptions if it doesn't
>>>>>>>>>>>>> know
>>>>>>>>>>>>> how
>>>>>>>>>>>>> to
>>>>>>>>>>>>> implement the partitioning strategy. For the consumer, the new
>>>>>>>>>>>>> interface
>>>>>>>>>>>>> might look something like this:
>>>>>>>>>>>>>
>>>>>>>>>>>>> // Return the partition dependencies following an epoch bump
>>>>>>>>>>>>> Map<Integer, List<Integer>> dependencies(int
>>>>>>>>>>>>> numPartitionsBeforeEpochBump,
>>>>>>>>>>>>> int numPartitionsAfterEpochBump)
>>>>>>>>>>>>>
>>>>>>>>>>>>> The unordered case then is just a particular implementation
>>>>>>>>>>>>> which
>>>>>>>>>>>>> never
>>>>>>>>>>>>> has
>>>>>>>>>>>>> any epoch dependencies. To implement this, we would need some
>>>>>>>>>>>>> way
>>>>>>>>>>>>> for
>>>>>>>>>>>>> the
>>>>>>>>>>>>> consumer to find out how many partitions there were in each
>>>>>>>>>>>>> epoch,
>>>>>>>>>>>>> but
>>>>>>>>>>>>> maybe that's not too unreasonable.
>>>>>>>>>>>>>
>>>>>>>>>>>>> Thanks,
>>>>>>>>>>>>> Jason
>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>> On Mon, Mar 5, 2018 at 4:51 AM, Jan Filipiak <
>>>>>>>>>>>>> Jan.Filipiak@trivago.com
>>>>>>>>>>>>> wrote:
>>>>>>>>>>>>>
>>>>>>>>>>>>> Hi Dong
>>>>>>>>>>>>>
>>>>>>>>>>>>> thank you very much for your questions.
>>>>>>>>>>>>>
>>>>>>>>>>>>> regarding the time spend copying data across:
>>>>>>>>>>>>>
>>>>>>>>>>>>>> It is correct that copying data from a topic with one
>>>>>>>>>>>>>> partition
>>>>>>>>>>>>>> mapping
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> to
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> a topic with a different partition mapping takes way longer
>>>>>>>>>>>>>> than
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> we
>>>>>>>>>>>>> can
>>>>>>>>>>>>>
>>>>>>>>>>>>> stop producers. Tens of minutes is a very optimistic estimate
>>>>>>>>>>>>> here.
>>>>>>>>>>>>>
>>>>>>>>>>>>> Many
>>>>>>>>>>>>>> people can not afford copy full steam and therefore will have
>>>>>>>>>>>>>> some
>>>>>>>>>>>>>> rate
>>>>>>>>>>>>>> limiting in place, this can bump the timespan into the day's.
>>>>>>>>>>>>>> The
>>>>>>>>>>>>>> good
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> part
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> is that the vast majority of the data can be copied while the
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> producers
>>>>>>>>>>>>>
>>>>>>>>>>>>> are
>>>>>>>>>>>>>
>>>>>>>>>>>>> still going. One can then, piggyback the consumers ontop of
>>>>>>>>>>>>>> this
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> timeframe,
>>>>>>>>>>>>>
>>>>>>>>>>>>> by the method mentioned (provide them an mapping from their old
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> offsets
>>>>>>>>>>>>>
>>>>>>>>>>>>> to
>>>>>>>>>>>>>
>>>>>>>>>>>>> new offsets in their repartitioned topics. In that way we
>>>>>>>>>>>>>> separate
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> migration of consumers from migration of producers (decoupling
>>>>>>>>>>>>>
>>>>>>>>>>>>> these
>>>>>>>>>>>>>> is
>>>>>>>>>>>>>> what kafka is strongest at). The time to actually swap over
>>>>>>>>>>>>>> the
>>>>>>>>>>>>>> producers
>>>>>>>>>>>>>> should be kept minimal by ensuring that when a swap attempt is
>>>>>>>>>>>>>> started
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> the
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> consumer copying over should be very close to the log end and
>>>>>>>>>>>>>> is
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> expected
>>>>>>>>>>>>>
>>>>>>>>>>>>> to finish within the next fetch. The operation should have a
>>>>>>>>>>>>>> time-out
>>>>>>>>>>>>>> and
>>>>>>>>>>>>>> should be "reattemtable".
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> Importance of logcompaction:
>>>>>>>>>>>>>> If a producer produces key A, to partiton 0, its forever gonna
>>>>>>>>>>>>>> be
>>>>>>>>>>>>>> there,
>>>>>>>>>>>>>> unless it gets deleted. The record might sit in there for
>>>>>>>>>>>>>> years. A
>>>>>>>>>>>>>> new
>>>>>>>>>>>>>> producer started with the new partitions will fail to delete
>>>>>>>>>>>>>> the
>>>>>>>>>>>>>> record
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> in
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> the correct partition. Th record will be there forever and one
>>>>>>>>>>>>>> can
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> not
>>>>>>>>>>>>>
>>>>>>>>>>>>> reliable bootstrap new consumers. I cannot see how linear
>>>>>>>>>>>>> hashing
>>>>>>>>>>>>>
>>>>>>>>>>>>> can
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> solve
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> this.
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> Regarding your skipping of userland copying:
>>>>>>>>>>>>>
>>>>>>>>>>>>> 100%, copying the data across in userland is, as far as i can
>>>>>>>>>>>>>> see,
>>>>>>>>>>>>>> only
>>>>>>>>>>>>>> a
>>>>>>>>>>>>>> usecase for log compacted topics. Even for logcompaction +
>>>>>>>>>>>>>> retentions
>>>>>>>>>>>>>> it
>>>>>>>>>>>>>> should only be opt-in. Why did I bring it up? I think log
>>>>>>>>>>>>>> compaction
>>>>>>>>>>>>>> is
>>>>>>>>>>>>>> a
>>>>>>>>>>>>>> very important feature to really embrace kafka as a "data
>>>>>>>>>>>>>> plattform".
>>>>>>>>>>>>>> The
>>>>>>>>>>>>>> point I also want to make is that copying data this way is
>>>>>>>>>>>>>> completely
>>>>>>>>>>>>>> inline with the kafka architecture. it only consists of
>>>>>>>>>>>>>> reading
>>>>>>>>>>>>>> and
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> writing
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> to topics.
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> I hope it clarifies more why I think we should aim for more
>>>>>>>>>>>>> than
>>>>>>>>>>>>>
>>>>>>>>>>>>> the
>>>>>>>>>>>>>> current KIP. I fear that once the KIP is done not much more
>>>>>>>>>>>>>> effort
>>>>>>>>>>>>>> will
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> be
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> taken.
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> On 04.03.2018 02:28, Dong Lin wrote:
>>>>>>>>>>>>>
>>>>>>>>>>>>>> Hey Jan,
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> In the current proposal, the consumer will be blocked on
>>>>>>>>>>>>>> waiting
>>>>>>>>>>>>>> for
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> other
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> consumers of the group to consume up to a given offset. In
>>>>>>>>>>>>>>> most
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> cases,
>>>>>>>>>>>>>> all
>>>>>>>>>>>>>> consumers should be close to the LEO of the partitions when
>>>>>>>>>>>>>> the
>>>>>>>>>>>>>> partition
>>>>>>>>>>>>>> expansion happens. Thus the time waiting should not be long
>>>>>>>>>>>>>> e.g.
>>>>>>>>>>>>>> on
>>>>>>>>>>>>>> the
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> order of seconds. On the other hand, it may take a long time
>>>>>>>>>>>>>> to
>>>>>>>>>>>>>> wait
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> for
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> the entire partition to be copied -- the amount of time is
>>>>>>>>>>>>>>> proportional
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> to
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> the amount of existing data in the partition, which can take
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> tens of
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> minutes. So the amount of time that we stop consumers may not
>>>>>>>>>>>>>> be
>>>>>>>>>>>>>> on
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> the
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> same order of magnitude.
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> If we can implement this suggestion without copying data over
>>>>>>>>>>>>>>> in
>>>>>>>>>>>>>>> purse
>>>>>>>>>>>>>>> userland, it will be much more valuable. Do you have ideas on
>>>>>>>>>>>>>>> how
>>>>>>>>>>>>>>> this
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> can
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> be done?
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> Not sure why the current KIP not help people who depend on
>>>>>>>>>>>>>> log
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> compaction.
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> Could you elaborate more on this point?
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> Thanks,
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> Dong
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> On Wed, Feb 28, 2018 at 10:55 PM, Jan
>>>>>>>>>>>>>>> Filipiak<Jan.Filipiak@trivago.
>>>>>>>>>>>>>>> com
>>>>>>>>>>>>>>> wrote:
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> Hi Dong,
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> I tried to focus on what the steps are one can currently
>>>>>>>>>>>>>>> perform
>>>>>>>>>>>>>>> to
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> expand
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> or shrink a keyed topic while maintaining a top notch
>>>>>>>>>>>>>>>> semantics.
>>>>>>>>>>>>>>>> I can understand that there might be confusion about
>>>>>>>>>>>>>>>> "stopping
>>>>>>>>>>>>>>>> the
>>>>>>>>>>>>>>>> consumer". It is exactly the same as proposed in the KIP.
>>>>>>>>>>>>>>>> there
>>>>>>>>>>>>>>>> needs
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> to
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> be
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> a time the producers agree on the new partitioning. The
>>>>>>>>>>>>>>> extra
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>> semantics I
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> want to put in there is that we have a possibility to wait
>>>>>>>>>>>>>>>> until
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> all
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>> the
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> existing data
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> is copied over into the new partitioning scheme. When I say
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>> stopping
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> I
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> think more of having a memory barrier that ensures the
>>>>>>>>>>>>>>>> ordering. I
>>>>>>>>>>>>>>>> am
>>>>>>>>>>>>>>>> still
>>>>>>>>>>>>>>>> aming for latencies  on the scale of leader failovers.
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> Consumers have to explicitly adapt the new partitioning
>>>>>>>>>>>>>>>> scheme
>>>>>>>>>>>>>>>> in
>>>>>>>>>>>>>>>> the
>>>>>>>>>>>>>>>> above scenario. The reason is that in these cases where you
>>>>>>>>>>>>>>>> are
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> dependent
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> on a particular partitioning scheme, you also have other
>>>>>>>>>>>>>>>> topics
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> that
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>> have
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> co-partition enforcements or the kind -frequently. Therefore
>>>>>>>>>>>>>> all
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> your
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>> other
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> input topics might need to grow accordingly.
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> What I was suggesting was to streamline all these operations
>>>>>>>>>>>>>>>> as
>>>>>>>>>>>>>>>> best
>>>>>>>>>>>>>>>> as
>>>>>>>>>>>>>>>> possible to have "real" partition grow and shrinkage going
>>>>>>>>>>>>>>>> on.
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> Migrating
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> the producers to a new partitioning scheme can be much more
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> streamlined
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>> with proper broker support for this. Migrating consumer is a
>>>>>>>>>>>>>> step
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> that
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> might be made completly unnecessary if - for example streams
>>>>>>>>>>>>>>>> -
>>>>>>>>>>>>>>>> takes
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> the
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> gcd as partitioning scheme instead of enforcing 1 to 1.
>>>>>>>>>>>>>>>> Connect
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> consumers
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>> and other consumers should be fine anyways.
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> I hope this makes more clear where I was aiming at. The rest
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>> needs
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> to
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> be
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> figured out. The only danger i see is that when we are
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> introducing
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> this
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>> feature as supposed in the KIP, it wont help any people
>>>>>>>>>>>>>> depending
>>>>>>>>>>>>>> on
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> log
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> compaction.
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> The other thing I wanted to mention is that I believe the
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>> current
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> suggestion (without copying data over) can be implemented in
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> pure
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> userland
>>>>>>>>>>>>>>>> with a custom partitioner and a small feedbackloop from
>>>>>>>>>>>>>>>> ProduceResponse
>>>>>>>>>>>>>>>> =>
>>>>>>>>>>>>>>>> Partitionier in coorporation with a change management
>>>>>>>>>>>>>>>> system.
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> Best Jan
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> On 28.02.2018 07:13, Dong Lin wrote:
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> Hey Jan,
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> I am not sure if it is acceptable for producer to be stopped
>>>>>>>>>>>>>>>> for a
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> while,
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> particularly for online application which requires low
>>>>>>>>>>>>>>>>> latency. I
>>>>>>>>>>>>>>>>> am
>>>>>>>>>>>>>>>>> also
>>>>>>>>>>>>>>>>> not sure how consumers can switch to a new topic. Does user
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> application
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> needs to explicitly specify a different topic for
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> producer/consumer
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> to
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> subscribe to? It will be helpful for discussion if you can
>>>>>>>>>>>>>> provide
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> more
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> detail on the interface change for this solution.
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> Thanks,
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> Dong
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> On Mon, Feb 26, 2018 at 12:48 AM, Jan
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> Filipiak<Jan.Filipiak@trivago.
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> com
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> wrote:
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> Hi,
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> just want to throw my though in. In general the functionality
>>>>>>>>>>>>>>> is
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> very
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> usefull, we should though not try to find the architecture
>>>>>>>>>>>>>>>>> to
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> hard
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> while
>>>>>>>>>>>>>>>>>> implementing.
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> The manual steps would be to
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> create a new topic
>>>>>>>>>>>>>>>>>> the mirrormake from the new old topic to the new topic
>>>>>>>>>>>>>>>>>> wait for mirror making to catch up.
>>>>>>>>>>>>>>>>>> then put the consumers onto the new topic
>>>>>>>>>>>>>>>>>>             (having mirrormaker spit out a mapping from
>>>>>>>>>>>>>>>>>> old
>>>>>>>>>>>>>>>>>> offsets to
>>>>>>>>>>>>>>>>>> new
>>>>>>>>>>>>>>>>>> offsets:
>>>>>>>>>>>>>>>>>>                 if topic is increased by factor X there is
>>>>>>>>>>>>>>>>>> gonna
>>>>>>>>>>>>>>>>>> be a
>>>>>>>>>>>>>>>>>> clean
>>>>>>>>>>>>>>>>>> mapping from 1 offset in the old topic to X offsets in the
>>>>>>>>>>>>>>>>>> new
>>>>>>>>>>>>>>>>>> topic,
>>>>>>>>>>>>>>>>>>                 if there is no factor then there is no
>>>>>>>>>>>>>>>>>> chance to
>>>>>>>>>>>>>>>>>> generate a
>>>>>>>>>>>>>>>>>> mapping that can be reasonable used for continuing)
>>>>>>>>>>>>>>>>>>             make consumers stop at appropriate points and
>>>>>>>>>>>>>>>>>> continue
>>>>>>>>>>>>>>>>>> consumption
>>>>>>>>>>>>>>>>>> with offsets from the mapping.
>>>>>>>>>>>>>>>>>> have the producers stop for a minimal time.
>>>>>>>>>>>>>>>>>> wait for mirrormaker to finish
>>>>>>>>>>>>>>>>>> let producer produce with the new metadata.
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> Instead of implementing the approach suggest in the KIP
>>>>>>>>>>>>>>>>>> which
>>>>>>>>>>>>>>>>>> will
>>>>>>>>>>>>>>>>>> leave
>>>>>>>>>>>>>>>>>> log compacted topic completely crumbled and unusable.
>>>>>>>>>>>>>>>>>> I would much rather try to build infrastructure to support
>>>>>>>>>>>>>>>>>> the
>>>>>>>>>>>>>>>>>> mentioned
>>>>>>>>>>>>>>>>>> above operations more smoothly.
>>>>>>>>>>>>>>>>>> Especially having producers stop and use another topic is
>>>>>>>>>>>>>>>>>> difficult
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> and
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> it would be nice if one can trigger "invalid metadata"
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> exceptions
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> for
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> them
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>> and
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> if one could give topics aliases so that their produces with
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> the
>>>>>>>>>>>>>>>>>> old
>>>>>>>>>>>>>>>>>> topic
>>>>>>>>>>>>>>>>>> will arrive in the new topic.
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> The downsides are obvious I guess ( having the same data
>>>>>>>>>>>>>>>>>> twice
>>>>>>>>>>>>>>>>>> for
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> the
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> transition period, but kafka tends to scale well with
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> datasize).
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> So
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> its a
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> nicer fit into the architecture.
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> I further want to argument that the functionality by the KIP
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> can
>>>>>>>>>>>>>>>>>> completely be implementing in "userland" with a custom
>>>>>>>>>>>>>>>>>> partitioner
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> that
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> handles the transition as needed. I would appreciate if
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> someone
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> could
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> point
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>> out what a custom partitioner couldn't handle in this case?
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> With the above approach, shrinking a topic becomes the same
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> steps.
>>>>>>>>>>>>>>>>>> Without
>>>>>>>>>>>>>>>>>> loosing keys in the discontinued partitions.
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> Would love to hear what everyone thinks.
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> Best Jan
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> On 11.02.2018 00:35, Dong Lin wrote:
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> Hi all,
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> I have created KIP-253: Support in-order message delivery
>>>>>>>>>>>>>>>>>> with
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> partition
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> expansion. See
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>> https://cwiki.apache.org/confl
>>>>>>>>>>>>>>>>>>> uence/display/KAFKA/KIP-253%
>>>>>>>>>>>>>>>>>>> 3A+Support+in-order+message+de
>>>>>>>>>>>>>>>>>>> livery+with+partition+expansio
>>>>>>>>>>>>>>>>>>> n
>>>>>>>>>>>>>>>>>>> .
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>> This KIP provides a way to allow messages of the same key
>>>>>>>>>>>>>>>>>>> from
>>>>>>>>>>>>>>>>>>> the
>>>>>>>>>>>>>>>>>>> same
>>>>>>>>>>>>>>>>>>> producer to be consumed in the same order they are
>>>>>>>>>>>>>>>>>>> produced
>>>>>>>>>>>>>>>>>>> even
>>>>>>>>>>>>>>>>>>> if
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>> we
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>> expand partition of the topic.
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>> Thanks,
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> Dong
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>
>>>
>

Re: [DISCUSS] KIP-253: Support in-order message delivery with partition expansion

Posted by Jan Filipiak <Ja...@trivago.com>.
Hi Jun,

thanks for your great reply, even though I only managed to throw a few 
sentences in, because of time last time. I think you are starting to 
understand me pretty well. There is still some minor things that need to 
be flattened out. I already had these points previously but I try to 
rephrase them into answers to your questions for clarity.

On 23.03.2018 01:43, Jun Rao wrote:
> Hi, Jan,
>
> Thanks for the reply.
>
> Ok. So your idea is to have a special consumer reshuffle the data to a new
> set of partitions. Each consumer group will not increase its tasks
> immediately. We just need to make sure that each consumer instance is
> assigned the set of new partitions covering the same set of keys. At some
> point later, each consumer group can decide independently when to increase
> the number of tasks. At that point, the consumer will need to rebuild the
> local state for the new tasks. Is that right?
This has multiple aspects. The middle part

  We just need to make sure that each consumer instance is
assigned the set of new partitions covering the same set of keys

is probably the most important one here. This is essentially what the 
second part of my idea is about.
We need a protocol that allows consumers to switch from old topic (old 
partiton count) to the new topic (new partion count). (If it really is a 
new topic or not depends on the implementation -I like to model it as 
such as its easier in my head). The protocol I envision is something 
like this:
Per partition there is information from the old offset to the new offset.

topicOldMapping-0 : 50 => [0:25,2:25]
topicOldMapping-1 : 60 => [1:15,3:45]

A consumer can get a hold on this information and stop at 50 and 60 and 
continue at 25,25,15,45

The same transition works when the data is not copied. a mapping would 
look like

topicOldMapping-0 : 50 => [0:0,2:0]
topicOldMapping-1 : 60 => [1:0,3:0]

No data would have been copied and 50 and 60 are the endoffsets and we 
would start at the very beginning of the new topic 0,0,0,0

>
> I agree that decoupling the number of tasks in a consumer group from the
> number of partitions in the input topic is a good idea. This allows each
> consumer group to change its degree of parallelism independently. There are
> different ways to achieve such decoupling. You suggested one approach,
> which works when splitting partitions. Not sure if this works in general,
> for example when merging partitions.
Merging is the same.

topicOldMapping-0 : 25 => [0:50]
topicOldMapping-1 : 25 => [1:50]
topicOldMapping-2 : 15 => [0:50]
topicOldMapping-3 : 45 => [1:50]

generating this mapping is trivial again if we do not copy data. (end 
offsets point to start offsets)
If we do copy data the consumer will create the mapping.

>
> Once a consumer group decides to change its degree of parallelism, it needs
> to rebuild the local state for the new tasks. We can either rebuild the
> states from the input topic or from the local state (through change capture
> topic). I think we agreed that rebuilding from the local state is more
> efficient. It also seems that it's better to let the KStreams library do
> the state rebuilding, instead of each application. Would you agree?
If you want todo by RPC, you are changing the running application 
without having a new good one. This
is against the kappa achitecture I would not recommend that.

If you replay the changelog and only poll records that are for your 
partition. You have the problem of knowing
which offset from the input topic your current state relates to.

If you rebuild you could leave the old running and just wait for the new 
to be _good_ then change who's output you
show to the customers.

>
> About the special consumer. I guess that's only needed if one wants to
> recopy the existing data? However, if we can truly decouple the tasks in
> the consumer group from the partitions in the input topic, it seems there
> is no need for copying existing data? It's also not clear to me who will
> start/stop this special consumer.
Who starts and stops it is also not very clear to me. I do not have 
strong opinions.
The thing is that I am looking for an explanation how you can have a 
logcompacted topic working without copying.
I agree that for running consumers its no problem as they are already 
past the history. But the whole purpose of Log compaction
is to be able to bootstrap new consumers. They are completely lost with 
a topic expanded without repartitioning.
The topic will be broken forever. and this is not acceptable.

This is why I am so intrigued to model the problem as described because 
it has no overhead for the no copy path while it allows
to also perform a copy.

State handling wise one has also all the options. Exactly the 3 you 
mentioned I guess. its just that this statestore RPC is a bad idea
and it was only invented to allow for optimisations that are better not 
done.Not to say they are premature ;)

I hope it makes it clear

best jan
>
> Thanks,
>
> Jun
>
> On Wed, Mar 21, 2018 at 6:57 AM, Jan Filipiak <Ja...@trivago.com>
> wrote:
>
>> Hi Jun,
>>
>> I was really seeing progress in our conversation but your latest reply is
>> just devastating.
>> I though we were getting close being on the same page now it feels like we
>> are in different libraries.
>>
>> I just quickly slam my answers in here. If they are to brief I am sorry
>> give me a ping and try to go into details more.
>> Just want to show that your pro/cons listing is broken.
>>
>> Best Jan
>>
>> and want to get rid of this horrible compromise
>>
>>
>> On 19.03.2018 05:48, Jun Rao wrote:
>>
>>> Hi, Jan,
>>>
>>> Thanks for the discussion. Great points.
>>>
>>> Let me try to summarize the approach that you are proposing. On the broker
>>> side, we reshuffle the existing data in a topic from current partitions to
>>> the new partitions. Once the reshuffle fully catches up, switch the
>>> consumers to start consuming from the new partitions. If a consumer needs
>>> to rebuild its local state (due to partition changes), let the consumer
>>> rebuild its state by reading all existing data from the new partitions.
>>> Once all consumers have switches over, cut over the producer to the new
>>> partitions.
>>>
>>> The pros for this approach are that :
>>> 1. There is just one way to rebuild the local state, which is simpler.
>>>
>> true thanks
>>
>>> The cons for this approach are:
>>> 1. Need to copy existing data.
>>>
>> Very unfair and not correct. It does not require you to copy over existing
>> data. It _allows_ you to copy all existing data.
>>
>> 2. The cutover of the producer is a bit complicated since it needs to
>>> coordinate with all consumer groups.
>>>
>> Also not true. I explicitly tried to make clear that there is only one
>> special consumer (in the case of actually copying data) coordination is
>> required.
>>
>>> 3. The rebuilding of the state in the consumer is from the input topic,
>>> which can be more expensive than rebuilding from the existing state.
>>>
>> true, but rebuilding state is only required if you want to increase
>> processing power, so we assume this is at hand.
>>
>>> 4. The broker potentially has to know the partitioning function. If this
>>> needs to be customized at the topic level, it can be a bit messy.
>>>
>> I would argue against having the operation being performed by the broker.
>> This was not discussed yet but if you see my original email i suggested
>> otherwise from the beginning.
>>
>>> Here is an alternative approach by applying your idea not in the broker,
>>> but in the consumer. When new partitions are added, we don't move existing
>>> data. In KStreams, we first reshuffle the new input data to a new topic T1
>>> with the old number of partitions and feed T1's data to the rest of the
>>> pipeline. In the meantime, KStreams reshuffles all existing data of the
>>> change capture topic to another topic C1 with the new number of
>>> partitions.
>>> We can then build the state of the new tasks from C1. Once the new states
>>> have been fully built, we can cut over the consumption to the input topic
>>> and delete T1. This approach works with compacted topic too. If an
>>> application reads from the beginning of a compacted topic, the consumer
>>> will reshuffle the portion of the input when the number of partitions
>>> doesn't match the number of tasks.
>>>
>> We all wipe this idea from our heads instantly. Mixing Ideas from an
>> argument is not a resolution strategy
>> just leads to horrible horrible software.
>>
>>
>>> The pros of this approach are:
>>> 1. No need to copy existing data.
>>> 2. Each consumer group can cut over to the new partitions independently.
>>> 3. The state is rebuilt from the change capture topic, which is cheaper
>>> than rebuilding from the input topic.
>>> 4. Only the KStreams job needs to know the partitioning function.
>>>
>>> The cons of this approach are:
>>> 1. Potentially the same input topic needs to be reshuffled more than once
>>> in different consumer groups during the transition phase.
>>>
>>> What do you think?
>>>
>>> Thanks,
>>>
>>> Jun
>>>
>>>
>>>
>>> On Thu, Mar 15, 2018 at 1:04 AM, Jan Filipiak <Ja...@trivago.com>
>>> wrote:
>>>
>>> Hi Jun,
>>>> thank you for following me on these thoughts. It was important to me to
>>>> feel that kind of understanding for my arguments.
>>>>
>>>> What I was hoping for (I mentioned this earlier) is that we can model the
>>>> case where we do not want to copy the data the exact same way as the case
>>>> when we do copy the data. Maybe you can peek into the mails before to see
>>>> more details for this.
>>>>
>>>> This means we have the same mechanism to transfer consumer groups to
>>>> switch topic. The offset mapping that would be generated would even be
>>>> simpler End Offset of the Old topic => offset 0 off all the partitions of
>>>> the new topic. Then we could model the transition of a non-copy expansion
>>>> the exact same way as a copy-expansion.
>>>>
>>>> I know this only works when topic growth by a factor. But the benefits of
>>>> only growing by a factor are to strong anyways. See Clemens's hint and
>>>> remember that state reshuffling is entirely not needed if one doesn't
>>>> want
>>>> to grow processing power.
>>>>
>>>> I think these benefits should be clear, and that there is basically no
>>>> downside to what is currently at hand but just makes everything easy.
>>>>
>>>> One thing you need to know is. that if you do not offer rebuilding a log
>>>> compacted topic like i suggest that even if you have consumer state
>>>> reshuffling. The topic is broken and can not be used to bootstrap new
>>>> consumers. They don't know if they need to apply a key from and old
>>>> partition or not. This is a horrible downside I haven't seen a solution
>>>> for
>>>> in the email conversation.
>>>>
>>>> I argue to:
>>>>
>>>> Only grow topic by a factor always.
>>>> Have the "no copy consumer" transition as the trivial case of the "copy
>>>> consumer transition".
>>>> If processors needs to be scaled, let them rebuild from the new topic and
>>>> leave the old running in the mean time.
>>>> Do not implement key shuffling in streams.
>>>>
>>>> I hope I can convince you especially with the fact how I want to handle
>>>> consumer transition. I think
>>>> you didn't quite understood me there before. I think the term "new topic"
>>>> intimidated you a little.
>>>> How we solve this on disc doesn't really matter, If the data goes into
>>>> the
>>>> same Dir or a different Dir or anything. I do think that it needs to
>>>> involve at least rolling a new segment for the existing partitions.
>>>> But most of the transitions should work without restarting consumers.
>>>> (newer consumers with support for this). But with new topic i just meant
>>>> the topic that now has a different partition count. Plenty of ways to
>>>> handle that (versions, aliases)
>>>>
>>>> Hope I can further get my idea across.
>>>>
>>>> Best Jan
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> On 14.03.2018 02:45, Jun Rao wrote:
>>>>
>>>> Hi, Jan,
>>>>> Thanks for sharing your view.
>>>>>
>>>>> I agree with you that recopying the data potentially makes the state
>>>>> management easier since the consumer can just rebuild its state from
>>>>> scratch (i.e., no need for state reshuffling).
>>>>>
>>>>> On the flip slide, I saw a few disadvantages of the approach that you
>>>>> suggested. (1) Building the state from the input topic from scratch is
>>>>> in
>>>>> general less efficient than state reshuffling. Let's say one computes a
>>>>> count per key from an input topic. The former requires reading all
>>>>> existing
>>>>> records in the input topic whereas the latter only requires reading data
>>>>> proportional to the number of unique keys. (2) The switching of the
>>>>> topic
>>>>> needs modification to the application. If there are many applications
>>>>> on a
>>>>> topic, coordinating such an effort may not be easy. Also, it's not clear
>>>>> how to enforce exactly-once semantic during the switch. (3) If a topic
>>>>> doesn't need any state management, recopying the data seems wasteful. In
>>>>> that case, in place partition expansion seems more desirable.
>>>>>
>>>>> I understand your concern about adding complexity in KStreams. But,
>>>>> perhaps
>>>>> we could iterate on that a bit more to see if it can be simplified.
>>>>>
>>>>> Jun
>>>>>
>>>>>
>>>>> On Mon, Mar 12, 2018 at 11:21 PM, Jan Filipiak <
>>>>> Jan.Filipiak@trivago.com>
>>>>> wrote:
>>>>>
>>>>> Hi Jun,
>>>>>
>>>>>> I will focus on point 61 as I think its _the_ fundamental part that I
>>>>>> cant
>>>>>> get across at the moment.
>>>>>>
>>>>>> Kafka is the platform to have state materialized multiple times from
>>>>>> one
>>>>>> input. I emphasize this: It is the building block in architectures that
>>>>>> allow you to
>>>>>> have your state maintained multiple times. You put a message in once,
>>>>>> and
>>>>>> you have it pop out as often as you like. I believe you understand
>>>>>> this.
>>>>>>
>>>>>> Now! The path of thinking goes the following: I am using apache kafka
>>>>>> and
>>>>>> I _want_ my state multiple times. What am I going todo?
>>>>>>
>>>>>> A) Am I going to take my state that I build up, plunge some sort of RPC
>>>>>> layer ontop of it, use that RPC layer to throw my records across
>>>>>> instances?
>>>>>> B) Am I just going to read the damn message twice?
>>>>>>
>>>>>> Approach A is fundamentally flawed and a violation of all that is good
>>>>>> and
>>>>>> holy in kafka deployments. I can not understand how this Idea can come
>>>>>> in
>>>>>> the first place.
>>>>>> (I do understand: IQ in streams, they polluted the kafka streams
>>>>>> codebase
>>>>>> really bad already. It is not funny! I think they are equally flawed as
>>>>>> A)
>>>>>>
>>>>>> I say, we do what Kafka is good at. We repartition the topic once. We
>>>>>> switch the consumers.
>>>>>> (Those that need more partitions are going to rebuild their state in
>>>>>> multiple partitions by reading the new topic, those that don't just
>>>>>> assign
>>>>>> the new partitions properly)
>>>>>> We switch producers. Done!
>>>>>>
>>>>>> The best thing! It is trivial, hipster stream processor will have an
>>>>>> easy
>>>>>> time with that aswell. Its so super simple. And simple IS good!
>>>>>> It is what kafka was build todo. It is how we do it today. All I am
>>>>>> saying
>>>>>> is that a little broker help doing the producer swap is super useful.
>>>>>>
>>>>>> For everyone interested in why kafka is so powerful with approach B,
>>>>>> please watch https://youtu.be/bEbeZPVo98c?t=1633
>>>>>> I already looked up a good point in time, I think after 5 minutes the
>>>>>> "state" topic is handled and you should be able to understand me
>>>>>> and inch better.
>>>>>>
>>>>>> Please do not do A to the project, it deserves better!
>>>>>>
>>>>>> Best Jan
>>>>>>
>>>>>>
>>>>>>
>>>>>> On 13.03.2018 02:40, Jun Rao wrote:
>>>>>>
>>>>>> Hi, Jan,
>>>>>>
>>>>>>> Thanks for the reply. A few more comments below.
>>>>>>>
>>>>>>> 50. Ok, we can think a bit harder for supporting compacted topics.
>>>>>>>
>>>>>>> 51. This is a fundamental design question. In the more common case,
>>>>>>> the
>>>>>>> reason why someone wants to increase the number of partitions is that
>>>>>>> the
>>>>>>> consumer application is slow and one wants to run more consumer
>>>>>>> instances
>>>>>>> to increase the degree of parallelism. So, fixing the number of
>>>>>>> running
>>>>>>> consumer instances when expanding the partitions won't help this case.
>>>>>>> If
>>>>>>> we do need to increase the number of consumer instances, we need to
>>>>>>> somehow
>>>>>>> reshuffle the state of the consumer across instances. What we have
>>>>>>> been
>>>>>>> discussing in this KIP is whether we can do this more effectively
>>>>>>> through
>>>>>>> the KStream library (e.g. through a 2-phase partition expansion). This
>>>>>>> will
>>>>>>> add some complexity, but it's probably better than everyone doing this
>>>>>>> in
>>>>>>> the application space. The recopying approach that you mentioned
>>>>>>> doesn't
>>>>>>> seem to address the consumer state management issue when the consumer
>>>>>>> switches from an old to a new topic.
>>>>>>>
>>>>>>> 52. As for your example, it depends on whether the join key is the
>>>>>>> same
>>>>>>> between (A,B) and (B,C). If the join key is the same, we can do a
>>>>>>> 2-phase
>>>>>>> partition expansion of A, B, and C together. If the join keys are
>>>>>>> different, one would need to repartition the data on a different key
>>>>>>> for
>>>>>>> the second join, then the partition expansion can be done
>>>>>>> independently
>>>>>>> between (A,B) and (B,C).
>>>>>>>
>>>>>>> 53. If you always fix the number of consumer instances, we you
>>>>>>> described
>>>>>>> works. However, as I mentioned in #51, I am not sure how your proposal
>>>>>>> deals with consumer states when the number of consumer instances
>>>>>>> grows.
>>>>>>> Also, it just seems that it's better to avoid re-copying the existing
>>>>>>> data.
>>>>>>>
>>>>>>> 60. "just want to throw in my question from the longer email in the
>>>>>>> other
>>>>>>> Thread here. How will the bloom filter help a new consumer to decide
>>>>>>> to
>>>>>>> apply the key or not?" Not sure that I fully understood your question.
>>>>>>> The
>>>>>>> consumer just reads whatever key is in the log. The bloom filter just
>>>>>>> helps
>>>>>>> clean up the old keys.
>>>>>>>
>>>>>>> 61. "Why can we afford having a topic where its apparently not
>>>>>>> possible
>>>>>>> to
>>>>>>> start a new application on? I think this is an overall flaw of the
>>>>>>> discussed idea here. Not playing attention to the overall
>>>>>>> architecture."
>>>>>>> Could you explain a bit more when one can't start a new application?
>>>>>>>
>>>>>>> Jun
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> On Sat, Mar 10, 2018 at 1:40 AM, Jan Filipiak <
>>>>>>> Jan.Filipiak@trivago.com
>>>>>>> wrote:
>>>>>>>
>>>>>>> Hi Jun, thanks for your mail.
>>>>>>>
>>>>>>> Thank you for your questions!
>>>>>>>> I think they are really good and tackle the core of the problem I
>>>>>>>> see.
>>>>>>>>
>>>>>>>> I will answer inline, mostly but still want to set the tone here.
>>>>>>>>
>>>>>>>> The core strength of kafka is what Martin once called the
>>>>>>>> kappa-Architecture. How does this work?
>>>>>>>> You have everything as a log as in kafka. When you need to change
>>>>>>>> something.
>>>>>>>> You create the new version of your application and leave it running
>>>>>>>> in
>>>>>>>> parallel.
>>>>>>>> Once the new version is good you switch your users to use the new
>>>>>>>> application.
>>>>>>>>
>>>>>>>> The online reshuffling effectively breaks this architecture and I
>>>>>>>> think
>>>>>>>> the switch in thinking here is more harmful
>>>>>>>> than any details about the partitioning function to allow such a
>>>>>>>> change.
>>>>>>>> I
>>>>>>>> feel with my suggestion we are the closest to
>>>>>>>> the original and battle proven architecture and I can only warn to
>>>>>>>> move
>>>>>>>> away from it.
>>>>>>>>
>>>>>>>> I might have forgotten something, sometimes its hard for me to
>>>>>>>> getting
>>>>>>>> all
>>>>>>>> the thoughts captured in a mail, but I hope the comments inline will
>>>>>>>> further make my concern clear, and put some emphasis on why I prefer
>>>>>>>> my
>>>>>>>> solution ;)
>>>>>>>>
>>>>>>>> One thing we should all be aware of when discussing this, and I think
>>>>>>>> Dong
>>>>>>>> should have mentioned it (maybe he did).
>>>>>>>> We are not discussing all of this out of thin air but there is an
>>>>>>>> effort
>>>>>>>> in the Samza project.
>>>>>>>>
>>>>>>>> https://cwiki.apache.org/confluence/display/SAMZA/SEP-5%3A+
>>>>>>>> Enable+partition+expansion+of+input+streams
>>>>>>>> https://issues.apache.org/jira/browse/SAMZA-1293
>>>>>>>>
>>>>>>>> To be clear. I think SEP-5 (state of last week, dont know if it
>>>>>>>> adapted
>>>>>>>> to
>>>>>>>> this discussion) is on a way better path than KIP-253, and I can't
>>>>>>>> really
>>>>>>>> explain why.
>>>>>>>>
>>>>>>>> Best Jan,
>>>>>>>>
>>>>>>>> nice weekend everyone
>>>>>>>>
>>>>>>>>
>>>>>>>> On 09.03.2018 03:36, Jun Rao wrote:
>>>>>>>>
>>>>>>>> Hi, Jan,
>>>>>>>>
>>>>>>>> Thanks for the feedback. Just some comments on the earlier points
>>>>>>>>> that
>>>>>>>>> you
>>>>>>>>> mentioned.
>>>>>>>>>
>>>>>>>>> 50. You brought up the question of whether existing data needs to be
>>>>>>>>> copied
>>>>>>>>> during partition expansion. My understand of your view is that avoid
>>>>>>>>> copying existing data will be more efficient, but it doesn't work
>>>>>>>>> well
>>>>>>>>> with
>>>>>>>>> compacted topics since some keys in the original partitions will
>>>>>>>>> never
>>>>>>>>> be
>>>>>>>>> cleaned. It would be useful to understand your use case of compacted
>>>>>>>>> topics
>>>>>>>>> a bit more. In the common use case, the data volume in a compacted
>>>>>>>>> topic
>>>>>>>>> may not be large. So, I am not sure if there is a strong need to
>>>>>>>>> expand
>>>>>>>>> partitions in a compacted topic, at least initially.
>>>>>>>>>
>>>>>>>>> I do agree. State is usually smaller. Update rates might be also
>>>>>>>>>
>>>>>>>>> competitively high.
>>>>>>>> Doing Log-compaction (even beeing very efficient and configurable) is
>>>>>>>> also
>>>>>>>> a more expensive operation than
>>>>>>>> just discarding old segments. Further if you want to use more
>>>>>>>> consumers
>>>>>>>> processing the events
>>>>>>>> you also have to grow the number of partitions. Especially for
>>>>>>>> use-cases
>>>>>>>> we do (KIP-213) a tiny state full
>>>>>>>> table might be very expensive to process if it joins against a huge
>>>>>>>> table.
>>>>>>>>
>>>>>>>> I can just say we have been in the spot of needing to grow log
>>>>>>>> compacted
>>>>>>>> topics. Mainly for processing power we can bring to the table.
>>>>>>>>
>>>>>>>> Further i am not at all concerned about the extra spaced used by
>>>>>>>> "garbage
>>>>>>>> keys". I am more concerned about the correctness of innocent
>>>>>>>> consumers.
>>>>>>>> The
>>>>>>>> logic becomes complicated. Say for streams one would need to load the
>>>>>>>> record into state but not forward it the topology ( to have it
>>>>>>>> available
>>>>>>>> for shuffeling). I rather have it simple and a topic clean regardless
>>>>>>>> if
>>>>>>>> it
>>>>>>>> still has its old partition count. Especially with multiple
>>>>>>>> partitions
>>>>>>>> growth's I think it becomes insanely hard to to this shuffle correct.
>>>>>>>> Maybe
>>>>>>>> Streams and Samza can do it. Especially if you do "hipster stream
>>>>>>>> processing" <https://www.confluent.io/blog
>>>>>>>> /introducing-kafka-streams-
>>>>>>>> stream-processing-made-simple/>. This makes kafka way to
>>>>>>>> complicated.
>>>>>>>> With my approach I think its way simpler because the topic has no
>>>>>>>> "history"
>>>>>>>> in terms of partitioning but is always clean.
>>>>>>>>
>>>>>>>>
>>>>>>>> 51. "Growing the topic by an integer factor does not require any
>>>>>>>> state
>>>>>>>>
>>>>>>>> redistribution at all." Could you clarify this a bit more? Let's say
>>>>>>>>> you
>>>>>>>>> have a consumer app that computes the windowed count per key. If you
>>>>>>>>> double
>>>>>>>>> the number of partitions from 1 to 2 and grow the consumer instances
>>>>>>>>> from
>>>>>>>>> 1
>>>>>>>>> to 2, we would need to redistribute some of the counts to the new
>>>>>>>>> consumer
>>>>>>>>> instance. Regarding to linear hashing, it's true that it won't solve
>>>>>>>>> the
>>>>>>>>> problem with compacted topics. The main benefit is that it
>>>>>>>>> redistributes
>>>>>>>>> the keys in one partition to no more than two partitions, which
>>>>>>>>> could
>>>>>>>>> help
>>>>>>>>> redistribute the state.
>>>>>>>>>
>>>>>>>>> You don't need to spin up a new consumer in this case. every
>>>>>>>>> consumer
>>>>>>>>>
>>>>>>>>> would just read every partition with the (partition % num_task)
>>>>>>>> task.
>>>>>>>> it
>>>>>>>> will still have the previous data right there and can go on.
>>>>>>>>
>>>>>>>> This sounds contradictory to what I said before, but please bear with
>>>>>>>> me.
>>>>>>>>
>>>>>>>> 52. Good point on coordinating the expansion of 2 topics that need to
>>>>>>>> be
>>>>>>>>
>>>>>>>> joined together. This is where the 2-phase partition expansion could
>>>>>>>>> potentially help. In the first phase, we could add new partitions to
>>>>>>>>> the 2
>>>>>>>>> topics one at a time but without publishing to the new patitions.
>>>>>>>>> Then,
>>>>>>>>> we
>>>>>>>>> can add new consumer instances to pick up the new partitions. In
>>>>>>>>> this
>>>>>>>>> transition phase, no reshuffling is needed since no data is coming
>>>>>>>>> from
>>>>>>>>> the
>>>>>>>>> new partitions. Finally, we can enable the publishing to the new
>>>>>>>>> partitions.
>>>>>>>>>
>>>>>>>>> I think its even worse than you think. I would like to introduce the
>>>>>>>>>
>>>>>>>>> Term
>>>>>>>> transitive copartitioning. Imagine
>>>>>>>> 2 streams application. One joins (A,B) the other (B,C) then there is
>>>>>>>> a
>>>>>>>> transitive copartition requirement for
>>>>>>>> (A,C) to be copartitioned aswell. This can spread significantly and
>>>>>>>> require many consumers to adapt at the same time.
>>>>>>>>
>>>>>>>> It is also not entirely clear to me how you not need reshuffling in
>>>>>>>> this
>>>>>>>> case. If A has a record that never gets updated after the expansion
>>>>>>>> and
>>>>>>>> the
>>>>>>>> coresponding B record moves to a new partition. How shall they meet
>>>>>>>> w/o
>>>>>>>> shuffle?
>>>>>>>>
>>>>>>>> 53. "Migrating consumer is a step that might be made completly
>>>>>>>>
>>>>>>>> unnecessary
>>>>>>>>> if - for example streams - takes the gcd as partitioning scheme
>>>>>>>>> instead
>>>>>>>>> of
>>>>>>>>> enforcing 1 to 1." Not sure that I fully understand this. I think
>>>>>>>>> you
>>>>>>>>> mean
>>>>>>>>> that a consumer application can run more instances than the number
>>>>>>>>> of
>>>>>>>>> partitions. In that case, the consumer can just repartitioning the
>>>>>>>>> input
>>>>>>>>> data according to the number of instances. This is possible, but
>>>>>>>>> just
>>>>>>>>> has
>>>>>>>>> the overhead of reshuffling the data.
>>>>>>>>>
>>>>>>>>> No what I meant is ( that is also your question i think Mathias)
>>>>>>>>> that
>>>>>>>>> if
>>>>>>>>>
>>>>>>>>> you grow a topic by a factor.
>>>>>>>> Even if your processor is statefull you can can just assign all the
>>>>>>>> multiples of the previous partition to
>>>>>>>> this consumer and the state to keep processing correctly will be
>>>>>>>> present
>>>>>>>> w/o any shuffling.
>>>>>>>>
>>>>>>>> Say you have an assignment
>>>>>>>> Statefull consumer => partition
>>>>>>>> 0 => 0
>>>>>>>> 1 => 1
>>>>>>>> 2 => 2
>>>>>>>>
>>>>>>>> and you grow you topic by 4 you get,
>>>>>>>>
>>>>>>>> 0 => 0,3,6,9
>>>>>>>> 1 => 1,4,7,10
>>>>>>>> 2 => 2,5,8,11
>>>>>>>>
>>>>>>>> Say your hashcode is 8. 8%3 => 2  before so consumer for partition 2
>>>>>>>> has
>>>>>>>> it.
>>>>>>>> Now you you have 12 partitions so 8%12 => 8, so it goes into
>>>>>>>> partition
>>>>>>>> 8
>>>>>>>> which is assigned to the same consumer
>>>>>>>> who had 2 before and therefore knows the key.
>>>>>>>>
>>>>>>>> Userland reshuffeling is there as an options. And it does exactly
>>>>>>>> what
>>>>>>>> I
>>>>>>>> suggest. And I think its the perfect strategie. All I am suggestion
>>>>>>>> is
>>>>>>>> broker side support to switch the producers to the newly partitioned
>>>>>>>> topic.
>>>>>>>> Then the old (to few partition topic) can go away.  Remember the list
>>>>>>>> of
>>>>>>>> steps in the beginning of this thread. If one has broker support for
>>>>>>>> all
>>>>>>>> where its required and streams support for those that aren’t
>>>>>>>> necessarily.
>>>>>>>> Then one has solved the problem.
>>>>>>>> I repeat it because I think its important. I am really happy that you
>>>>>>>> brought that up! because its 100% what I want just with the
>>>>>>>> differences
>>>>>>>> to
>>>>>>>> have an option to discard the to small topic later (after all
>>>>>>>> consumers
>>>>>>>> adapted). And to have order correct there. I need broker support
>>>>>>>> managing
>>>>>>>> the copy process + the produces and fence them against each other. I
>>>>>>>> also
>>>>>>>> repeat. the copy process can run for weeks in the worst case. Copying
>>>>>>>> the
>>>>>>>> data is not the longest task migrating consumers might very well be.
>>>>>>>> Once all consumers switched and copying is really up to date (think
>>>>>>>> ISR
>>>>>>>> like up to date) only then we stop the producer, wait for the copy to
>>>>>>>> finish and use the new topic for producing.
>>>>>>>>
>>>>>>>> After this the topic is perfect in shape. and no one needs to worry
>>>>>>>> about
>>>>>>>> complicated stuff. (old keys hanging around might arrive in some
>>>>>>>> other
>>>>>>>> topic later.....). can only imagine how many tricky bugs gonna arrive
>>>>>>>> after
>>>>>>>> someone had grown and shrunken is topic 10 times.
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> 54. "The other thing I wanted to mention is that I believe the
>>>>>>>> current
>>>>>>>>
>>>>>>>> suggestion (without copying data over) can be implemented in pure
>>>>>>>>> userland
>>>>>>>>> with a custom partitioner and a small feedbackloop from
>>>>>>>>> ProduceResponse
>>>>>>>>> =>
>>>>>>>>> Partitionier in coorporation with a change management system." I am
>>>>>>>>> not
>>>>>>>>> sure a customized partitioner itself solves the problem. We probably
>>>>>>>>> need
>>>>>>>>> some broker side support to enforce when the new partitions can be
>>>>>>>>> used.
>>>>>>>>> We
>>>>>>>>> also need some support on the consumer/kstream side to preserve the
>>>>>>>>> per
>>>>>>>>> key
>>>>>>>>> ordering and potentially migrate the processing state. This is not
>>>>>>>>> trivial
>>>>>>>>> and I am not sure if it's ideal to fully push to the application
>>>>>>>>> space.
>>>>>>>>>
>>>>>>>>> Broker support is defenitly the preferred way here. I have nothing
>>>>>>>>>
>>>>>>>>> against
>>>>>>>> broker support.
>>>>>>>> I tried to say that for what I would preffer - copying the data over,
>>>>>>>> at
>>>>>>>> least for log compacted topics -
>>>>>>>> I would require more broker support than the KIP currently offers.
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> Jun
>>>>>>>>
>>>>>>>> On Tue, Mar 6, 2018 at 10:33 PM, Jan Filipiak <
>>>>>>>>> Jan.Filipiak@trivago.com
>>>>>>>>> wrote:
>>>>>>>>>
>>>>>>>>> Hi Dong,
>>>>>>>>>
>>>>>>>>> are you actually reading my emails, or are you just using the
>>>>>>>>> thread I
>>>>>>>>>
>>>>>>>>>> started for general announcements regarding the KIP?
>>>>>>>>>>
>>>>>>>>>> I tried to argue really hard against linear hashing. Growing the
>>>>>>>>>> topic
>>>>>>>>>> by
>>>>>>>>>> an integer factor does not require any state redistribution at
>>>>>>>>>> all. I
>>>>>>>>>> fail
>>>>>>>>>> to see completely where linear hashing helps on log compacted
>>>>>>>>>> topics.
>>>>>>>>>>
>>>>>>>>>> If you are not willing to explain to me what I might be
>>>>>>>>>> overlooking:
>>>>>>>>>> that
>>>>>>>>>> is fine.
>>>>>>>>>> But I ask you to not reply to my emails then. Please understand my
>>>>>>>>>> frustration with this.
>>>>>>>>>>
>>>>>>>>>> Best Jan
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> On 06.03.2018 19:38, Dong Lin wrote:
>>>>>>>>>>
>>>>>>>>>> Hi everyone,
>>>>>>>>>>
>>>>>>>>>> Thanks for all the comments! It appears that everyone prefers
>>>>>>>>>> linear
>>>>>>>>>>
>>>>>>>>>>> hashing because it reduces the amount of state that needs to be
>>>>>>>>>>> moved
>>>>>>>>>>> between consumers (for stream processing). The KIP has been
>>>>>>>>>>> updated
>>>>>>>>>>> to
>>>>>>>>>>> use
>>>>>>>>>>> linear hashing.
>>>>>>>>>>>
>>>>>>>>>>> Regarding the migration endeavor: it seems that migrating producer
>>>>>>>>>>> library
>>>>>>>>>>> to use linear hashing should be pretty straightforward without
>>>>>>>>>>> much operational endeavor. If we don't upgrade client library to
>>>>>>>>>>> use
>>>>>>>>>>> this
>>>>>>>>>>> KIP, we can not support in-order delivery after partition is
>>>>>>>>>>> changed
>>>>>>>>>>> anyway. Suppose we upgrade client library to use this KIP, if
>>>>>>>>>>> partition
>>>>>>>>>>> number is not changed, the key -> partition mapping will be
>>>>>>>>>>> exactly
>>>>>>>>>>> the
>>>>>>>>>>> same as it is now because it is still determined using
>>>>>>>>>>> murmur_hash(key)
>>>>>>>>>>> %
>>>>>>>>>>> original_partition_num. In other words, this change is backward
>>>>>>>>>>> compatible.
>>>>>>>>>>>
>>>>>>>>>>> Regarding the load distribution: if we use linear hashing, the
>>>>>>>>>>> load
>>>>>>>>>>> may
>>>>>>>>>>> be
>>>>>>>>>>> unevenly distributed because those partitions which are not split
>>>>>>>>>>> may
>>>>>>>>>>> receive twice as much traffic as other partitions that are split.
>>>>>>>>>>> This
>>>>>>>>>>> issue can be mitigated by creating topic with partitions that are
>>>>>>>>>>> several
>>>>>>>>>>> times the number of consumers. And there will be no imbalance if
>>>>>>>>>>> the
>>>>>>>>>>> partition number is always doubled. So this imbalance seems
>>>>>>>>>>> acceptable.
>>>>>>>>>>>
>>>>>>>>>>> Regarding storing the partition strategy as per-topic config: It
>>>>>>>>>>> seems
>>>>>>>>>>> not
>>>>>>>>>>> necessary since we can still use murmur_hash as the default hash
>>>>>>>>>>> function
>>>>>>>>>>> and additionally apply the linear hashing algorithm if the
>>>>>>>>>>> partition
>>>>>>>>>>> number
>>>>>>>>>>> has increased. Not sure if there is any use-case for producer to
>>>>>>>>>>> use a
>>>>>>>>>>> different hash function. Jason, can you check if there is some
>>>>>>>>>>> use-case
>>>>>>>>>>> that I missed for using the per-topic partition strategy?
>>>>>>>>>>>
>>>>>>>>>>> Regarding how to reduce latency (due to state store/load) in
>>>>>>>>>>> stream
>>>>>>>>>>> processing consumer when partition number changes: I need to read
>>>>>>>>>>> the
>>>>>>>>>>> Kafka
>>>>>>>>>>> Stream code to understand how Kafka Stream currently migrate state
>>>>>>>>>>> between
>>>>>>>>>>> consumers when the application is added/removed for a given job. I
>>>>>>>>>>> will
>>>>>>>>>>> reply after I finish reading the documentation and code.
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> Thanks,
>>>>>>>>>>> Dong
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> On Mon, Mar 5, 2018 at 10:43 AM, Jason Gustafson <
>>>>>>>>>>> jason@confluent.io>
>>>>>>>>>>> wrote:
>>>>>>>>>>>
>>>>>>>>>>> Great discussion. I think I'm wondering whether we can continue to
>>>>>>>>>>> leave
>>>>>>>>>>>
>>>>>>>>>>> Kafka agnostic to the partitioning strategy. The challenge is
>>>>>>>>>>>
>>>>>>>>>>> communicating
>>>>>>>>>>>> the partitioning logic from producers to consumers so that the
>>>>>>>>>>>> dependencies
>>>>>>>>>>>> between each epoch can be determined. For the sake of discussion,
>>>>>>>>>>>> imagine
>>>>>>>>>>>> you did something like the following:
>>>>>>>>>>>>
>>>>>>>>>>>> 1. The name (and perhaps version) of a partitioning strategy is
>>>>>>>>>>>> stored
>>>>>>>>>>>> in
>>>>>>>>>>>> topic configuration when a topic is created.
>>>>>>>>>>>> 2. The producer looks up the partitioning strategy before writing
>>>>>>>>>>>> to
>>>>>>>>>>>> a
>>>>>>>>>>>> topic and includes it in the produce request (for fencing). If it
>>>>>>>>>>>> doesn't
>>>>>>>>>>>> have an implementation for the configured strategy, it fails.
>>>>>>>>>>>> 3. The consumer also looks up the partitioning strategy and uses
>>>>>>>>>>>> it
>>>>>>>>>>>> to
>>>>>>>>>>>> determine dependencies when reading a new epoch. It could either
>>>>>>>>>>>> fail
>>>>>>>>>>>> or
>>>>>>>>>>>> make the most conservative dependency assumptions if it doesn't
>>>>>>>>>>>> know
>>>>>>>>>>>> how
>>>>>>>>>>>> to
>>>>>>>>>>>> implement the partitioning strategy. For the consumer, the new
>>>>>>>>>>>> interface
>>>>>>>>>>>> might look something like this:
>>>>>>>>>>>>
>>>>>>>>>>>> // Return the partition dependencies following an epoch bump
>>>>>>>>>>>> Map<Integer, List<Integer>> dependencies(int
>>>>>>>>>>>> numPartitionsBeforeEpochBump,
>>>>>>>>>>>> int numPartitionsAfterEpochBump)
>>>>>>>>>>>>
>>>>>>>>>>>> The unordered case then is just a particular implementation which
>>>>>>>>>>>> never
>>>>>>>>>>>> has
>>>>>>>>>>>> any epoch dependencies. To implement this, we would need some way
>>>>>>>>>>>> for
>>>>>>>>>>>> the
>>>>>>>>>>>> consumer to find out how many partitions there were in each
>>>>>>>>>>>> epoch,
>>>>>>>>>>>> but
>>>>>>>>>>>> maybe that's not too unreasonable.
>>>>>>>>>>>>
>>>>>>>>>>>> Thanks,
>>>>>>>>>>>> Jason
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>> On Mon, Mar 5, 2018 at 4:51 AM, Jan Filipiak <
>>>>>>>>>>>> Jan.Filipiak@trivago.com
>>>>>>>>>>>> wrote:
>>>>>>>>>>>>
>>>>>>>>>>>> Hi Dong
>>>>>>>>>>>>
>>>>>>>>>>>> thank you very much for your questions.
>>>>>>>>>>>>
>>>>>>>>>>>> regarding the time spend copying data across:
>>>>>>>>>>>>> It is correct that copying data from a topic with one partition
>>>>>>>>>>>>> mapping
>>>>>>>>>>>>>
>>>>>>>>>>>>> to
>>>>>>>>>>>>>
>>>>>>>>>>>>> a topic with a different partition mapping takes way longer than
>>>>>>>>>>>>>
>>>>>>>>>>>> we
>>>>>>>>>>>> can
>>>>>>>>>>>>
>>>>>>>>>>>> stop producers. Tens of minutes is a very optimistic estimate
>>>>>>>>>>>> here.
>>>>>>>>>>>>
>>>>>>>>>>>>> Many
>>>>>>>>>>>>> people can not afford copy full steam and therefore will have
>>>>>>>>>>>>> some
>>>>>>>>>>>>> rate
>>>>>>>>>>>>> limiting in place, this can bump the timespan into the day's.
>>>>>>>>>>>>> The
>>>>>>>>>>>>> good
>>>>>>>>>>>>>
>>>>>>>>>>>>> part
>>>>>>>>>>>>>
>>>>>>>>>>>>> is that the vast majority of the data can be copied while the
>>>>>>>>>>>>>
>>>>>>>>>>>> producers
>>>>>>>>>>>>
>>>>>>>>>>>> are
>>>>>>>>>>>>
>>>>>>>>>>>>> still going. One can then, piggyback the consumers ontop of this
>>>>>>>>>>>>>
>>>>>>>>>>>> timeframe,
>>>>>>>>>>>>
>>>>>>>>>>>>> by the method mentioned (provide them an mapping from their old
>>>>>>>>>>>>>
>>>>>>>>>>>> offsets
>>>>>>>>>>>>
>>>>>>>>>>>> to
>>>>>>>>>>>>
>>>>>>>>>>>>> new offsets in their repartitioned topics. In that way we
>>>>>>>>>>>>> separate
>>>>>>>>>>>>>
>>>>>>>>>>>> migration of consumers from migration of producers (decoupling
>>>>>>>>>>>>
>>>>>>>>>>>>> these
>>>>>>>>>>>>> is
>>>>>>>>>>>>> what kafka is strongest at). The time to actually swap over the
>>>>>>>>>>>>> producers
>>>>>>>>>>>>> should be kept minimal by ensuring that when a swap attempt is
>>>>>>>>>>>>> started
>>>>>>>>>>>>>
>>>>>>>>>>>>> the
>>>>>>>>>>>>>
>>>>>>>>>>>>> consumer copying over should be very close to the log end and is
>>>>>>>>>>>>>
>>>>>>>>>>>> expected
>>>>>>>>>>>>
>>>>>>>>>>>>> to finish within the next fetch. The operation should have a
>>>>>>>>>>>>> time-out
>>>>>>>>>>>>> and
>>>>>>>>>>>>> should be "reattemtable".
>>>>>>>>>>>>>
>>>>>>>>>>>>> Importance of logcompaction:
>>>>>>>>>>>>> If a producer produces key A, to partiton 0, its forever gonna
>>>>>>>>>>>>> be
>>>>>>>>>>>>> there,
>>>>>>>>>>>>> unless it gets deleted. The record might sit in there for
>>>>>>>>>>>>> years. A
>>>>>>>>>>>>> new
>>>>>>>>>>>>> producer started with the new partitions will fail to delete the
>>>>>>>>>>>>> record
>>>>>>>>>>>>>
>>>>>>>>>>>>> in
>>>>>>>>>>>>>
>>>>>>>>>>>>> the correct partition. Th record will be there forever and one
>>>>>>>>>>>>> can
>>>>>>>>>>>>>
>>>>>>>>>>>> not
>>>>>>>>>>>>
>>>>>>>>>>>> reliable bootstrap new consumers. I cannot see how linear hashing
>>>>>>>>>>>>
>>>>>>>>>>>>> can
>>>>>>>>>>>>>
>>>>>>>>>>>>> solve
>>>>>>>>>>>>>
>>>>>>>>>>>>> this.
>>>>>>>>>>>>>
>>>>>>>>>>>> Regarding your skipping of userland copying:
>>>>>>>>>>>>
>>>>>>>>>>>>> 100%, copying the data across in userland is, as far as i can
>>>>>>>>>>>>> see,
>>>>>>>>>>>>> only
>>>>>>>>>>>>> a
>>>>>>>>>>>>> usecase for log compacted topics. Even for logcompaction +
>>>>>>>>>>>>> retentions
>>>>>>>>>>>>> it
>>>>>>>>>>>>> should only be opt-in. Why did I bring it up? I think log
>>>>>>>>>>>>> compaction
>>>>>>>>>>>>> is
>>>>>>>>>>>>> a
>>>>>>>>>>>>> very important feature to really embrace kafka as a "data
>>>>>>>>>>>>> plattform".
>>>>>>>>>>>>> The
>>>>>>>>>>>>> point I also want to make is that copying data this way is
>>>>>>>>>>>>> completely
>>>>>>>>>>>>> inline with the kafka architecture. it only consists of reading
>>>>>>>>>>>>> and
>>>>>>>>>>>>>
>>>>>>>>>>>>> writing
>>>>>>>>>>>>>
>>>>>>>>>>>>> to topics.
>>>>>>>>>>>>>
>>>>>>>>>>>> I hope it clarifies more why I think we should aim for more than
>>>>>>>>>>>>
>>>>>>>>>>>>> the
>>>>>>>>>>>>> current KIP. I fear that once the KIP is done not much more
>>>>>>>>>>>>> effort
>>>>>>>>>>>>> will
>>>>>>>>>>>>>
>>>>>>>>>>>>> be
>>>>>>>>>>>>>
>>>>>>>>>>>>> taken.
>>>>>>>>>>>>>
>>>>>>>>>>>> On 04.03.2018 02:28, Dong Lin wrote:
>>>>>>>>>>>>> Hey Jan,
>>>>>>>>>>>>>
>>>>>>>>>>>>> In the current proposal, the consumer will be blocked on waiting
>>>>>>>>>>>>> for
>>>>>>>>>>>>>
>>>>>>>>>>>>> other
>>>>>>>>>>>>>> consumers of the group to consume up to a given offset. In most
>>>>>>>>>>>>>>
>>>>>>>>>>>>> cases,
>>>>>>>>>>>>> all
>>>>>>>>>>>>> consumers should be close to the LEO of the partitions when the
>>>>>>>>>>>>> partition
>>>>>>>>>>>>> expansion happens. Thus the time waiting should not be long e.g.
>>>>>>>>>>>>> on
>>>>>>>>>>>>> the
>>>>>>>>>>>>>
>>>>>>>>>>>>> order of seconds. On the other hand, it may take a long time to
>>>>>>>>>>>>> wait
>>>>>>>>>>>>>
>>>>>>>>>>>>> for
>>>>>>>>>>>>>> the entire partition to be copied -- the amount of time is
>>>>>>>>>>>>>> proportional
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> to
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> the amount of existing data in the partition, which can take
>>>>>>>>>>>>>>
>>>>>>>>>>>>> tens of
>>>>>>>>>>>>>
>>>>>>>>>>>>> minutes. So the amount of time that we stop consumers may not be
>>>>>>>>>>>>> on
>>>>>>>>>>>>>
>>>>>>>>>>>>> the
>>>>>>>>>>>>>> same order of magnitude.
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> If we can implement this suggestion without copying data over
>>>>>>>>>>>>>> in
>>>>>>>>>>>>>> purse
>>>>>>>>>>>>>> userland, it will be much more valuable. Do you have ideas on
>>>>>>>>>>>>>> how
>>>>>>>>>>>>>> this
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> can
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> be done?
>>>>>>>>>>>>>>
>>>>>>>>>>>>> Not sure why the current KIP not help people who depend on log
>>>>>>>>>>>>>
>>>>>>>>>>>>> compaction.
>>>>>>>>>>>>>> Could you elaborate more on this point?
>>>>>>>>>>>>>>
>>>>>>>>>>>>> Thanks,
>>>>>>>>>>>>>
>>>>>>>>>>>>> Dong
>>>>>>>>>>>>>> On Wed, Feb 28, 2018 at 10:55 PM, Jan
>>>>>>>>>>>>>> Filipiak<Jan.Filipiak@trivago.
>>>>>>>>>>>>>> com
>>>>>>>>>>>>>> wrote:
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> Hi Dong,
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> I tried to focus on what the steps are one can currently
>>>>>>>>>>>>>> perform
>>>>>>>>>>>>>> to
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> expand
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> or shrink a keyed topic while maintaining a top notch
>>>>>>>>>>>>>>> semantics.
>>>>>>>>>>>>>>> I can understand that there might be confusion about "stopping
>>>>>>>>>>>>>>> the
>>>>>>>>>>>>>>> consumer". It is exactly the same as proposed in the KIP.
>>>>>>>>>>>>>>> there
>>>>>>>>>>>>>>> needs
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> to
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> be
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>> a time the producers agree on the new partitioning. The extra
>>>>>>>>>>>>> semantics I
>>>>>>>>>>>>>>> want to put in there is that we have a possibility to wait
>>>>>>>>>>>>>>> until
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>> all
>>>>>>>>>>>>> the
>>>>>>>>>>>>>
>>>>>>>>>>>>> existing data
>>>>>>>>>>>>>> is copied over into the new partitioning scheme. When I say
>>>>>>>>>>>>> stopping
>>>>>>>>>>>>>
>>>>>>>>>>>>> I
>>>>>>>>>>>>>>> think more of having a memory barrier that ensures the
>>>>>>>>>>>>>>> ordering. I
>>>>>>>>>>>>>>> am
>>>>>>>>>>>>>>> still
>>>>>>>>>>>>>>> aming for latencies  on the scale of leader failovers.
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> Consumers have to explicitly adapt the new partitioning scheme
>>>>>>>>>>>>>>> in
>>>>>>>>>>>>>>> the
>>>>>>>>>>>>>>> above scenario. The reason is that in these cases where you
>>>>>>>>>>>>>>> are
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> dependent
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> on a particular partitioning scheme, you also have other
>>>>>>>>>>>>>>> topics
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>> that
>>>>>>>>>>>>> have
>>>>>>>>>>>>>
>>>>>>>>>>>>> co-partition enforcements or the kind -frequently. Therefore all
>>>>>>>>>>>>>> your
>>>>>>>>>>>>> other
>>>>>>>>>>>>>
>>>>>>>>>>>>> input topics might need to grow accordingly.
>>>>>>>>>>>>>>> What I was suggesting was to streamline all these operations
>>>>>>>>>>>>>>> as
>>>>>>>>>>>>>>> best
>>>>>>>>>>>>>>> as
>>>>>>>>>>>>>>> possible to have "real" partition grow and shrinkage going on.
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> Migrating
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> the producers to a new partitioning scheme can be much more
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>> streamlined
>>>>>>>>>>>>> with proper broker support for this. Migrating consumer is a
>>>>>>>>>>>>> step
>>>>>>>>>>>>>
>>>>>>>>>>>>> that
>>>>>>>>>>>>>>> might be made completly unnecessary if - for example streams -
>>>>>>>>>>>>>>> takes
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> the
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> gcd as partitioning scheme instead of enforcing 1 to 1.
>>>>>>>>>>>>>>> Connect
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>> consumers
>>>>>>>>>>>>> and other consumers should be fine anyways.
>>>>>>>>>>>>>> I hope this makes more clear where I was aiming at. The rest
>>>>>>>>>>>>> needs
>>>>>>>>>>>>>
>>>>>>>>>>>>> to
>>>>>>>>>>>>>> be
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> figured out. The only danger i see is that when we are
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>> introducing
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> this
>>>>>>>>>>>>> feature as supposed in the KIP, it wont help any people
>>>>>>>>>>>>> depending
>>>>>>>>>>>>> on
>>>>>>>>>>>>>
>>>>>>>>>>>>> log
>>>>>>>>>>>>>>> compaction.
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>> The other thing I wanted to mention is that I believe the
>>>>>>>>>>>>> current
>>>>>>>>>>>>>
>>>>>>>>>>>>> suggestion (without copying data over) can be implemented in
>>>>>>>>>>>>>> pure
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> userland
>>>>>>>>>>>>>>> with a custom partitioner and a small feedbackloop from
>>>>>>>>>>>>>>> ProduceResponse
>>>>>>>>>>>>>>> =>
>>>>>>>>>>>>>>> Partitionier in coorporation with a change management system.
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> Best Jan
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> On 28.02.2018 07:13, Dong Lin wrote:
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> Hey Jan,
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> I am not sure if it is acceptable for producer to be stopped
>>>>>>>>>>>>>>> for a
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> while,
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> particularly for online application which requires low
>>>>>>>>>>>>>>>> latency. I
>>>>>>>>>>>>>>>> am
>>>>>>>>>>>>>>>> also
>>>>>>>>>>>>>>>> not sure how consumers can switch to a new topic. Does user
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> application
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> needs to explicitly specify a different topic for
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> producer/consumer
>>>>>>>>>>>>>> to
>>>>>>>>>>>>>>
>>>>>>>>>>>>> subscribe to? It will be helpful for discussion if you can
>>>>>>>>>>>>> provide
>>>>>>>>>>>>>
>>>>>>>>>>>>> more
>>>>>>>>>>>>>>> detail on the interface change for this solution.
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> Thanks,
>>>>>>>>>>>>>> Dong
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> On Mon, Feb 26, 2018 at 12:48 AM, Jan
>>>>>>>>>>>>>>>> Filipiak<Jan.Filipiak@trivago.
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> com
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> wrote:
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> Hi,
>>>>>>>>>>>>>> just want to throw my though in. In general the functionality
>>>>>>>>>>>>>> is
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> very
>>>>>>>>>>>>>>>> usefull, we should though not try to find the architecture to
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> hard
>>>>>>>>>>>>>>>>> while
>>>>>>>>>>>>>>>>> implementing.
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> The manual steps would be to
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> create a new topic
>>>>>>>>>>>>>>>>> the mirrormake from the new old topic to the new topic
>>>>>>>>>>>>>>>>> wait for mirror making to catch up.
>>>>>>>>>>>>>>>>> then put the consumers onto the new topic
>>>>>>>>>>>>>>>>>             (having mirrormaker spit out a mapping from old
>>>>>>>>>>>>>>>>> offsets to
>>>>>>>>>>>>>>>>> new
>>>>>>>>>>>>>>>>> offsets:
>>>>>>>>>>>>>>>>>                 if topic is increased by factor X there is
>>>>>>>>>>>>>>>>> gonna
>>>>>>>>>>>>>>>>> be a
>>>>>>>>>>>>>>>>> clean
>>>>>>>>>>>>>>>>> mapping from 1 offset in the old topic to X offsets in the
>>>>>>>>>>>>>>>>> new
>>>>>>>>>>>>>>>>> topic,
>>>>>>>>>>>>>>>>>                 if there is no factor then there is no
>>>>>>>>>>>>>>>>> chance to
>>>>>>>>>>>>>>>>> generate a
>>>>>>>>>>>>>>>>> mapping that can be reasonable used for continuing)
>>>>>>>>>>>>>>>>>             make consumers stop at appropriate points and
>>>>>>>>>>>>>>>>> continue
>>>>>>>>>>>>>>>>> consumption
>>>>>>>>>>>>>>>>> with offsets from the mapping.
>>>>>>>>>>>>>>>>> have the producers stop for a minimal time.
>>>>>>>>>>>>>>>>> wait for mirrormaker to finish
>>>>>>>>>>>>>>>>> let producer produce with the new metadata.
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> Instead of implementing the approach suggest in the KIP
>>>>>>>>>>>>>>>>> which
>>>>>>>>>>>>>>>>> will
>>>>>>>>>>>>>>>>> leave
>>>>>>>>>>>>>>>>> log compacted topic completely crumbled and unusable.
>>>>>>>>>>>>>>>>> I would much rather try to build infrastructure to support
>>>>>>>>>>>>>>>>> the
>>>>>>>>>>>>>>>>> mentioned
>>>>>>>>>>>>>>>>> above operations more smoothly.
>>>>>>>>>>>>>>>>> Especially having producers stop and use another topic is
>>>>>>>>>>>>>>>>> difficult
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> and
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> it would be nice if one can trigger "invalid metadata"
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> exceptions
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> for
>>>>>>>>>>>>>> them
>>>>>>>>>>>>> and
>>>>>>>>>>>>>>> if one could give topics aliases so that their produces with
>>>>>>>>>>>>>>>>> the
>>>>>>>>>>>>>>>>> old
>>>>>>>>>>>>>>>>> topic
>>>>>>>>>>>>>>>>> will arrive in the new topic.
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> The downsides are obvious I guess ( having the same data
>>>>>>>>>>>>>>>>> twice
>>>>>>>>>>>>>>>>> for
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> the
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> transition period, but kafka tends to scale well with
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> datasize).
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> So
>>>>>>>>>>>>>>> its a
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>> nicer fit into the architecture.
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> I further want to argument that the functionality by the KIP
>>>>>>>>>>>>>>>>> can
>>>>>>>>>>>>>>>>> completely be implementing in "userland" with a custom
>>>>>>>>>>>>>>>>> partitioner
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> that
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> handles the transition as needed. I would appreciate if
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> someone
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> could
>>>>>>>>>>>>>> point
>>>>>>>>>>>>> out what a custom partitioner couldn't handle in this case?
>>>>>>>>>>>>>>> With the above approach, shrinking a topic becomes the same
>>>>>>>>>>>>>>>>> steps.
>>>>>>>>>>>>>>>>> Without
>>>>>>>>>>>>>>>>> loosing keys in the discontinued partitions.
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> Would love to hear what everyone thinks.
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> Best Jan
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> On 11.02.2018 00:35, Dong Lin wrote:
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> Hi all,
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> I have created KIP-253: Support in-order message delivery
>>>>>>>>>>>>>>>>> with
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> partition
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> expansion. See
>>>>>>>>>>>>>>>>>> https://cwiki.apache.org/confluence/display/KAFKA/KIP-253%
>>>>>>>>>>>>>>>>>> 3A+Support+in-order+message+de
>>>>>>>>>>>>>>>>>> livery+with+partition+expansio
>>>>>>>>>>>>>>>>>> n
>>>>>>>>>>>>>>>>>> .
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> This KIP provides a way to allow messages of the same key
>>>>>>>>>>>>>>>>>> from
>>>>>>>>>>>>>>>>>> the
>>>>>>>>>>>>>>>>>> same
>>>>>>>>>>>>>>>>>> producer to be consumed in the same order they are produced
>>>>>>>>>>>>>>>>>> even
>>>>>>>>>>>>>>>>>> if
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> we
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> expand partition of the topic.
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> Thanks,
>>>>>>>>>>>>>>> Dong
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>
>>


Re: [DISCUSS] KIP-253: Support in-order message delivery with partition expansion

Posted by Jun Rao <ju...@confluent.io>.
Hi, Jan,

Thanks for the reply.

Ok. So your idea is to have a special consumer reshuffle the data to a new
set of partitions. Each consumer group will not increase its tasks
immediately. We just need to make sure that each consumer instance is
assigned the set of new partitions covering the same set of keys. At some
point later, each consumer group can decide independently when to increase
the number of tasks. At that point, the consumer will need to rebuild the
local state for the new tasks. Is that right?

I agree that decoupling the number of tasks in a consumer group from the
number of partitions in the input topic is a good idea. This allows each
consumer group to change its degree of parallelism independently. There are
different ways to achieve such decoupling. You suggested one approach,
which works when splitting partitions. Not sure if this works in general,
for example when merging partitions.

Once a consumer group decides to change its degree of parallelism, it needs
to rebuild the local state for the new tasks. We can either rebuild the
states from the input topic or from the local state (through change capture
topic). I think we agreed that rebuilding from the local state is more
efficient. It also seems that it's better to let the KStreams library do
the state rebuilding, instead of each application. Would you agree?

About the special consumer. I guess that's only needed if one wants to
recopy the existing data? However, if we can truly decouple the tasks in
the consumer group from the partitions in the input topic, it seems there
is no need for copying existing data? It's also not clear to me who will
start/stop this special consumer.

Thanks,

Jun

On Wed, Mar 21, 2018 at 6:57 AM, Jan Filipiak <Ja...@trivago.com>
wrote:

> Hi Jun,
>
> I was really seeing progress in our conversation but your latest reply is
> just devastating.
> I though we were getting close being on the same page now it feels like we
> are in different libraries.
>
> I just quickly slam my answers in here. If they are to brief I am sorry
> give me a ping and try to go into details more.
> Just want to show that your pro/cons listing is broken.
>
> Best Jan
>
> and want to get rid of this horrible compromise
>
>
> On 19.03.2018 05:48, Jun Rao wrote:
>
>> Hi, Jan,
>>
>> Thanks for the discussion. Great points.
>>
>> Let me try to summarize the approach that you are proposing. On the broker
>> side, we reshuffle the existing data in a topic from current partitions to
>> the new partitions. Once the reshuffle fully catches up, switch the
>> consumers to start consuming from the new partitions. If a consumer needs
>> to rebuild its local state (due to partition changes), let the consumer
>> rebuild its state by reading all existing data from the new partitions.
>> Once all consumers have switches over, cut over the producer to the new
>> partitions.
>>
>> The pros for this approach are that :
>> 1. There is just one way to rebuild the local state, which is simpler.
>>
> true thanks
>
>>
>> The cons for this approach are:
>> 1. Need to copy existing data.
>>
> Very unfair and not correct. It does not require you to copy over existing
> data. It _allows_ you to copy all existing data.
>
> 2. The cutover of the producer is a bit complicated since it needs to
>> coordinate with all consumer groups.
>>
> Also not true. I explicitly tried to make clear that there is only one
> special consumer (in the case of actually copying data) coordination is
> required.
>
>> 3. The rebuilding of the state in the consumer is from the input topic,
>> which can be more expensive than rebuilding from the existing state.
>>
> true, but rebuilding state is only required if you want to increase
> processing power, so we assume this is at hand.
>
>> 4. The broker potentially has to know the partitioning function. If this
>> needs to be customized at the topic level, it can be a bit messy.
>>
> I would argue against having the operation being performed by the broker.
> This was not discussed yet but if you see my original email i suggested
> otherwise from the beginning.
>
>>
>> Here is an alternative approach by applying your idea not in the broker,
>> but in the consumer. When new partitions are added, we don't move existing
>> data. In KStreams, we first reshuffle the new input data to a new topic T1
>> with the old number of partitions and feed T1's data to the rest of the
>> pipeline. In the meantime, KStreams reshuffles all existing data of the
>> change capture topic to another topic C1 with the new number of
>> partitions.
>> We can then build the state of the new tasks from C1. Once the new states
>> have been fully built, we can cut over the consumption to the input topic
>> and delete T1. This approach works with compacted topic too. If an
>> application reads from the beginning of a compacted topic, the consumer
>> will reshuffle the portion of the input when the number of partitions
>> doesn't match the number of tasks.
>>
> We all wipe this idea from our heads instantly. Mixing Ideas from an
> argument is not a resolution strategy
> just leads to horrible horrible software.
>
>
>> The pros of this approach are:
>> 1. No need to copy existing data.
>> 2. Each consumer group can cut over to the new partitions independently.
>> 3. The state is rebuilt from the change capture topic, which is cheaper
>> than rebuilding from the input topic.
>> 4. Only the KStreams job needs to know the partitioning function.
>>
>> The cons of this approach are:
>> 1. Potentially the same input topic needs to be reshuffled more than once
>> in different consumer groups during the transition phase.
>>
>> What do you think?
>>
>> Thanks,
>>
>> Jun
>>
>>
>>
>> On Thu, Mar 15, 2018 at 1:04 AM, Jan Filipiak <Ja...@trivago.com>
>> wrote:
>>
>> Hi Jun,
>>>
>>> thank you for following me on these thoughts. It was important to me to
>>> feel that kind of understanding for my arguments.
>>>
>>> What I was hoping for (I mentioned this earlier) is that we can model the
>>> case where we do not want to copy the data the exact same way as the case
>>> when we do copy the data. Maybe you can peek into the mails before to see
>>> more details for this.
>>>
>>> This means we have the same mechanism to transfer consumer groups to
>>> switch topic. The offset mapping that would be generated would even be
>>> simpler End Offset of the Old topic => offset 0 off all the partitions of
>>> the new topic. Then we could model the transition of a non-copy expansion
>>> the exact same way as a copy-expansion.
>>>
>>> I know this only works when topic growth by a factor. But the benefits of
>>> only growing by a factor are to strong anyways. See Clemens's hint and
>>> remember that state reshuffling is entirely not needed if one doesn't
>>> want
>>> to grow processing power.
>>>
>>> I think these benefits should be clear, and that there is basically no
>>> downside to what is currently at hand but just makes everything easy.
>>>
>>> One thing you need to know is. that if you do not offer rebuilding a log
>>> compacted topic like i suggest that even if you have consumer state
>>> reshuffling. The topic is broken and can not be used to bootstrap new
>>> consumers. They don't know if they need to apply a key from and old
>>> partition or not. This is a horrible downside I haven't seen a solution
>>> for
>>> in the email conversation.
>>>
>>> I argue to:
>>>
>>> Only grow topic by a factor always.
>>> Have the "no copy consumer" transition as the trivial case of the "copy
>>> consumer transition".
>>> If processors needs to be scaled, let them rebuild from the new topic and
>>> leave the old running in the mean time.
>>> Do not implement key shuffling in streams.
>>>
>>> I hope I can convince you especially with the fact how I want to handle
>>> consumer transition. I think
>>> you didn't quite understood me there before. I think the term "new topic"
>>> intimidated you a little.
>>> How we solve this on disc doesn't really matter, If the data goes into
>>> the
>>> same Dir or a different Dir or anything. I do think that it needs to
>>> involve at least rolling a new segment for the existing partitions.
>>> But most of the transitions should work without restarting consumers.
>>> (newer consumers with support for this). But with new topic i just meant
>>> the topic that now has a different partition count. Plenty of ways to
>>> handle that (versions, aliases)
>>>
>>> Hope I can further get my idea across.
>>>
>>> Best Jan
>>>
>>>
>>>
>>>
>>>
>>>
>>> On 14.03.2018 02:45, Jun Rao wrote:
>>>
>>> Hi, Jan,
>>>>
>>>> Thanks for sharing your view.
>>>>
>>>> I agree with you that recopying the data potentially makes the state
>>>> management easier since the consumer can just rebuild its state from
>>>> scratch (i.e., no need for state reshuffling).
>>>>
>>>> On the flip slide, I saw a few disadvantages of the approach that you
>>>> suggested. (1) Building the state from the input topic from scratch is
>>>> in
>>>> general less efficient than state reshuffling. Let's say one computes a
>>>> count per key from an input topic. The former requires reading all
>>>> existing
>>>> records in the input topic whereas the latter only requires reading data
>>>> proportional to the number of unique keys. (2) The switching of the
>>>> topic
>>>> needs modification to the application. If there are many applications
>>>> on a
>>>> topic, coordinating such an effort may not be easy. Also, it's not clear
>>>> how to enforce exactly-once semantic during the switch. (3) If a topic
>>>> doesn't need any state management, recopying the data seems wasteful. In
>>>> that case, in place partition expansion seems more desirable.
>>>>
>>>> I understand your concern about adding complexity in KStreams. But,
>>>> perhaps
>>>> we could iterate on that a bit more to see if it can be simplified.
>>>>
>>>> Jun
>>>>
>>>>
>>>> On Mon, Mar 12, 2018 at 11:21 PM, Jan Filipiak <
>>>> Jan.Filipiak@trivago.com>
>>>> wrote:
>>>>
>>>> Hi Jun,
>>>>
>>>>> I will focus on point 61 as I think its _the_ fundamental part that I
>>>>> cant
>>>>> get across at the moment.
>>>>>
>>>>> Kafka is the platform to have state materialized multiple times from
>>>>> one
>>>>> input. I emphasize this: It is the building block in architectures that
>>>>> allow you to
>>>>> have your state maintained multiple times. You put a message in once,
>>>>> and
>>>>> you have it pop out as often as you like. I believe you understand
>>>>> this.
>>>>>
>>>>> Now! The path of thinking goes the following: I am using apache kafka
>>>>> and
>>>>> I _want_ my state multiple times. What am I going todo?
>>>>>
>>>>> A) Am I going to take my state that I build up, plunge some sort of RPC
>>>>> layer ontop of it, use that RPC layer to throw my records across
>>>>> instances?
>>>>> B) Am I just going to read the damn message twice?
>>>>>
>>>>> Approach A is fundamentally flawed and a violation of all that is good
>>>>> and
>>>>> holy in kafka deployments. I can not understand how this Idea can come
>>>>> in
>>>>> the first place.
>>>>> (I do understand: IQ in streams, they polluted the kafka streams
>>>>> codebase
>>>>> really bad already. It is not funny! I think they are equally flawed as
>>>>> A)
>>>>>
>>>>> I say, we do what Kafka is good at. We repartition the topic once. We
>>>>> switch the consumers.
>>>>> (Those that need more partitions are going to rebuild their state in
>>>>> multiple partitions by reading the new topic, those that don't just
>>>>> assign
>>>>> the new partitions properly)
>>>>> We switch producers. Done!
>>>>>
>>>>> The best thing! It is trivial, hipster stream processor will have an
>>>>> easy
>>>>> time with that aswell. Its so super simple. And simple IS good!
>>>>> It is what kafka was build todo. It is how we do it today. All I am
>>>>> saying
>>>>> is that a little broker help doing the producer swap is super useful.
>>>>>
>>>>> For everyone interested in why kafka is so powerful with approach B,
>>>>> please watch https://youtu.be/bEbeZPVo98c?t=1633
>>>>> I already looked up a good point in time, I think after 5 minutes the
>>>>> "state" topic is handled and you should be able to understand me
>>>>> and inch better.
>>>>>
>>>>> Please do not do A to the project, it deserves better!
>>>>>
>>>>> Best Jan
>>>>>
>>>>>
>>>>>
>>>>> On 13.03.2018 02:40, Jun Rao wrote:
>>>>>
>>>>> Hi, Jan,
>>>>>
>>>>>> Thanks for the reply. A few more comments below.
>>>>>>
>>>>>> 50. Ok, we can think a bit harder for supporting compacted topics.
>>>>>>
>>>>>> 51. This is a fundamental design question. In the more common case,
>>>>>> the
>>>>>> reason why someone wants to increase the number of partitions is that
>>>>>> the
>>>>>> consumer application is slow and one wants to run more consumer
>>>>>> instances
>>>>>> to increase the degree of parallelism. So, fixing the number of
>>>>>> running
>>>>>> consumer instances when expanding the partitions won't help this case.
>>>>>> If
>>>>>> we do need to increase the number of consumer instances, we need to
>>>>>> somehow
>>>>>> reshuffle the state of the consumer across instances. What we have
>>>>>> been
>>>>>> discussing in this KIP is whether we can do this more effectively
>>>>>> through
>>>>>> the KStream library (e.g. through a 2-phase partition expansion). This
>>>>>> will
>>>>>> add some complexity, but it's probably better than everyone doing this
>>>>>> in
>>>>>> the application space. The recopying approach that you mentioned
>>>>>> doesn't
>>>>>> seem to address the consumer state management issue when the consumer
>>>>>> switches from an old to a new topic.
>>>>>>
>>>>>> 52. As for your example, it depends on whether the join key is the
>>>>>> same
>>>>>> between (A,B) and (B,C). If the join key is the same, we can do a
>>>>>> 2-phase
>>>>>> partition expansion of A, B, and C together. If the join keys are
>>>>>> different, one would need to repartition the data on a different key
>>>>>> for
>>>>>> the second join, then the partition expansion can be done
>>>>>> independently
>>>>>> between (A,B) and (B,C).
>>>>>>
>>>>>> 53. If you always fix the number of consumer instances, we you
>>>>>> described
>>>>>> works. However, as I mentioned in #51, I am not sure how your proposal
>>>>>> deals with consumer states when the number of consumer instances
>>>>>> grows.
>>>>>> Also, it just seems that it's better to avoid re-copying the existing
>>>>>> data.
>>>>>>
>>>>>> 60. "just want to throw in my question from the longer email in the
>>>>>> other
>>>>>> Thread here. How will the bloom filter help a new consumer to decide
>>>>>> to
>>>>>> apply the key or not?" Not sure that I fully understood your question.
>>>>>> The
>>>>>> consumer just reads whatever key is in the log. The bloom filter just
>>>>>> helps
>>>>>> clean up the old keys.
>>>>>>
>>>>>> 61. "Why can we afford having a topic where its apparently not
>>>>>> possible
>>>>>> to
>>>>>> start a new application on? I think this is an overall flaw of the
>>>>>> discussed idea here. Not playing attention to the overall
>>>>>> architecture."
>>>>>> Could you explain a bit more when one can't start a new application?
>>>>>>
>>>>>> Jun
>>>>>>
>>>>>>
>>>>>>
>>>>>> On Sat, Mar 10, 2018 at 1:40 AM, Jan Filipiak <
>>>>>> Jan.Filipiak@trivago.com
>>>>>> wrote:
>>>>>>
>>>>>> Hi Jun, thanks for your mail.
>>>>>>
>>>>>> Thank you for your questions!
>>>>>>> I think they are really good and tackle the core of the problem I
>>>>>>> see.
>>>>>>>
>>>>>>> I will answer inline, mostly but still want to set the tone here.
>>>>>>>
>>>>>>> The core strength of kafka is what Martin once called the
>>>>>>> kappa-Architecture. How does this work?
>>>>>>> You have everything as a log as in kafka. When you need to change
>>>>>>> something.
>>>>>>> You create the new version of your application and leave it running
>>>>>>> in
>>>>>>> parallel.
>>>>>>> Once the new version is good you switch your users to use the new
>>>>>>> application.
>>>>>>>
>>>>>>> The online reshuffling effectively breaks this architecture and I
>>>>>>> think
>>>>>>> the switch in thinking here is more harmful
>>>>>>> than any details about the partitioning function to allow such a
>>>>>>> change.
>>>>>>> I
>>>>>>> feel with my suggestion we are the closest to
>>>>>>> the original and battle proven architecture and I can only warn to
>>>>>>> move
>>>>>>> away from it.
>>>>>>>
>>>>>>> I might have forgotten something, sometimes its hard for me to
>>>>>>> getting
>>>>>>> all
>>>>>>> the thoughts captured in a mail, but I hope the comments inline will
>>>>>>> further make my concern clear, and put some emphasis on why I prefer
>>>>>>> my
>>>>>>> solution ;)
>>>>>>>
>>>>>>> One thing we should all be aware of when discussing this, and I think
>>>>>>> Dong
>>>>>>> should have mentioned it (maybe he did).
>>>>>>> We are not discussing all of this out of thin air but there is an
>>>>>>> effort
>>>>>>> in the Samza project.
>>>>>>>
>>>>>>> https://cwiki.apache.org/confluence/display/SAMZA/SEP-5%3A+
>>>>>>> Enable+partition+expansion+of+input+streams
>>>>>>> https://issues.apache.org/jira/browse/SAMZA-1293
>>>>>>>
>>>>>>> To be clear. I think SEP-5 (state of last week, dont know if it
>>>>>>> adapted
>>>>>>> to
>>>>>>> this discussion) is on a way better path than KIP-253, and I can't
>>>>>>> really
>>>>>>> explain why.
>>>>>>>
>>>>>>> Best Jan,
>>>>>>>
>>>>>>> nice weekend everyone
>>>>>>>
>>>>>>>
>>>>>>> On 09.03.2018 03:36, Jun Rao wrote:
>>>>>>>
>>>>>>> Hi, Jan,
>>>>>>>
>>>>>>> Thanks for the feedback. Just some comments on the earlier points
>>>>>>>> that
>>>>>>>> you
>>>>>>>> mentioned.
>>>>>>>>
>>>>>>>> 50. You brought up the question of whether existing data needs to be
>>>>>>>> copied
>>>>>>>> during partition expansion. My understand of your view is that avoid
>>>>>>>> copying existing data will be more efficient, but it doesn't work
>>>>>>>> well
>>>>>>>> with
>>>>>>>> compacted topics since some keys in the original partitions will
>>>>>>>> never
>>>>>>>> be
>>>>>>>> cleaned. It would be useful to understand your use case of compacted
>>>>>>>> topics
>>>>>>>> a bit more. In the common use case, the data volume in a compacted
>>>>>>>> topic
>>>>>>>> may not be large. So, I am not sure if there is a strong need to
>>>>>>>> expand
>>>>>>>> partitions in a compacted topic, at least initially.
>>>>>>>>
>>>>>>>> I do agree. State is usually smaller. Update rates might be also
>>>>>>>>
>>>>>>>> competitively high.
>>>>>>> Doing Log-compaction (even beeing very efficient and configurable) is
>>>>>>> also
>>>>>>> a more expensive operation than
>>>>>>> just discarding old segments. Further if you want to use more
>>>>>>> consumers
>>>>>>> processing the events
>>>>>>> you also have to grow the number of partitions. Especially for
>>>>>>> use-cases
>>>>>>> we do (KIP-213) a tiny state full
>>>>>>> table might be very expensive to process if it joins against a huge
>>>>>>> table.
>>>>>>>
>>>>>>> I can just say we have been in the spot of needing to grow log
>>>>>>> compacted
>>>>>>> topics. Mainly for processing power we can bring to the table.
>>>>>>>
>>>>>>> Further i am not at all concerned about the extra spaced used by
>>>>>>> "garbage
>>>>>>> keys". I am more concerned about the correctness of innocent
>>>>>>> consumers.
>>>>>>> The
>>>>>>> logic becomes complicated. Say for streams one would need to load the
>>>>>>> record into state but not forward it the topology ( to have it
>>>>>>> available
>>>>>>> for shuffeling). I rather have it simple and a topic clean regardless
>>>>>>> if
>>>>>>> it
>>>>>>> still has its old partition count. Especially with multiple
>>>>>>> partitions
>>>>>>> growth's I think it becomes insanely hard to to this shuffle correct.
>>>>>>> Maybe
>>>>>>> Streams and Samza can do it. Especially if you do "hipster stream
>>>>>>> processing" <https://www.confluent.io/blog
>>>>>>> /introducing-kafka-streams-
>>>>>>> stream-processing-made-simple/>. This makes kafka way to
>>>>>>> complicated.
>>>>>>> With my approach I think its way simpler because the topic has no
>>>>>>> "history"
>>>>>>> in terms of partitioning but is always clean.
>>>>>>>
>>>>>>>
>>>>>>> 51. "Growing the topic by an integer factor does not require any
>>>>>>> state
>>>>>>>
>>>>>>> redistribution at all." Could you clarify this a bit more? Let's say
>>>>>>>> you
>>>>>>>> have a consumer app that computes the windowed count per key. If you
>>>>>>>> double
>>>>>>>> the number of partitions from 1 to 2 and grow the consumer instances
>>>>>>>> from
>>>>>>>> 1
>>>>>>>> to 2, we would need to redistribute some of the counts to the new
>>>>>>>> consumer
>>>>>>>> instance. Regarding to linear hashing, it's true that it won't solve
>>>>>>>> the
>>>>>>>> problem with compacted topics. The main benefit is that it
>>>>>>>> redistributes
>>>>>>>> the keys in one partition to no more than two partitions, which
>>>>>>>> could
>>>>>>>> help
>>>>>>>> redistribute the state.
>>>>>>>>
>>>>>>>> You don't need to spin up a new consumer in this case. every
>>>>>>>> consumer
>>>>>>>>
>>>>>>>> would just read every partition with the (partition % num_task)
>>>>>>> task.
>>>>>>> it
>>>>>>> will still have the previous data right there and can go on.
>>>>>>>
>>>>>>> This sounds contradictory to what I said before, but please bear with
>>>>>>> me.
>>>>>>>
>>>>>>> 52. Good point on coordinating the expansion of 2 topics that need to
>>>>>>> be
>>>>>>>
>>>>>>> joined together. This is where the 2-phase partition expansion could
>>>>>>>> potentially help. In the first phase, we could add new partitions to
>>>>>>>> the 2
>>>>>>>> topics one at a time but without publishing to the new patitions.
>>>>>>>> Then,
>>>>>>>> we
>>>>>>>> can add new consumer instances to pick up the new partitions. In
>>>>>>>> this
>>>>>>>> transition phase, no reshuffling is needed since no data is coming
>>>>>>>> from
>>>>>>>> the
>>>>>>>> new partitions. Finally, we can enable the publishing to the new
>>>>>>>> partitions.
>>>>>>>>
>>>>>>>> I think its even worse than you think. I would like to introduce the
>>>>>>>>
>>>>>>>> Term
>>>>>>> transitive copartitioning. Imagine
>>>>>>> 2 streams application. One joins (A,B) the other (B,C) then there is
>>>>>>> a
>>>>>>> transitive copartition requirement for
>>>>>>> (A,C) to be copartitioned aswell. This can spread significantly and
>>>>>>> require many consumers to adapt at the same time.
>>>>>>>
>>>>>>> It is also not entirely clear to me how you not need reshuffling in
>>>>>>> this
>>>>>>> case. If A has a record that never gets updated after the expansion
>>>>>>> and
>>>>>>> the
>>>>>>> coresponding B record moves to a new partition. How shall they meet
>>>>>>> w/o
>>>>>>> shuffle?
>>>>>>>
>>>>>>> 53. "Migrating consumer is a step that might be made completly
>>>>>>>
>>>>>>> unnecessary
>>>>>>>> if - for example streams - takes the gcd as partitioning scheme
>>>>>>>> instead
>>>>>>>> of
>>>>>>>> enforcing 1 to 1." Not sure that I fully understand this. I think
>>>>>>>> you
>>>>>>>> mean
>>>>>>>> that a consumer application can run more instances than the number
>>>>>>>> of
>>>>>>>> partitions. In that case, the consumer can just repartitioning the
>>>>>>>> input
>>>>>>>> data according to the number of instances. This is possible, but
>>>>>>>> just
>>>>>>>> has
>>>>>>>> the overhead of reshuffling the data.
>>>>>>>>
>>>>>>>> No what I meant is ( that is also your question i think Mathias)
>>>>>>>> that
>>>>>>>> if
>>>>>>>>
>>>>>>>> you grow a topic by a factor.
>>>>>>> Even if your processor is statefull you can can just assign all the
>>>>>>> multiples of the previous partition to
>>>>>>> this consumer and the state to keep processing correctly will be
>>>>>>> present
>>>>>>> w/o any shuffling.
>>>>>>>
>>>>>>> Say you have an assignment
>>>>>>> Statefull consumer => partition
>>>>>>> 0 => 0
>>>>>>> 1 => 1
>>>>>>> 2 => 2
>>>>>>>
>>>>>>> and you grow you topic by 4 you get,
>>>>>>>
>>>>>>> 0 => 0,3,6,9
>>>>>>> 1 => 1,4,7,10
>>>>>>> 2 => 2,5,8,11
>>>>>>>
>>>>>>> Say your hashcode is 8. 8%3 => 2  before so consumer for partition 2
>>>>>>> has
>>>>>>> it.
>>>>>>> Now you you have 12 partitions so 8%12 => 8, so it goes into
>>>>>>> partition
>>>>>>> 8
>>>>>>> which is assigned to the same consumer
>>>>>>> who had 2 before and therefore knows the key.
>>>>>>>
>>>>>>> Userland reshuffeling is there as an options. And it does exactly
>>>>>>> what
>>>>>>> I
>>>>>>> suggest. And I think its the perfect strategie. All I am suggestion
>>>>>>> is
>>>>>>> broker side support to switch the producers to the newly partitioned
>>>>>>> topic.
>>>>>>> Then the old (to few partition topic) can go away.  Remember the list
>>>>>>> of
>>>>>>> steps in the beginning of this thread. If one has broker support for
>>>>>>> all
>>>>>>> where its required and streams support for those that aren’t
>>>>>>> necessarily.
>>>>>>> Then one has solved the problem.
>>>>>>> I repeat it because I think its important. I am really happy that you
>>>>>>> brought that up! because its 100% what I want just with the
>>>>>>> differences
>>>>>>> to
>>>>>>> have an option to discard the to small topic later (after all
>>>>>>> consumers
>>>>>>> adapted). And to have order correct there. I need broker support
>>>>>>> managing
>>>>>>> the copy process + the produces and fence them against each other. I
>>>>>>> also
>>>>>>> repeat. the copy process can run for weeks in the worst case. Copying
>>>>>>> the
>>>>>>> data is not the longest task migrating consumers might very well be.
>>>>>>> Once all consumers switched and copying is really up to date (think
>>>>>>> ISR
>>>>>>> like up to date) only then we stop the producer, wait for the copy to
>>>>>>> finish and use the new topic for producing.
>>>>>>>
>>>>>>> After this the topic is perfect in shape. and no one needs to worry
>>>>>>> about
>>>>>>> complicated stuff. (old keys hanging around might arrive in some
>>>>>>> other
>>>>>>> topic later.....). can only imagine how many tricky bugs gonna arrive
>>>>>>> after
>>>>>>> someone had grown and shrunken is topic 10 times.
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> 54. "The other thing I wanted to mention is that I believe the
>>>>>>> current
>>>>>>>
>>>>>>> suggestion (without copying data over) can be implemented in pure
>>>>>>>> userland
>>>>>>>> with a custom partitioner and a small feedbackloop from
>>>>>>>> ProduceResponse
>>>>>>>> =>
>>>>>>>> Partitionier in coorporation with a change management system." I am
>>>>>>>> not
>>>>>>>> sure a customized partitioner itself solves the problem. We probably
>>>>>>>> need
>>>>>>>> some broker side support to enforce when the new partitions can be
>>>>>>>> used.
>>>>>>>> We
>>>>>>>> also need some support on the consumer/kstream side to preserve the
>>>>>>>> per
>>>>>>>> key
>>>>>>>> ordering and potentially migrate the processing state. This is not
>>>>>>>> trivial
>>>>>>>> and I am not sure if it's ideal to fully push to the application
>>>>>>>> space.
>>>>>>>>
>>>>>>>> Broker support is defenitly the preferred way here. I have nothing
>>>>>>>>
>>>>>>>> against
>>>>>>> broker support.
>>>>>>> I tried to say that for what I would preffer - copying the data over,
>>>>>>> at
>>>>>>> least for log compacted topics -
>>>>>>> I would require more broker support than the KIP currently offers.
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> Jun
>>>>>>>
>>>>>>> On Tue, Mar 6, 2018 at 10:33 PM, Jan Filipiak <
>>>>>>>> Jan.Filipiak@trivago.com
>>>>>>>> wrote:
>>>>>>>>
>>>>>>>> Hi Dong,
>>>>>>>>
>>>>>>>> are you actually reading my emails, or are you just using the
>>>>>>>> thread I
>>>>>>>>
>>>>>>>>> started for general announcements regarding the KIP?
>>>>>>>>>
>>>>>>>>> I tried to argue really hard against linear hashing. Growing the
>>>>>>>>> topic
>>>>>>>>> by
>>>>>>>>> an integer factor does not require any state redistribution at
>>>>>>>>> all. I
>>>>>>>>> fail
>>>>>>>>> to see completely where linear hashing helps on log compacted
>>>>>>>>> topics.
>>>>>>>>>
>>>>>>>>> If you are not willing to explain to me what I might be
>>>>>>>>> overlooking:
>>>>>>>>> that
>>>>>>>>> is fine.
>>>>>>>>> But I ask you to not reply to my emails then. Please understand my
>>>>>>>>> frustration with this.
>>>>>>>>>
>>>>>>>>> Best Jan
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> On 06.03.2018 19:38, Dong Lin wrote:
>>>>>>>>>
>>>>>>>>> Hi everyone,
>>>>>>>>>
>>>>>>>>> Thanks for all the comments! It appears that everyone prefers
>>>>>>>>> linear
>>>>>>>>>
>>>>>>>>>> hashing because it reduces the amount of state that needs to be
>>>>>>>>>> moved
>>>>>>>>>> between consumers (for stream processing). The KIP has been
>>>>>>>>>> updated
>>>>>>>>>> to
>>>>>>>>>> use
>>>>>>>>>> linear hashing.
>>>>>>>>>>
>>>>>>>>>> Regarding the migration endeavor: it seems that migrating producer
>>>>>>>>>> library
>>>>>>>>>> to use linear hashing should be pretty straightforward without
>>>>>>>>>> much operational endeavor. If we don't upgrade client library to
>>>>>>>>>> use
>>>>>>>>>> this
>>>>>>>>>> KIP, we can not support in-order delivery after partition is
>>>>>>>>>> changed
>>>>>>>>>> anyway. Suppose we upgrade client library to use this KIP, if
>>>>>>>>>> partition
>>>>>>>>>> number is not changed, the key -> partition mapping will be
>>>>>>>>>> exactly
>>>>>>>>>> the
>>>>>>>>>> same as it is now because it is still determined using
>>>>>>>>>> murmur_hash(key)
>>>>>>>>>> %
>>>>>>>>>> original_partition_num. In other words, this change is backward
>>>>>>>>>> compatible.
>>>>>>>>>>
>>>>>>>>>> Regarding the load distribution: if we use linear hashing, the
>>>>>>>>>> load
>>>>>>>>>> may
>>>>>>>>>> be
>>>>>>>>>> unevenly distributed because those partitions which are not split
>>>>>>>>>> may
>>>>>>>>>> receive twice as much traffic as other partitions that are split.
>>>>>>>>>> This
>>>>>>>>>> issue can be mitigated by creating topic with partitions that are
>>>>>>>>>> several
>>>>>>>>>> times the number of consumers. And there will be no imbalance if
>>>>>>>>>> the
>>>>>>>>>> partition number is always doubled. So this imbalance seems
>>>>>>>>>> acceptable.
>>>>>>>>>>
>>>>>>>>>> Regarding storing the partition strategy as per-topic config: It
>>>>>>>>>> seems
>>>>>>>>>> not
>>>>>>>>>> necessary since we can still use murmur_hash as the default hash
>>>>>>>>>> function
>>>>>>>>>> and additionally apply the linear hashing algorithm if the
>>>>>>>>>> partition
>>>>>>>>>> number
>>>>>>>>>> has increased. Not sure if there is any use-case for producer to
>>>>>>>>>> use a
>>>>>>>>>> different hash function. Jason, can you check if there is some
>>>>>>>>>> use-case
>>>>>>>>>> that I missed for using the per-topic partition strategy?
>>>>>>>>>>
>>>>>>>>>> Regarding how to reduce latency (due to state store/load) in
>>>>>>>>>> stream
>>>>>>>>>> processing consumer when partition number changes: I need to read
>>>>>>>>>> the
>>>>>>>>>> Kafka
>>>>>>>>>> Stream code to understand how Kafka Stream currently migrate state
>>>>>>>>>> between
>>>>>>>>>> consumers when the application is added/removed for a given job. I
>>>>>>>>>> will
>>>>>>>>>> reply after I finish reading the documentation and code.
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> Thanks,
>>>>>>>>>> Dong
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> On Mon, Mar 5, 2018 at 10:43 AM, Jason Gustafson <
>>>>>>>>>> jason@confluent.io>
>>>>>>>>>> wrote:
>>>>>>>>>>
>>>>>>>>>> Great discussion. I think I'm wondering whether we can continue to
>>>>>>>>>> leave
>>>>>>>>>>
>>>>>>>>>> Kafka agnostic to the partitioning strategy. The challenge is
>>>>>>>>>>
>>>>>>>>>> communicating
>>>>>>>>>>> the partitioning logic from producers to consumers so that the
>>>>>>>>>>> dependencies
>>>>>>>>>>> between each epoch can be determined. For the sake of discussion,
>>>>>>>>>>> imagine
>>>>>>>>>>> you did something like the following:
>>>>>>>>>>>
>>>>>>>>>>> 1. The name (and perhaps version) of a partitioning strategy is
>>>>>>>>>>> stored
>>>>>>>>>>> in
>>>>>>>>>>> topic configuration when a topic is created.
>>>>>>>>>>> 2. The producer looks up the partitioning strategy before writing
>>>>>>>>>>> to
>>>>>>>>>>> a
>>>>>>>>>>> topic and includes it in the produce request (for fencing). If it
>>>>>>>>>>> doesn't
>>>>>>>>>>> have an implementation for the configured strategy, it fails.
>>>>>>>>>>> 3. The consumer also looks up the partitioning strategy and uses
>>>>>>>>>>> it
>>>>>>>>>>> to
>>>>>>>>>>> determine dependencies when reading a new epoch. It could either
>>>>>>>>>>> fail
>>>>>>>>>>> or
>>>>>>>>>>> make the most conservative dependency assumptions if it doesn't
>>>>>>>>>>> know
>>>>>>>>>>> how
>>>>>>>>>>> to
>>>>>>>>>>> implement the partitioning strategy. For the consumer, the new
>>>>>>>>>>> interface
>>>>>>>>>>> might look something like this:
>>>>>>>>>>>
>>>>>>>>>>> // Return the partition dependencies following an epoch bump
>>>>>>>>>>> Map<Integer, List<Integer>> dependencies(int
>>>>>>>>>>> numPartitionsBeforeEpochBump,
>>>>>>>>>>> int numPartitionsAfterEpochBump)
>>>>>>>>>>>
>>>>>>>>>>> The unordered case then is just a particular implementation which
>>>>>>>>>>> never
>>>>>>>>>>> has
>>>>>>>>>>> any epoch dependencies. To implement this, we would need some way
>>>>>>>>>>> for
>>>>>>>>>>> the
>>>>>>>>>>> consumer to find out how many partitions there were in each
>>>>>>>>>>> epoch,
>>>>>>>>>>> but
>>>>>>>>>>> maybe that's not too unreasonable.
>>>>>>>>>>>
>>>>>>>>>>> Thanks,
>>>>>>>>>>> Jason
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> On Mon, Mar 5, 2018 at 4:51 AM, Jan Filipiak <
>>>>>>>>>>> Jan.Filipiak@trivago.com
>>>>>>>>>>> wrote:
>>>>>>>>>>>
>>>>>>>>>>> Hi Dong
>>>>>>>>>>>
>>>>>>>>>>> thank you very much for your questions.
>>>>>>>>>>>
>>>>>>>>>>> regarding the time spend copying data across:
>>>>>>>>>>>> It is correct that copying data from a topic with one partition
>>>>>>>>>>>> mapping
>>>>>>>>>>>>
>>>>>>>>>>>> to
>>>>>>>>>>>>
>>>>>>>>>>>> a topic with a different partition mapping takes way longer than
>>>>>>>>>>>>
>>>>>>>>>>> we
>>>>>>>>>>> can
>>>>>>>>>>>
>>>>>>>>>>> stop producers. Tens of minutes is a very optimistic estimate
>>>>>>>>>>> here.
>>>>>>>>>>>
>>>>>>>>>>>> Many
>>>>>>>>>>>> people can not afford copy full steam and therefore will have
>>>>>>>>>>>> some
>>>>>>>>>>>> rate
>>>>>>>>>>>> limiting in place, this can bump the timespan into the day's.
>>>>>>>>>>>> The
>>>>>>>>>>>> good
>>>>>>>>>>>>
>>>>>>>>>>>> part
>>>>>>>>>>>>
>>>>>>>>>>>> is that the vast majority of the data can be copied while the
>>>>>>>>>>>>
>>>>>>>>>>> producers
>>>>>>>>>>>
>>>>>>>>>>> are
>>>>>>>>>>>
>>>>>>>>>>>> still going. One can then, piggyback the consumers ontop of this
>>>>>>>>>>>>
>>>>>>>>>>> timeframe,
>>>>>>>>>>>
>>>>>>>>>>>> by the method mentioned (provide them an mapping from their old
>>>>>>>>>>>>
>>>>>>>>>>> offsets
>>>>>>>>>>>
>>>>>>>>>>> to
>>>>>>>>>>>
>>>>>>>>>>>> new offsets in their repartitioned topics. In that way we
>>>>>>>>>>>> separate
>>>>>>>>>>>>
>>>>>>>>>>> migration of consumers from migration of producers (decoupling
>>>>>>>>>>>
>>>>>>>>>>>> these
>>>>>>>>>>>> is
>>>>>>>>>>>> what kafka is strongest at). The time to actually swap over the
>>>>>>>>>>>> producers
>>>>>>>>>>>> should be kept minimal by ensuring that when a swap attempt is
>>>>>>>>>>>> started
>>>>>>>>>>>>
>>>>>>>>>>>> the
>>>>>>>>>>>>
>>>>>>>>>>>> consumer copying over should be very close to the log end and is
>>>>>>>>>>>>
>>>>>>>>>>> expected
>>>>>>>>>>>
>>>>>>>>>>>> to finish within the next fetch. The operation should have a
>>>>>>>>>>>> time-out
>>>>>>>>>>>> and
>>>>>>>>>>>> should be "reattemtable".
>>>>>>>>>>>>
>>>>>>>>>>>> Importance of logcompaction:
>>>>>>>>>>>> If a producer produces key A, to partiton 0, its forever gonna
>>>>>>>>>>>> be
>>>>>>>>>>>> there,
>>>>>>>>>>>> unless it gets deleted. The record might sit in there for
>>>>>>>>>>>> years. A
>>>>>>>>>>>> new
>>>>>>>>>>>> producer started with the new partitions will fail to delete the
>>>>>>>>>>>> record
>>>>>>>>>>>>
>>>>>>>>>>>> in
>>>>>>>>>>>>
>>>>>>>>>>>> the correct partition. Th record will be there forever and one
>>>>>>>>>>>> can
>>>>>>>>>>>>
>>>>>>>>>>> not
>>>>>>>>>>>
>>>>>>>>>>> reliable bootstrap new consumers. I cannot see how linear hashing
>>>>>>>>>>>
>>>>>>>>>>>> can
>>>>>>>>>>>>
>>>>>>>>>>>> solve
>>>>>>>>>>>>
>>>>>>>>>>>> this.
>>>>>>>>>>>>
>>>>>>>>>>> Regarding your skipping of userland copying:
>>>>>>>>>>>
>>>>>>>>>>>> 100%, copying the data across in userland is, as far as i can
>>>>>>>>>>>> see,
>>>>>>>>>>>> only
>>>>>>>>>>>> a
>>>>>>>>>>>> usecase for log compacted topics. Even for logcompaction +
>>>>>>>>>>>> retentions
>>>>>>>>>>>> it
>>>>>>>>>>>> should only be opt-in. Why did I bring it up? I think log
>>>>>>>>>>>> compaction
>>>>>>>>>>>> is
>>>>>>>>>>>> a
>>>>>>>>>>>> very important feature to really embrace kafka as a "data
>>>>>>>>>>>> plattform".
>>>>>>>>>>>> The
>>>>>>>>>>>> point I also want to make is that copying data this way is
>>>>>>>>>>>> completely
>>>>>>>>>>>> inline with the kafka architecture. it only consists of reading
>>>>>>>>>>>> and
>>>>>>>>>>>>
>>>>>>>>>>>> writing
>>>>>>>>>>>>
>>>>>>>>>>>> to topics.
>>>>>>>>>>>>
>>>>>>>>>>> I hope it clarifies more why I think we should aim for more than
>>>>>>>>>>>
>>>>>>>>>>>> the
>>>>>>>>>>>> current KIP. I fear that once the KIP is done not much more
>>>>>>>>>>>> effort
>>>>>>>>>>>> will
>>>>>>>>>>>>
>>>>>>>>>>>> be
>>>>>>>>>>>>
>>>>>>>>>>>> taken.
>>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> On 04.03.2018 02:28, Dong Lin wrote:
>>>>>>>>>>>>
>>>>>>>>>>>> Hey Jan,
>>>>>>>>>>>>
>>>>>>>>>>>> In the current proposal, the consumer will be blocked on waiting
>>>>>>>>>>>> for
>>>>>>>>>>>>
>>>>>>>>>>>> other
>>>>>>>>>>>>>
>>>>>>>>>>>>> consumers of the group to consume up to a given offset. In most
>>>>>>>>>>>>>
>>>>>>>>>>>> cases,
>>>>>>>>>>>> all
>>>>>>>>>>>> consumers should be close to the LEO of the partitions when the
>>>>>>>>>>>> partition
>>>>>>>>>>>> expansion happens. Thus the time waiting should not be long e.g.
>>>>>>>>>>>> on
>>>>>>>>>>>> the
>>>>>>>>>>>>
>>>>>>>>>>>> order of seconds. On the other hand, it may take a long time to
>>>>>>>>>>>> wait
>>>>>>>>>>>>
>>>>>>>>>>>> for
>>>>>>>>>>>>> the entire partition to be copied -- the amount of time is
>>>>>>>>>>>>> proportional
>>>>>>>>>>>>>
>>>>>>>>>>>>> to
>>>>>>>>>>>>>
>>>>>>>>>>>>> the amount of existing data in the partition, which can take
>>>>>>>>>>>>>
>>>>>>>>>>>> tens of
>>>>>>>>>>>>
>>>>>>>>>>>> minutes. So the amount of time that we stop consumers may not be
>>>>>>>>>>>> on
>>>>>>>>>>>>
>>>>>>>>>>>> the
>>>>>>>>>>>>> same order of magnitude.
>>>>>>>>>>>>>
>>>>>>>>>>>>> If we can implement this suggestion without copying data over
>>>>>>>>>>>>> in
>>>>>>>>>>>>> purse
>>>>>>>>>>>>> userland, it will be much more valuable. Do you have ideas on
>>>>>>>>>>>>> how
>>>>>>>>>>>>> this
>>>>>>>>>>>>>
>>>>>>>>>>>>> can
>>>>>>>>>>>>>
>>>>>>>>>>>>> be done?
>>>>>>>>>>>>>
>>>>>>>>>>>> Not sure why the current KIP not help people who depend on log
>>>>>>>>>>>>
>>>>>>>>>>>> compaction.
>>>>>>>>>>>>>
>>>>>>>>>>>>> Could you elaborate more on this point?
>>>>>>>>>>>>>
>>>>>>>>>>>> Thanks,
>>>>>>>>>>>>
>>>>>>>>>>>> Dong
>>>>>>>>>>>>>
>>>>>>>>>>>>> On Wed, Feb 28, 2018 at 10:55 PM, Jan
>>>>>>>>>>>>> Filipiak<Jan.Filipiak@trivago.
>>>>>>>>>>>>> com
>>>>>>>>>>>>> wrote:
>>>>>>>>>>>>>
>>>>>>>>>>>>> Hi Dong,
>>>>>>>>>>>>>
>>>>>>>>>>>>> I tried to focus on what the steps are one can currently
>>>>>>>>>>>>> perform
>>>>>>>>>>>>> to
>>>>>>>>>>>>>
>>>>>>>>>>>>> expand
>>>>>>>>>>>>>
>>>>>>>>>>>>>> or shrink a keyed topic while maintaining a top notch
>>>>>>>>>>>>>> semantics.
>>>>>>>>>>>>>> I can understand that there might be confusion about "stopping
>>>>>>>>>>>>>> the
>>>>>>>>>>>>>> consumer". It is exactly the same as proposed in the KIP.
>>>>>>>>>>>>>> there
>>>>>>>>>>>>>> needs
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> to
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> be
>>>>>>>>>>>>>>
>>>>>>>>>>>>> a time the producers agree on the new partitioning. The extra
>>>>>>>>>>>>
>>>>>>>>>>>> semantics I
>>>>>>>>>>>>>
>>>>>>>>>>>>>> want to put in there is that we have a possibility to wait
>>>>>>>>>>>>>> until
>>>>>>>>>>>>>>
>>>>>>>>>>>>> all
>>>>>>>>>>>>
>>>>>>>>>>>> the
>>>>>>>>>>>>
>>>>>>>>>>>> existing data
>>>>>>>>>>>>>
>>>>>>>>>>>>> is copied over into the new partitioning scheme. When I say
>>>>>>>>>>>> stopping
>>>>>>>>>>>>
>>>>>>>>>>>> I
>>>>>>>>>>>>>
>>>>>>>>>>>>>> think more of having a memory barrier that ensures the
>>>>>>>>>>>>>> ordering. I
>>>>>>>>>>>>>> am
>>>>>>>>>>>>>> still
>>>>>>>>>>>>>> aming for latencies  on the scale of leader failovers.
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> Consumers have to explicitly adapt the new partitioning scheme
>>>>>>>>>>>>>> in
>>>>>>>>>>>>>> the
>>>>>>>>>>>>>> above scenario. The reason is that in these cases where you
>>>>>>>>>>>>>> are
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> dependent
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> on a particular partitioning scheme, you also have other
>>>>>>>>>>>>>> topics
>>>>>>>>>>>>>>
>>>>>>>>>>>>> that
>>>>>>>>>>>>
>>>>>>>>>>>> have
>>>>>>>>>>>>
>>>>>>>>>>>> co-partition enforcements or the kind -frequently. Therefore all
>>>>>>>>>>>>>
>>>>>>>>>>>>> your
>>>>>>>>>>>>
>>>>>>>>>>>> other
>>>>>>>>>>>>
>>>>>>>>>>>> input topics might need to grow accordingly.
>>>>>>>>>>>>>
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> What I was suggesting was to streamline all these operations
>>>>>>>>>>>>>> as
>>>>>>>>>>>>>> best
>>>>>>>>>>>>>> as
>>>>>>>>>>>>>> possible to have "real" partition grow and shrinkage going on.
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> Migrating
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> the producers to a new partitioning scheme can be much more
>>>>>>>>>>>>>>
>>>>>>>>>>>>> streamlined
>>>>>>>>>>>>
>>>>>>>>>>>> with proper broker support for this. Migrating consumer is a
>>>>>>>>>>>> step
>>>>>>>>>>>>
>>>>>>>>>>>> that
>>>>>>>>>>>>>
>>>>>>>>>>>>>> might be made completly unnecessary if - for example streams -
>>>>>>>>>>>>>> takes
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> the
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> gcd as partitioning scheme instead of enforcing 1 to 1.
>>>>>>>>>>>>>> Connect
>>>>>>>>>>>>>>
>>>>>>>>>>>>> consumers
>>>>>>>>>>>>
>>>>>>>>>>>> and other consumers should be fine anyways.
>>>>>>>>>>>>>
>>>>>>>>>>>>> I hope this makes more clear where I was aiming at. The rest
>>>>>>>>>>>> needs
>>>>>>>>>>>>
>>>>>>>>>>>> to
>>>>>>>>>>>>>
>>>>>>>>>>>>> be
>>>>>>>>>>>>>
>>>>>>>>>>>>>> figured out. The only danger i see is that when we are
>>>>>>>>>>>>>>
>>>>>>>>>>>>> introducing
>>>>>>>>>>>>>
>>>>>>>>>>>>> this
>>>>>>>>>>>>
>>>>>>>>>>>> feature as supposed in the KIP, it wont help any people
>>>>>>>>>>>> depending
>>>>>>>>>>>> on
>>>>>>>>>>>>
>>>>>>>>>>>> log
>>>>>>>>>>>>>
>>>>>>>>>>>>>> compaction.
>>>>>>>>>>>>>>
>>>>>>>>>>>>> The other thing I wanted to mention is that I believe the
>>>>>>>>>>>> current
>>>>>>>>>>>>
>>>>>>>>>>>> suggestion (without copying data over) can be implemented in
>>>>>>>>>>>>> pure
>>>>>>>>>>>>>
>>>>>>>>>>>>>> userland
>>>>>>>>>>>>>> with a custom partitioner and a small feedbackloop from
>>>>>>>>>>>>>> ProduceResponse
>>>>>>>>>>>>>> =>
>>>>>>>>>>>>>> Partitionier in coorporation with a change management system.
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> Best Jan
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> On 28.02.2018 07:13, Dong Lin wrote:
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> Hey Jan,
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> I am not sure if it is acceptable for producer to be stopped
>>>>>>>>>>>>>> for a
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> while,
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> particularly for online application which requires low
>>>>>>>>>>>>>>> latency. I
>>>>>>>>>>>>>>> am
>>>>>>>>>>>>>>> also
>>>>>>>>>>>>>>> not sure how consumers can switch to a new topic. Does user
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> application
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> needs to explicitly specify a different topic for
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>> producer/consumer
>>>>>>>>>>>>>
>>>>>>>>>>>>> to
>>>>>>>>>>>>>
>>>>>>>>>>>> subscribe to? It will be helpful for discussion if you can
>>>>>>>>>>>> provide
>>>>>>>>>>>>
>>>>>>>>>>>> more
>>>>>>>>>>>>>
>>>>>>>>>>>>>> detail on the interface change for this solution.
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> Thanks,
>>>>>>>>>>>>>
>>>>>>>>>>>>> Dong
>>>>>>>>>>>>>
>>>>>>>>>>>>>> On Mon, Feb 26, 2018 at 12:48 AM, Jan
>>>>>>>>>>>>>>> Filipiak<Jan.Filipiak@trivago.
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> com
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> wrote:
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>> Hi,
>>>>>>>>>>>>>
>>>>>>>>>>>>> just want to throw my though in. In general the functionality
>>>>>>>>>>>>> is
>>>>>>>>>>>>>
>>>>>>>>>>>>>> very
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> usefull, we should though not try to find the architecture to
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> hard
>>>>>>>>>>>>>>>> while
>>>>>>>>>>>>>>>> implementing.
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> The manual steps would be to
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> create a new topic
>>>>>>>>>>>>>>>> the mirrormake from the new old topic to the new topic
>>>>>>>>>>>>>>>> wait for mirror making to catch up.
>>>>>>>>>>>>>>>> then put the consumers onto the new topic
>>>>>>>>>>>>>>>>            (having mirrormaker spit out a mapping from old
>>>>>>>>>>>>>>>> offsets to
>>>>>>>>>>>>>>>> new
>>>>>>>>>>>>>>>> offsets:
>>>>>>>>>>>>>>>>                if topic is increased by factor X there is
>>>>>>>>>>>>>>>> gonna
>>>>>>>>>>>>>>>> be a
>>>>>>>>>>>>>>>> clean
>>>>>>>>>>>>>>>> mapping from 1 offset in the old topic to X offsets in the
>>>>>>>>>>>>>>>> new
>>>>>>>>>>>>>>>> topic,
>>>>>>>>>>>>>>>>                if there is no factor then there is no
>>>>>>>>>>>>>>>> chance to
>>>>>>>>>>>>>>>> generate a
>>>>>>>>>>>>>>>> mapping that can be reasonable used for continuing)
>>>>>>>>>>>>>>>>            make consumers stop at appropriate points and
>>>>>>>>>>>>>>>> continue
>>>>>>>>>>>>>>>> consumption
>>>>>>>>>>>>>>>> with offsets from the mapping.
>>>>>>>>>>>>>>>> have the producers stop for a minimal time.
>>>>>>>>>>>>>>>> wait for mirrormaker to finish
>>>>>>>>>>>>>>>> let producer produce with the new metadata.
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> Instead of implementing the approach suggest in the KIP
>>>>>>>>>>>>>>>> which
>>>>>>>>>>>>>>>> will
>>>>>>>>>>>>>>>> leave
>>>>>>>>>>>>>>>> log compacted topic completely crumbled and unusable.
>>>>>>>>>>>>>>>> I would much rather try to build infrastructure to support
>>>>>>>>>>>>>>>> the
>>>>>>>>>>>>>>>> mentioned
>>>>>>>>>>>>>>>> above operations more smoothly.
>>>>>>>>>>>>>>>> Especially having producers stop and use another topic is
>>>>>>>>>>>>>>>> difficult
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> and
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> it would be nice if one can trigger "invalid metadata"
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> exceptions
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> for
>>>>>>>>>>>>>>
>>>>>>>>>>>>> them
>>>>>>>>>>>>
>>>>>>>>>>>> and
>>>>>>>>>>>>>
>>>>>>>>>>>>>> if one could give topics aliases so that their produces with
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> the
>>>>>>>>>>>>>>>> old
>>>>>>>>>>>>>>>> topic
>>>>>>>>>>>>>>>> will arrive in the new topic.
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> The downsides are obvious I guess ( having the same data
>>>>>>>>>>>>>>>> twice
>>>>>>>>>>>>>>>> for
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> the
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> transition period, but kafka tends to scale well with
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> datasize).
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> So
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> its a
>>>>>>>>>>>>>>
>>>>>>>>>>>>> nicer fit into the architecture.
>>>>>>>>>>>>>
>>>>>>>>>>>>>> I further want to argument that the functionality by the KIP
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> can
>>>>>>>>>>>>>>>> completely be implementing in "userland" with a custom
>>>>>>>>>>>>>>>> partitioner
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> that
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> handles the transition as needed. I would appreciate if
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> someone
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> could
>>>>>>>>>>>>>>
>>>>>>>>>>>>> point
>>>>>>>>>>>>
>>>>>>>>>>>> out what a custom partitioner couldn't handle in this case?
>>>>>>>>>>>>>
>>>>>>>>>>>>>> With the above approach, shrinking a topic becomes the same
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> steps.
>>>>>>>>>>>>>>>> Without
>>>>>>>>>>>>>>>> loosing keys in the discontinued partitions.
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> Would love to hear what everyone thinks.
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> Best Jan
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> On 11.02.2018 00:35, Dong Lin wrote:
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> Hi all,
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> I have created KIP-253: Support in-order message delivery
>>>>>>>>>>>>>>>> with
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> partition
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> expansion. See
>>>>>>>>>>>>>>>>> https://cwiki.apache.org/confluence/display/KAFKA/KIP-253%
>>>>>>>>>>>>>>>>> 3A+Support+in-order+message+de
>>>>>>>>>>>>>>>>> livery+with+partition+expansio
>>>>>>>>>>>>>>>>> n
>>>>>>>>>>>>>>>>> .
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> This KIP provides a way to allow messages of the same key
>>>>>>>>>>>>>>>>> from
>>>>>>>>>>>>>>>>> the
>>>>>>>>>>>>>>>>> same
>>>>>>>>>>>>>>>>> producer to be consumed in the same order they are produced
>>>>>>>>>>>>>>>>> even
>>>>>>>>>>>>>>>>> if
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> we
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> expand partition of the topic.
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> Thanks,
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>> Dong
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>
>>>
>
>

Re: [DISCUSS] KIP-253: Support in-order message delivery with partition expansion

Posted by Ray Chiang <rc...@apache.org>.
Hi Jun, please add me to the invitation as well.  If this is happening 
near Palo Alto, let me know if I can join in person. Thanks.

-Ray

On 4/4/18 1:34 PM, Jun Rao wrote:
> Hi, Jan, Dong, John, Guozhang,
>
> Perhaps it will be useful to have a KIP meeting to discuss this together as
> a group. Would Apr. 9 (Monday) at 9:00am PDT work? If so, I will send out
> an invite to the mailing list.
>
> Thanks,
>
> Jun
>
>
> On Wed, Apr 4, 2018 at 1:25 AM, Jan Filipiak <Ja...@trivago.com>
> wrote:
>
>> Want to quickly step in here again because it is going places again.
>>
>> The last part of the discussion is just a pain to read and completely
>> diverged from what I suggested without making the reasons clear to me.
>>
>> I don't know why this happens.... here are my comments anyway.
>>
>> @Guozhang: That Streams is working on automatic creating
>> copartition-usuable topics: great for streams, has literally nothing todo
>> with the KIP as we want to grow the
>> input topic. Everyone can reshuffle rel. easily but that is not what we
>> need todo, we need to grow the topic in question. After streams
>> automatically reshuffled the input topic
>> still has the same size and it didn't help a bit. I fail to see why this
>> is relevant. What am i missing here?
>>
>> @Dong
>> I am still on the position that the current proposal brings us into the
>> wrong direction. Especially introducing PartitionKeyRebalanceListener
>>  From this point we can never move away to proper state full handling
>> without completely deprecating this creature from hell again.
>> Linear hashing is not the optimising step we have todo here. An interface
>> that when a topic is a topic its always the same even after it had
>> grown or shrunk is important. So from my POV I have major concerns that
>> this KIP is benefitial in its current state.
>>
>> What is it that makes everyone so addicted to the idea of linear hashing?
>> not attractive at all for me.
>> And with statefull consumers still a complete mess. Why not stick with the
>> Kappa architecture???
>>
>>
>>
>>
>>
>> On 03.04.2018 17:38, Dong Lin wrote:
>>
>>> Hey John,
>>>
>>> Thanks much for your comments!!
>>>
>>> I have yet to go through the emails of John/Jun/Guozhang in detail. But
>>> let
>>> me present my idea for how to minimize the delay for state loading for
>>> stream use-case.
>>>
>>> For ease of understanding, let's assume that the initial partition number
>>> of input topics and change log topic are both 10. And initial number of
>>> stream processor is also 10. If we only increase initial partition number
>>> of input topics to 15 without changing number of stream processor, the
>>> current KIP already guarantees in-order delivery and no state needs to be
>>> moved between consumers for stream use-case. Next, let's say we want to
>>> increase the number of processor to expand the processing capacity for
>>> stream use-case. This requires us to move state between processors which
>>> will take time. Our goal is to minimize the impact (i.e. delay) for
>>> processing while we increase the number of processors.
>>>
>>> Note that stream processor generally includes both consumer and producer.
>>> In addition to consume from the input topic, consumer may also need to
>>> consume from change log topic on startup for recovery. And producer may
>>> produce state to the change log topic.
>>>
>>>
>> The solution will include the following steps:
>>> 1) Increase partition number of the input topic from 10 to 15. Since the
>>> messages with the same key will still go to the same consume before and
>>> after the partition expansion, this step can be done without having to
>>> move
>>> state between processors.
>>>
>>> 2) Increase partition number of the change log topic from 10 to 15. Note
>>> that this step can also be done without impacting existing workflow. After
>>> we increase partition number of the change log topic, key space may split
>>> and some key will be produced to the newly-added partition. But the same
>>> key will still go to the same processor (i.e. consumer) before and after
>>> the partition. Thus this step can also be done without having to move
>>> state
>>> between processors.
>>>
>>> 3) Now, let's add 5 new consumers whose groupId is different from the
>>> existing processor's groupId. Thus these new consumers will not impact
>>> existing workflow. Each of these new consumers should consume two
>>> partitions from the earliest offset, where these two partitions are the
>>> same partitions that will be consumed if the consumers have the same
>>> groupId as the existing processor's groupId. For example, the first of the
>>> five consumers will consume partition 0 and partition 10. The purpose of
>>> these consumers is to rebuild the state (e.g. RocksDB) for the processors
>>> in advance. Also note that, by design of the current KIP, each consume
>>> will
>>> consume the existing partition of the change log topic up to the offset
>>> before the partition expansion. Then they will only need to consume the
>>> state of the new partition of the change log topic.
>>>
>>> 4) After consumers have caught up in step 3), we should stop these
>>> consumers and add 5 new processors to the stream processing job. These 5
>>> new processors should run in the same location as the previous 5 consumers
>>> to re-use the state (e.g. RocksDB). And these processors' consumers should
>>> consume partitions of the change log topic from the committed offset the
>>> previous 5 consumers so that no state is missed.
>>>
>>> One important trick to note here is that, the mapping from partition to
>>> consumer should also use linear hashing. And we need to remember the
>>> initial number of processors in the job, 10 in this example, and use this
>>> number in the linear hashing algorithm. This is pretty much the same as
>>> how
>>> we use linear hashing to map key to partition. In this case, we get an
>>> identity map from partition -> processor, for both input topic and the
>>> change log topic. For example, processor 12 will consume partition 12 of
>>> the input topic and produce state to the partition 12 of the change log
>>> topic.
>>>
>>> There are a few important properties of this solution to note:
>>>
>>> - We can increase the number of partitions for input topic and the change
>>> log topic in any order asynchronously.
>>> - The expansion of the processors in a given job in step 4) only requires
>>> the step 3) for the same job. It does not require coordination across
>>> different jobs for step 3) and 4). Thus different jobs can independently
>>> expand there capacity without waiting for each other.
>>> - The logic for 1) and 2) is already supported in the current KIP. The
>>> logic for 3) and 4) appears to be independent of the core Kafka logic and
>>> can be implemented separately outside core Kafka. Thus the current KIP is
>>> probably sufficient after we agree on the efficiency and the correctness
>>> of
>>> the solution. We can have a separate KIP for Kafka Stream to support 3)
>>> and
>>> 4).
>>>
>>>
>>> Cheers,
>>> Dong
>>>
>>>
>>> On Mon, Apr 2, 2018 at 3:25 PM, Guozhang Wang <wa...@gmail.com> wrote:
>>>
>>> Hey guys, just sharing my two cents here (I promise it will be shorter
>>>> than
>>>> John's article :).
>>>>
>>>> 0. Just to quickly recap, the main discussion point now is how to support
>>>> "key partitioning preservation" (John's #4 in topic characteristics
>>>> above)
>>>> beyond the "single-key ordering preservation" that KIP-253 was originally
>>>> proposed to maintain (John's #6 above).
>>>>
>>>> 1. From the streams project, we are actively working on improving the
>>>> elastic scalability of the library. One of the key features is to
>>>> decouple
>>>> the input topics from the parallelism model of Streams: i.e. not
>>>> enforcing
>>>> the topic to be partitioned by the key, not enforcing joining topics to
>>>> be
>>>> co-partitioned, not relying the number of parallel tasks on the input
>>>> topic
>>>> partitions. This can be achieved by re-shuffling on the input topics to
>>>> make sure key-partitioning / co-partitioning on the internal topics. Note
>>>> the re-shuffling task is purely stateless and hence does not require "key
>>>> partitioning preservation". Operational-wise it is similar to the
>>>> "creating
>>>> a new topic with new number of partitions, pipe the data to the new topic
>>>> and cut over consumers from old topics" idea, just that users can
>>>> optionally let Streams to handle such rather than doing it manually
>>>> themselves. There are a few more details on that regard but I will skip
>>>> since they are not directly related to this discussion.
>>>>
>>>> 2. Assuming that 1) above is done, then the only topics involved in the
>>>> scaling events are all input topics. For these topics the only producers
>>>> /
>>>> consumers of these topics are controlled by Streams clients themselves,
>>>> and
>>>> hence achieving "key partitioning preservation" is simpler than
>>>> non-Streams
>>>> scenarios: consumers know the partitioning scheme that producers are
>>>> using,
>>>> so that for their stateful operations it is doable to split the local
>>>> state
>>>> stores accordingly or execute backfilling on its own. Of course, if we
>>>> decide to do server-side backfilling, it can still help Streams to
>>>> directly
>>>> rely on that functionality.
>>>>
>>>> 3. As John mentioned, another way inside Streams is to do
>>>> over-partitioning
>>>> on all internal topics; then with 1) Streams would not rely on KIP-253 at
>>>> all. But personally I'd like to avoid it if possible to reduce Kafka side
>>>> footprint: say we overpartition each input topic up to 1k, with a
>>>> reasonable sized stateful topology it can still contribute to tens of
>>>> thousands of topics to the topic partition capacity of a single cluster.
>>>>
>>>> 4. Summing up 1/2/3, I think we should focus more on non-Streams users
>>>> writing their stateful computations with local states, and think whether
>>>> /
>>>> how we could enable "key partitioning preservation" for them easily, than
>>>> to think heavily for Streams library. People may have different opinion
>>>> on
>>>> how common of a usage pattern it is (I think Jun might be suggesting that
>>>> for DIY apps people may more likely use remote states so that it is not a
>>>> problem for them). My opinion is that for non-Streams users such usage
>>>> pattern could still be large (think: if you are piping data from Kafka to
>>>> an external data storage which has single-writer requirements for each
>>>> single shard, even though it is not a stateful computational application
>>>> it
>>>> may still require "key partitioning preservation"), so I prefer to have
>>>> backfilling in our KIP than only exposing the API for expansion and
>>>> requires consumers to have pre-knowledge of the producer's partitioning
>>>> scheme.
>>>>
>>>>
>>>>
>>>> Guozhang
>>>>
>>>>
>>>>
>>>> On Thu, Mar 29, 2018 at 2:33 PM, John Roesler <jo...@confluent.io> wrote:
>>>>
>>>> Hey Dong,
>>>>> Congrats on becoming a committer!!!
>>>>>
>>>>> Since I just sent a novel-length email, I'll try and keep this one brief
>>>>>
>>>> ;)
>>>>
>>>>> Regarding producer coordination, I'll grant that in that case, producers
>>>>> may coordinate among themselves to produce into the same topic or to
>>>>> produce co-partitioned topics. Nothing in KStreams or the Kafka
>>>>> ecosystem
>>>>> in general requires such coordination for correctness or in fact for any
>>>>> optional features, though, so I would not say that we require producer
>>>>> coordination of partition logic. If producers currently coordinate, it's
>>>>> completely optional and their own choice.
>>>>>
>>>>> Regarding the portability of partition algorithms, my observation is
>>>>> that
>>>>> systems requiring independent implementations of the same algorithm with
>>>>> 100% correctness are a large source of risk and also a burden on those
>>>>>
>>>> who
>>>>
>>>>> have to maintain them. If people could flawlessly implement algorithms
>>>>> in
>>>>> actual software, the world would be a wonderful place indeed! For a
>>>>>
>>>> system
>>>>
>>>>> as important and widespread as Kafka, I would recommend restricting
>>>>> limiting such requirements as aggressively as possible.
>>>>>
>>>>> I'd agree that we can always revisit decisions like allowing arbitrary
>>>>> partition functions, but of course, we shouldn't do that in a vacuum.
>>>>>
>>>> That
>>>>
>>>>> feels like the kind of thing we'd need to proactively seek guidance from
>>>>> the users list about. I do think that the general approach of saying
>>>>> that
>>>>> "if you use a custom partitioner, you cannot do partition expansion" is
>>>>> very reasonable (but I don't think we need to go that far with the
>>>>>
>>>> current
>>>>
>>>>> proposal). It's similar to my statement in my email to Jun that in
>>>>> principle KStreams doesn't *need* backfill, we only need it if we want
>>>>> to
>>>>> employ partition expansion.
>>>>>
>>>>> I reckon that the main motivation for backfill is to support KStreams
>>>>> use
>>>>> cases and also any other use cases involving stateful consumers.
>>>>>
>>>>> Thanks for your response, and congrats again!
>>>>> -John
>>>>>
>>>>>
>>>>> On Wed, Mar 28, 2018 at 1:34 AM, Dong Lin <li...@gmail.com> wrote:
>>>>>
>>>>> Hey John,
>>>>>> Great! Thanks for all the comment. It seems that we agree that the
>>>>>>
>>>>> current
>>>>>
>>>>>> KIP is in good shape for core Kafka. IMO, what we have been discussing
>>>>>>
>>>>> in
>>>>> the recent email exchanges is mostly about the second step, i.e. how to
>>>>>> address problem for the stream use-case (or stateful processing in
>>>>>> general).
>>>>>>
>>>>>> I will comment inline.
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> On Tue, Mar 27, 2018 at 4:38 PM, John Roesler <jo...@confluent.io>
>>>>>>
>>>>> wrote:
>>>>> Thanks for the response, Dong.
>>>>>>> Here are my answers to your questions:
>>>>>>>
>>>>>>> - "Asking producers and consumers, or even two different producers,
>>>>>>>
>>>>>> to
>>>>> share code like the partition function is a pretty huge ask. What
>>>>>>> if
>>>>> they
>>>>>>> are using different languages?". It seems that today we already
>>>>>>> require
>>>>>> different producer's to use the same hash function -- otherwise
>>>>>>> messages
>>>>>>> with the same key will go to different partitions of the same topic
>>>>>>> which
>>>>>>> may cause problem for downstream consumption. So not sure if it
>>>>>>> adds
>>>>> any
>>>>>>> more constraint by assuming consumers know the hash function of
>>>>>>> producer.
>>>>>>> Could you explain more why user would want to use a cusmtom
>>>>>>> partition
>>>>> function? Maybe we can check if this is something that can be
>>>>>>> supported
>>>>>> in
>>>>>>>> the default Kafka hash function. Also, can you explain more why it
>>>>>>>>
>>>>>>> is
>>>>> difficuilt to implement the same hash function in different
>>>>>>> languages?
>>>>>>> Sorry, I meant two different producers as in producers to two
>>>>>>>
>>>>>> different
>>>>> topics. This was in response to the suggestion that we already
>>>>>> require
>>>>> coordination among producers to different topics in order to achieve
>>>>>>> co-partitioning. I was saying that we do not (and should not).
>>>>>>>
>>>>>> It is probably common for producers of different team to produce
>>>>>>
>>>>> message
>>>>> to
>>>>>
>>>>>> the same topic. In order to ensure that messages with the same key go
>>>>>>
>>>>> to
>>>>> same partition, we need producers of different team to share the same
>>>>>> partition algorithm, which by definition requires coordination among
>>>>>> producers of different teams in an organization. Even for producers of
>>>>>> different topics, it may be common to require producers to use the same
>>>>>> partition algorithm in order to join two topics for stream processing.
>>>>>>
>>>>> Does
>>>>>
>>>>>> this make it reasonable to say we already require coordination across
>>>>>> producers?
>>>>>>
>>>>>>
>>>>>> By design, consumers are currently ignorant of the partitioning
>>>>>> scheme.
>>>>> It
>>>>>>> suffices to trust that the producer has partitioned the topic by key,
>>>>>>>
>>>>>> if
>>>>>> they claim to have done so. If you don't trust that, or even if you
>>>>>> just
>>>>>> need some other partitioning scheme, then you must re-partition it
>>>>>>> yourself. Nothing we're discussing can or should change that. The
>>>>>>>
>>>>>> value
>>>>> of
>>>>>>> backfill is that it preserves the ability for consumers to avoid
>>>>>>> re-partitioning before consuming, in the case where they don't need
>>>>>>>
>>>>>> to
>>>>> today.
>>>>>> Regarding shared "hash functions", note that it's a bit inaccurate to
>>>>>> talk
>>>>>>
>>>>>>> about the "hash function" of the producer. Properly speaking, the
>>>>>>>
>>>>>> producer
>>>>>>
>>>>>>> has only a "partition function". We do not know that it is a hash.
>>>>>>>
>>>>>> The
>>>>> producer can use any method at their disposal to assign a partition
>>>>>> to
>>>>> a
>>>>>
>>>>>> record. The partition function obviously may we written in any
>>>>>> programming
>>>>>>
>>>>>>> language, so in general it's not something that can be shared around
>>>>>>> without a formal spec or the ability to execute arbitrary executables
>>>>>>>
>>>>>> in
>>>>>> arbitrary runtime environments.
>>>>>>> Yeah it is probably better to say partition algorithm. I guess it
>>>>> should
>>>>> not be difficult to implement same partition algorithms in different
>>>>>> languages, right? Yes we would need a formal specification of the
>>>>>>
>>>>> default
>>>>> partition algorithm in the producer. I think that can be documented as
>>>>> part
>>>>>
>>>>>> of the producer interface.
>>>>>>
>>>>>>
>>>>>> Why would a producer want a custom partition function? I don't
>>>>>> know...
>>>>> why
>>>>>>> did we design the interface so that our users can provide one? In
>>>>>>>
>>>>>> general,
>>>>>>
>>>>>>> such systems provide custom partitioners because some data sets may
>>>>>>>
>>>>>> be
>>>>> unbalanced under the default or because they can provide some
>>>>>> interesting
>>>>>> functionality built on top of the partitioning scheme, etc. Having
>>>>>> provided
>>>>>>
>>>>>>> this ability, I don't know why we would remove it.
>>>>>>>
>>>>>>> Yeah it is reasonable to assume that there was reason to support
>>>>>> custom
>>>>>> partition function in producer. On the other hand it may also be
>>>>>>
>>>>> reasonable
>>>>>
>>>>>> to revisit this interface and discuss whether we actually need to
>>>>>>
>>>>> support
>>>>> custom partition function. If we don't have a good reason, we can
>>>>> choose
>>>>> not to support custom partition function in this KIP in a backward
>>>>>> compatible manner, i.e. user can still use custom partition function
>>>>>>
>>>>> but
>>>>> they would not get the benefit of in-order delivery when there is
>>>>> partition
>>>>>
>>>>>> expansion. What do you think?
>>>>>>
>>>>>>
>>>>>> - Besides the assumption that consumer needs to share the hash
>>>>>> function
>>>>> of
>>>>>>> producer, is there other organization overhead of the proposal in
>>>>>>> the
>>>>> current KIP?
>>>>>>>> It wasn't clear to me that KIP-253 currently required the producer
>>>>>> and
>>>>> consumer to share the partition function, or in fact that it had a
>>>>>> hard
>>>>> requirement to abandon the general partition function and use a
>>>>>> linear
>>>>> hash
>>>>>>> function instead.
>>>>>>>
>>>>>> In my reading, there is a requirement to track the metadata about
>>>>>> what
>>>>> partitions split into what other partitions during an expansion
>>>>>> operation.
>>>>>>
>>>>>>> If the partition function is linear, this is easy. If not, you can
>>>>>>>
>>>>>> always
>>>>>> just record that all old partitions split into all new partitions.
>>>>>> This
>>>>> has
>>>>>>> the effect of forcing all consumers to wait until the old epoch is
>>>>>>> completely consumed before starting on the new epoch. But this may
>>>>>>>
>>>>>> be a
>>>>> reasonable tradeoff, and it doesn't otherwise alter your design.
>>>>>>> You only mention the consumer needing to know that the partition
>>>>>>>
>>>>>> function
>>>>>> is linear, not what the actual function is, so I don't think your
>>>>>> design
>>>>>> actually calls for sharing the function. Plus, really all the
>>>>>> consumer
>>>>> needs is the metadata about what old-epoch partitions to wait for
>>>>>> before
>>>>>> consuming a new-epoch partition. This information is directly
>>>>>> captured
>>>>> in
>>>>>
>>>>>> metadata, so I don't think it actually even cares whether the
>>>>>> partition
>>>>> function is linear or not.
>>>>>>> You are right that the current KIP does not mention it. My comment
>>>>> related
>>>>>
>>>>>> to the partition function coordination was related to support the
>>>>>> stream-use case which we have been discussing so far.
>>>>>>
>>>>>>
>>>>>> So, no, I really think KIP-253 is in good shape. I was really more
>>>>>> talking
>>>>>>
>>>>>>> about the part of this thread that's outside of KIP-253's scope,
>>>>>>>
>>>>>> namely,
>>>>>> creating the possibility of backfilling partitions after expansion.
>>>>>>> Great! Can you also confirm that the main motivation for backfilling
>>>>>> partitions after expansion is to support the stream use-case?
>>>>>>
>>>>>>
>>>>>> - Currently producer can forget about the message that has been
>>>>>>>> acknowledged by the broker. Thus the producer probably does not
>>>>>>>>
>>>>>>> know
>>>>> most
>>>>>>> of the exiting messages in topic, including those messages produced
>>>>>>> by
>>>>>> other producers. We can have the owner of the producer to
>>>>>>> split+backfill.
>>>>>>> In my opion it will be a new program that wraps around the existing
>>>>>>>> producer and consumer classes.
>>>>>>>>
>>>>>>>> This sounds fine by me!
>>>>>>> Really, I was just emphasizing that the part of the organization that
>>>>>>> produces a topic shouldn't have to export their partition function to
>>>>>>>
>>>>>> the
>>>>>> part(s) of the organization (or other organizations) that consume the
>>>>>>> topic. Whether the backfill operation goes into the Producer
>>>>>>>
>>>>>> interface
>>>>> is
>>>>>
>>>>>> secondary, I think.
>>>>>>> - Regarding point 5. The argument is in favor of the split+backfill
>>>>>>>
>>>>>> but
>>>>> for
>>>>>>> changelog topic. And it intends to address the problem for stream
>>>>>>> use-case
>>>>>>>
>>>>>>>> in general. In this KIP we will provide interface (i.e.
>>>>>>>> PartitionKeyRebalanceListener in the KIP) to be used by sream
>>>>>>>>
>>>>>>> use-case
>>>>>> and
>>>>>>>> the goal is that user can flush/re-consume the state as part of the
>>>>>>>> interface implementation regardless of whether there is change log
>>>>>>>>
>>>>>>> topic.
>>>>>>> Maybe you are suggesting that the main reason to do split+backfill
>>>>>>> of
>>>>> input
>>>>>>>> topic is to support log compacted topics? You mentioned in Point 1
>>>>>>>>
>>>>>>> that
>>>>>> log
>>>>>>>> compacted topics is out of the scope of this KIP. Maybe I could
>>>>>>>>
>>>>>>> understand
>>>>>>>
>>>>>>>> your position better. Regarding Jan's proposal to split partitions
>>>>>>>>
>>>>>>> with
>>>>>> backfill, do you think this should replace the proposal in the
>>>>>>> existing
>>>>>> KIP, or do you think this is something that we should do in
>>>>>>> addition
>>>>> to
>>>>>
>>>>>> the
>>>>>>>> existing KIP?
>>>>>>>>
>>>>>>>> I think that interface is a good/necessary component of KIP-253.
>>>>>>> I personally (FWIW) feel that KIP-253 is appropriately scoped, but I
>>>>>>>
>>>>>> do
>>>>> think its utility will be limited unless there is a later KIP
>>>>>> offering
>>>>> backfill. But, maybe unlike Jan, I think it makes sense to try and
>>>>>> tackle
>>>>>> the ordering problem independently of backfill, so I'm in support of
>>>>>> the
>>>>>> current KIP.
>>>>>>> - Regarding point 6. I guess we can agree that it is better not to
>>>>>>>
>>>>>> have
>>>>> the
>>>>>>> performance overhread of copying the input data. Before we discuss
>>>>>>> more
>>>>>> on
>>>>>>>> whether the performance overhead is acceptable or not, I am trying
>>>>>>>>
>>>>>>> to
>>>>> figure out what is the benefit of introducing this overhread. You
>>>>>>> mentioned
>>>>>>>
>>>>>>>> that the benefit is the loose organizational coupling. By
>>>>>>>>
>>>>>>> "organizational
>>>>>>> coupling", are you referring to the requirement that consumer needs
>>>>>>> to
>>>>>> know
>>>>>>>> the hash function of producer? If so, maybe we can discuss the
>>>>>>>>
>>>>>>> use-case
>>>>>> of
>>>>>>>> custom partiton function and see whether we can find a way to
>>>>>>>>
>>>>>>> support
>>>>> such
>>>>>>>> use-case without having to copy the input data.
>>>>>>>>
>>>>>>>> I'm not too sure about what an "input" is in this sense, since we are
>>>>>> just
>>>>>>
>>>>>>> talking about topics. Actually the point I was making there is that
>>>>>>>
>>>>>> AKAICT
>>>>>>
>>>>>>> the performance overhead of a backfill is less than any other option,
>>>>>>> assuming you split partitions rarely.
>>>>>>>
>>>>>>> By "input" I was referring to source Kafka topic of a stream
>>>>>> processing
>>>>>> job.
>>>>>>
>>>>>>
>>>>>> Separately, yes, "organizational coupling" increases if producers and
>>>>>>> consumers have to share code, such as the partition function. This
>>>>>>>
>>>>>> would
>>>>>> not be the case if producers could only pick from a menu of a few
>>>>>>> well-known partition functions, but I think this is a poor tradeoff.
>>>>>>>
>>>>>>> Maybe we can revisit the custom partition function and see whether we
>>>>>> actually need it? Otherwise, I am concerned that every user will pay
>>>>>>
>>>>> the
>>>>> overhead of data movement to support something that was not really
>>>>> needed
>>>>> for most users.
>>>>>>
>>>>>> To me, this is two strong arguments in favor of backfill being less
>>>>>>> expensive than no backfill, but again, I think that particular debate
>>>>>>>
>>>>>> comes
>>>>>>
>>>>>>> after KIP-253, so I don't want to create the impression of opposition
>>>>>>>
>>>>>> to
>>>>>> your proposal.
>>>>>>>
>>>>>>> Finally, to respond to a new email I just noticed:
>>>>>>>
>>>>>>> BTW, here is my understanding of the scope of this KIP. We want to
>>>>>>> allow
>>>>>>> consumers to always consume messages with the same key from the
>>>>>>> same
>>>>> producer in the order they are produced. And we need to provide a
>>>>>>> way
>>>>> for
>>>>>>> stream use-case to be able to flush/load state when messages with
>>>>>>> the
>>>>> same
>>>>>>>> key are migrated between consumers. In addition to ensuring that
>>>>>>>>
>>>>>>> this
>>>>> goal
>>>>>>>> is correctly supported, we should do our best to keep the
>>>>>>>>
>>>>>>> performance
>>>>> and
>>>>>>> organization overhead of this KIP as low as possible.
>>>>>>>> I think we're on the same page there! In fact, I would generalize a
>>>>>> little
>>>>>>
>>>>>>> more and say that the mechanism you've designed provides *all
>>>>>>>
>>>>>> consumers*
>>>>>> the ability "to flush/load state when messages with the same key are
>>>>>>> migrated between consumers", not just Streams.
>>>>>>>
>>>>>>> Thanks for all the comment!
>>>>>>
>>>>>> Thanks for the discussion,
>>>>>>> -John
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> On Tue, Mar 27, 2018 at 3:14 PM, Dong Lin <li...@gmail.com>
>>>>>>>
>>>>>> wrote:
>>>>> Hey John,
>>>>>>>> Thanks much for the detailed comments. Here are my thoughts:
>>>>>>>>
>>>>>>>> - The need to delete messages from log compacted topics is mainly
>>>>>>>>
>>>>>>> for
>>>>> performance (e.g. storage space) optimization than for correctness
>>>>>>> for
>>>>>> this
>>>>>>>> KIP. I agree that we probably don't need to focus on this in our
>>>>>>>>
>>>>>>> discussion
>>>>>>>
>>>>>>>> since it is mostly for performance optimization.
>>>>>>>>
>>>>>>>> - "Asking producers and consumers, or even two different producers,
>>>>>>>>
>>>>>>> to
>>>>>> share code like the partition function is a pretty huge ask. What
>>>>>>> if
>>>>> they
>>>>>>> are using different languages?". It seems that today we already
>>>>>>> require
>>>>>> different producer's to use the same hash function -- otherwise
>>>>>>> messages
>>>>>>> with the same key will go to different partitions of the same topic
>>>>>>> which
>>>>>>> may cause problem for downstream consumption. So not sure if it
>>>>>>> adds
>>>>> any
>>>>>>> more constraint by assuming consumers know the hash function of
>>>>>>> producer.
>>>>>>> Could you explain more why user would want to use a cusmtom
>>>>>>> partition
>>>>> function? Maybe we can check if this is something that can be
>>>>>>> supported
>>>>>> in
>>>>>>>> the default Kafka hash function. Also, can you explain more why it
>>>>>>>>
>>>>>>> is
>>>>> difficuilt to implement the same hash function in different
>>>>>>> languages?
>>>>>> - Besides the assumption that consumer needs to share the hash
>>>>>>> function
>>>>>> of
>>>>>>>> producer, is there other organization overhead of the proposal in
>>>>>>>>
>>>>>>> the
>>>>> current KIP?
>>>>>>>> - Currently producer can forget about the message that has been
>>>>>>>> acknowledged by the broker. Thus the producer probably does not
>>>>>>>>
>>>>>>> know
>>>>> most
>>>>>>> of the exiting messages in topic, including those messages produced
>>>>>>> by
>>>>>> other producers. We can have the owner of the producer to
>>>>>>> split+backfill.
>>>>>>> In my opion it will be a new program that wraps around the existing
>>>>>>>> producer and consumer classes.
>>>>>>>>
>>>>>>>> - Regarding point 5. The argument is in favor of the split+backfill
>>>>>>>>
>>>>>>> but
>>>>>> for
>>>>>>>> changelog topic. And it intends to address the problem for stream
>>>>>>>>
>>>>>>> use-case
>>>>>>>
>>>>>>>> in general. In this KIP we will provide interface (i.e.
>>>>>>>> PartitionKeyRebalanceListener in the KIP) to be used by sream
>>>>>>>>
>>>>>>> use-case
>>>>>> and
>>>>>>>> the goal is that user can flush/re-consume the state as part of the
>>>>>>>> interface implementation regardless of whether there is change log
>>>>>>>>
>>>>>>> topic.
>>>>>>> Maybe you are suggesting that the main reason to do split+backfill
>>>>>>> of
>>>>> input
>>>>>>>> topic is to support log compacted topics? You mentioned in Point 1
>>>>>>>>
>>>>>>> that
>>>>>> log
>>>>>>>> compacted topics is out of the scope of this KIP. Maybe I could
>>>>>>>>
>>>>>>> understand
>>>>>>>
>>>>>>>> your position better. Regarding Jan's proposal to split partitions
>>>>>>>>
>>>>>>> with
>>>>>> backfill, do you think this should replace the proposal in the
>>>>>>> existing
>>>>>> KIP, or do you think this is something that we should do in
>>>>>>> addition
>>>>> to
>>>>>
>>>>>> the
>>>>>>>> existing KIP?
>>>>>>>>
>>>>>>>> - Regarding point 6. I guess we can agree that it is better not to
>>>>>>>>
>>>>>>> have
>>>>>> the
>>>>>>>> performance overhread of copying the input data. Before we discuss
>>>>>>>>
>>>>>>> more
>>>>>> on
>>>>>>>> whether the performance overhead is acceptable or not, I am trying
>>>>>>>>
>>>>>>> to
>>>>> figure out what is the benefit of introducing this overhread. You
>>>>>>> mentioned
>>>>>>>
>>>>>>>> that the benefit is the loose organizational coupling. By
>>>>>>>>
>>>>>>> "organizational
>>>>>>> coupling", are you referring to the requirement that consumer needs
>>>>>>> to
>>>>>> know
>>>>>>>> the hash function of producer? If so, maybe we can discuss the
>>>>>>>>
>>>>>>> use-case
>>>>>> of
>>>>>>>> custom partiton function and see whether we can find a way to
>>>>>>>>
>>>>>>> support
>>>>> such
>>>>>>>> use-case without having to copy the input data.
>>>>>>>>
>>>>>>>> Thanks,
>>>>>>>> Dong
>>>>>>>>
>>>>>>>>
>>>>>>>> On Tue, Mar 27, 2018 at 11:34 AM, John Roesler <jo...@confluent.io>
>>>>>>>>
>>>>>>> wrote:
>>>>>>>
>>>>>>>> Hey Dong and Jun,
>>>>>>>>> Thanks for the thoughtful responses. If you don't mind, I'll mix
>>>>>>>>>
>>>>>>>> my
>>>>> replies
>>>>>>>>> together to try for a coherent response. I'm not too familiar
>>>>>>>>>
>>>>>>>> with
>>>>> mailing-list etiquette, though.
>>>>>>>>> I'm going to keep numbering my points because it makes it easy
>>>>>>>>>
>>>>>>>> for
>>>>> you
>>>>>>> all
>>>>>>>>> to respond.
>>>>>>>>>
>>>>>>>>> Point 1:
>>>>>>>>> As I read it, KIP-253 is *just* about properly fencing the
>>>>>>>>>
>>>>>>>> producers
>>>>>> and
>>>>>>>> consumers so that you preserve the correct ordering of records
>>>>>>>> during
>>>>>> partition expansion. This is clearly necessary regardless of
>>>>>>>> anything
>>>>>> else
>>>>>>>>> we discuss. I think this whole discussion about backfill,
>>>>>>>>>
>>>>>>>> consumers,
>>>>>> streams, etc., is beyond the scope of KIP-253. But it would be
>>>>>>>> cumbersome
>>>>>>>> to start a new thread at this point.
>>>>>>>>> I had missed KIP-253's Proposed Change #9 among all the
>>>>>>>>>
>>>>>>>> details...
>>>>> I
>>>>>
>>>>>> think
>>>>>>>>> this is a nice addition to the proposal. One thought is that it's
>>>>>>>>>
>>>>>>>> actually
>>>>>>>>
>>>>>>>>> irrelevant whether the hash function is linear. This is simply an
>>>>>>>>>
>>>>>>>> algorithm
>>>>>>>>
>>>>>>>>> for moving a key from one partition to another, so the type of
>>>>>>>>>
>>>>>>>> hash
>>>>> function need not be a precondition. In fact, it also doesn't
>>>>>>>> matter
>>>>>> whether the topic is compacted or not, the algorithm works
>>>>>>>> regardless.
>>>>>>> I think this is a good algorithm to keep in mind, as it might
>>>>>>>> solve a
>>>>>> variety of problems, but it does have a downside: that the
>>>>>>>> producer
>>>>> won't
>>>>>>>> know whether or not K1 was actually in P1, it just knows that K1
>>>>>>>> was
>>>>>> in
>>>>>>
>>>>>>> P1's keyspace before the new epoch. Therefore, it will have to
>>>>>>>>> pessimistically send (K1,null) to P1 just in case. But the next
>>>>>>>>>
>>>>>>>> time
>>>>>> K1
>>>>>>
>>>>>>> comes along, the producer *also* won't remember that it already
>>>>>>>> retracted
>>>>>>>> K1 from P1, so it will have to send (K1,null) *again*. By
>>>>>>>> extension,
>>>>>> every
>>>>>>>>> time the producer sends to P2, it will also have to send a
>>>>>>>>>
>>>>>>>> tombstone
>>>>>> to
>>>>>>
>>>>>>> P1,
>>>>>>>>> which is a pretty big burden. To make the situation worse, if
>>>>>>>>>
>>>>>>>> there
>>>>> is
>>>>>>> a
>>>>>>>
>>>>>>>> second split, say P2 becomes P2 and P3, then any key Kx belonging
>>>>>>>> to
>>>>>> P3
>>>>>>
>>>>>>> will also have to be retracted from P2 *and* P1, since the
>>>>>>>> producer
>>>>> can't
>>>>>>>> know whether Kx had been last written to P2 or P1. Over a long
>>>>>>>> period
>>>>>> of
>>>>>>>> time, this clearly becomes a issue, as the producer must send an
>>>>>>>> arbitrary
>>>>>>>>
>>>>>>>>> number of retractions along with every update.
>>>>>>>>>
>>>>>>>>> In contrast, the proposed backfill operation has an end, and
>>>>>>>>>
>>>>>>>> after
>>>>> it
>>>>>
>>>>>> ends,
>>>>>>>>> everyone can afford to forget that there ever was a different
>>>>>>>>>
>>>>>>>> partition
>>>>>>> layout.
>>>>>>>>> Really, though, figuring out how to split compacted topics is
>>>>>>>>>
>>>>>>>> beyond
>>>>>> the
>>>>>>>> scope of KIP-253, so I'm not sure #9 really even needs to be in
>>>>>>>> this
>>>>>> KIP...
>>>>>>>>> We do need in-order delivery during partition expansion. It would
>>>>>>>>>
>>>>>>>> be
>>>>>> fine
>>>>>>>> by me to say that you *cannot* expand partitions of a
>>>>>>>> log-compacted
>>>>> topic
>>>>>>>> and call it a day. I think it would be better to tackle that in
>>>>>>>> another
>>>>>>> KIP.
>>>>>>>>>
>>>>>>>>> Point 2:
>>>>>>>>> Regarding whether the consumer re-shuffles its inputs, this is
>>>>>>>>>
>>>>>>>> always
>>>>>> on
>>>>>>>> the table; any consumer who wants to re-shuffle its input is free
>>>>>>>> to
>>>>>> do
>>>>>>
>>>>>>> so.
>>>>>>>>> But this is currently not required. It's just that the current
>>>>>>>>>
>>>>>>>> high-level
>>>>>>>> story with Kafka encourages the use of partitions as a unit of
>>>>>>>> concurrency.
>>>>>>>>
>>>>>>>>> As long as consumers are single-threaded, they can happily
>>>>>>>>>
>>>>>>>> consume
>>>>> a
>>>>>
>>>>>> single
>>>>>>>>> partition without concurrency control of any kind. This is a key
>>>>>>>>>
>>>>>>>> aspect
>>>>>>> to
>>>>>>>>> this system that lets folks design high-throughput systems on top
>>>>>>>>>
>>>>>>>> of
>>>>>> it
>>>>>>
>>>>>>> surprisingly easily. If all consumers were instead
>>>>>>>> encouraged/required
>>>>>>> to
>>>>>>>
>>>>>>>> implement a repartition of their own, then the consumer becomes
>>>>>>>>> significantly more complex, requiring either the consumer to
>>>>>>>>>
>>>>>>>> first
>>>>> produce
>>>>>>>>> to its own intermediate repartition topic or to ensure that
>>>>>>>>>
>>>>>>>> consumer
>>>>>> threads have a reliable, high-bandwith channel of communication
>>>>>>>> with
>>>>>> every
>>>>>>>>> other consumer thread.
>>>>>>>>>
>>>>>>>>> Either of those tradeoffs may be reasonable for a particular user
>>>>>>>>>
>>>>>>>> of
>>>>>> Kafka,
>>>>>>>>> but I don't know if we're in a position to say that they are
>>>>>>>>>
>>>>>>>> reasonable
>>>>>>> for
>>>>>>>>> *every* user of Kafka.
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> Point 3:
>>>>>>>>> Regarding Jun's point about this use case, "(3) stateful and
>>>>>>>>>
>>>>>>>> maintaining
>>>>>>>> the
>>>>>>>>> states in a local store", I agree that they may use a framework
>>>>>>>>>
>>>>>>>> *like*
>>>>>>> Kafka Streams, but that is not the same as using Kafka Streams.
>>>>>>>> This
>>>>>> is
>>>>>>
>>>>>>> why
>>>>>>>>> I think it's better to solve it in Core: because it is then
>>>>>>>>>
>>>>>>>> solved
>>>>> for
>>>>>>> KStreams and also for everything else that facilitates local
>>>>>>>> state
>>>>> maintenance. To me, Streams is a member of the category of
>>>>>>>> "stream
>>>>> processing frameworks", which is itself a subcategory of "things
>>>>>>>> requiring
>>>>>>>>
>>>>>>>>> local state maintenence". I'm not sure if it makes sense to
>>>>>>>>


Re: [DISCUSS] KIP-253: Support in-order message delivery with partition expansion

Posted by John Roesler <jo...@confluent.io>.
Thanks Jun, That time also works for me.
-john

On Wed, Apr 4, 2018 at 6:28 PM, Guozhang Wang <wa...@gmail.com> wrote:

> @Jun, yeah that works for me too.
>
> @Jan, just to clarify on my previous email: assuming we do the reshuffling
> out of the user input topics, Streams has the advantage that the
> repartition topic is purely owned by itself: the only producer writing to
> this repartition topic is Streams itself; so then we can change the split
> the number of partitions of the repartition without requiring to expand the
> input topics. And since the reshuffling task itself is stateless, it does
> not require key partitioning preservation. So as I mentioned, it is indeed
> not dependent on KIP-253 itself as KIP-254 is primarily for expanding an
> input topic for consumer applications.
>
>
> Guozhang
>
> On Wed, Apr 4, 2018 at 4:01 PM, Dong Lin <li...@gmail.com> wrote:
>
> > Thanks Jun! The time works for me.
> >
> >
> > On Thu, 5 Apr 2018 at 4:34 AM Jun Rao <ju...@confluent.io> wrote:
> >
> > > Hi, Jan, Dong, John, Guozhang,
> > >
> > > Perhaps it will be useful to have a KIP meeting to discuss this
> together
> > as
> > > a group. Would Apr. 9 (Monday) at 9:00am PDT work? If so, I will send
> out
> > > an invite to the mailing list.
> > >
> > > Thanks,
> > >
> > > Jun
> > >
> > >
> > > On Wed, Apr 4, 2018 at 1:25 AM, Jan Filipiak <Jan.Filipiak@trivago.com
> >
> > > wrote:
> > >
> > > > Want to quickly step in here again because it is going places again.
> > > >
> > > > The last part of the discussion is just a pain to read and completely
> > > > diverged from what I suggested without making the reasons clear to
> me.
> > > >
> > > > I don't know why this happens.... here are my comments anyway.
> > > >
> > > > @Guozhang: That Streams is working on automatic creating
> > > > copartition-usuable topics: great for streams, has literally nothing
> > todo
> > > > with the KIP as we want to grow the
> > > > input topic. Everyone can reshuffle rel. easily but that is not what
> we
> > > > need todo, we need to grow the topic in question. After streams
> > > > automatically reshuffled the input topic
> > > > still has the same size and it didn't help a bit. I fail to see why
> > this
> > > > is relevant. What am i missing here?
> > > >
> > > > @Dong
> > > > I am still on the position that the current proposal brings us into
> the
> > > > wrong direction. Especially introducing PartitionKeyRebalanceListener
> > > > From this point we can never move away to proper state full handling
> > > > without completely deprecating this creature from hell again.
> > > > Linear hashing is not the optimising step we have todo here. An
> > interface
> > > > that when a topic is a topic its always the same even after it had
> > > > grown or shrunk is important. So from my POV I have major concerns
> that
> > > > this KIP is benefitial in its current state.
> > > >
> > > > What is it that makes everyone so addicted to the idea of linear
> > hashing?
> > > > not attractive at all for me.
> > > > And with statefull consumers still a complete mess. Why not stick
> with
> > > the
> > > > Kappa architecture???
> > > >
> > > >
> > > >
> > > >
> > > >
> > > > On 03.04.2018 17:38, Dong Lin wrote:
> > > >
> > > >> Hey John,
> > > >>
> > > >> Thanks much for your comments!!
> > > >>
> > > >> I have yet to go through the emails of John/Jun/Guozhang in detail.
> > But
> > > >> let
> > > >> me present my idea for how to minimize the delay for state loading
> for
> > > >> stream use-case.
> > > >>
> > > >> For ease of understanding, let's assume that the initial partition
> > > number
> > > >> of input topics and change log topic are both 10. And initial number
> > of
> > > >> stream processor is also 10. If we only increase initial partition
> > > number
> > > >> of input topics to 15 without changing number of stream processor,
> the
> > > >> current KIP already guarantees in-order delivery and no state needs
> to
> > > be
> > > >> moved between consumers for stream use-case. Next, let's say we want
> > to
> > > >> increase the number of processor to expand the processing capacity
> for
> > > >> stream use-case. This requires us to move state between processors
> > which
> > > >> will take time. Our goal is to minimize the impact (i.e. delay) for
> > > >> processing while we increase the number of processors.
> > > >>
> > > >> Note that stream processor generally includes both consumer and
> > > producer.
> > > >> In addition to consume from the input topic, consumer may also need
> to
> > > >> consume from change log topic on startup for recovery. And producer
> > may
> > > >> produce state to the change log topic.
> > > >>
> > > >>
> > > > The solution will include the following steps:
> > > >>
> > > >> 1) Increase partition number of the input topic from 10 to 15. Since
> > the
> > > >> messages with the same key will still go to the same consume before
> > and
> > > >> after the partition expansion, this step can be done without having
> to
> > > >> move
> > > >> state between processors.
> > > >>
> > > >> 2) Increase partition number of the change log topic from 10 to 15.
> > Note
> > > >> that this step can also be done without impacting existing workflow.
> > > After
> > > >> we increase partition number of the change log topic, key space may
> > > split
> > > >> and some key will be produced to the newly-added partition. But the
> > same
> > > >> key will still go to the same processor (i.e. consumer) before and
> > after
> > > >> the partition. Thus this step can also be done without having to
> move
> > > >> state
> > > >> between processors.
> > > >>
> > > >> 3) Now, let's add 5 new consumers whose groupId is different from
> the
> > > >> existing processor's groupId. Thus these new consumers will not
> impact
> > > >> existing workflow. Each of these new consumers should consume two
> > > >> partitions from the earliest offset, where these two partitions are
> > the
> > > >> same partitions that will be consumed if the consumers have the same
> > > >> groupId as the existing processor's groupId. For example, the first
> of
> > > the
> > > >> five consumers will consume partition 0 and partition 10. The
> purpose
> > of
> > > >> these consumers is to rebuild the state (e.g. RocksDB) for the
> > > processors
> > > >> in advance. Also note that, by design of the current KIP, each
> consume
> > > >> will
> > > >> consume the existing partition of the change log topic up to the
> > offset
> > > >> before the partition expansion. Then they will only need to consume
> > the
> > > >> state of the new partition of the change log topic.
> > > >>
> > > >> 4) After consumers have caught up in step 3), we should stop these
> > > >> consumers and add 5 new processors to the stream processing job.
> > These 5
> > > >> new processors should run in the same location as the previous 5
> > > consumers
> > > >> to re-use the state (e.g. RocksDB). And these processors' consumers
> > > should
> > > >> consume partitions of the change log topic from the committed offset
> > the
> > > >> previous 5 consumers so that no state is missed.
> > > >>
> > > >> One important trick to note here is that, the mapping from partition
> > to
> > > >> consumer should also use linear hashing. And we need to remember the
> > > >> initial number of processors in the job, 10 in this example, and use
> > > this
> > > >> number in the linear hashing algorithm. This is pretty much the same
> > as
> > > >> how
> > > >> we use linear hashing to map key to partition. In this case, we get
> an
> > > >> identity map from partition -> processor, for both input topic and
> the
> > > >> change log topic. For example, processor 12 will consume partition
> 12
> > of
> > > >> the input topic and produce state to the partition 12 of the change
> > log
> > > >> topic.
> > > >>
> > > >> There are a few important properties of this solution to note:
> > > >>
> > > >> - We can increase the number of partitions for input topic and the
> > > change
> > > >> log topic in any order asynchronously.
> > > >> - The expansion of the processors in a given job in step 4) only
> > > requires
> > > >> the step 3) for the same job. It does not require coordination
> across
> > > >> different jobs for step 3) and 4). Thus different jobs can
> > independently
> > > >> expand there capacity without waiting for each other.
> > > >> - The logic for 1) and 2) is already supported in the current KIP.
> The
> > > >> logic for 3) and 4) appears to be independent of the core Kafka
> logic
> > > and
> > > >> can be implemented separately outside core Kafka. Thus the current
> KIP
> > > is
> > > >> probably sufficient after we agree on the efficiency and the
> > correctness
> > > >> of
> > > >> the solution. We can have a separate KIP for Kafka Stream to support
> > 3)
> > > >> and
> > > >> 4).
> > > >>
> > > >>
> > > >> Cheers,
> > > >> Dong
> > > >>
> > > >>
> > > >> On Mon, Apr 2, 2018 at 3:25 PM, Guozhang Wang <wa...@gmail.com>
> > > wrote:
> > > >>
> > > >> Hey guys, just sharing my two cents here (I promise it will be
> shorter
> > > >>> than
> > > >>> John's article :).
> > > >>>
> > > >>> 0. Just to quickly recap, the main discussion point now is how to
> > > support
> > > >>> "key partitioning preservation" (John's #4 in topic characteristics
> > > >>> above)
> > > >>> beyond the "single-key ordering preservation" that KIP-253 was
> > > originally
> > > >>> proposed to maintain (John's #6 above).
> > > >>>
> > > >>> 1. From the streams project, we are actively working on improving
> the
> > > >>> elastic scalability of the library. One of the key features is to
> > > >>> decouple
> > > >>> the input topics from the parallelism model of Streams: i.e. not
> > > >>> enforcing
> > > >>> the topic to be partitioned by the key, not enforcing joining
> topics
> > to
> > > >>> be
> > > >>> co-partitioned, not relying the number of parallel tasks on the
> input
> > > >>> topic
> > > >>> partitions. This can be achieved by re-shuffling on the input
> topics
> > to
> > > >>> make sure key-partitioning / co-partitioning on the internal
> topics.
> > > Note
> > > >>> the re-shuffling task is purely stateless and hence does not
> require
> > > "key
> > > >>> partitioning preservation". Operational-wise it is similar to the
> > > >>> "creating
> > > >>> a new topic with new number of partitions, pipe the data to the new
> > > topic
> > > >>> and cut over consumers from old topics" idea, just that users can
> > > >>> optionally let Streams to handle such rather than doing it manually
> > > >>> themselves. There are a few more details on that regard but I will
> > skip
> > > >>> since they are not directly related to this discussion.
> > > >>>
> > > >>> 2. Assuming that 1) above is done, then the only topics involved in
> > the
> > > >>> scaling events are all input topics. For these topics the only
> > > producers
> > > >>> /
> > > >>> consumers of these topics are controlled by Streams clients
> > themselves,
> > > >>> and
> > > >>> hence achieving "key partitioning preservation" is simpler than
> > > >>> non-Streams
> > > >>> scenarios: consumers know the partitioning scheme that producers
> are
> > > >>> using,
> > > >>> so that for their stateful operations it is doable to split the
> local
> > > >>> state
> > > >>> stores accordingly or execute backfilling on its own. Of course, if
> > we
> > > >>> decide to do server-side backfilling, it can still help Streams to
> > > >>> directly
> > > >>> rely on that functionality.
> > > >>>
> > > >>> 3. As John mentioned, another way inside Streams is to do
> > > >>> over-partitioning
> > > >>> on all internal topics; then with 1) Streams would not rely on
> > KIP-253
> > > at
> > > >>> all. But personally I'd like to avoid it if possible to reduce
> Kafka
> > > side
> > > >>> footprint: say we overpartition each input topic up to 1k, with a
> > > >>> reasonable sized stateful topology it can still contribute to tens
> of
> > > >>> thousands of topics to the topic partition capacity of a single
> > > cluster.
> > > >>>
> > > >>> 4. Summing up 1/2/3, I think we should focus more on non-Streams
> > users
> > > >>> writing their stateful computations with local states, and think
> > > whether
> > > >>> /
> > > >>> how we could enable "key partitioning preservation" for them
> easily,
> > > than
> > > >>> to think heavily for Streams library. People may have different
> > opinion
> > > >>> on
> > > >>> how common of a usage pattern it is (I think Jun might be
> suggesting
> > > that
> > > >>> for DIY apps people may more likely use remote states so that it is
> > > not a
> > > >>> problem for them). My opinion is that for non-Streams users such
> > usage
> > > >>> pattern could still be large (think: if you are piping data from
> > Kafka
> > > to
> > > >>> an external data storage which has single-writer requirements for
> > each
> > > >>> single shard, even though it is not a stateful computational
> > > application
> > > >>> it
> > > >>> may still require "key partitioning preservation"), so I prefer to
> > have
> > > >>> backfilling in our KIP than only exposing the API for expansion and
> > > >>> requires consumers to have pre-knowledge of the producer's
> > partitioning
> > > >>> scheme.
> > > >>>
> > > >>>
> > > >>>
> > > >>> Guozhang
> > > >>>
> > > >>>
> > > >>>
> > > >>> On Thu, Mar 29, 2018 at 2:33 PM, John Roesler <jo...@confluent.io>
> > > wrote:
> > > >>>
> > > >>> Hey Dong,
> > > >>>>
> > > >>>> Congrats on becoming a committer!!!
> > > >>>>
> > > >>>> Since I just sent a novel-length email, I'll try and keep this one
> > > brief
> > > >>>>
> > > >>> ;)
> > > >>>
> > > >>>> Regarding producer coordination, I'll grant that in that case,
> > > producers
> > > >>>> may coordinate among themselves to produce into the same topic or
> to
> > > >>>> produce co-partitioned topics. Nothing in KStreams or the Kafka
> > > >>>> ecosystem
> > > >>>> in general requires such coordination for correctness or in fact
> for
> > > any
> > > >>>> optional features, though, so I would not say that we require
> > producer
> > > >>>> coordination of partition logic. If producers currently
> coordinate,
> > > it's
> > > >>>> completely optional and their own choice.
> > > >>>>
> > > >>>> Regarding the portability of partition algorithms, my observation
> is
> > > >>>> that
> > > >>>> systems requiring independent implementations of the same
> algorithm
> > > with
> > > >>>> 100% correctness are a large source of risk and also a burden on
> > those
> > > >>>>
> > > >>> who
> > > >>>
> > > >>>> have to maintain them. If people could flawlessly implement
> > algorithms
> > > >>>> in
> > > >>>> actual software, the world would be a wonderful place indeed! For
> a
> > > >>>>
> > > >>> system
> > > >>>
> > > >>>> as important and widespread as Kafka, I would recommend
> restricting
> > > >>>> limiting such requirements as aggressively as possible.
> > > >>>>
> > > >>>> I'd agree that we can always revisit decisions like allowing
> > arbitrary
> > > >>>> partition functions, but of course, we shouldn't do that in a
> > vacuum.
> > > >>>>
> > > >>> That
> > > >>>
> > > >>>> feels like the kind of thing we'd need to proactively seek
> guidance
> > > from
> > > >>>> the users list about. I do think that the general approach of
> saying
> > > >>>> that
> > > >>>> "if you use a custom partitioner, you cannot do partition
> expansion"
> > > is
> > > >>>> very reasonable (but I don't think we need to go that far with the
> > > >>>>
> > > >>> current
> > > >>>
> > > >>>> proposal). It's similar to my statement in my email to Jun that in
> > > >>>> principle KStreams doesn't *need* backfill, we only need it if we
> > want
> > > >>>> to
> > > >>>> employ partition expansion.
> > > >>>>
> > > >>>> I reckon that the main motivation for backfill is to support
> > KStreams
> > > >>>> use
> > > >>>> cases and also any other use cases involving stateful consumers.
> > > >>>>
> > > >>>> Thanks for your response, and congrats again!
> > > >>>> -John
> > > >>>>
> > > >>>>
> > > >>>> On Wed, Mar 28, 2018 at 1:34 AM, Dong Lin <li...@gmail.com>
> > > wrote:
> > > >>>>
> > > >>>> Hey John,
> > > >>>>>
> > > >>>>> Great! Thanks for all the comment. It seems that we agree that
> the
> > > >>>>>
> > > >>>> current
> > > >>>>
> > > >>>>> KIP is in good shape for core Kafka. IMO, what we have been
> > > discussing
> > > >>>>>
> > > >>>> in
> > > >>>
> > > >>>> the recent email exchanges is mostly about the second step, i.e.
> how
> > > to
> > > >>>>> address problem for the stream use-case (or stateful processing
> in
> > > >>>>> general).
> > > >>>>>
> > > >>>>> I will comment inline.
> > > >>>>>
> > > >>>>>
> > > >>>>>
> > > >>>>>
> > > >>>>> On Tue, Mar 27, 2018 at 4:38 PM, John Roesler <john@confluent.io
> >
> > > >>>>>
> > > >>>> wrote:
> > > >>>
> > > >>>> Thanks for the response, Dong.
> > > >>>>>>
> > > >>>>>> Here are my answers to your questions:
> > > >>>>>>
> > > >>>>>> - "Asking producers and consumers, or even two different
> > producers,
> > > >>>>>>
> > > >>>>> to
> > > >>>
> > > >>>> share code like the partition function is a pretty huge ask. What
> > > >>>>>>>
> > > >>>>>> if
> > > >>>
> > > >>>> they
> > > >>>>>
> > > >>>>>> are using different languages?". It seems that today we already
> > > >>>>>>>
> > > >>>>>> require
> > > >>>>
> > > >>>>> different producer's to use the same hash function -- otherwise
> > > >>>>>>>
> > > >>>>>> messages
> > > >>>>>
> > > >>>>>> with the same key will go to different partitions of the same
> > topic
> > > >>>>>>>
> > > >>>>>> which
> > > >>>>>
> > > >>>>>> may cause problem for downstream consumption. So not sure if it
> > > >>>>>>>
> > > >>>>>> adds
> > > >>>
> > > >>>> any
> > > >>>>>
> > > >>>>>> more constraint by assuming consumers know the hash function of
> > > >>>>>>>
> > > >>>>>> producer.
> > > >>>>>
> > > >>>>>> Could you explain more why user would want to use a cusmtom
> > > >>>>>>>
> > > >>>>>> partition
> > > >>>
> > > >>>> function? Maybe we can check if this is something that can be
> > > >>>>>>>
> > > >>>>>> supported
> > > >>>>
> > > >>>>> in
> > > >>>>>>
> > > >>>>>>> the default Kafka hash function. Also, can you explain more why
> > it
> > > >>>>>>>
> > > >>>>>> is
> > > >>>
> > > >>>> difficuilt to implement the same hash function in different
> > > >>>>>>>
> > > >>>>>> languages?
> > > >>>>
> > > >>>>>
> > > >>>>>> Sorry, I meant two different producers as in producers to two
> > > >>>>>>
> > > >>>>> different
> > > >>>
> > > >>>> topics. This was in response to the suggestion that we already
> > > >>>>>>
> > > >>>>> require
> > > >>>
> > > >>>> coordination among producers to different topics in order to
> achieve
> > > >>>>>> co-partitioning. I was saying that we do not (and should not).
> > > >>>>>>
> > > >>>>>
> > > >>>>> It is probably common for producers of different team to produce
> > > >>>>>
> > > >>>> message
> > > >>>
> > > >>>> to
> > > >>>>
> > > >>>>> the same topic. In order to ensure that messages with the same
> key
> > go
> > > >>>>>
> > > >>>> to
> > > >>>
> > > >>>> same partition, we need producers of different team to share the
> > same
> > > >>>>> partition algorithm, which by definition requires coordination
> > among
> > > >>>>> producers of different teams in an organization. Even for
> producers
> > > of
> > > >>>>> different topics, it may be common to require producers to use
> the
> > > same
> > > >>>>> partition algorithm in order to join two topics for stream
> > > processing.
> > > >>>>>
> > > >>>> Does
> > > >>>>
> > > >>>>> this make it reasonable to say we already require coordination
> > across
> > > >>>>> producers?
> > > >>>>>
> > > >>>>>
> > > >>>>> By design, consumers are currently ignorant of the partitioning
> > > >>>>>>
> > > >>>>> scheme.
> > > >>>
> > > >>>> It
> > > >>>>>
> > > >>>>>> suffices to trust that the producer has partitioned the topic by
> > > key,
> > > >>>>>>
> > > >>>>> if
> > > >>>>
> > > >>>>> they claim to have done so. If you don't trust that, or even if
> you
> > > >>>>>>
> > > >>>>> just
> > > >>>>
> > > >>>>> need some other partitioning scheme, then you must re-partition
> it
> > > >>>>>> yourself. Nothing we're discussing can or should change that.
> The
> > > >>>>>>
> > > >>>>> value
> > > >>>
> > > >>>> of
> > > >>>>>
> > > >>>>>> backfill is that it preserves the ability for consumers to avoid
> > > >>>>>> re-partitioning before consuming, in the case where they don't
> > need
> > > >>>>>>
> > > >>>>> to
> > > >>>
> > > >>>> today.
> > > >>>>>>
> > > >>>>>
> > > >>>>> Regarding shared "hash functions", note that it's a bit
> inaccurate
> > to
> > > >>>>>>
> > > >>>>> talk
> > > >>>>>
> > > >>>>>> about the "hash function" of the producer. Properly speaking,
> the
> > > >>>>>>
> > > >>>>> producer
> > > >>>>>
> > > >>>>>> has only a "partition function". We do not know that it is a
> hash.
> > > >>>>>>
> > > >>>>> The
> > > >>>
> > > >>>> producer can use any method at their disposal to assign a
> partition
> > > >>>>>>
> > > >>>>> to
> > > >>>
> > > >>>> a
> > > >>>>
> > > >>>>> record. The partition function obviously may we written in any
> > > >>>>>>
> > > >>>>> programming
> > > >>>>>
> > > >>>>>> language, so in general it's not something that can be shared
> > around
> > > >>>>>> without a formal spec or the ability to execute arbitrary
> > > executables
> > > >>>>>>
> > > >>>>> in
> > > >>>>
> > > >>>>> arbitrary runtime environments.
> > > >>>>>>
> > > >>>>>> Yeah it is probably better to say partition algorithm. I guess
> it
> > > >>>>>
> > > >>>> should
> > > >>>
> > > >>>> not be difficult to implement same partition algorithms in
> different
> > > >>>>> languages, right? Yes we would need a formal specification of the
> > > >>>>>
> > > >>>> default
> > > >>>
> > > >>>> partition algorithm in the producer. I think that can be
> documented
> > as
> > > >>>>>
> > > >>>> part
> > > >>>>
> > > >>>>> of the producer interface.
> > > >>>>>
> > > >>>>>
> > > >>>>> Why would a producer want a custom partition function? I don't
> > > >>>>>>
> > > >>>>> know...
> > > >>>
> > > >>>> why
> > > >>>>>
> > > >>>>>> did we design the interface so that our users can provide one?
> In
> > > >>>>>>
> > > >>>>> general,
> > > >>>>>
> > > >>>>>> such systems provide custom partitioners because some data sets
> > may
> > > >>>>>>
> > > >>>>> be
> > > >>>
> > > >>>> unbalanced under the default or because they can provide some
> > > >>>>>>
> > > >>>>> interesting
> > > >>>>
> > > >>>>> functionality built on top of the partitioning scheme, etc.
> Having
> > > >>>>>>
> > > >>>>> provided
> > > >>>>>
> > > >>>>>> this ability, I don't know why we would remove it.
> > > >>>>>>
> > > >>>>>> Yeah it is reasonable to assume that there was reason to support
> > > >>>>> custom
> > > >>>>> partition function in producer. On the other hand it may also be
> > > >>>>>
> > > >>>> reasonable
> > > >>>>
> > > >>>>> to revisit this interface and discuss whether we actually need to
> > > >>>>>
> > > >>>> support
> > > >>>
> > > >>>> custom partition function. If we don't have a good reason, we can
> > > >>>>>
> > > >>>> choose
> > > >>>
> > > >>>> not to support custom partition function in this KIP in a backward
> > > >>>>> compatible manner, i.e. user can still use custom partition
> > function
> > > >>>>>
> > > >>>> but
> > > >>>
> > > >>>> they would not get the benefit of in-order delivery when there is
> > > >>>>>
> > > >>>> partition
> > > >>>>
> > > >>>>> expansion. What do you think?
> > > >>>>>
> > > >>>>>
> > > >>>>> - Besides the assumption that consumer needs to share the hash
> > > >>>>>>
> > > >>>>> function
> > > >>>
> > > >>>> of
> > > >>>>>
> > > >>>>>> producer, is there other organization overhead of the proposal
> in
> > > >>>>>>>
> > > >>>>>> the
> > > >>>
> > > >>>> current KIP?
> > > >>>>>>>
> > > >>>>>>> It wasn't clear to me that KIP-253 currently required the
> > producer
> > > >>>>>>
> > > >>>>> and
> > > >>>
> > > >>>> consumer to share the partition function, or in fact that it had a
> > > >>>>>>
> > > >>>>> hard
> > > >>>
> > > >>>> requirement to abandon the general partition function and use a
> > > >>>>>>
> > > >>>>> linear
> > > >>>
> > > >>>> hash
> > > >>>>>
> > > >>>>>> function instead.
> > > >>>>>>
> > > >>>>>
> > > >>>>> In my reading, there is a requirement to track the metadata about
> > > >>>>>>
> > > >>>>> what
> > > >>>
> > > >>>> partitions split into what other partitions during an expansion
> > > >>>>>>
> > > >>>>> operation.
> > > >>>>>
> > > >>>>>> If the partition function is linear, this is easy. If not, you
> can
> > > >>>>>>
> > > >>>>> always
> > > >>>>
> > > >>>>> just record that all old partitions split into all new
> partitions.
> > > >>>>>>
> > > >>>>> This
> > > >>>
> > > >>>> has
> > > >>>>>
> > > >>>>>> the effect of forcing all consumers to wait until the old epoch
> is
> > > >>>>>> completely consumed before starting on the new epoch. But this
> may
> > > >>>>>>
> > > >>>>> be a
> > > >>>
> > > >>>> reasonable tradeoff, and it doesn't otherwise alter your design.
> > > >>>>>>
> > > >>>>>> You only mention the consumer needing to know that the partition
> > > >>>>>>
> > > >>>>> function
> > > >>>>
> > > >>>>> is linear, not what the actual function is, so I don't think your
> > > >>>>>>
> > > >>>>> design
> > > >>>>
> > > >>>>> actually calls for sharing the function. Plus, really all the
> > > >>>>>>
> > > >>>>> consumer
> > > >>>
> > > >>>> needs is the metadata about what old-epoch partitions to wait for
> > > >>>>>>
> > > >>>>> before
> > > >>>>
> > > >>>>> consuming a new-epoch partition. This information is directly
> > > >>>>>>
> > > >>>>> captured
> > > >>>
> > > >>>> in
> > > >>>>
> > > >>>>> metadata, so I don't think it actually even cares whether the
> > > >>>>>>
> > > >>>>> partition
> > > >>>
> > > >>>> function is linear or not.
> > > >>>>>>
> > > >>>>>> You are right that the current KIP does not mention it. My
> comment
> > > >>>>>
> > > >>>> related
> > > >>>>
> > > >>>>> to the partition function coordination was related to support the
> > > >>>>> stream-use case which we have been discussing so far.
> > > >>>>>
> > > >>>>>
> > > >>>>> So, no, I really think KIP-253 is in good shape. I was really
> more
> > > >>>>>>
> > > >>>>> talking
> > > >>>>>
> > > >>>>>> about the part of this thread that's outside of KIP-253's scope,
> > > >>>>>>
> > > >>>>> namely,
> > > >>>>
> > > >>>>> creating the possibility of backfilling partitions after
> expansion.
> > > >>>>>>
> > > >>>>>> Great! Can you also confirm that the main motivation for
> > backfilling
> > > >>>>> partitions after expansion is to support the stream use-case?
> > > >>>>>
> > > >>>>>
> > > >>>>> - Currently producer can forget about the message that has been
> > > >>>>>>
> > > >>>>>>> acknowledged by the broker. Thus the producer probably does not
> > > >>>>>>>
> > > >>>>>> know
> > > >>>
> > > >>>> most
> > > >>>>>
> > > >>>>>> of the exiting messages in topic, including those messages
> > produced
> > > >>>>>>>
> > > >>>>>> by
> > > >>>>
> > > >>>>> other producers. We can have the owner of the producer to
> > > >>>>>>>
> > > >>>>>> split+backfill.
> > > >>>>>
> > > >>>>>> In my opion it will be a new program that wraps around the
> > existing
> > > >>>>>>> producer and consumer classes.
> > > >>>>>>>
> > > >>>>>>> This sounds fine by me!
> > > >>>>>>
> > > >>>>>> Really, I was just emphasizing that the part of the organization
> > > that
> > > >>>>>> produces a topic shouldn't have to export their partition
> function
> > > to
> > > >>>>>>
> > > >>>>> the
> > > >>>>
> > > >>>>> part(s) of the organization (or other organizations) that consume
> > the
> > > >>>>>> topic. Whether the backfill operation goes into the Producer
> > > >>>>>>
> > > >>>>> interface
> > > >>>
> > > >>>> is
> > > >>>>
> > > >>>>> secondary, I think.
> > > >>>>>>
> > > >>>>>> - Regarding point 5. The argument is in favor of the
> > split+backfill
> > > >>>>>>
> > > >>>>> but
> > > >>>
> > > >>>> for
> > > >>>>>
> > > >>>>>> changelog topic. And it intends to address the problem for
> stream
> > > >>>>>>>
> > > >>>>>> use-case
> > > >>>>>>
> > > >>>>>>> in general. In this KIP we will provide interface (i.e.
> > > >>>>>>> PartitionKeyRebalanceListener in the KIP) to be used by sream
> > > >>>>>>>
> > > >>>>>> use-case
> > > >>>>
> > > >>>>> and
> > > >>>>>>
> > > >>>>>>> the goal is that user can flush/re-consume the state as part of
> > the
> > > >>>>>>> interface implementation regardless of whether there is change
> > log
> > > >>>>>>>
> > > >>>>>> topic.
> > > >>>>>
> > > >>>>>> Maybe you are suggesting that the main reason to do
> split+backfill
> > > >>>>>>>
> > > >>>>>> of
> > > >>>
> > > >>>> input
> > > >>>>>>
> > > >>>>>>> topic is to support log compacted topics? You mentioned in
> Point
> > 1
> > > >>>>>>>
> > > >>>>>> that
> > > >>>>
> > > >>>>> log
> > > >>>>>>
> > > >>>>>>> compacted topics is out of the scope of this KIP. Maybe I could
> > > >>>>>>>
> > > >>>>>> understand
> > > >>>>>>
> > > >>>>>>> your position better. Regarding Jan's proposal to split
> > partitions
> > > >>>>>>>
> > > >>>>>> with
> > > >>>>
> > > >>>>> backfill, do you think this should replace the proposal in the
> > > >>>>>>>
> > > >>>>>> existing
> > > >>>>
> > > >>>>> KIP, or do you think this is something that we should do in
> > > >>>>>>>
> > > >>>>>> addition
> > > >>>
> > > >>>> to
> > > >>>>
> > > >>>>> the
> > > >>>>>>
> > > >>>>>>> existing KIP?
> > > >>>>>>>
> > > >>>>>>> I think that interface is a good/necessary component of
> KIP-253.
> > > >>>>>>
> > > >>>>>> I personally (FWIW) feel that KIP-253 is appropriately scoped,
> > but I
> > > >>>>>>
> > > >>>>> do
> > > >>>
> > > >>>> think its utility will be limited unless there is a later KIP
> > > >>>>>>
> > > >>>>> offering
> > > >>>
> > > >>>> backfill. But, maybe unlike Jan, I think it makes sense to try and
> > > >>>>>>
> > > >>>>> tackle
> > > >>>>
> > > >>>>> the ordering problem independently of backfill, so I'm in support
> > of
> > > >>>>>>
> > > >>>>> the
> > > >>>>
> > > >>>>> current KIP.
> > > >>>>>>
> > > >>>>>> - Regarding point 6. I guess we can agree that it is better not
> to
> > > >>>>>>
> > > >>>>> have
> > > >>>
> > > >>>> the
> > > >>>>>
> > > >>>>>> performance overhread of copying the input data. Before we
> discuss
> > > >>>>>>>
> > > >>>>>> more
> > > >>>>
> > > >>>>> on
> > > >>>>>>
> > > >>>>>>> whether the performance overhead is acceptable or not, I am
> > trying
> > > >>>>>>>
> > > >>>>>> to
> > > >>>
> > > >>>> figure out what is the benefit of introducing this overhread. You
> > > >>>>>>>
> > > >>>>>> mentioned
> > > >>>>>>
> > > >>>>>>> that the benefit is the loose organizational coupling. By
> > > >>>>>>>
> > > >>>>>> "organizational
> > > >>>>>
> > > >>>>>> coupling", are you referring to the requirement that consumer
> > needs
> > > >>>>>>>
> > > >>>>>> to
> > > >>>>
> > > >>>>> know
> > > >>>>>>
> > > >>>>>>> the hash function of producer? If so, maybe we can discuss the
> > > >>>>>>>
> > > >>>>>> use-case
> > > >>>>
> > > >>>>> of
> > > >>>>>>
> > > >>>>>>> custom partiton function and see whether we can find a way to
> > > >>>>>>>
> > > >>>>>> support
> > > >>>
> > > >>>> such
> > > >>>>>>
> > > >>>>>>> use-case without having to copy the input data.
> > > >>>>>>>
> > > >>>>>>> I'm not too sure about what an "input" is in this sense, since
> we
> > > are
> > > >>>>>>
> > > >>>>> just
> > > >>>>>
> > > >>>>>> talking about topics. Actually the point I was making there is
> > that
> > > >>>>>>
> > > >>>>> AKAICT
> > > >>>>>
> > > >>>>>> the performance overhead of a backfill is less than any other
> > > option,
> > > >>>>>> assuming you split partitions rarely.
> > > >>>>>>
> > > >>>>>> By "input" I was referring to source Kafka topic of a stream
> > > >>>>> processing
> > > >>>>> job.
> > > >>>>>
> > > >>>>>
> > > >>>>> Separately, yes, "organizational coupling" increases if producers
> > and
> > > >>>>>> consumers have to share code, such as the partition function.
> This
> > > >>>>>>
> > > >>>>> would
> > > >>>>
> > > >>>>> not be the case if producers could only pick from a menu of a few
> > > >>>>>> well-known partition functions, but I think this is a poor
> > tradeoff.
> > > >>>>>>
> > > >>>>>> Maybe we can revisit the custom partition function and see
> whether
> > > we
> > > >>>>> actually need it? Otherwise, I am concerned that every user will
> > pay
> > > >>>>>
> > > >>>> the
> > > >>>
> > > >>>> overhead of data movement to support something that was not really
> > > >>>>>
> > > >>>> needed
> > > >>>
> > > >>>> for most users.
> > > >>>>>
> > > >>>>>
> > > >>>>> To me, this is two strong arguments in favor of backfill being
> less
> > > >>>>>> expensive than no backfill, but again, I think that particular
> > > debate
> > > >>>>>>
> > > >>>>> comes
> > > >>>>>
> > > >>>>>> after KIP-253, so I don't want to create the impression of
> > > opposition
> > > >>>>>>
> > > >>>>> to
> > > >>>>
> > > >>>>> your proposal.
> > > >>>>>>
> > > >>>>>>
> > > >>>>>> Finally, to respond to a new email I just noticed:
> > > >>>>>>
> > > >>>>>> BTW, here is my understanding of the scope of this KIP. We want
> to
> > > >>>>>>>
> > > >>>>>> allow
> > > >>>>>
> > > >>>>>> consumers to always consume messages with the same key from the
> > > >>>>>>>
> > > >>>>>> same
> > > >>>
> > > >>>> producer in the order they are produced. And we need to provide a
> > > >>>>>>>
> > > >>>>>> way
> > > >>>
> > > >>>> for
> > > >>>>>
> > > >>>>>> stream use-case to be able to flush/load state when messages
> with
> > > >>>>>>>
> > > >>>>>> the
> > > >>>
> > > >>>> same
> > > >>>>>>
> > > >>>>>>> key are migrated between consumers. In addition to ensuring
> that
> > > >>>>>>>
> > > >>>>>> this
> > > >>>
> > > >>>> goal
> > > >>>>>>
> > > >>>>>>> is correctly supported, we should do our best to keep the
> > > >>>>>>>
> > > >>>>>> performance
> > > >>>
> > > >>>> and
> > > >>>>>
> > > >>>>>> organization overhead of this KIP as low as possible.
> > > >>>>>>>
> > > >>>>>>> I think we're on the same page there! In fact, I would
> > generalize a
> > > >>>>>>
> > > >>>>> little
> > > >>>>>
> > > >>>>>> more and say that the mechanism you've designed provides *all
> > > >>>>>>
> > > >>>>> consumers*
> > > >>>>
> > > >>>>> the ability "to flush/load state when messages with the same key
> > are
> > > >>>>>> migrated between consumers", not just Streams.
> > > >>>>>>
> > > >>>>>> Thanks for all the comment!
> > > >>>>>
> > > >>>>>
> > > >>>>> Thanks for the discussion,
> > > >>>>>> -John
> > > >>>>>>
> > > >>>>>>
> > > >>>>>>
> > > >>>>>> On Tue, Mar 27, 2018 at 3:14 PM, Dong Lin <li...@gmail.com>
> > > >>>>>>
> > > >>>>> wrote:
> > > >>>
> > > >>>> Hey John,
> > > >>>>>>>
> > > >>>>>>> Thanks much for the detailed comments. Here are my thoughts:
> > > >>>>>>>
> > > >>>>>>> - The need to delete messages from log compacted topics is
> mainly
> > > >>>>>>>
> > > >>>>>> for
> > > >>>
> > > >>>> performance (e.g. storage space) optimization than for correctness
> > > >>>>>>>
> > > >>>>>> for
> > > >>>>
> > > >>>>> this
> > > >>>>>>
> > > >>>>>>> KIP. I agree that we probably don't need to focus on this in
> our
> > > >>>>>>>
> > > >>>>>> discussion
> > > >>>>>>
> > > >>>>>>> since it is mostly for performance optimization.
> > > >>>>>>>
> > > >>>>>>> - "Asking producers and consumers, or even two different
> > producers,
> > > >>>>>>>
> > > >>>>>> to
> > > >>>>
> > > >>>>> share code like the partition function is a pretty huge ask. What
> > > >>>>>>>
> > > >>>>>> if
> > > >>>
> > > >>>> they
> > > >>>>>
> > > >>>>>> are using different languages?". It seems that today we already
> > > >>>>>>>
> > > >>>>>> require
> > > >>>>
> > > >>>>> different producer's to use the same hash function -- otherwise
> > > >>>>>>>
> > > >>>>>> messages
> > > >>>>>
> > > >>>>>> with the same key will go to different partitions of the same
> > topic
> > > >>>>>>>
> > > >>>>>> which
> > > >>>>>
> > > >>>>>> may cause problem for downstream consumption. So not sure if it
> > > >>>>>>>
> > > >>>>>> adds
> > > >>>
> > > >>>> any
> > > >>>>>
> > > >>>>>> more constraint by assuming consumers know the hash function of
> > > >>>>>>>
> > > >>>>>> producer.
> > > >>>>>
> > > >>>>>> Could you explain more why user would want to use a cusmtom
> > > >>>>>>>
> > > >>>>>> partition
> > > >>>
> > > >>>> function? Maybe we can check if this is something that can be
> > > >>>>>>>
> > > >>>>>> supported
> > > >>>>
> > > >>>>> in
> > > >>>>>>
> > > >>>>>>> the default Kafka hash function. Also, can you explain more why
> > it
> > > >>>>>>>
> > > >>>>>> is
> > > >>>
> > > >>>> difficuilt to implement the same hash function in different
> > > >>>>>>>
> > > >>>>>> languages?
> > > >>>>
> > > >>>>> - Besides the assumption that consumer needs to share the hash
> > > >>>>>>>
> > > >>>>>> function
> > > >>>>
> > > >>>>> of
> > > >>>>>>
> > > >>>>>>> producer, is there other organization overhead of the proposal
> in
> > > >>>>>>>
> > > >>>>>> the
> > > >>>
> > > >>>> current KIP?
> > > >>>>>>>
> > > >>>>>>> - Currently producer can forget about the message that has been
> > > >>>>>>> acknowledged by the broker. Thus the producer probably does not
> > > >>>>>>>
> > > >>>>>> know
> > > >>>
> > > >>>> most
> > > >>>>>
> > > >>>>>> of the exiting messages in topic, including those messages
> > produced
> > > >>>>>>>
> > > >>>>>> by
> > > >>>>
> > > >>>>> other producers. We can have the owner of the producer to
> > > >>>>>>>
> > > >>>>>> split+backfill.
> > > >>>>>
> > > >>>>>> In my opion it will be a new program that wraps around the
> > existing
> > > >>>>>>> producer and consumer classes.
> > > >>>>>>>
> > > >>>>>>> - Regarding point 5. The argument is in favor of the
> > split+backfill
> > > >>>>>>>
> > > >>>>>> but
> > > >>>>
> > > >>>>> for
> > > >>>>>>
> > > >>>>>>> changelog topic. And it intends to address the problem for
> stream
> > > >>>>>>>
> > > >>>>>> use-case
> > > >>>>>>
> > > >>>>>>> in general. In this KIP we will provide interface (i.e.
> > > >>>>>>> PartitionKeyRebalanceListener in the KIP) to be used by sream
> > > >>>>>>>
> > > >>>>>> use-case
> > > >>>>
> > > >>>>> and
> > > >>>>>>
> > > >>>>>>> the goal is that user can flush/re-consume the state as part of
> > the
> > > >>>>>>> interface implementation regardless of whether there is change
> > log
> > > >>>>>>>
> > > >>>>>> topic.
> > > >>>>>
> > > >>>>>> Maybe you are suggesting that the main reason to do
> split+backfill
> > > >>>>>>>
> > > >>>>>> of
> > > >>>
> > > >>>> input
> > > >>>>>>
> > > >>>>>>> topic is to support log compacted topics? You mentioned in
> Point
> > 1
> > > >>>>>>>
> > > >>>>>> that
> > > >>>>
> > > >>>>> log
> > > >>>>>>
> > > >>>>>>> compacted topics is out of the scope of this KIP. Maybe I could
> > > >>>>>>>
> > > >>>>>> understand
> > > >>>>>>
> > > >>>>>>> your position better. Regarding Jan's proposal to split
> > partitions
> > > >>>>>>>
> > > >>>>>> with
> > > >>>>
> > > >>>>> backfill, do you think this should replace the proposal in the
> > > >>>>>>>
> > > >>>>>> existing
> > > >>>>
> > > >>>>> KIP, or do you think this is something that we should do in
> > > >>>>>>>
> > > >>>>>> addition
> > > >>>
> > > >>>> to
> > > >>>>
> > > >>>>> the
> > > >>>>>>
> > > >>>>>>> existing KIP?
> > > >>>>>>>
> > > >>>>>>> - Regarding point 6. I guess we can agree that it is better not
> > to
> > > >>>>>>>
> > > >>>>>> have
> > > >>>>
> > > >>>>> the
> > > >>>>>>
> > > >>>>>>> performance overhread of copying the input data. Before we
> > discuss
> > > >>>>>>>
> > > >>>>>> more
> > > >>>>
> > > >>>>> on
> > > >>>>>>
> > > >>>>>>> whether the performance overhead is acceptable or not, I am
> > trying
> > > >>>>>>>
> > > >>>>>> to
> > > >>>
> > > >>>> figure out what is the benefit of introducing this overhread. You
> > > >>>>>>>
> > > >>>>>> mentioned
> > > >>>>>>
> > > >>>>>>> that the benefit is the loose organizational coupling. By
> > > >>>>>>>
> > > >>>>>> "organizational
> > > >>>>>
> > > >>>>>> coupling", are you referring to the requirement that consumer
> > needs
> > > >>>>>>>
> > > >>>>>> to
> > > >>>>
> > > >>>>> know
> > > >>>>>>
> > > >>>>>>> the hash function of producer? If so, maybe we can discuss the
> > > >>>>>>>
> > > >>>>>> use-case
> > > >>>>
> > > >>>>> of
> > > >>>>>>
> > > >>>>>>> custom partiton function and see whether we can find a way to
> > > >>>>>>>
> > > >>>>>> support
> > > >>>
> > > >>>> such
> > > >>>>>>
> > > >>>>>>> use-case without having to copy the input data.
> > > >>>>>>>
> > > >>>>>>> Thanks,
> > > >>>>>>> Dong
> > > >>>>>>>
> > > >>>>>>>
> > > >>>>>>> On Tue, Mar 27, 2018 at 11:34 AM, John Roesler <
> > john@confluent.io>
> > > >>>>>>>
> > > >>>>>> wrote:
> > > >>>>>>
> > > >>>>>>> Hey Dong and Jun,
> > > >>>>>>>>
> > > >>>>>>>> Thanks for the thoughtful responses. If you don't mind, I'll
> mix
> > > >>>>>>>>
> > > >>>>>>> my
> > > >>>
> > > >>>> replies
> > > >>>>>>>
> > > >>>>>>>> together to try for a coherent response. I'm not too familiar
> > > >>>>>>>>
> > > >>>>>>> with
> > > >>>
> > > >>>> mailing-list etiquette, though.
> > > >>>>>>>>
> > > >>>>>>>> I'm going to keep numbering my points because it makes it easy
> > > >>>>>>>>
> > > >>>>>>> for
> > > >>>
> > > >>>> you
> > > >>>>>
> > > >>>>>> all
> > > >>>>>>>
> > > >>>>>>>> to respond.
> > > >>>>>>>>
> > > >>>>>>>> Point 1:
> > > >>>>>>>> As I read it, KIP-253 is *just* about properly fencing the
> > > >>>>>>>>
> > > >>>>>>> producers
> > > >>>>
> > > >>>>> and
> > > >>>>>>
> > > >>>>>>> consumers so that you preserve the correct ordering of records
> > > >>>>>>>>
> > > >>>>>>> during
> > > >>>>
> > > >>>>> partition expansion. This is clearly necessary regardless of
> > > >>>>>>>>
> > > >>>>>>> anything
> > > >>>>
> > > >>>>> else
> > > >>>>>>>
> > > >>>>>>>> we discuss. I think this whole discussion about backfill,
> > > >>>>>>>>
> > > >>>>>>> consumers,
> > > >>>>
> > > >>>>> streams, etc., is beyond the scope of KIP-253. But it would be
> > > >>>>>>>>
> > > >>>>>>> cumbersome
> > > >>>>>>
> > > >>>>>>> to start a new thread at this point.
> > > >>>>>>>>
> > > >>>>>>>> I had missed KIP-253's Proposed Change #9 among all the
> > > >>>>>>>>
> > > >>>>>>> details...
> > > >>>
> > > >>>> I
> > > >>>>
> > > >>>>> think
> > > >>>>>>>
> > > >>>>>>>> this is a nice addition to the proposal. One thought is that
> > it's
> > > >>>>>>>>
> > > >>>>>>> actually
> > > >>>>>>>
> > > >>>>>>>> irrelevant whether the hash function is linear. This is simply
> > an
> > > >>>>>>>>
> > > >>>>>>> algorithm
> > > >>>>>>>
> > > >>>>>>>> for moving a key from one partition to another, so the type of
> > > >>>>>>>>
> > > >>>>>>> hash
> > > >>>
> > > >>>> function need not be a precondition. In fact, it also doesn't
> > > >>>>>>>>
> > > >>>>>>> matter
> > > >>>>
> > > >>>>> whether the topic is compacted or not, the algorithm works
> > > >>>>>>>>
> > > >>>>>>> regardless.
> > > >>>>>
> > > >>>>>> I think this is a good algorithm to keep in mind, as it might
> > > >>>>>>>>
> > > >>>>>>> solve a
> > > >>>>
> > > >>>>> variety of problems, but it does have a downside: that the
> > > >>>>>>>>
> > > >>>>>>> producer
> > > >>>
> > > >>>> won't
> > > >>>>>>
> > > >>>>>>> know whether or not K1 was actually in P1, it just knows that
> K1
> > > >>>>>>>>
> > > >>>>>>> was
> > > >>>>
> > > >>>>> in
> > > >>>>>
> > > >>>>>> P1's keyspace before the new epoch. Therefore, it will have to
> > > >>>>>>>> pessimistically send (K1,null) to P1 just in case. But the
> next
> > > >>>>>>>>
> > > >>>>>>> time
> > > >>>>
> > > >>>>> K1
> > > >>>>>
> > > >>>>>> comes along, the producer *also* won't remember that it already
> > > >>>>>>>>
> > > >>>>>>> retracted
> > > >>>>>>
> > > >>>>>>> K1 from P1, so it will have to send (K1,null) *again*. By
> > > >>>>>>>>
> > > >>>>>>> extension,
> > > >>>>
> > > >>>>> every
> > > >>>>>>>
> > > >>>>>>>> time the producer sends to P2, it will also have to send a
> > > >>>>>>>>
> > > >>>>>>> tombstone
> > > >>>>
> > > >>>>> to
> > > >>>>>
> > > >>>>>> P1,
> > > >>>>>>>
> > > >>>>>>>> which is a pretty big burden. To make the situation worse, if
> > > >>>>>>>>
> > > >>>>>>> there
> > > >>>
> > > >>>> is
> > > >>>>>
> > > >>>>>> a
> > > >>>>>>
> > > >>>>>>> second split, say P2 becomes P2 and P3, then any key Kx
> belonging
> > > >>>>>>>>
> > > >>>>>>> to
> > > >>>>
> > > >>>>> P3
> > > >>>>>
> > > >>>>>> will also have to be retracted from P2 *and* P1, since the
> > > >>>>>>>>
> > > >>>>>>> producer
> > > >>>
> > > >>>> can't
> > > >>>>>>
> > > >>>>>>> know whether Kx had been last written to P2 or P1. Over a long
> > > >>>>>>>>
> > > >>>>>>> period
> > > >>>>
> > > >>>>> of
> > > >>>>>>
> > > >>>>>>> time, this clearly becomes a issue, as the producer must send
> an
> > > >>>>>>>>
> > > >>>>>>> arbitrary
> > > >>>>>>>
> > > >>>>>>>> number of retractions along with every update.
> > > >>>>>>>>
> > > >>>>>>>> In contrast, the proposed backfill operation has an end, and
> > > >>>>>>>>
> > > >>>>>>> after
> > > >>>
> > > >>>> it
> > > >>>>
> > > >>>>> ends,
> > > >>>>>>>
> > > >>>>>>>> everyone can afford to forget that there ever was a different
> > > >>>>>>>>
> > > >>>>>>> partition
> > > >>>>>
> > > >>>>>> layout.
> > > >>>>>>>>
> > > >>>>>>>> Really, though, figuring out how to split compacted topics is
> > > >>>>>>>>
> > > >>>>>>> beyond
> > > >>>>
> > > >>>>> the
> > > >>>>>>
> > > >>>>>>> scope of KIP-253, so I'm not sure #9 really even needs to be in
> > > >>>>>>>>
> > > >>>>>>> this
> > > >>>>
> > > >>>>> KIP...
> > > >>>>>>>
> > > >>>>>>>> We do need in-order delivery during partition expansion. It
> > would
> > > >>>>>>>>
> > > >>>>>>> be
> > > >>>>
> > > >>>>> fine
> > > >>>>>>
> > > >>>>>>> by me to say that you *cannot* expand partitions of a
> > > >>>>>>>>
> > > >>>>>>> log-compacted
> > > >>>
> > > >>>> topic
> > > >>>>>>
> > > >>>>>>> and call it a day. I think it would be better to tackle that in
> > > >>>>>>>>
> > > >>>>>>> another
> > > >>>>>
> > > >>>>>> KIP.
> > > >>>>>>>>
> > > >>>>>>>>
> > > >>>>>>>> Point 2:
> > > >>>>>>>> Regarding whether the consumer re-shuffles its inputs, this is
> > > >>>>>>>>
> > > >>>>>>> always
> > > >>>>
> > > >>>>> on
> > > >>>>>>
> > > >>>>>>> the table; any consumer who wants to re-shuffle its input is
> free
> > > >>>>>>>>
> > > >>>>>>> to
> > > >>>>
> > > >>>>> do
> > > >>>>>
> > > >>>>>> so.
> > > >>>>>>>
> > > >>>>>>>> But this is currently not required. It's just that the current
> > > >>>>>>>>
> > > >>>>>>> high-level
> > > >>>>>>
> > > >>>>>>> story with Kafka encourages the use of partitions as a unit of
> > > >>>>>>>>
> > > >>>>>>> concurrency.
> > > >>>>>>>
> > > >>>>>>>> As long as consumers are single-threaded, they can happily
> > > >>>>>>>>
> > > >>>>>>> consume
> > > >>>
> > > >>>> a
> > > >>>>
> > > >>>>> single
> > > >>>>>>>
> > > >>>>>>>> partition without concurrency control of any kind. This is a
> key
> > > >>>>>>>>
> > > >>>>>>> aspect
> > > >>>>>
> > > >>>>>> to
> > > >>>>>>>
> > > >>>>>>>> this system that lets folks design high-throughput systems on
> > top
> > > >>>>>>>>
> > > >>>>>>> of
> > > >>>>
> > > >>>>> it
> > > >>>>>
> > > >>>>>> surprisingly easily. If all consumers were instead
> > > >>>>>>>>
> > > >>>>>>> encouraged/required
> > > >>>>>
> > > >>>>>> to
> > > >>>>>>
> > > >>>>>>> implement a repartition of their own, then the consumer becomes
> > > >>>>>>>> significantly more complex, requiring either the consumer to
> > > >>>>>>>>
> > > >>>>>>> first
> > > >>>
> > > >>>> produce
> > > >>>>>>>
> > > >>>>>>>> to its own intermediate repartition topic or to ensure that
> > > >>>>>>>>
> > > >>>>>>> consumer
> > > >>>>
> > > >>>>> threads have a reliable, high-bandwith channel of communication
> > > >>>>>>>>
> > > >>>>>>> with
> > > >>>>
> > > >>>>> every
> > > >>>>>>>
> > > >>>>>>>> other consumer thread.
> > > >>>>>>>>
> > > >>>>>>>> Either of those tradeoffs may be reasonable for a particular
> > user
> > > >>>>>>>>
> > > >>>>>>> of
> > > >>>>
> > > >>>>> Kafka,
> > > >>>>>>>
> > > >>>>>>>> but I don't know if we're in a position to say that they are
> > > >>>>>>>>
> > > >>>>>>> reasonable
> > > >>>>>
> > > >>>>>> for
> > > >>>>>>>
> > > >>>>>>>> *every* user of Kafka.
> > > >>>>>>>>
> > > >>>>>>>>
> > > >>>>>>>> Point 3:
> > > >>>>>>>> Regarding Jun's point about this use case, "(3) stateful and
> > > >>>>>>>>
> > > >>>>>>> maintaining
> > > >>>>>>
> > > >>>>>>> the
> > > >>>>>>>> states in a local store", I agree that they may use a
> framework
> > > >>>>>>>>
> > > >>>>>>> *like*
> > > >>>>>
> > > >>>>>> Kafka Streams, but that is not the same as using Kafka Streams.
> > > >>>>>>>>
> > > >>>>>>> This
> > > >>>>
> > > >>>>> is
> > > >>>>>
> > > >>>>>> why
> > > >>>>>>>
> > > >>>>>>>> I think it's better to solve it in Core: because it is then
> > > >>>>>>>>
> > > >>>>>>> solved
> > > >>>
> > > >>>> for
> > > >>>>>
> > > >>>>>> KStreams and also for everything else that facilitates local
> > > >>>>>>>>
> > > >>>>>>> state
> > > >>>
> > > >>>> maintenance. To me, Streams is a member of the category of
> > > >>>>>>>>
> > > >>>>>>> "stream
> > > >>>
> > > >>>> processing frameworks", which is itself a subcategory of "things
> > > >>>>>>>>
> > > >>>>>>> requiring
> > > >>>>>>>
> > > >>>>>>>> local state maintenence". I'm not sure if it makes sense to
> > > >>>>>>>
> > > >>>>>>>
> > >
> >
>
>
>
> --
> -- Guozhang
>

Re: [DISCUSS] KIP-253: Support in-order message delivery with partition expansion

Posted by Guozhang Wang <wa...@gmail.com>.
@Jun, yeah that works for me too.

@Jan, just to clarify on my previous email: assuming we do the reshuffling
out of the user input topics, Streams has the advantage that the
repartition topic is purely owned by itself: the only producer writing to
this repartition topic is Streams itself; so then we can change the split
the number of partitions of the repartition without requiring to expand the
input topics. And since the reshuffling task itself is stateless, it does
not require key partitioning preservation. So as I mentioned, it is indeed
not dependent on KIP-253 itself as KIP-254 is primarily for expanding an
input topic for consumer applications.


Guozhang

On Wed, Apr 4, 2018 at 4:01 PM, Dong Lin <li...@gmail.com> wrote:

> Thanks Jun! The time works for me.
>
>
> On Thu, 5 Apr 2018 at 4:34 AM Jun Rao <ju...@confluent.io> wrote:
>
> > Hi, Jan, Dong, John, Guozhang,
> >
> > Perhaps it will be useful to have a KIP meeting to discuss this together
> as
> > a group. Would Apr. 9 (Monday) at 9:00am PDT work? If so, I will send out
> > an invite to the mailing list.
> >
> > Thanks,
> >
> > Jun
> >
> >
> > On Wed, Apr 4, 2018 at 1:25 AM, Jan Filipiak <Ja...@trivago.com>
> > wrote:
> >
> > > Want to quickly step in here again because it is going places again.
> > >
> > > The last part of the discussion is just a pain to read and completely
> > > diverged from what I suggested without making the reasons clear to me.
> > >
> > > I don't know why this happens.... here are my comments anyway.
> > >
> > > @Guozhang: That Streams is working on automatic creating
> > > copartition-usuable topics: great for streams, has literally nothing
> todo
> > > with the KIP as we want to grow the
> > > input topic. Everyone can reshuffle rel. easily but that is not what we
> > > need todo, we need to grow the topic in question. After streams
> > > automatically reshuffled the input topic
> > > still has the same size and it didn't help a bit. I fail to see why
> this
> > > is relevant. What am i missing here?
> > >
> > > @Dong
> > > I am still on the position that the current proposal brings us into the
> > > wrong direction. Especially introducing PartitionKeyRebalanceListener
> > > From this point we can never move away to proper state full handling
> > > without completely deprecating this creature from hell again.
> > > Linear hashing is not the optimising step we have todo here. An
> interface
> > > that when a topic is a topic its always the same even after it had
> > > grown or shrunk is important. So from my POV I have major concerns that
> > > this KIP is benefitial in its current state.
> > >
> > > What is it that makes everyone so addicted to the idea of linear
> hashing?
> > > not attractive at all for me.
> > > And with statefull consumers still a complete mess. Why not stick with
> > the
> > > Kappa architecture???
> > >
> > >
> > >
> > >
> > >
> > > On 03.04.2018 17:38, Dong Lin wrote:
> > >
> > >> Hey John,
> > >>
> > >> Thanks much for your comments!!
> > >>
> > >> I have yet to go through the emails of John/Jun/Guozhang in detail.
> But
> > >> let
> > >> me present my idea for how to minimize the delay for state loading for
> > >> stream use-case.
> > >>
> > >> For ease of understanding, let's assume that the initial partition
> > number
> > >> of input topics and change log topic are both 10. And initial number
> of
> > >> stream processor is also 10. If we only increase initial partition
> > number
> > >> of input topics to 15 without changing number of stream processor, the
> > >> current KIP already guarantees in-order delivery and no state needs to
> > be
> > >> moved between consumers for stream use-case. Next, let's say we want
> to
> > >> increase the number of processor to expand the processing capacity for
> > >> stream use-case. This requires us to move state between processors
> which
> > >> will take time. Our goal is to minimize the impact (i.e. delay) for
> > >> processing while we increase the number of processors.
> > >>
> > >> Note that stream processor generally includes both consumer and
> > producer.
> > >> In addition to consume from the input topic, consumer may also need to
> > >> consume from change log topic on startup for recovery. And producer
> may
> > >> produce state to the change log topic.
> > >>
> > >>
> > > The solution will include the following steps:
> > >>
> > >> 1) Increase partition number of the input topic from 10 to 15. Since
> the
> > >> messages with the same key will still go to the same consume before
> and
> > >> after the partition expansion, this step can be done without having to
> > >> move
> > >> state between processors.
> > >>
> > >> 2) Increase partition number of the change log topic from 10 to 15.
> Note
> > >> that this step can also be done without impacting existing workflow.
> > After
> > >> we increase partition number of the change log topic, key space may
> > split
> > >> and some key will be produced to the newly-added partition. But the
> same
> > >> key will still go to the same processor (i.e. consumer) before and
> after
> > >> the partition. Thus this step can also be done without having to move
> > >> state
> > >> between processors.
> > >>
> > >> 3) Now, let's add 5 new consumers whose groupId is different from the
> > >> existing processor's groupId. Thus these new consumers will not impact
> > >> existing workflow. Each of these new consumers should consume two
> > >> partitions from the earliest offset, where these two partitions are
> the
> > >> same partitions that will be consumed if the consumers have the same
> > >> groupId as the existing processor's groupId. For example, the first of
> > the
> > >> five consumers will consume partition 0 and partition 10. The purpose
> of
> > >> these consumers is to rebuild the state (e.g. RocksDB) for the
> > processors
> > >> in advance. Also note that, by design of the current KIP, each consume
> > >> will
> > >> consume the existing partition of the change log topic up to the
> offset
> > >> before the partition expansion. Then they will only need to consume
> the
> > >> state of the new partition of the change log topic.
> > >>
> > >> 4) After consumers have caught up in step 3), we should stop these
> > >> consumers and add 5 new processors to the stream processing job.
> These 5
> > >> new processors should run in the same location as the previous 5
> > consumers
> > >> to re-use the state (e.g. RocksDB). And these processors' consumers
> > should
> > >> consume partitions of the change log topic from the committed offset
> the
> > >> previous 5 consumers so that no state is missed.
> > >>
> > >> One important trick to note here is that, the mapping from partition
> to
> > >> consumer should also use linear hashing. And we need to remember the
> > >> initial number of processors in the job, 10 in this example, and use
> > this
> > >> number in the linear hashing algorithm. This is pretty much the same
> as
> > >> how
> > >> we use linear hashing to map key to partition. In this case, we get an
> > >> identity map from partition -> processor, for both input topic and the
> > >> change log topic. For example, processor 12 will consume partition 12
> of
> > >> the input topic and produce state to the partition 12 of the change
> log
> > >> topic.
> > >>
> > >> There are a few important properties of this solution to note:
> > >>
> > >> - We can increase the number of partitions for input topic and the
> > change
> > >> log topic in any order asynchronously.
> > >> - The expansion of the processors in a given job in step 4) only
> > requires
> > >> the step 3) for the same job. It does not require coordination across
> > >> different jobs for step 3) and 4). Thus different jobs can
> independently
> > >> expand there capacity without waiting for each other.
> > >> - The logic for 1) and 2) is already supported in the current KIP. The
> > >> logic for 3) and 4) appears to be independent of the core Kafka logic
> > and
> > >> can be implemented separately outside core Kafka. Thus the current KIP
> > is
> > >> probably sufficient after we agree on the efficiency and the
> correctness
> > >> of
> > >> the solution. We can have a separate KIP for Kafka Stream to support
> 3)
> > >> and
> > >> 4).
> > >>
> > >>
> > >> Cheers,
> > >> Dong
> > >>
> > >>
> > >> On Mon, Apr 2, 2018 at 3:25 PM, Guozhang Wang <wa...@gmail.com>
> > wrote:
> > >>
> > >> Hey guys, just sharing my two cents here (I promise it will be shorter
> > >>> than
> > >>> John's article :).
> > >>>
> > >>> 0. Just to quickly recap, the main discussion point now is how to
> > support
> > >>> "key partitioning preservation" (John's #4 in topic characteristics
> > >>> above)
> > >>> beyond the "single-key ordering preservation" that KIP-253 was
> > originally
> > >>> proposed to maintain (John's #6 above).
> > >>>
> > >>> 1. From the streams project, we are actively working on improving the
> > >>> elastic scalability of the library. One of the key features is to
> > >>> decouple
> > >>> the input topics from the parallelism model of Streams: i.e. not
> > >>> enforcing
> > >>> the topic to be partitioned by the key, not enforcing joining topics
> to
> > >>> be
> > >>> co-partitioned, not relying the number of parallel tasks on the input
> > >>> topic
> > >>> partitions. This can be achieved by re-shuffling on the input topics
> to
> > >>> make sure key-partitioning / co-partitioning on the internal topics.
> > Note
> > >>> the re-shuffling task is purely stateless and hence does not require
> > "key
> > >>> partitioning preservation". Operational-wise it is similar to the
> > >>> "creating
> > >>> a new topic with new number of partitions, pipe the data to the new
> > topic
> > >>> and cut over consumers from old topics" idea, just that users can
> > >>> optionally let Streams to handle such rather than doing it manually
> > >>> themselves. There are a few more details on that regard but I will
> skip
> > >>> since they are not directly related to this discussion.
> > >>>
> > >>> 2. Assuming that 1) above is done, then the only topics involved in
> the
> > >>> scaling events are all input topics. For these topics the only
> > producers
> > >>> /
> > >>> consumers of these topics are controlled by Streams clients
> themselves,
> > >>> and
> > >>> hence achieving "key partitioning preservation" is simpler than
> > >>> non-Streams
> > >>> scenarios: consumers know the partitioning scheme that producers are
> > >>> using,
> > >>> so that for their stateful operations it is doable to split the local
> > >>> state
> > >>> stores accordingly or execute backfilling on its own. Of course, if
> we
> > >>> decide to do server-side backfilling, it can still help Streams to
> > >>> directly
> > >>> rely on that functionality.
> > >>>
> > >>> 3. As John mentioned, another way inside Streams is to do
> > >>> over-partitioning
> > >>> on all internal topics; then with 1) Streams would not rely on
> KIP-253
> > at
> > >>> all. But personally I'd like to avoid it if possible to reduce Kafka
> > side
> > >>> footprint: say we overpartition each input topic up to 1k, with a
> > >>> reasonable sized stateful topology it can still contribute to tens of
> > >>> thousands of topics to the topic partition capacity of a single
> > cluster.
> > >>>
> > >>> 4. Summing up 1/2/3, I think we should focus more on non-Streams
> users
> > >>> writing their stateful computations with local states, and think
> > whether
> > >>> /
> > >>> how we could enable "key partitioning preservation" for them easily,
> > than
> > >>> to think heavily for Streams library. People may have different
> opinion
> > >>> on
> > >>> how common of a usage pattern it is (I think Jun might be suggesting
> > that
> > >>> for DIY apps people may more likely use remote states so that it is
> > not a
> > >>> problem for them). My opinion is that for non-Streams users such
> usage
> > >>> pattern could still be large (think: if you are piping data from
> Kafka
> > to
> > >>> an external data storage which has single-writer requirements for
> each
> > >>> single shard, even though it is not a stateful computational
> > application
> > >>> it
> > >>> may still require "key partitioning preservation"), so I prefer to
> have
> > >>> backfilling in our KIP than only exposing the API for expansion and
> > >>> requires consumers to have pre-knowledge of the producer's
> partitioning
> > >>> scheme.
> > >>>
> > >>>
> > >>>
> > >>> Guozhang
> > >>>
> > >>>
> > >>>
> > >>> On Thu, Mar 29, 2018 at 2:33 PM, John Roesler <jo...@confluent.io>
> > wrote:
> > >>>
> > >>> Hey Dong,
> > >>>>
> > >>>> Congrats on becoming a committer!!!
> > >>>>
> > >>>> Since I just sent a novel-length email, I'll try and keep this one
> > brief
> > >>>>
> > >>> ;)
> > >>>
> > >>>> Regarding producer coordination, I'll grant that in that case,
> > producers
> > >>>> may coordinate among themselves to produce into the same topic or to
> > >>>> produce co-partitioned topics. Nothing in KStreams or the Kafka
> > >>>> ecosystem
> > >>>> in general requires such coordination for correctness or in fact for
> > any
> > >>>> optional features, though, so I would not say that we require
> producer
> > >>>> coordination of partition logic. If producers currently coordinate,
> > it's
> > >>>> completely optional and their own choice.
> > >>>>
> > >>>> Regarding the portability of partition algorithms, my observation is
> > >>>> that
> > >>>> systems requiring independent implementations of the same algorithm
> > with
> > >>>> 100% correctness are a large source of risk and also a burden on
> those
> > >>>>
> > >>> who
> > >>>
> > >>>> have to maintain them. If people could flawlessly implement
> algorithms
> > >>>> in
> > >>>> actual software, the world would be a wonderful place indeed! For a
> > >>>>
> > >>> system
> > >>>
> > >>>> as important and widespread as Kafka, I would recommend restricting
> > >>>> limiting such requirements as aggressively as possible.
> > >>>>
> > >>>> I'd agree that we can always revisit decisions like allowing
> arbitrary
> > >>>> partition functions, but of course, we shouldn't do that in a
> vacuum.
> > >>>>
> > >>> That
> > >>>
> > >>>> feels like the kind of thing we'd need to proactively seek guidance
> > from
> > >>>> the users list about. I do think that the general approach of saying
> > >>>> that
> > >>>> "if you use a custom partitioner, you cannot do partition expansion"
> > is
> > >>>> very reasonable (but I don't think we need to go that far with the
> > >>>>
> > >>> current
> > >>>
> > >>>> proposal). It's similar to my statement in my email to Jun that in
> > >>>> principle KStreams doesn't *need* backfill, we only need it if we
> want
> > >>>> to
> > >>>> employ partition expansion.
> > >>>>
> > >>>> I reckon that the main motivation for backfill is to support
> KStreams
> > >>>> use
> > >>>> cases and also any other use cases involving stateful consumers.
> > >>>>
> > >>>> Thanks for your response, and congrats again!
> > >>>> -John
> > >>>>
> > >>>>
> > >>>> On Wed, Mar 28, 2018 at 1:34 AM, Dong Lin <li...@gmail.com>
> > wrote:
> > >>>>
> > >>>> Hey John,
> > >>>>>
> > >>>>> Great! Thanks for all the comment. It seems that we agree that the
> > >>>>>
> > >>>> current
> > >>>>
> > >>>>> KIP is in good shape for core Kafka. IMO, what we have been
> > discussing
> > >>>>>
> > >>>> in
> > >>>
> > >>>> the recent email exchanges is mostly about the second step, i.e. how
> > to
> > >>>>> address problem for the stream use-case (or stateful processing in
> > >>>>> general).
> > >>>>>
> > >>>>> I will comment inline.
> > >>>>>
> > >>>>>
> > >>>>>
> > >>>>>
> > >>>>> On Tue, Mar 27, 2018 at 4:38 PM, John Roesler <jo...@confluent.io>
> > >>>>>
> > >>>> wrote:
> > >>>
> > >>>> Thanks for the response, Dong.
> > >>>>>>
> > >>>>>> Here are my answers to your questions:
> > >>>>>>
> > >>>>>> - "Asking producers and consumers, or even two different
> producers,
> > >>>>>>
> > >>>>> to
> > >>>
> > >>>> share code like the partition function is a pretty huge ask. What
> > >>>>>>>
> > >>>>>> if
> > >>>
> > >>>> they
> > >>>>>
> > >>>>>> are using different languages?". It seems that today we already
> > >>>>>>>
> > >>>>>> require
> > >>>>
> > >>>>> different producer's to use the same hash function -- otherwise
> > >>>>>>>
> > >>>>>> messages
> > >>>>>
> > >>>>>> with the same key will go to different partitions of the same
> topic
> > >>>>>>>
> > >>>>>> which
> > >>>>>
> > >>>>>> may cause problem for downstream consumption. So not sure if it
> > >>>>>>>
> > >>>>>> adds
> > >>>
> > >>>> any
> > >>>>>
> > >>>>>> more constraint by assuming consumers know the hash function of
> > >>>>>>>
> > >>>>>> producer.
> > >>>>>
> > >>>>>> Could you explain more why user would want to use a cusmtom
> > >>>>>>>
> > >>>>>> partition
> > >>>
> > >>>> function? Maybe we can check if this is something that can be
> > >>>>>>>
> > >>>>>> supported
> > >>>>
> > >>>>> in
> > >>>>>>
> > >>>>>>> the default Kafka hash function. Also, can you explain more why
> it
> > >>>>>>>
> > >>>>>> is
> > >>>
> > >>>> difficuilt to implement the same hash function in different
> > >>>>>>>
> > >>>>>> languages?
> > >>>>
> > >>>>>
> > >>>>>> Sorry, I meant two different producers as in producers to two
> > >>>>>>
> > >>>>> different
> > >>>
> > >>>> topics. This was in response to the suggestion that we already
> > >>>>>>
> > >>>>> require
> > >>>
> > >>>> coordination among producers to different topics in order to achieve
> > >>>>>> co-partitioning. I was saying that we do not (and should not).
> > >>>>>>
> > >>>>>
> > >>>>> It is probably common for producers of different team to produce
> > >>>>>
> > >>>> message
> > >>>
> > >>>> to
> > >>>>
> > >>>>> the same topic. In order to ensure that messages with the same key
> go
> > >>>>>
> > >>>> to
> > >>>
> > >>>> same partition, we need producers of different team to share the
> same
> > >>>>> partition algorithm, which by definition requires coordination
> among
> > >>>>> producers of different teams in an organization. Even for producers
> > of
> > >>>>> different topics, it may be common to require producers to use the
> > same
> > >>>>> partition algorithm in order to join two topics for stream
> > processing.
> > >>>>>
> > >>>> Does
> > >>>>
> > >>>>> this make it reasonable to say we already require coordination
> across
> > >>>>> producers?
> > >>>>>
> > >>>>>
> > >>>>> By design, consumers are currently ignorant of the partitioning
> > >>>>>>
> > >>>>> scheme.
> > >>>
> > >>>> It
> > >>>>>
> > >>>>>> suffices to trust that the producer has partitioned the topic by
> > key,
> > >>>>>>
> > >>>>> if
> > >>>>
> > >>>>> they claim to have done so. If you don't trust that, or even if you
> > >>>>>>
> > >>>>> just
> > >>>>
> > >>>>> need some other partitioning scheme, then you must re-partition it
> > >>>>>> yourself. Nothing we're discussing can or should change that. The
> > >>>>>>
> > >>>>> value
> > >>>
> > >>>> of
> > >>>>>
> > >>>>>> backfill is that it preserves the ability for consumers to avoid
> > >>>>>> re-partitioning before consuming, in the case where they don't
> need
> > >>>>>>
> > >>>>> to
> > >>>
> > >>>> today.
> > >>>>>>
> > >>>>>
> > >>>>> Regarding shared "hash functions", note that it's a bit inaccurate
> to
> > >>>>>>
> > >>>>> talk
> > >>>>>
> > >>>>>> about the "hash function" of the producer. Properly speaking, the
> > >>>>>>
> > >>>>> producer
> > >>>>>
> > >>>>>> has only a "partition function". We do not know that it is a hash.
> > >>>>>>
> > >>>>> The
> > >>>
> > >>>> producer can use any method at their disposal to assign a partition
> > >>>>>>
> > >>>>> to
> > >>>
> > >>>> a
> > >>>>
> > >>>>> record. The partition function obviously may we written in any
> > >>>>>>
> > >>>>> programming
> > >>>>>
> > >>>>>> language, so in general it's not something that can be shared
> around
> > >>>>>> without a formal spec or the ability to execute arbitrary
> > executables
> > >>>>>>
> > >>>>> in
> > >>>>
> > >>>>> arbitrary runtime environments.
> > >>>>>>
> > >>>>>> Yeah it is probably better to say partition algorithm. I guess it
> > >>>>>
> > >>>> should
> > >>>
> > >>>> not be difficult to implement same partition algorithms in different
> > >>>>> languages, right? Yes we would need a formal specification of the
> > >>>>>
> > >>>> default
> > >>>
> > >>>> partition algorithm in the producer. I think that can be documented
> as
> > >>>>>
> > >>>> part
> > >>>>
> > >>>>> of the producer interface.
> > >>>>>
> > >>>>>
> > >>>>> Why would a producer want a custom partition function? I don't
> > >>>>>>
> > >>>>> know...
> > >>>
> > >>>> why
> > >>>>>
> > >>>>>> did we design the interface so that our users can provide one? In
> > >>>>>>
> > >>>>> general,
> > >>>>>
> > >>>>>> such systems provide custom partitioners because some data sets
> may
> > >>>>>>
> > >>>>> be
> > >>>
> > >>>> unbalanced under the default or because they can provide some
> > >>>>>>
> > >>>>> interesting
> > >>>>
> > >>>>> functionality built on top of the partitioning scheme, etc. Having
> > >>>>>>
> > >>>>> provided
> > >>>>>
> > >>>>>> this ability, I don't know why we would remove it.
> > >>>>>>
> > >>>>>> Yeah it is reasonable to assume that there was reason to support
> > >>>>> custom
> > >>>>> partition function in producer. On the other hand it may also be
> > >>>>>
> > >>>> reasonable
> > >>>>
> > >>>>> to revisit this interface and discuss whether we actually need to
> > >>>>>
> > >>>> support
> > >>>
> > >>>> custom partition function. If we don't have a good reason, we can
> > >>>>>
> > >>>> choose
> > >>>
> > >>>> not to support custom partition function in this KIP in a backward
> > >>>>> compatible manner, i.e. user can still use custom partition
> function
> > >>>>>
> > >>>> but
> > >>>
> > >>>> they would not get the benefit of in-order delivery when there is
> > >>>>>
> > >>>> partition
> > >>>>
> > >>>>> expansion. What do you think?
> > >>>>>
> > >>>>>
> > >>>>> - Besides the assumption that consumer needs to share the hash
> > >>>>>>
> > >>>>> function
> > >>>
> > >>>> of
> > >>>>>
> > >>>>>> producer, is there other organization overhead of the proposal in
> > >>>>>>>
> > >>>>>> the
> > >>>
> > >>>> current KIP?
> > >>>>>>>
> > >>>>>>> It wasn't clear to me that KIP-253 currently required the
> producer
> > >>>>>>
> > >>>>> and
> > >>>
> > >>>> consumer to share the partition function, or in fact that it had a
> > >>>>>>
> > >>>>> hard
> > >>>
> > >>>> requirement to abandon the general partition function and use a
> > >>>>>>
> > >>>>> linear
> > >>>
> > >>>> hash
> > >>>>>
> > >>>>>> function instead.
> > >>>>>>
> > >>>>>
> > >>>>> In my reading, there is a requirement to track the metadata about
> > >>>>>>
> > >>>>> what
> > >>>
> > >>>> partitions split into what other partitions during an expansion
> > >>>>>>
> > >>>>> operation.
> > >>>>>
> > >>>>>> If the partition function is linear, this is easy. If not, you can
> > >>>>>>
> > >>>>> always
> > >>>>
> > >>>>> just record that all old partitions split into all new partitions.
> > >>>>>>
> > >>>>> This
> > >>>
> > >>>> has
> > >>>>>
> > >>>>>> the effect of forcing all consumers to wait until the old epoch is
> > >>>>>> completely consumed before starting on the new epoch. But this may
> > >>>>>>
> > >>>>> be a
> > >>>
> > >>>> reasonable tradeoff, and it doesn't otherwise alter your design.
> > >>>>>>
> > >>>>>> You only mention the consumer needing to know that the partition
> > >>>>>>
> > >>>>> function
> > >>>>
> > >>>>> is linear, not what the actual function is, so I don't think your
> > >>>>>>
> > >>>>> design
> > >>>>
> > >>>>> actually calls for sharing the function. Plus, really all the
> > >>>>>>
> > >>>>> consumer
> > >>>
> > >>>> needs is the metadata about what old-epoch partitions to wait for
> > >>>>>>
> > >>>>> before
> > >>>>
> > >>>>> consuming a new-epoch partition. This information is directly
> > >>>>>>
> > >>>>> captured
> > >>>
> > >>>> in
> > >>>>
> > >>>>> metadata, so I don't think it actually even cares whether the
> > >>>>>>
> > >>>>> partition
> > >>>
> > >>>> function is linear or not.
> > >>>>>>
> > >>>>>> You are right that the current KIP does not mention it. My comment
> > >>>>>
> > >>>> related
> > >>>>
> > >>>>> to the partition function coordination was related to support the
> > >>>>> stream-use case which we have been discussing so far.
> > >>>>>
> > >>>>>
> > >>>>> So, no, I really think KIP-253 is in good shape. I was really more
> > >>>>>>
> > >>>>> talking
> > >>>>>
> > >>>>>> about the part of this thread that's outside of KIP-253's scope,
> > >>>>>>
> > >>>>> namely,
> > >>>>
> > >>>>> creating the possibility of backfilling partitions after expansion.
> > >>>>>>
> > >>>>>> Great! Can you also confirm that the main motivation for
> backfilling
> > >>>>> partitions after expansion is to support the stream use-case?
> > >>>>>
> > >>>>>
> > >>>>> - Currently producer can forget about the message that has been
> > >>>>>>
> > >>>>>>> acknowledged by the broker. Thus the producer probably does not
> > >>>>>>>
> > >>>>>> know
> > >>>
> > >>>> most
> > >>>>>
> > >>>>>> of the exiting messages in topic, including those messages
> produced
> > >>>>>>>
> > >>>>>> by
> > >>>>
> > >>>>> other producers. We can have the owner of the producer to
> > >>>>>>>
> > >>>>>> split+backfill.
> > >>>>>
> > >>>>>> In my opion it will be a new program that wraps around the
> existing
> > >>>>>>> producer and consumer classes.
> > >>>>>>>
> > >>>>>>> This sounds fine by me!
> > >>>>>>
> > >>>>>> Really, I was just emphasizing that the part of the organization
> > that
> > >>>>>> produces a topic shouldn't have to export their partition function
> > to
> > >>>>>>
> > >>>>> the
> > >>>>
> > >>>>> part(s) of the organization (or other organizations) that consume
> the
> > >>>>>> topic. Whether the backfill operation goes into the Producer
> > >>>>>>
> > >>>>> interface
> > >>>
> > >>>> is
> > >>>>
> > >>>>> secondary, I think.
> > >>>>>>
> > >>>>>> - Regarding point 5. The argument is in favor of the
> split+backfill
> > >>>>>>
> > >>>>> but
> > >>>
> > >>>> for
> > >>>>>
> > >>>>>> changelog topic. And it intends to address the problem for stream
> > >>>>>>>
> > >>>>>> use-case
> > >>>>>>
> > >>>>>>> in general. In this KIP we will provide interface (i.e.
> > >>>>>>> PartitionKeyRebalanceListener in the KIP) to be used by sream
> > >>>>>>>
> > >>>>>> use-case
> > >>>>
> > >>>>> and
> > >>>>>>
> > >>>>>>> the goal is that user can flush/re-consume the state as part of
> the
> > >>>>>>> interface implementation regardless of whether there is change
> log
> > >>>>>>>
> > >>>>>> topic.
> > >>>>>
> > >>>>>> Maybe you are suggesting that the main reason to do split+backfill
> > >>>>>>>
> > >>>>>> of
> > >>>
> > >>>> input
> > >>>>>>
> > >>>>>>> topic is to support log compacted topics? You mentioned in Point
> 1
> > >>>>>>>
> > >>>>>> that
> > >>>>
> > >>>>> log
> > >>>>>>
> > >>>>>>> compacted topics is out of the scope of this KIP. Maybe I could
> > >>>>>>>
> > >>>>>> understand
> > >>>>>>
> > >>>>>>> your position better. Regarding Jan's proposal to split
> partitions
> > >>>>>>>
> > >>>>>> with
> > >>>>
> > >>>>> backfill, do you think this should replace the proposal in the
> > >>>>>>>
> > >>>>>> existing
> > >>>>
> > >>>>> KIP, or do you think this is something that we should do in
> > >>>>>>>
> > >>>>>> addition
> > >>>
> > >>>> to
> > >>>>
> > >>>>> the
> > >>>>>>
> > >>>>>>> existing KIP?
> > >>>>>>>
> > >>>>>>> I think that interface is a good/necessary component of KIP-253.
> > >>>>>>
> > >>>>>> I personally (FWIW) feel that KIP-253 is appropriately scoped,
> but I
> > >>>>>>
> > >>>>> do
> > >>>
> > >>>> think its utility will be limited unless there is a later KIP
> > >>>>>>
> > >>>>> offering
> > >>>
> > >>>> backfill. But, maybe unlike Jan, I think it makes sense to try and
> > >>>>>>
> > >>>>> tackle
> > >>>>
> > >>>>> the ordering problem independently of backfill, so I'm in support
> of
> > >>>>>>
> > >>>>> the
> > >>>>
> > >>>>> current KIP.
> > >>>>>>
> > >>>>>> - Regarding point 6. I guess we can agree that it is better not to
> > >>>>>>
> > >>>>> have
> > >>>
> > >>>> the
> > >>>>>
> > >>>>>> performance overhread of copying the input data. Before we discuss
> > >>>>>>>
> > >>>>>> more
> > >>>>
> > >>>>> on
> > >>>>>>
> > >>>>>>> whether the performance overhead is acceptable or not, I am
> trying
> > >>>>>>>
> > >>>>>> to
> > >>>
> > >>>> figure out what is the benefit of introducing this overhread. You
> > >>>>>>>
> > >>>>>> mentioned
> > >>>>>>
> > >>>>>>> that the benefit is the loose organizational coupling. By
> > >>>>>>>
> > >>>>>> "organizational
> > >>>>>
> > >>>>>> coupling", are you referring to the requirement that consumer
> needs
> > >>>>>>>
> > >>>>>> to
> > >>>>
> > >>>>> know
> > >>>>>>
> > >>>>>>> the hash function of producer? If so, maybe we can discuss the
> > >>>>>>>
> > >>>>>> use-case
> > >>>>
> > >>>>> of
> > >>>>>>
> > >>>>>>> custom partiton function and see whether we can find a way to
> > >>>>>>>
> > >>>>>> support
> > >>>
> > >>>> such
> > >>>>>>
> > >>>>>>> use-case without having to copy the input data.
> > >>>>>>>
> > >>>>>>> I'm not too sure about what an "input" is in this sense, since we
> > are
> > >>>>>>
> > >>>>> just
> > >>>>>
> > >>>>>> talking about topics. Actually the point I was making there is
> that
> > >>>>>>
> > >>>>> AKAICT
> > >>>>>
> > >>>>>> the performance overhead of a backfill is less than any other
> > option,
> > >>>>>> assuming you split partitions rarely.
> > >>>>>>
> > >>>>>> By "input" I was referring to source Kafka topic of a stream
> > >>>>> processing
> > >>>>> job.
> > >>>>>
> > >>>>>
> > >>>>> Separately, yes, "organizational coupling" increases if producers
> and
> > >>>>>> consumers have to share code, such as the partition function. This
> > >>>>>>
> > >>>>> would
> > >>>>
> > >>>>> not be the case if producers could only pick from a menu of a few
> > >>>>>> well-known partition functions, but I think this is a poor
> tradeoff.
> > >>>>>>
> > >>>>>> Maybe we can revisit the custom partition function and see whether
> > we
> > >>>>> actually need it? Otherwise, I am concerned that every user will
> pay
> > >>>>>
> > >>>> the
> > >>>
> > >>>> overhead of data movement to support something that was not really
> > >>>>>
> > >>>> needed
> > >>>
> > >>>> for most users.
> > >>>>>
> > >>>>>
> > >>>>> To me, this is two strong arguments in favor of backfill being less
> > >>>>>> expensive than no backfill, but again, I think that particular
> > debate
> > >>>>>>
> > >>>>> comes
> > >>>>>
> > >>>>>> after KIP-253, so I don't want to create the impression of
> > opposition
> > >>>>>>
> > >>>>> to
> > >>>>
> > >>>>> your proposal.
> > >>>>>>
> > >>>>>>
> > >>>>>> Finally, to respond to a new email I just noticed:
> > >>>>>>
> > >>>>>> BTW, here is my understanding of the scope of this KIP. We want to
> > >>>>>>>
> > >>>>>> allow
> > >>>>>
> > >>>>>> consumers to always consume messages with the same key from the
> > >>>>>>>
> > >>>>>> same
> > >>>
> > >>>> producer in the order they are produced. And we need to provide a
> > >>>>>>>
> > >>>>>> way
> > >>>
> > >>>> for
> > >>>>>
> > >>>>>> stream use-case to be able to flush/load state when messages with
> > >>>>>>>
> > >>>>>> the
> > >>>
> > >>>> same
> > >>>>>>
> > >>>>>>> key are migrated between consumers. In addition to ensuring that
> > >>>>>>>
> > >>>>>> this
> > >>>
> > >>>> goal
> > >>>>>>
> > >>>>>>> is correctly supported, we should do our best to keep the
> > >>>>>>>
> > >>>>>> performance
> > >>>
> > >>>> and
> > >>>>>
> > >>>>>> organization overhead of this KIP as low as possible.
> > >>>>>>>
> > >>>>>>> I think we're on the same page there! In fact, I would
> generalize a
> > >>>>>>
> > >>>>> little
> > >>>>>
> > >>>>>> more and say that the mechanism you've designed provides *all
> > >>>>>>
> > >>>>> consumers*
> > >>>>
> > >>>>> the ability "to flush/load state when messages with the same key
> are
> > >>>>>> migrated between consumers", not just Streams.
> > >>>>>>
> > >>>>>> Thanks for all the comment!
> > >>>>>
> > >>>>>
> > >>>>> Thanks for the discussion,
> > >>>>>> -John
> > >>>>>>
> > >>>>>>
> > >>>>>>
> > >>>>>> On Tue, Mar 27, 2018 at 3:14 PM, Dong Lin <li...@gmail.com>
> > >>>>>>
> > >>>>> wrote:
> > >>>
> > >>>> Hey John,
> > >>>>>>>
> > >>>>>>> Thanks much for the detailed comments. Here are my thoughts:
> > >>>>>>>
> > >>>>>>> - The need to delete messages from log compacted topics is mainly
> > >>>>>>>
> > >>>>>> for
> > >>>
> > >>>> performance (e.g. storage space) optimization than for correctness
> > >>>>>>>
> > >>>>>> for
> > >>>>
> > >>>>> this
> > >>>>>>
> > >>>>>>> KIP. I agree that we probably don't need to focus on this in our
> > >>>>>>>
> > >>>>>> discussion
> > >>>>>>
> > >>>>>>> since it is mostly for performance optimization.
> > >>>>>>>
> > >>>>>>> - "Asking producers and consumers, or even two different
> producers,
> > >>>>>>>
> > >>>>>> to
> > >>>>
> > >>>>> share code like the partition function is a pretty huge ask. What
> > >>>>>>>
> > >>>>>> if
> > >>>
> > >>>> they
> > >>>>>
> > >>>>>> are using different languages?". It seems that today we already
> > >>>>>>>
> > >>>>>> require
> > >>>>
> > >>>>> different producer's to use the same hash function -- otherwise
> > >>>>>>>
> > >>>>>> messages
> > >>>>>
> > >>>>>> with the same key will go to different partitions of the same
> topic
> > >>>>>>>
> > >>>>>> which
> > >>>>>
> > >>>>>> may cause problem for downstream consumption. So not sure if it
> > >>>>>>>
> > >>>>>> adds
> > >>>
> > >>>> any
> > >>>>>
> > >>>>>> more constraint by assuming consumers know the hash function of
> > >>>>>>>
> > >>>>>> producer.
> > >>>>>
> > >>>>>> Could you explain more why user would want to use a cusmtom
> > >>>>>>>
> > >>>>>> partition
> > >>>
> > >>>> function? Maybe we can check if this is something that can be
> > >>>>>>>
> > >>>>>> supported
> > >>>>
> > >>>>> in
> > >>>>>>
> > >>>>>>> the default Kafka hash function. Also, can you explain more why
> it
> > >>>>>>>
> > >>>>>> is
> > >>>
> > >>>> difficuilt to implement the same hash function in different
> > >>>>>>>
> > >>>>>> languages?
> > >>>>
> > >>>>> - Besides the assumption that consumer needs to share the hash
> > >>>>>>>
> > >>>>>> function
> > >>>>
> > >>>>> of
> > >>>>>>
> > >>>>>>> producer, is there other organization overhead of the proposal in
> > >>>>>>>
> > >>>>>> the
> > >>>
> > >>>> current KIP?
> > >>>>>>>
> > >>>>>>> - Currently producer can forget about the message that has been
> > >>>>>>> acknowledged by the broker. Thus the producer probably does not
> > >>>>>>>
> > >>>>>> know
> > >>>
> > >>>> most
> > >>>>>
> > >>>>>> of the exiting messages in topic, including those messages
> produced
> > >>>>>>>
> > >>>>>> by
> > >>>>
> > >>>>> other producers. We can have the owner of the producer to
> > >>>>>>>
> > >>>>>> split+backfill.
> > >>>>>
> > >>>>>> In my opion it will be a new program that wraps around the
> existing
> > >>>>>>> producer and consumer classes.
> > >>>>>>>
> > >>>>>>> - Regarding point 5. The argument is in favor of the
> split+backfill
> > >>>>>>>
> > >>>>>> but
> > >>>>
> > >>>>> for
> > >>>>>>
> > >>>>>>> changelog topic. And it intends to address the problem for stream
> > >>>>>>>
> > >>>>>> use-case
> > >>>>>>
> > >>>>>>> in general. In this KIP we will provide interface (i.e.
> > >>>>>>> PartitionKeyRebalanceListener in the KIP) to be used by sream
> > >>>>>>>
> > >>>>>> use-case
> > >>>>
> > >>>>> and
> > >>>>>>
> > >>>>>>> the goal is that user can flush/re-consume the state as part of
> the
> > >>>>>>> interface implementation regardless of whether there is change
> log
> > >>>>>>>
> > >>>>>> topic.
> > >>>>>
> > >>>>>> Maybe you are suggesting that the main reason to do split+backfill
> > >>>>>>>
> > >>>>>> of
> > >>>
> > >>>> input
> > >>>>>>
> > >>>>>>> topic is to support log compacted topics? You mentioned in Point
> 1
> > >>>>>>>
> > >>>>>> that
> > >>>>
> > >>>>> log
> > >>>>>>
> > >>>>>>> compacted topics is out of the scope of this KIP. Maybe I could
> > >>>>>>>
> > >>>>>> understand
> > >>>>>>
> > >>>>>>> your position better. Regarding Jan's proposal to split
> partitions
> > >>>>>>>
> > >>>>>> with
> > >>>>
> > >>>>> backfill, do you think this should replace the proposal in the
> > >>>>>>>
> > >>>>>> existing
> > >>>>
> > >>>>> KIP, or do you think this is something that we should do in
> > >>>>>>>
> > >>>>>> addition
> > >>>
> > >>>> to
> > >>>>
> > >>>>> the
> > >>>>>>
> > >>>>>>> existing KIP?
> > >>>>>>>
> > >>>>>>> - Regarding point 6. I guess we can agree that it is better not
> to
> > >>>>>>>
> > >>>>>> have
> > >>>>
> > >>>>> the
> > >>>>>>
> > >>>>>>> performance overhread of copying the input data. Before we
> discuss
> > >>>>>>>
> > >>>>>> more
> > >>>>
> > >>>>> on
> > >>>>>>
> > >>>>>>> whether the performance overhead is acceptable or not, I am
> trying
> > >>>>>>>
> > >>>>>> to
> > >>>
> > >>>> figure out what is the benefit of introducing this overhread. You
> > >>>>>>>
> > >>>>>> mentioned
> > >>>>>>
> > >>>>>>> that the benefit is the loose organizational coupling. By
> > >>>>>>>
> > >>>>>> "organizational
> > >>>>>
> > >>>>>> coupling", are you referring to the requirement that consumer
> needs
> > >>>>>>>
> > >>>>>> to
> > >>>>
> > >>>>> know
> > >>>>>>
> > >>>>>>> the hash function of producer? If so, maybe we can discuss the
> > >>>>>>>
> > >>>>>> use-case
> > >>>>
> > >>>>> of
> > >>>>>>
> > >>>>>>> custom partiton function and see whether we can find a way to
> > >>>>>>>
> > >>>>>> support
> > >>>
> > >>>> such
> > >>>>>>
> > >>>>>>> use-case without having to copy the input data.
> > >>>>>>>
> > >>>>>>> Thanks,
> > >>>>>>> Dong
> > >>>>>>>
> > >>>>>>>
> > >>>>>>> On Tue, Mar 27, 2018 at 11:34 AM, John Roesler <
> john@confluent.io>
> > >>>>>>>
> > >>>>>> wrote:
> > >>>>>>
> > >>>>>>> Hey Dong and Jun,
> > >>>>>>>>
> > >>>>>>>> Thanks for the thoughtful responses. If you don't mind, I'll mix
> > >>>>>>>>
> > >>>>>>> my
> > >>>
> > >>>> replies
> > >>>>>>>
> > >>>>>>>> together to try for a coherent response. I'm not too familiar
> > >>>>>>>>
> > >>>>>>> with
> > >>>
> > >>>> mailing-list etiquette, though.
> > >>>>>>>>
> > >>>>>>>> I'm going to keep numbering my points because it makes it easy
> > >>>>>>>>
> > >>>>>>> for
> > >>>
> > >>>> you
> > >>>>>
> > >>>>>> all
> > >>>>>>>
> > >>>>>>>> to respond.
> > >>>>>>>>
> > >>>>>>>> Point 1:
> > >>>>>>>> As I read it, KIP-253 is *just* about properly fencing the
> > >>>>>>>>
> > >>>>>>> producers
> > >>>>
> > >>>>> and
> > >>>>>>
> > >>>>>>> consumers so that you preserve the correct ordering of records
> > >>>>>>>>
> > >>>>>>> during
> > >>>>
> > >>>>> partition expansion. This is clearly necessary regardless of
> > >>>>>>>>
> > >>>>>>> anything
> > >>>>
> > >>>>> else
> > >>>>>>>
> > >>>>>>>> we discuss. I think this whole discussion about backfill,
> > >>>>>>>>
> > >>>>>>> consumers,
> > >>>>
> > >>>>> streams, etc., is beyond the scope of KIP-253. But it would be
> > >>>>>>>>
> > >>>>>>> cumbersome
> > >>>>>>
> > >>>>>>> to start a new thread at this point.
> > >>>>>>>>
> > >>>>>>>> I had missed KIP-253's Proposed Change #9 among all the
> > >>>>>>>>
> > >>>>>>> details...
> > >>>
> > >>>> I
> > >>>>
> > >>>>> think
> > >>>>>>>
> > >>>>>>>> this is a nice addition to the proposal. One thought is that
> it's
> > >>>>>>>>
> > >>>>>>> actually
> > >>>>>>>
> > >>>>>>>> irrelevant whether the hash function is linear. This is simply
> an
> > >>>>>>>>
> > >>>>>>> algorithm
> > >>>>>>>
> > >>>>>>>> for moving a key from one partition to another, so the type of
> > >>>>>>>>
> > >>>>>>> hash
> > >>>
> > >>>> function need not be a precondition. In fact, it also doesn't
> > >>>>>>>>
> > >>>>>>> matter
> > >>>>
> > >>>>> whether the topic is compacted or not, the algorithm works
> > >>>>>>>>
> > >>>>>>> regardless.
> > >>>>>
> > >>>>>> I think this is a good algorithm to keep in mind, as it might
> > >>>>>>>>
> > >>>>>>> solve a
> > >>>>
> > >>>>> variety of problems, but it does have a downside: that the
> > >>>>>>>>
> > >>>>>>> producer
> > >>>
> > >>>> won't
> > >>>>>>
> > >>>>>>> know whether or not K1 was actually in P1, it just knows that K1
> > >>>>>>>>
> > >>>>>>> was
> > >>>>
> > >>>>> in
> > >>>>>
> > >>>>>> P1's keyspace before the new epoch. Therefore, it will have to
> > >>>>>>>> pessimistically send (K1,null) to P1 just in case. But the next
> > >>>>>>>>
> > >>>>>>> time
> > >>>>
> > >>>>> K1
> > >>>>>
> > >>>>>> comes along, the producer *also* won't remember that it already
> > >>>>>>>>
> > >>>>>>> retracted
> > >>>>>>
> > >>>>>>> K1 from P1, so it will have to send (K1,null) *again*. By
> > >>>>>>>>
> > >>>>>>> extension,
> > >>>>
> > >>>>> every
> > >>>>>>>
> > >>>>>>>> time the producer sends to P2, it will also have to send a
> > >>>>>>>>
> > >>>>>>> tombstone
> > >>>>
> > >>>>> to
> > >>>>>
> > >>>>>> P1,
> > >>>>>>>
> > >>>>>>>> which is a pretty big burden. To make the situation worse, if
> > >>>>>>>>
> > >>>>>>> there
> > >>>
> > >>>> is
> > >>>>>
> > >>>>>> a
> > >>>>>>
> > >>>>>>> second split, say P2 becomes P2 and P3, then any key Kx belonging
> > >>>>>>>>
> > >>>>>>> to
> > >>>>
> > >>>>> P3
> > >>>>>
> > >>>>>> will also have to be retracted from P2 *and* P1, since the
> > >>>>>>>>
> > >>>>>>> producer
> > >>>
> > >>>> can't
> > >>>>>>
> > >>>>>>> know whether Kx had been last written to P2 or P1. Over a long
> > >>>>>>>>
> > >>>>>>> period
> > >>>>
> > >>>>> of
> > >>>>>>
> > >>>>>>> time, this clearly becomes a issue, as the producer must send an
> > >>>>>>>>
> > >>>>>>> arbitrary
> > >>>>>>>
> > >>>>>>>> number of retractions along with every update.
> > >>>>>>>>
> > >>>>>>>> In contrast, the proposed backfill operation has an end, and
> > >>>>>>>>
> > >>>>>>> after
> > >>>
> > >>>> it
> > >>>>
> > >>>>> ends,
> > >>>>>>>
> > >>>>>>>> everyone can afford to forget that there ever was a different
> > >>>>>>>>
> > >>>>>>> partition
> > >>>>>
> > >>>>>> layout.
> > >>>>>>>>
> > >>>>>>>> Really, though, figuring out how to split compacted topics is
> > >>>>>>>>
> > >>>>>>> beyond
> > >>>>
> > >>>>> the
> > >>>>>>
> > >>>>>>> scope of KIP-253, so I'm not sure #9 really even needs to be in
> > >>>>>>>>
> > >>>>>>> this
> > >>>>
> > >>>>> KIP...
> > >>>>>>>
> > >>>>>>>> We do need in-order delivery during partition expansion. It
> would
> > >>>>>>>>
> > >>>>>>> be
> > >>>>
> > >>>>> fine
> > >>>>>>
> > >>>>>>> by me to say that you *cannot* expand partitions of a
> > >>>>>>>>
> > >>>>>>> log-compacted
> > >>>
> > >>>> topic
> > >>>>>>
> > >>>>>>> and call it a day. I think it would be better to tackle that in
> > >>>>>>>>
> > >>>>>>> another
> > >>>>>
> > >>>>>> KIP.
> > >>>>>>>>
> > >>>>>>>>
> > >>>>>>>> Point 2:
> > >>>>>>>> Regarding whether the consumer re-shuffles its inputs, this is
> > >>>>>>>>
> > >>>>>>> always
> > >>>>
> > >>>>> on
> > >>>>>>
> > >>>>>>> the table; any consumer who wants to re-shuffle its input is free
> > >>>>>>>>
> > >>>>>>> to
> > >>>>
> > >>>>> do
> > >>>>>
> > >>>>>> so.
> > >>>>>>>
> > >>>>>>>> But this is currently not required. It's just that the current
> > >>>>>>>>
> > >>>>>>> high-level
> > >>>>>>
> > >>>>>>> story with Kafka encourages the use of partitions as a unit of
> > >>>>>>>>
> > >>>>>>> concurrency.
> > >>>>>>>
> > >>>>>>>> As long as consumers are single-threaded, they can happily
> > >>>>>>>>
> > >>>>>>> consume
> > >>>
> > >>>> a
> > >>>>
> > >>>>> single
> > >>>>>>>
> > >>>>>>>> partition without concurrency control of any kind. This is a key
> > >>>>>>>>
> > >>>>>>> aspect
> > >>>>>
> > >>>>>> to
> > >>>>>>>
> > >>>>>>>> this system that lets folks design high-throughput systems on
> top
> > >>>>>>>>
> > >>>>>>> of
> > >>>>
> > >>>>> it
> > >>>>>
> > >>>>>> surprisingly easily. If all consumers were instead
> > >>>>>>>>
> > >>>>>>> encouraged/required
> > >>>>>
> > >>>>>> to
> > >>>>>>
> > >>>>>>> implement a repartition of their own, then the consumer becomes
> > >>>>>>>> significantly more complex, requiring either the consumer to
> > >>>>>>>>
> > >>>>>>> first
> > >>>
> > >>>> produce
> > >>>>>>>
> > >>>>>>>> to its own intermediate repartition topic or to ensure that
> > >>>>>>>>
> > >>>>>>> consumer
> > >>>>
> > >>>>> threads have a reliable, high-bandwith channel of communication
> > >>>>>>>>
> > >>>>>>> with
> > >>>>
> > >>>>> every
> > >>>>>>>
> > >>>>>>>> other consumer thread.
> > >>>>>>>>
> > >>>>>>>> Either of those tradeoffs may be reasonable for a particular
> user
> > >>>>>>>>
> > >>>>>>> of
> > >>>>
> > >>>>> Kafka,
> > >>>>>>>
> > >>>>>>>> but I don't know if we're in a position to say that they are
> > >>>>>>>>
> > >>>>>>> reasonable
> > >>>>>
> > >>>>>> for
> > >>>>>>>
> > >>>>>>>> *every* user of Kafka.
> > >>>>>>>>
> > >>>>>>>>
> > >>>>>>>> Point 3:
> > >>>>>>>> Regarding Jun's point about this use case, "(3) stateful and
> > >>>>>>>>
> > >>>>>>> maintaining
> > >>>>>>
> > >>>>>>> the
> > >>>>>>>> states in a local store", I agree that they may use a framework
> > >>>>>>>>
> > >>>>>>> *like*
> > >>>>>
> > >>>>>> Kafka Streams, but that is not the same as using Kafka Streams.
> > >>>>>>>>
> > >>>>>>> This
> > >>>>
> > >>>>> is
> > >>>>>
> > >>>>>> why
> > >>>>>>>
> > >>>>>>>> I think it's better to solve it in Core: because it is then
> > >>>>>>>>
> > >>>>>>> solved
> > >>>
> > >>>> for
> > >>>>>
> > >>>>>> KStreams and also for everything else that facilitates local
> > >>>>>>>>
> > >>>>>>> state
> > >>>
> > >>>> maintenance. To me, Streams is a member of the category of
> > >>>>>>>>
> > >>>>>>> "stream
> > >>>
> > >>>> processing frameworks", which is itself a subcategory of "things
> > >>>>>>>>
> > >>>>>>> requiring
> > >>>>>>>
> > >>>>>>>> local state maintenence". I'm not sure if it makes sense to
> > >>>>>>>
> > >>>>>>>
> >
>



-- 
-- Guozhang

Re: [DISCUSS] KIP-253: Support in-order message delivery with partition expansion

Posted by Dong Lin <li...@gmail.com>.
Thanks Jun! The time works for me.


On Thu, 5 Apr 2018 at 4:34 AM Jun Rao <ju...@confluent.io> wrote:

> Hi, Jan, Dong, John, Guozhang,
>
> Perhaps it will be useful to have a KIP meeting to discuss this together as
> a group. Would Apr. 9 (Monday) at 9:00am PDT work? If so, I will send out
> an invite to the mailing list.
>
> Thanks,
>
> Jun
>
>
> On Wed, Apr 4, 2018 at 1:25 AM, Jan Filipiak <Ja...@trivago.com>
> wrote:
>
> > Want to quickly step in here again because it is going places again.
> >
> > The last part of the discussion is just a pain to read and completely
> > diverged from what I suggested without making the reasons clear to me.
> >
> > I don't know why this happens.... here are my comments anyway.
> >
> > @Guozhang: That Streams is working on automatic creating
> > copartition-usuable topics: great for streams, has literally nothing todo
> > with the KIP as we want to grow the
> > input topic. Everyone can reshuffle rel. easily but that is not what we
> > need todo, we need to grow the topic in question. After streams
> > automatically reshuffled the input topic
> > still has the same size and it didn't help a bit. I fail to see why this
> > is relevant. What am i missing here?
> >
> > @Dong
> > I am still on the position that the current proposal brings us into the
> > wrong direction. Especially introducing PartitionKeyRebalanceListener
> > From this point we can never move away to proper state full handling
> > without completely deprecating this creature from hell again.
> > Linear hashing is not the optimising step we have todo here. An interface
> > that when a topic is a topic its always the same even after it had
> > grown or shrunk is important. So from my POV I have major concerns that
> > this KIP is benefitial in its current state.
> >
> > What is it that makes everyone so addicted to the idea of linear hashing?
> > not attractive at all for me.
> > And with statefull consumers still a complete mess. Why not stick with
> the
> > Kappa architecture???
> >
> >
> >
> >
> >
> > On 03.04.2018 17:38, Dong Lin wrote:
> >
> >> Hey John,
> >>
> >> Thanks much for your comments!!
> >>
> >> I have yet to go through the emails of John/Jun/Guozhang in detail. But
> >> let
> >> me present my idea for how to minimize the delay for state loading for
> >> stream use-case.
> >>
> >> For ease of understanding, let's assume that the initial partition
> number
> >> of input topics and change log topic are both 10. And initial number of
> >> stream processor is also 10. If we only increase initial partition
> number
> >> of input topics to 15 without changing number of stream processor, the
> >> current KIP already guarantees in-order delivery and no state needs to
> be
> >> moved between consumers for stream use-case. Next, let's say we want to
> >> increase the number of processor to expand the processing capacity for
> >> stream use-case. This requires us to move state between processors which
> >> will take time. Our goal is to minimize the impact (i.e. delay) for
> >> processing while we increase the number of processors.
> >>
> >> Note that stream processor generally includes both consumer and
> producer.
> >> In addition to consume from the input topic, consumer may also need to
> >> consume from change log topic on startup for recovery. And producer may
> >> produce state to the change log topic.
> >>
> >>
> > The solution will include the following steps:
> >>
> >> 1) Increase partition number of the input topic from 10 to 15. Since the
> >> messages with the same key will still go to the same consume before and
> >> after the partition expansion, this step can be done without having to
> >> move
> >> state between processors.
> >>
> >> 2) Increase partition number of the change log topic from 10 to 15. Note
> >> that this step can also be done without impacting existing workflow.
> After
> >> we increase partition number of the change log topic, key space may
> split
> >> and some key will be produced to the newly-added partition. But the same
> >> key will still go to the same processor (i.e. consumer) before and after
> >> the partition. Thus this step can also be done without having to move
> >> state
> >> between processors.
> >>
> >> 3) Now, let's add 5 new consumers whose groupId is different from the
> >> existing processor's groupId. Thus these new consumers will not impact
> >> existing workflow. Each of these new consumers should consume two
> >> partitions from the earliest offset, where these two partitions are the
> >> same partitions that will be consumed if the consumers have the same
> >> groupId as the existing processor's groupId. For example, the first of
> the
> >> five consumers will consume partition 0 and partition 10. The purpose of
> >> these consumers is to rebuild the state (e.g. RocksDB) for the
> processors
> >> in advance. Also note that, by design of the current KIP, each consume
> >> will
> >> consume the existing partition of the change log topic up to the offset
> >> before the partition expansion. Then they will only need to consume the
> >> state of the new partition of the change log topic.
> >>
> >> 4) After consumers have caught up in step 3), we should stop these
> >> consumers and add 5 new processors to the stream processing job. These 5
> >> new processors should run in the same location as the previous 5
> consumers
> >> to re-use the state (e.g. RocksDB). And these processors' consumers
> should
> >> consume partitions of the change log topic from the committed offset the
> >> previous 5 consumers so that no state is missed.
> >>
> >> One important trick to note here is that, the mapping from partition to
> >> consumer should also use linear hashing. And we need to remember the
> >> initial number of processors in the job, 10 in this example, and use
> this
> >> number in the linear hashing algorithm. This is pretty much the same as
> >> how
> >> we use linear hashing to map key to partition. In this case, we get an
> >> identity map from partition -> processor, for both input topic and the
> >> change log topic. For example, processor 12 will consume partition 12 of
> >> the input topic and produce state to the partition 12 of the change log
> >> topic.
> >>
> >> There are a few important properties of this solution to note:
> >>
> >> - We can increase the number of partitions for input topic and the
> change
> >> log topic in any order asynchronously.
> >> - The expansion of the processors in a given job in step 4) only
> requires
> >> the step 3) for the same job. It does not require coordination across
> >> different jobs for step 3) and 4). Thus different jobs can independently
> >> expand there capacity without waiting for each other.
> >> - The logic for 1) and 2) is already supported in the current KIP. The
> >> logic for 3) and 4) appears to be independent of the core Kafka logic
> and
> >> can be implemented separately outside core Kafka. Thus the current KIP
> is
> >> probably sufficient after we agree on the efficiency and the correctness
> >> of
> >> the solution. We can have a separate KIP for Kafka Stream to support 3)
> >> and
> >> 4).
> >>
> >>
> >> Cheers,
> >> Dong
> >>
> >>
> >> On Mon, Apr 2, 2018 at 3:25 PM, Guozhang Wang <wa...@gmail.com>
> wrote:
> >>
> >> Hey guys, just sharing my two cents here (I promise it will be shorter
> >>> than
> >>> John's article :).
> >>>
> >>> 0. Just to quickly recap, the main discussion point now is how to
> support
> >>> "key partitioning preservation" (John's #4 in topic characteristics
> >>> above)
> >>> beyond the "single-key ordering preservation" that KIP-253 was
> originally
> >>> proposed to maintain (John's #6 above).
> >>>
> >>> 1. From the streams project, we are actively working on improving the
> >>> elastic scalability of the library. One of the key features is to
> >>> decouple
> >>> the input topics from the parallelism model of Streams: i.e. not
> >>> enforcing
> >>> the topic to be partitioned by the key, not enforcing joining topics to
> >>> be
> >>> co-partitioned, not relying the number of parallel tasks on the input
> >>> topic
> >>> partitions. This can be achieved by re-shuffling on the input topics to
> >>> make sure key-partitioning / co-partitioning on the internal topics.
> Note
> >>> the re-shuffling task is purely stateless and hence does not require
> "key
> >>> partitioning preservation". Operational-wise it is similar to the
> >>> "creating
> >>> a new topic with new number of partitions, pipe the data to the new
> topic
> >>> and cut over consumers from old topics" idea, just that users can
> >>> optionally let Streams to handle such rather than doing it manually
> >>> themselves. There are a few more details on that regard but I will skip
> >>> since they are not directly related to this discussion.
> >>>
> >>> 2. Assuming that 1) above is done, then the only topics involved in the
> >>> scaling events are all input topics. For these topics the only
> producers
> >>> /
> >>> consumers of these topics are controlled by Streams clients themselves,
> >>> and
> >>> hence achieving "key partitioning preservation" is simpler than
> >>> non-Streams
> >>> scenarios: consumers know the partitioning scheme that producers are
> >>> using,
> >>> so that for their stateful operations it is doable to split the local
> >>> state
> >>> stores accordingly or execute backfilling on its own. Of course, if we
> >>> decide to do server-side backfilling, it can still help Streams to
> >>> directly
> >>> rely on that functionality.
> >>>
> >>> 3. As John mentioned, another way inside Streams is to do
> >>> over-partitioning
> >>> on all internal topics; then with 1) Streams would not rely on KIP-253
> at
> >>> all. But personally I'd like to avoid it if possible to reduce Kafka
> side
> >>> footprint: say we overpartition each input topic up to 1k, with a
> >>> reasonable sized stateful topology it can still contribute to tens of
> >>> thousands of topics to the topic partition capacity of a single
> cluster.
> >>>
> >>> 4. Summing up 1/2/3, I think we should focus more on non-Streams users
> >>> writing their stateful computations with local states, and think
> whether
> >>> /
> >>> how we could enable "key partitioning preservation" for them easily,
> than
> >>> to think heavily for Streams library. People may have different opinion
> >>> on
> >>> how common of a usage pattern it is (I think Jun might be suggesting
> that
> >>> for DIY apps people may more likely use remote states so that it is
> not a
> >>> problem for them). My opinion is that for non-Streams users such usage
> >>> pattern could still be large (think: if you are piping data from Kafka
> to
> >>> an external data storage which has single-writer requirements for each
> >>> single shard, even though it is not a stateful computational
> application
> >>> it
> >>> may still require "key partitioning preservation"), so I prefer to have
> >>> backfilling in our KIP than only exposing the API for expansion and
> >>> requires consumers to have pre-knowledge of the producer's partitioning
> >>> scheme.
> >>>
> >>>
> >>>
> >>> Guozhang
> >>>
> >>>
> >>>
> >>> On Thu, Mar 29, 2018 at 2:33 PM, John Roesler <jo...@confluent.io>
> wrote:
> >>>
> >>> Hey Dong,
> >>>>
> >>>> Congrats on becoming a committer!!!
> >>>>
> >>>> Since I just sent a novel-length email, I'll try and keep this one
> brief
> >>>>
> >>> ;)
> >>>
> >>>> Regarding producer coordination, I'll grant that in that case,
> producers
> >>>> may coordinate among themselves to produce into the same topic or to
> >>>> produce co-partitioned topics. Nothing in KStreams or the Kafka
> >>>> ecosystem
> >>>> in general requires such coordination for correctness or in fact for
> any
> >>>> optional features, though, so I would not say that we require producer
> >>>> coordination of partition logic. If producers currently coordinate,
> it's
> >>>> completely optional and their own choice.
> >>>>
> >>>> Regarding the portability of partition algorithms, my observation is
> >>>> that
> >>>> systems requiring independent implementations of the same algorithm
> with
> >>>> 100% correctness are a large source of risk and also a burden on those
> >>>>
> >>> who
> >>>
> >>>> have to maintain them. If people could flawlessly implement algorithms
> >>>> in
> >>>> actual software, the world would be a wonderful place indeed! For a
> >>>>
> >>> system
> >>>
> >>>> as important and widespread as Kafka, I would recommend restricting
> >>>> limiting such requirements as aggressively as possible.
> >>>>
> >>>> I'd agree that we can always revisit decisions like allowing arbitrary
> >>>> partition functions, but of course, we shouldn't do that in a vacuum.
> >>>>
> >>> That
> >>>
> >>>> feels like the kind of thing we'd need to proactively seek guidance
> from
> >>>> the users list about. I do think that the general approach of saying
> >>>> that
> >>>> "if you use a custom partitioner, you cannot do partition expansion"
> is
> >>>> very reasonable (but I don't think we need to go that far with the
> >>>>
> >>> current
> >>>
> >>>> proposal). It's similar to my statement in my email to Jun that in
> >>>> principle KStreams doesn't *need* backfill, we only need it if we want
> >>>> to
> >>>> employ partition expansion.
> >>>>
> >>>> I reckon that the main motivation for backfill is to support KStreams
> >>>> use
> >>>> cases and also any other use cases involving stateful consumers.
> >>>>
> >>>> Thanks for your response, and congrats again!
> >>>> -John
> >>>>
> >>>>
> >>>> On Wed, Mar 28, 2018 at 1:34 AM, Dong Lin <li...@gmail.com>
> wrote:
> >>>>
> >>>> Hey John,
> >>>>>
> >>>>> Great! Thanks for all the comment. It seems that we agree that the
> >>>>>
> >>>> current
> >>>>
> >>>>> KIP is in good shape for core Kafka. IMO, what we have been
> discussing
> >>>>>
> >>>> in
> >>>
> >>>> the recent email exchanges is mostly about the second step, i.e. how
> to
> >>>>> address problem for the stream use-case (or stateful processing in
> >>>>> general).
> >>>>>
> >>>>> I will comment inline.
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>> On Tue, Mar 27, 2018 at 4:38 PM, John Roesler <jo...@confluent.io>
> >>>>>
> >>>> wrote:
> >>>
> >>>> Thanks for the response, Dong.
> >>>>>>
> >>>>>> Here are my answers to your questions:
> >>>>>>
> >>>>>> - "Asking producers and consumers, or even two different producers,
> >>>>>>
> >>>>> to
> >>>
> >>>> share code like the partition function is a pretty huge ask. What
> >>>>>>>
> >>>>>> if
> >>>
> >>>> they
> >>>>>
> >>>>>> are using different languages?". It seems that today we already
> >>>>>>>
> >>>>>> require
> >>>>
> >>>>> different producer's to use the same hash function -- otherwise
> >>>>>>>
> >>>>>> messages
> >>>>>
> >>>>>> with the same key will go to different partitions of the same topic
> >>>>>>>
> >>>>>> which
> >>>>>
> >>>>>> may cause problem for downstream consumption. So not sure if it
> >>>>>>>
> >>>>>> adds
> >>>
> >>>> any
> >>>>>
> >>>>>> more constraint by assuming consumers know the hash function of
> >>>>>>>
> >>>>>> producer.
> >>>>>
> >>>>>> Could you explain more why user would want to use a cusmtom
> >>>>>>>
> >>>>>> partition
> >>>
> >>>> function? Maybe we can check if this is something that can be
> >>>>>>>
> >>>>>> supported
> >>>>
> >>>>> in
> >>>>>>
> >>>>>>> the default Kafka hash function. Also, can you explain more why it
> >>>>>>>
> >>>>>> is
> >>>
> >>>> difficuilt to implement the same hash function in different
> >>>>>>>
> >>>>>> languages?
> >>>>
> >>>>>
> >>>>>> Sorry, I meant two different producers as in producers to two
> >>>>>>
> >>>>> different
> >>>
> >>>> topics. This was in response to the suggestion that we already
> >>>>>>
> >>>>> require
> >>>
> >>>> coordination among producers to different topics in order to achieve
> >>>>>> co-partitioning. I was saying that we do not (and should not).
> >>>>>>
> >>>>>
> >>>>> It is probably common for producers of different team to produce
> >>>>>
> >>>> message
> >>>
> >>>> to
> >>>>
> >>>>> the same topic. In order to ensure that messages with the same key go
> >>>>>
> >>>> to
> >>>
> >>>> same partition, we need producers of different team to share the same
> >>>>> partition algorithm, which by definition requires coordination among
> >>>>> producers of different teams in an organization. Even for producers
> of
> >>>>> different topics, it may be common to require producers to use the
> same
> >>>>> partition algorithm in order to join two topics for stream
> processing.
> >>>>>
> >>>> Does
> >>>>
> >>>>> this make it reasonable to say we already require coordination across
> >>>>> producers?
> >>>>>
> >>>>>
> >>>>> By design, consumers are currently ignorant of the partitioning
> >>>>>>
> >>>>> scheme.
> >>>
> >>>> It
> >>>>>
> >>>>>> suffices to trust that the producer has partitioned the topic by
> key,
> >>>>>>
> >>>>> if
> >>>>
> >>>>> they claim to have done so. If you don't trust that, or even if you
> >>>>>>
> >>>>> just
> >>>>
> >>>>> need some other partitioning scheme, then you must re-partition it
> >>>>>> yourself. Nothing we're discussing can or should change that. The
> >>>>>>
> >>>>> value
> >>>
> >>>> of
> >>>>>
> >>>>>> backfill is that it preserves the ability for consumers to avoid
> >>>>>> re-partitioning before consuming, in the case where they don't need
> >>>>>>
> >>>>> to
> >>>
> >>>> today.
> >>>>>>
> >>>>>
> >>>>> Regarding shared "hash functions", note that it's a bit inaccurate to
> >>>>>>
> >>>>> talk
> >>>>>
> >>>>>> about the "hash function" of the producer. Properly speaking, the
> >>>>>>
> >>>>> producer
> >>>>>
> >>>>>> has only a "partition function". We do not know that it is a hash.
> >>>>>>
> >>>>> The
> >>>
> >>>> producer can use any method at their disposal to assign a partition
> >>>>>>
> >>>>> to
> >>>
> >>>> a
> >>>>
> >>>>> record. The partition function obviously may we written in any
> >>>>>>
> >>>>> programming
> >>>>>
> >>>>>> language, so in general it's not something that can be shared around
> >>>>>> without a formal spec or the ability to execute arbitrary
> executables
> >>>>>>
> >>>>> in
> >>>>
> >>>>> arbitrary runtime environments.
> >>>>>>
> >>>>>> Yeah it is probably better to say partition algorithm. I guess it
> >>>>>
> >>>> should
> >>>
> >>>> not be difficult to implement same partition algorithms in different
> >>>>> languages, right? Yes we would need a formal specification of the
> >>>>>
> >>>> default
> >>>
> >>>> partition algorithm in the producer. I think that can be documented as
> >>>>>
> >>>> part
> >>>>
> >>>>> of the producer interface.
> >>>>>
> >>>>>
> >>>>> Why would a producer want a custom partition function? I don't
> >>>>>>
> >>>>> know...
> >>>
> >>>> why
> >>>>>
> >>>>>> did we design the interface so that our users can provide one? In
> >>>>>>
> >>>>> general,
> >>>>>
> >>>>>> such systems provide custom partitioners because some data sets may
> >>>>>>
> >>>>> be
> >>>
> >>>> unbalanced under the default or because they can provide some
> >>>>>>
> >>>>> interesting
> >>>>
> >>>>> functionality built on top of the partitioning scheme, etc. Having
> >>>>>>
> >>>>> provided
> >>>>>
> >>>>>> this ability, I don't know why we would remove it.
> >>>>>>
> >>>>>> Yeah it is reasonable to assume that there was reason to support
> >>>>> custom
> >>>>> partition function in producer. On the other hand it may also be
> >>>>>
> >>>> reasonable
> >>>>
> >>>>> to revisit this interface and discuss whether we actually need to
> >>>>>
> >>>> support
> >>>
> >>>> custom partition function. If we don't have a good reason, we can
> >>>>>
> >>>> choose
> >>>
> >>>> not to support custom partition function in this KIP in a backward
> >>>>> compatible manner, i.e. user can still use custom partition function
> >>>>>
> >>>> but
> >>>
> >>>> they would not get the benefit of in-order delivery when there is
> >>>>>
> >>>> partition
> >>>>
> >>>>> expansion. What do you think?
> >>>>>
> >>>>>
> >>>>> - Besides the assumption that consumer needs to share the hash
> >>>>>>
> >>>>> function
> >>>
> >>>> of
> >>>>>
> >>>>>> producer, is there other organization overhead of the proposal in
> >>>>>>>
> >>>>>> the
> >>>
> >>>> current KIP?
> >>>>>>>
> >>>>>>> It wasn't clear to me that KIP-253 currently required the producer
> >>>>>>
> >>>>> and
> >>>
> >>>> consumer to share the partition function, or in fact that it had a
> >>>>>>
> >>>>> hard
> >>>
> >>>> requirement to abandon the general partition function and use a
> >>>>>>
> >>>>> linear
> >>>
> >>>> hash
> >>>>>
> >>>>>> function instead.
> >>>>>>
> >>>>>
> >>>>> In my reading, there is a requirement to track the metadata about
> >>>>>>
> >>>>> what
> >>>
> >>>> partitions split into what other partitions during an expansion
> >>>>>>
> >>>>> operation.
> >>>>>
> >>>>>> If the partition function is linear, this is easy. If not, you can
> >>>>>>
> >>>>> always
> >>>>
> >>>>> just record that all old partitions split into all new partitions.
> >>>>>>
> >>>>> This
> >>>
> >>>> has
> >>>>>
> >>>>>> the effect of forcing all consumers to wait until the old epoch is
> >>>>>> completely consumed before starting on the new epoch. But this may
> >>>>>>
> >>>>> be a
> >>>
> >>>> reasonable tradeoff, and it doesn't otherwise alter your design.
> >>>>>>
> >>>>>> You only mention the consumer needing to know that the partition
> >>>>>>
> >>>>> function
> >>>>
> >>>>> is linear, not what the actual function is, so I don't think your
> >>>>>>
> >>>>> design
> >>>>
> >>>>> actually calls for sharing the function. Plus, really all the
> >>>>>>
> >>>>> consumer
> >>>
> >>>> needs is the metadata about what old-epoch partitions to wait for
> >>>>>>
> >>>>> before
> >>>>
> >>>>> consuming a new-epoch partition. This information is directly
> >>>>>>
> >>>>> captured
> >>>
> >>>> in
> >>>>
> >>>>> metadata, so I don't think it actually even cares whether the
> >>>>>>
> >>>>> partition
> >>>
> >>>> function is linear or not.
> >>>>>>
> >>>>>> You are right that the current KIP does not mention it. My comment
> >>>>>
> >>>> related
> >>>>
> >>>>> to the partition function coordination was related to support the
> >>>>> stream-use case which we have been discussing so far.
> >>>>>
> >>>>>
> >>>>> So, no, I really think KIP-253 is in good shape. I was really more
> >>>>>>
> >>>>> talking
> >>>>>
> >>>>>> about the part of this thread that's outside of KIP-253's scope,
> >>>>>>
> >>>>> namely,
> >>>>
> >>>>> creating the possibility of backfilling partitions after expansion.
> >>>>>>
> >>>>>> Great! Can you also confirm that the main motivation for backfilling
> >>>>> partitions after expansion is to support the stream use-case?
> >>>>>
> >>>>>
> >>>>> - Currently producer can forget about the message that has been
> >>>>>>
> >>>>>>> acknowledged by the broker. Thus the producer probably does not
> >>>>>>>
> >>>>>> know
> >>>
> >>>> most
> >>>>>
> >>>>>> of the exiting messages in topic, including those messages produced
> >>>>>>>
> >>>>>> by
> >>>>
> >>>>> other producers. We can have the owner of the producer to
> >>>>>>>
> >>>>>> split+backfill.
> >>>>>
> >>>>>> In my opion it will be a new program that wraps around the existing
> >>>>>>> producer and consumer classes.
> >>>>>>>
> >>>>>>> This sounds fine by me!
> >>>>>>
> >>>>>> Really, I was just emphasizing that the part of the organization
> that
> >>>>>> produces a topic shouldn't have to export their partition function
> to
> >>>>>>
> >>>>> the
> >>>>
> >>>>> part(s) of the organization (or other organizations) that consume the
> >>>>>> topic. Whether the backfill operation goes into the Producer
> >>>>>>
> >>>>> interface
> >>>
> >>>> is
> >>>>
> >>>>> secondary, I think.
> >>>>>>
> >>>>>> - Regarding point 5. The argument is in favor of the split+backfill
> >>>>>>
> >>>>> but
> >>>
> >>>> for
> >>>>>
> >>>>>> changelog topic. And it intends to address the problem for stream
> >>>>>>>
> >>>>>> use-case
> >>>>>>
> >>>>>>> in general. In this KIP we will provide interface (i.e.
> >>>>>>> PartitionKeyRebalanceListener in the KIP) to be used by sream
> >>>>>>>
> >>>>>> use-case
> >>>>
> >>>>> and
> >>>>>>
> >>>>>>> the goal is that user can flush/re-consume the state as part of the
> >>>>>>> interface implementation regardless of whether there is change log
> >>>>>>>
> >>>>>> topic.
> >>>>>
> >>>>>> Maybe you are suggesting that the main reason to do split+backfill
> >>>>>>>
> >>>>>> of
> >>>
> >>>> input
> >>>>>>
> >>>>>>> topic is to support log compacted topics? You mentioned in Point 1
> >>>>>>>
> >>>>>> that
> >>>>
> >>>>> log
> >>>>>>
> >>>>>>> compacted topics is out of the scope of this KIP. Maybe I could
> >>>>>>>
> >>>>>> understand
> >>>>>>
> >>>>>>> your position better. Regarding Jan's proposal to split partitions
> >>>>>>>
> >>>>>> with
> >>>>
> >>>>> backfill, do you think this should replace the proposal in the
> >>>>>>>
> >>>>>> existing
> >>>>
> >>>>> KIP, or do you think this is something that we should do in
> >>>>>>>
> >>>>>> addition
> >>>
> >>>> to
> >>>>
> >>>>> the
> >>>>>>
> >>>>>>> existing KIP?
> >>>>>>>
> >>>>>>> I think that interface is a good/necessary component of KIP-253.
> >>>>>>
> >>>>>> I personally (FWIW) feel that KIP-253 is appropriately scoped, but I
> >>>>>>
> >>>>> do
> >>>
> >>>> think its utility will be limited unless there is a later KIP
> >>>>>>
> >>>>> offering
> >>>
> >>>> backfill. But, maybe unlike Jan, I think it makes sense to try and
> >>>>>>
> >>>>> tackle
> >>>>
> >>>>> the ordering problem independently of backfill, so I'm in support of
> >>>>>>
> >>>>> the
> >>>>
> >>>>> current KIP.
> >>>>>>
> >>>>>> - Regarding point 6. I guess we can agree that it is better not to
> >>>>>>
> >>>>> have
> >>>
> >>>> the
> >>>>>
> >>>>>> performance overhread of copying the input data. Before we discuss
> >>>>>>>
> >>>>>> more
> >>>>
> >>>>> on
> >>>>>>
> >>>>>>> whether the performance overhead is acceptable or not, I am trying
> >>>>>>>
> >>>>>> to
> >>>
> >>>> figure out what is the benefit of introducing this overhread. You
> >>>>>>>
> >>>>>> mentioned
> >>>>>>
> >>>>>>> that the benefit is the loose organizational coupling. By
> >>>>>>>
> >>>>>> "organizational
> >>>>>
> >>>>>> coupling", are you referring to the requirement that consumer needs
> >>>>>>>
> >>>>>> to
> >>>>
> >>>>> know
> >>>>>>
> >>>>>>> the hash function of producer? If so, maybe we can discuss the
> >>>>>>>
> >>>>>> use-case
> >>>>
> >>>>> of
> >>>>>>
> >>>>>>> custom partiton function and see whether we can find a way to
> >>>>>>>
> >>>>>> support
> >>>
> >>>> such
> >>>>>>
> >>>>>>> use-case without having to copy the input data.
> >>>>>>>
> >>>>>>> I'm not too sure about what an "input" is in this sense, since we
> are
> >>>>>>
> >>>>> just
> >>>>>
> >>>>>> talking about topics. Actually the point I was making there is that
> >>>>>>
> >>>>> AKAICT
> >>>>>
> >>>>>> the performance overhead of a backfill is less than any other
> option,
> >>>>>> assuming you split partitions rarely.
> >>>>>>
> >>>>>> By "input" I was referring to source Kafka topic of a stream
> >>>>> processing
> >>>>> job.
> >>>>>
> >>>>>
> >>>>> Separately, yes, "organizational coupling" increases if producers and
> >>>>>> consumers have to share code, such as the partition function. This
> >>>>>>
> >>>>> would
> >>>>
> >>>>> not be the case if producers could only pick from a menu of a few
> >>>>>> well-known partition functions, but I think this is a poor tradeoff.
> >>>>>>
> >>>>>> Maybe we can revisit the custom partition function and see whether
> we
> >>>>> actually need it? Otherwise, I am concerned that every user will pay
> >>>>>
> >>>> the
> >>>
> >>>> overhead of data movement to support something that was not really
> >>>>>
> >>>> needed
> >>>
> >>>> for most users.
> >>>>>
> >>>>>
> >>>>> To me, this is two strong arguments in favor of backfill being less
> >>>>>> expensive than no backfill, but again, I think that particular
> debate
> >>>>>>
> >>>>> comes
> >>>>>
> >>>>>> after KIP-253, so I don't want to create the impression of
> opposition
> >>>>>>
> >>>>> to
> >>>>
> >>>>> your proposal.
> >>>>>>
> >>>>>>
> >>>>>> Finally, to respond to a new email I just noticed:
> >>>>>>
> >>>>>> BTW, here is my understanding of the scope of this KIP. We want to
> >>>>>>>
> >>>>>> allow
> >>>>>
> >>>>>> consumers to always consume messages with the same key from the
> >>>>>>>
> >>>>>> same
> >>>
> >>>> producer in the order they are produced. And we need to provide a
> >>>>>>>
> >>>>>> way
> >>>
> >>>> for
> >>>>>
> >>>>>> stream use-case to be able to flush/load state when messages with
> >>>>>>>
> >>>>>> the
> >>>
> >>>> same
> >>>>>>
> >>>>>>> key are migrated between consumers. In addition to ensuring that
> >>>>>>>
> >>>>>> this
> >>>
> >>>> goal
> >>>>>>
> >>>>>>> is correctly supported, we should do our best to keep the
> >>>>>>>
> >>>>>> performance
> >>>
> >>>> and
> >>>>>
> >>>>>> organization overhead of this KIP as low as possible.
> >>>>>>>
> >>>>>>> I think we're on the same page there! In fact, I would generalize a
> >>>>>>
> >>>>> little
> >>>>>
> >>>>>> more and say that the mechanism you've designed provides *all
> >>>>>>
> >>>>> consumers*
> >>>>
> >>>>> the ability "to flush/load state when messages with the same key are
> >>>>>> migrated between consumers", not just Streams.
> >>>>>>
> >>>>>> Thanks for all the comment!
> >>>>>
> >>>>>
> >>>>> Thanks for the discussion,
> >>>>>> -John
> >>>>>>
> >>>>>>
> >>>>>>
> >>>>>> On Tue, Mar 27, 2018 at 3:14 PM, Dong Lin <li...@gmail.com>
> >>>>>>
> >>>>> wrote:
> >>>
> >>>> Hey John,
> >>>>>>>
> >>>>>>> Thanks much for the detailed comments. Here are my thoughts:
> >>>>>>>
> >>>>>>> - The need to delete messages from log compacted topics is mainly
> >>>>>>>
> >>>>>> for
> >>>
> >>>> performance (e.g. storage space) optimization than for correctness
> >>>>>>>
> >>>>>> for
> >>>>
> >>>>> this
> >>>>>>
> >>>>>>> KIP. I agree that we probably don't need to focus on this in our
> >>>>>>>
> >>>>>> discussion
> >>>>>>
> >>>>>>> since it is mostly for performance optimization.
> >>>>>>>
> >>>>>>> - "Asking producers and consumers, or even two different producers,
> >>>>>>>
> >>>>>> to
> >>>>
> >>>>> share code like the partition function is a pretty huge ask. What
> >>>>>>>
> >>>>>> if
> >>>
> >>>> they
> >>>>>
> >>>>>> are using different languages?". It seems that today we already
> >>>>>>>
> >>>>>> require
> >>>>
> >>>>> different producer's to use the same hash function -- otherwise
> >>>>>>>
> >>>>>> messages
> >>>>>
> >>>>>> with the same key will go to different partitions of the same topic
> >>>>>>>
> >>>>>> which
> >>>>>
> >>>>>> may cause problem for downstream consumption. So not sure if it
> >>>>>>>
> >>>>>> adds
> >>>
> >>>> any
> >>>>>
> >>>>>> more constraint by assuming consumers know the hash function of
> >>>>>>>
> >>>>>> producer.
> >>>>>
> >>>>>> Could you explain more why user would want to use a cusmtom
> >>>>>>>
> >>>>>> partition
> >>>
> >>>> function? Maybe we can check if this is something that can be
> >>>>>>>
> >>>>>> supported
> >>>>
> >>>>> in
> >>>>>>
> >>>>>>> the default Kafka hash function. Also, can you explain more why it
> >>>>>>>
> >>>>>> is
> >>>
> >>>> difficuilt to implement the same hash function in different
> >>>>>>>
> >>>>>> languages?
> >>>>
> >>>>> - Besides the assumption that consumer needs to share the hash
> >>>>>>>
> >>>>>> function
> >>>>
> >>>>> of
> >>>>>>
> >>>>>>> producer, is there other organization overhead of the proposal in
> >>>>>>>
> >>>>>> the
> >>>
> >>>> current KIP?
> >>>>>>>
> >>>>>>> - Currently producer can forget about the message that has been
> >>>>>>> acknowledged by the broker. Thus the producer probably does not
> >>>>>>>
> >>>>>> know
> >>>
> >>>> most
> >>>>>
> >>>>>> of the exiting messages in topic, including those messages produced
> >>>>>>>
> >>>>>> by
> >>>>
> >>>>> other producers. We can have the owner of the producer to
> >>>>>>>
> >>>>>> split+backfill.
> >>>>>
> >>>>>> In my opion it will be a new program that wraps around the existing
> >>>>>>> producer and consumer classes.
> >>>>>>>
> >>>>>>> - Regarding point 5. The argument is in favor of the split+backfill
> >>>>>>>
> >>>>>> but
> >>>>
> >>>>> for
> >>>>>>
> >>>>>>> changelog topic. And it intends to address the problem for stream
> >>>>>>>
> >>>>>> use-case
> >>>>>>
> >>>>>>> in general. In this KIP we will provide interface (i.e.
> >>>>>>> PartitionKeyRebalanceListener in the KIP) to be used by sream
> >>>>>>>
> >>>>>> use-case
> >>>>
> >>>>> and
> >>>>>>
> >>>>>>> the goal is that user can flush/re-consume the state as part of the
> >>>>>>> interface implementation regardless of whether there is change log
> >>>>>>>
> >>>>>> topic.
> >>>>>
> >>>>>> Maybe you are suggesting that the main reason to do split+backfill
> >>>>>>>
> >>>>>> of
> >>>
> >>>> input
> >>>>>>
> >>>>>>> topic is to support log compacted topics? You mentioned in Point 1
> >>>>>>>
> >>>>>> that
> >>>>
> >>>>> log
> >>>>>>
> >>>>>>> compacted topics is out of the scope of this KIP. Maybe I could
> >>>>>>>
> >>>>>> understand
> >>>>>>
> >>>>>>> your position better. Regarding Jan's proposal to split partitions
> >>>>>>>
> >>>>>> with
> >>>>
> >>>>> backfill, do you think this should replace the proposal in the
> >>>>>>>
> >>>>>> existing
> >>>>
> >>>>> KIP, or do you think this is something that we should do in
> >>>>>>>
> >>>>>> addition
> >>>
> >>>> to
> >>>>
> >>>>> the
> >>>>>>
> >>>>>>> existing KIP?
> >>>>>>>
> >>>>>>> - Regarding point 6. I guess we can agree that it is better not to
> >>>>>>>
> >>>>>> have
> >>>>
> >>>>> the
> >>>>>>
> >>>>>>> performance overhread of copying the input data. Before we discuss
> >>>>>>>
> >>>>>> more
> >>>>
> >>>>> on
> >>>>>>
> >>>>>>> whether the performance overhead is acceptable or not, I am trying
> >>>>>>>
> >>>>>> to
> >>>
> >>>> figure out what is the benefit of introducing this overhread. You
> >>>>>>>
> >>>>>> mentioned
> >>>>>>
> >>>>>>> that the benefit is the loose organizational coupling. By
> >>>>>>>
> >>>>>> "organizational
> >>>>>
> >>>>>> coupling", are you referring to the requirement that consumer needs
> >>>>>>>
> >>>>>> to
> >>>>
> >>>>> know
> >>>>>>
> >>>>>>> the hash function of producer? If so, maybe we can discuss the
> >>>>>>>
> >>>>>> use-case
> >>>>
> >>>>> of
> >>>>>>
> >>>>>>> custom partiton function and see whether we can find a way to
> >>>>>>>
> >>>>>> support
> >>>
> >>>> such
> >>>>>>
> >>>>>>> use-case without having to copy the input data.
> >>>>>>>
> >>>>>>> Thanks,
> >>>>>>> Dong
> >>>>>>>
> >>>>>>>
> >>>>>>> On Tue, Mar 27, 2018 at 11:34 AM, John Roesler <jo...@confluent.io>
> >>>>>>>
> >>>>>> wrote:
> >>>>>>
> >>>>>>> Hey Dong and Jun,
> >>>>>>>>
> >>>>>>>> Thanks for the thoughtful responses. If you don't mind, I'll mix
> >>>>>>>>
> >>>>>>> my
> >>>
> >>>> replies
> >>>>>>>
> >>>>>>>> together to try for a coherent response. I'm not too familiar
> >>>>>>>>
> >>>>>>> with
> >>>
> >>>> mailing-list etiquette, though.
> >>>>>>>>
> >>>>>>>> I'm going to keep numbering my points because it makes it easy
> >>>>>>>>
> >>>>>>> for
> >>>
> >>>> you
> >>>>>
> >>>>>> all
> >>>>>>>
> >>>>>>>> to respond.
> >>>>>>>>
> >>>>>>>> Point 1:
> >>>>>>>> As I read it, KIP-253 is *just* about properly fencing the
> >>>>>>>>
> >>>>>>> producers
> >>>>
> >>>>> and
> >>>>>>
> >>>>>>> consumers so that you preserve the correct ordering of records
> >>>>>>>>
> >>>>>>> during
> >>>>
> >>>>> partition expansion. This is clearly necessary regardless of
> >>>>>>>>
> >>>>>>> anything
> >>>>
> >>>>> else
> >>>>>>>
> >>>>>>>> we discuss. I think this whole discussion about backfill,
> >>>>>>>>
> >>>>>>> consumers,
> >>>>
> >>>>> streams, etc., is beyond the scope of KIP-253. But it would be
> >>>>>>>>
> >>>>>>> cumbersome
> >>>>>>
> >>>>>>> to start a new thread at this point.
> >>>>>>>>
> >>>>>>>> I had missed KIP-253's Proposed Change #9 among all the
> >>>>>>>>
> >>>>>>> details...
> >>>
> >>>> I
> >>>>
> >>>>> think
> >>>>>>>
> >>>>>>>> this is a nice addition to the proposal. One thought is that it's
> >>>>>>>>
> >>>>>>> actually
> >>>>>>>
> >>>>>>>> irrelevant whether the hash function is linear. This is simply an
> >>>>>>>>
> >>>>>>> algorithm
> >>>>>>>
> >>>>>>>> for moving a key from one partition to another, so the type of
> >>>>>>>>
> >>>>>>> hash
> >>>
> >>>> function need not be a precondition. In fact, it also doesn't
> >>>>>>>>
> >>>>>>> matter
> >>>>
> >>>>> whether the topic is compacted or not, the algorithm works
> >>>>>>>>
> >>>>>>> regardless.
> >>>>>
> >>>>>> I think this is a good algorithm to keep in mind, as it might
> >>>>>>>>
> >>>>>>> solve a
> >>>>
> >>>>> variety of problems, but it does have a downside: that the
> >>>>>>>>
> >>>>>>> producer
> >>>
> >>>> won't
> >>>>>>
> >>>>>>> know whether or not K1 was actually in P1, it just knows that K1
> >>>>>>>>
> >>>>>>> was
> >>>>
> >>>>> in
> >>>>>
> >>>>>> P1's keyspace before the new epoch. Therefore, it will have to
> >>>>>>>> pessimistically send (K1,null) to P1 just in case. But the next
> >>>>>>>>
> >>>>>>> time
> >>>>
> >>>>> K1
> >>>>>
> >>>>>> comes along, the producer *also* won't remember that it already
> >>>>>>>>
> >>>>>>> retracted
> >>>>>>
> >>>>>>> K1 from P1, so it will have to send (K1,null) *again*. By
> >>>>>>>>
> >>>>>>> extension,
> >>>>
> >>>>> every
> >>>>>>>
> >>>>>>>> time the producer sends to P2, it will also have to send a
> >>>>>>>>
> >>>>>>> tombstone
> >>>>
> >>>>> to
> >>>>>
> >>>>>> P1,
> >>>>>>>
> >>>>>>>> which is a pretty big burden. To make the situation worse, if
> >>>>>>>>
> >>>>>>> there
> >>>
> >>>> is
> >>>>>
> >>>>>> a
> >>>>>>
> >>>>>>> second split, say P2 becomes P2 and P3, then any key Kx belonging
> >>>>>>>>
> >>>>>>> to
> >>>>
> >>>>> P3
> >>>>>
> >>>>>> will also have to be retracted from P2 *and* P1, since the
> >>>>>>>>
> >>>>>>> producer
> >>>
> >>>> can't
> >>>>>>
> >>>>>>> know whether Kx had been last written to P2 or P1. Over a long
> >>>>>>>>
> >>>>>>> period
> >>>>
> >>>>> of
> >>>>>>
> >>>>>>> time, this clearly becomes a issue, as the producer must send an
> >>>>>>>>
> >>>>>>> arbitrary
> >>>>>>>
> >>>>>>>> number of retractions along with every update.
> >>>>>>>>
> >>>>>>>> In contrast, the proposed backfill operation has an end, and
> >>>>>>>>
> >>>>>>> after
> >>>
> >>>> it
> >>>>
> >>>>> ends,
> >>>>>>>
> >>>>>>>> everyone can afford to forget that there ever was a different
> >>>>>>>>
> >>>>>>> partition
> >>>>>
> >>>>>> layout.
> >>>>>>>>
> >>>>>>>> Really, though, figuring out how to split compacted topics is
> >>>>>>>>
> >>>>>>> beyond
> >>>>
> >>>>> the
> >>>>>>
> >>>>>>> scope of KIP-253, so I'm not sure #9 really even needs to be in
> >>>>>>>>
> >>>>>>> this
> >>>>
> >>>>> KIP...
> >>>>>>>
> >>>>>>>> We do need in-order delivery during partition expansion. It would
> >>>>>>>>
> >>>>>>> be
> >>>>
> >>>>> fine
> >>>>>>
> >>>>>>> by me to say that you *cannot* expand partitions of a
> >>>>>>>>
> >>>>>>> log-compacted
> >>>
> >>>> topic
> >>>>>>
> >>>>>>> and call it a day. I think it would be better to tackle that in
> >>>>>>>>
> >>>>>>> another
> >>>>>
> >>>>>> KIP.
> >>>>>>>>
> >>>>>>>>
> >>>>>>>> Point 2:
> >>>>>>>> Regarding whether the consumer re-shuffles its inputs, this is
> >>>>>>>>
> >>>>>>> always
> >>>>
> >>>>> on
> >>>>>>
> >>>>>>> the table; any consumer who wants to re-shuffle its input is free
> >>>>>>>>
> >>>>>>> to
> >>>>
> >>>>> do
> >>>>>
> >>>>>> so.
> >>>>>>>
> >>>>>>>> But this is currently not required. It's just that the current
> >>>>>>>>
> >>>>>>> high-level
> >>>>>>
> >>>>>>> story with Kafka encourages the use of partitions as a unit of
> >>>>>>>>
> >>>>>>> concurrency.
> >>>>>>>
> >>>>>>>> As long as consumers are single-threaded, they can happily
> >>>>>>>>
> >>>>>>> consume
> >>>
> >>>> a
> >>>>
> >>>>> single
> >>>>>>>
> >>>>>>>> partition without concurrency control of any kind. This is a key
> >>>>>>>>
> >>>>>>> aspect
> >>>>>
> >>>>>> to
> >>>>>>>
> >>>>>>>> this system that lets folks design high-throughput systems on top
> >>>>>>>>
> >>>>>>> of
> >>>>
> >>>>> it
> >>>>>
> >>>>>> surprisingly easily. If all consumers were instead
> >>>>>>>>
> >>>>>>> encouraged/required
> >>>>>
> >>>>>> to
> >>>>>>
> >>>>>>> implement a repartition of their own, then the consumer becomes
> >>>>>>>> significantly more complex, requiring either the consumer to
> >>>>>>>>
> >>>>>>> first
> >>>
> >>>> produce
> >>>>>>>
> >>>>>>>> to its own intermediate repartition topic or to ensure that
> >>>>>>>>
> >>>>>>> consumer
> >>>>
> >>>>> threads have a reliable, high-bandwith channel of communication
> >>>>>>>>
> >>>>>>> with
> >>>>
> >>>>> every
> >>>>>>>
> >>>>>>>> other consumer thread.
> >>>>>>>>
> >>>>>>>> Either of those tradeoffs may be reasonable for a particular user
> >>>>>>>>
> >>>>>>> of
> >>>>
> >>>>> Kafka,
> >>>>>>>
> >>>>>>>> but I don't know if we're in a position to say that they are
> >>>>>>>>
> >>>>>>> reasonable
> >>>>>
> >>>>>> for
> >>>>>>>
> >>>>>>>> *every* user of Kafka.
> >>>>>>>>
> >>>>>>>>
> >>>>>>>> Point 3:
> >>>>>>>> Regarding Jun's point about this use case, "(3) stateful and
> >>>>>>>>
> >>>>>>> maintaining
> >>>>>>
> >>>>>>> the
> >>>>>>>> states in a local store", I agree that they may use a framework
> >>>>>>>>
> >>>>>>> *like*
> >>>>>
> >>>>>> Kafka Streams, but that is not the same as using Kafka Streams.
> >>>>>>>>
> >>>>>>> This
> >>>>
> >>>>> is
> >>>>>
> >>>>>> why
> >>>>>>>
> >>>>>>>> I think it's better to solve it in Core: because it is then
> >>>>>>>>
> >>>>>>> solved
> >>>
> >>>> for
> >>>>>
> >>>>>> KStreams and also for everything else that facilitates local
> >>>>>>>>
> >>>>>>> state
> >>>
> >>>> maintenance. To me, Streams is a member of the category of
> >>>>>>>>
> >>>>>>> "stream
> >>>
> >>>> processing frameworks", which is itself a subcategory of "things
> >>>>>>>>
> >>>>>>> requiring
> >>>>>>>
> >>>>>>>> local state maintenence". I'm not sure if it makes sense to
> >>>>>>>
> >>>>>>>
>

Re: [DISCUSS] KIP-253: Support in-order message delivery with partition expansion

Posted by Jan Filipiak <Ja...@trivago.com>.
Yes I can be there.

On 04.04.2018 22:34, Jun Rao wrote:
> Hi, Jan, Dong, John, Guozhang,
>
> Perhaps it will be useful to have a KIP meeting to discuss this together as
> a group. Would Apr. 9 (Monday) at 9:00am PDT work? If so, I will send out
> an invite to the mailing list.
>
> Thanks,
>
> Jun
>
>
> On Wed, Apr 4, 2018 at 1:25 AM, Jan Filipiak <Ja...@trivago.com>
> wrote:
>
>> Want to quickly step in here again because it is going places again.
>>
>> The last part of the discussion is just a pain to read and completely
>> diverged from what I suggested without making the reasons clear to me.
>>
>> I don't know why this happens.... here are my comments anyway.
>>
>> @Guozhang: That Streams is working on automatic creating
>> copartition-usuable topics: great for streams, has literally nothing todo
>> with the KIP as we want to grow the
>> input topic. Everyone can reshuffle rel. easily but that is not what we
>> need todo, we need to grow the topic in question. After streams
>> automatically reshuffled the input topic
>> still has the same size and it didn't help a bit. I fail to see why this
>> is relevant. What am i missing here?
>>
>> @Dong
>> I am still on the position that the current proposal brings us into the
>> wrong direction. Especially introducing PartitionKeyRebalanceListener
>>  From this point we can never move away to proper state full handling
>> without completely deprecating this creature from hell again.
>> Linear hashing is not the optimising step we have todo here. An interface
>> that when a topic is a topic its always the same even after it had
>> grown or shrunk is important. So from my POV I have major concerns that
>> this KIP is benefitial in its current state.
>>
>> What is it that makes everyone so addicted to the idea of linear hashing?
>> not attractive at all for me.
>> And with statefull consumers still a complete mess. Why not stick with the
>> Kappa architecture???
>>
>>
>>
>>
>>
>> On 03.04.2018 17:38, Dong Lin wrote:
>>
>>> Hey John,
>>>
>>> Thanks much for your comments!!
>>>
>>> I have yet to go through the emails of John/Jun/Guozhang in detail. But
>>> let
>>> me present my idea for how to minimize the delay for state loading for
>>> stream use-case.
>>>
>>> For ease of understanding, let's assume that the initial partition number
>>> of input topics and change log topic are both 10. And initial number of
>>> stream processor is also 10. If we only increase initial partition number
>>> of input topics to 15 without changing number of stream processor, the
>>> current KIP already guarantees in-order delivery and no state needs to be
>>> moved between consumers for stream use-case. Next, let's say we want to
>>> increase the number of processor to expand the processing capacity for
>>> stream use-case. This requires us to move state between processors which
>>> will take time. Our goal is to minimize the impact (i.e. delay) for
>>> processing while we increase the number of processors.
>>>
>>> Note that stream processor generally includes both consumer and producer.
>>> In addition to consume from the input topic, consumer may also need to
>>> consume from change log topic on startup for recovery. And producer may
>>> produce state to the change log topic.
>>>
>>>
>> The solution will include the following steps:
>>> 1) Increase partition number of the input topic from 10 to 15. Since the
>>> messages with the same key will still go to the same consume before and
>>> after the partition expansion, this step can be done without having to
>>> move
>>> state between processors.
>>>
>>> 2) Increase partition number of the change log topic from 10 to 15. Note
>>> that this step can also be done without impacting existing workflow. After
>>> we increase partition number of the change log topic, key space may split
>>> and some key will be produced to the newly-added partition. But the same
>>> key will still go to the same processor (i.e. consumer) before and after
>>> the partition. Thus this step can also be done without having to move
>>> state
>>> between processors.
>>>
>>> 3) Now, let's add 5 new consumers whose groupId is different from the
>>> existing processor's groupId. Thus these new consumers will not impact
>>> existing workflow. Each of these new consumers should consume two
>>> partitions from the earliest offset, where these two partitions are the
>>> same partitions that will be consumed if the consumers have the same
>>> groupId as the existing processor's groupId. For example, the first of the
>>> five consumers will consume partition 0 and partition 10. The purpose of
>>> these consumers is to rebuild the state (e.g. RocksDB) for the processors
>>> in advance. Also note that, by design of the current KIP, each consume
>>> will
>>> consume the existing partition of the change log topic up to the offset
>>> before the partition expansion. Then they will only need to consume the
>>> state of the new partition of the change log topic.
>>>
>>> 4) After consumers have caught up in step 3), we should stop these
>>> consumers and add 5 new processors to the stream processing job. These 5
>>> new processors should run in the same location as the previous 5 consumers
>>> to re-use the state (e.g. RocksDB). And these processors' consumers should
>>> consume partitions of the change log topic from the committed offset the
>>> previous 5 consumers so that no state is missed.
>>>
>>> One important trick to note here is that, the mapping from partition to
>>> consumer should also use linear hashing. And we need to remember the
>>> initial number of processors in the job, 10 in this example, and use this
>>> number in the linear hashing algorithm. This is pretty much the same as
>>> how
>>> we use linear hashing to map key to partition. In this case, we get an
>>> identity map from partition -> processor, for both input topic and the
>>> change log topic. For example, processor 12 will consume partition 12 of
>>> the input topic and produce state to the partition 12 of the change log
>>> topic.
>>>
>>> There are a few important properties of this solution to note:
>>>
>>> - We can increase the number of partitions for input topic and the change
>>> log topic in any order asynchronously.
>>> - The expansion of the processors in a given job in step 4) only requires
>>> the step 3) for the same job. It does not require coordination across
>>> different jobs for step 3) and 4). Thus different jobs can independently
>>> expand there capacity without waiting for each other.
>>> - The logic for 1) and 2) is already supported in the current KIP. The
>>> logic for 3) and 4) appears to be independent of the core Kafka logic and
>>> can be implemented separately outside core Kafka. Thus the current KIP is
>>> probably sufficient after we agree on the efficiency and the correctness
>>> of
>>> the solution. We can have a separate KIP for Kafka Stream to support 3)
>>> and
>>> 4).
>>>
>>>
>>> Cheers,
>>> Dong
>>>
>>>
>>> On Mon, Apr 2, 2018 at 3:25 PM, Guozhang Wang <wa...@gmail.com> wrote:
>>>
>>> Hey guys, just sharing my two cents here (I promise it will be shorter
>>>> than
>>>> John's article :).
>>>>
>>>> 0. Just to quickly recap, the main discussion point now is how to support
>>>> "key partitioning preservation" (John's #4 in topic characteristics
>>>> above)
>>>> beyond the "single-key ordering preservation" that KIP-253 was originally
>>>> proposed to maintain (John's #6 above).
>>>>
>>>> 1. From the streams project, we are actively working on improving the
>>>> elastic scalability of the library. One of the key features is to
>>>> decouple
>>>> the input topics from the parallelism model of Streams: i.e. not
>>>> enforcing
>>>> the topic to be partitioned by the key, not enforcing joining topics to
>>>> be
>>>> co-partitioned, not relying the number of parallel tasks on the input
>>>> topic
>>>> partitions. This can be achieved by re-shuffling on the input topics to
>>>> make sure key-partitioning / co-partitioning on the internal topics. Note
>>>> the re-shuffling task is purely stateless and hence does not require "key
>>>> partitioning preservation". Operational-wise it is similar to the
>>>> "creating
>>>> a new topic with new number of partitions, pipe the data to the new topic
>>>> and cut over consumers from old topics" idea, just that users can
>>>> optionally let Streams to handle such rather than doing it manually
>>>> themselves. There are a few more details on that regard but I will skip
>>>> since they are not directly related to this discussion.
>>>>
>>>> 2. Assuming that 1) above is done, then the only topics involved in the
>>>> scaling events are all input topics. For these topics the only producers
>>>> /
>>>> consumers of these topics are controlled by Streams clients themselves,
>>>> and
>>>> hence achieving "key partitioning preservation" is simpler than
>>>> non-Streams
>>>> scenarios: consumers know the partitioning scheme that producers are
>>>> using,
>>>> so that for their stateful operations it is doable to split the local
>>>> state
>>>> stores accordingly or execute backfilling on its own. Of course, if we
>>>> decide to do server-side backfilling, it can still help Streams to
>>>> directly
>>>> rely on that functionality.
>>>>
>>>> 3. As John mentioned, another way inside Streams is to do
>>>> over-partitioning
>>>> on all internal topics; then with 1) Streams would not rely on KIP-253 at
>>>> all. But personally I'd like to avoid it if possible to reduce Kafka side
>>>> footprint: say we overpartition each input topic up to 1k, with a
>>>> reasonable sized stateful topology it can still contribute to tens of
>>>> thousands of topics to the topic partition capacity of a single cluster.
>>>>
>>>> 4. Summing up 1/2/3, I think we should focus more on non-Streams users
>>>> writing their stateful computations with local states, and think whether
>>>> /
>>>> how we could enable "key partitioning preservation" for them easily, than
>>>> to think heavily for Streams library. People may have different opinion
>>>> on
>>>> how common of a usage pattern it is (I think Jun might be suggesting that
>>>> for DIY apps people may more likely use remote states so that it is not a
>>>> problem for them). My opinion is that for non-Streams users such usage
>>>> pattern could still be large (think: if you are piping data from Kafka to
>>>> an external data storage which has single-writer requirements for each
>>>> single shard, even though it is not a stateful computational application
>>>> it
>>>> may still require "key partitioning preservation"), so I prefer to have
>>>> backfilling in our KIP than only exposing the API for expansion and
>>>> requires consumers to have pre-knowledge of the producer's partitioning
>>>> scheme.
>>>>
>>>>
>>>>
>>>> Guozhang
>>>>
>>>>
>>>>
>>>> On Thu, Mar 29, 2018 at 2:33 PM, John Roesler <jo...@confluent.io> wrote:
>>>>
>>>> Hey Dong,
>>>>> Congrats on becoming a committer!!!
>>>>>
>>>>> Since I just sent a novel-length email, I'll try and keep this one brief
>>>>>
>>>> ;)
>>>>
>>>>> Regarding producer coordination, I'll grant that in that case, producers
>>>>> may coordinate among themselves to produce into the same topic or to
>>>>> produce co-partitioned topics. Nothing in KStreams or the Kafka
>>>>> ecosystem
>>>>> in general requires such coordination for correctness or in fact for any
>>>>> optional features, though, so I would not say that we require producer
>>>>> coordination of partition logic. If producers currently coordinate, it's
>>>>> completely optional and their own choice.
>>>>>
>>>>> Regarding the portability of partition algorithms, my observation is
>>>>> that
>>>>> systems requiring independent implementations of the same algorithm with
>>>>> 100% correctness are a large source of risk and also a burden on those
>>>>>
>>>> who
>>>>
>>>>> have to maintain them. If people could flawlessly implement algorithms
>>>>> in
>>>>> actual software, the world would be a wonderful place indeed! For a
>>>>>
>>>> system
>>>>
>>>>> as important and widespread as Kafka, I would recommend restricting
>>>>> limiting such requirements as aggressively as possible.
>>>>>
>>>>> I'd agree that we can always revisit decisions like allowing arbitrary
>>>>> partition functions, but of course, we shouldn't do that in a vacuum.
>>>>>
>>>> That
>>>>
>>>>> feels like the kind of thing we'd need to proactively seek guidance from
>>>>> the users list about. I do think that the general approach of saying
>>>>> that
>>>>> "if you use a custom partitioner, you cannot do partition expansion" is
>>>>> very reasonable (but I don't think we need to go that far with the
>>>>>
>>>> current
>>>>
>>>>> proposal). It's similar to my statement in my email to Jun that in
>>>>> principle KStreams doesn't *need* backfill, we only need it if we want
>>>>> to
>>>>> employ partition expansion.
>>>>>
>>>>> I reckon that the main motivation for backfill is to support KStreams
>>>>> use
>>>>> cases and also any other use cases involving stateful consumers.
>>>>>
>>>>> Thanks for your response, and congrats again!
>>>>> -John
>>>>>
>>>>>
>>>>> On Wed, Mar 28, 2018 at 1:34 AM, Dong Lin <li...@gmail.com> wrote:
>>>>>
>>>>> Hey John,
>>>>>> Great! Thanks for all the comment. It seems that we agree that the
>>>>>>
>>>>> current
>>>>>
>>>>>> KIP is in good shape for core Kafka. IMO, what we have been discussing
>>>>>>
>>>>> in
>>>>> the recent email exchanges is mostly about the second step, i.e. how to
>>>>>> address problem for the stream use-case (or stateful processing in
>>>>>> general).
>>>>>>
>>>>>> I will comment inline.
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> On Tue, Mar 27, 2018 at 4:38 PM, John Roesler <jo...@confluent.io>
>>>>>>
>>>>> wrote:
>>>>> Thanks for the response, Dong.
>>>>>>> Here are my answers to your questions:
>>>>>>>
>>>>>>> - "Asking producers and consumers, or even two different producers,
>>>>>>>
>>>>>> to
>>>>> share code like the partition function is a pretty huge ask. What
>>>>>>> if
>>>>> they
>>>>>>> are using different languages?". It seems that today we already
>>>>>>> require
>>>>>> different producer's to use the same hash function -- otherwise
>>>>>>> messages
>>>>>>> with the same key will go to different partitions of the same topic
>>>>>>> which
>>>>>>> may cause problem for downstream consumption. So not sure if it
>>>>>>> adds
>>>>> any
>>>>>>> more constraint by assuming consumers know the hash function of
>>>>>>> producer.
>>>>>>> Could you explain more why user would want to use a cusmtom
>>>>>>> partition
>>>>> function? Maybe we can check if this is something that can be
>>>>>>> supported
>>>>>> in
>>>>>>>> the default Kafka hash function. Also, can you explain more why it
>>>>>>>>
>>>>>>> is
>>>>> difficuilt to implement the same hash function in different
>>>>>>> languages?
>>>>>>> Sorry, I meant two different producers as in producers to two
>>>>>>>
>>>>>> different
>>>>> topics. This was in response to the suggestion that we already
>>>>>> require
>>>>> coordination among producers to different topics in order to achieve
>>>>>>> co-partitioning. I was saying that we do not (and should not).
>>>>>>>
>>>>>> It is probably common for producers of different team to produce
>>>>>>
>>>>> message
>>>>> to
>>>>>
>>>>>> the same topic. In order to ensure that messages with the same key go
>>>>>>
>>>>> to
>>>>> same partition, we need producers of different team to share the same
>>>>>> partition algorithm, which by definition requires coordination among
>>>>>> producers of different teams in an organization. Even for producers of
>>>>>> different topics, it may be common to require producers to use the same
>>>>>> partition algorithm in order to join two topics for stream processing.
>>>>>>
>>>>> Does
>>>>>
>>>>>> this make it reasonable to say we already require coordination across
>>>>>> producers?
>>>>>>
>>>>>>
>>>>>> By design, consumers are currently ignorant of the partitioning
>>>>>> scheme.
>>>>> It
>>>>>>> suffices to trust that the producer has partitioned the topic by key,
>>>>>>>
>>>>>> if
>>>>>> they claim to have done so. If you don't trust that, or even if you
>>>>>> just
>>>>>> need some other partitioning scheme, then you must re-partition it
>>>>>>> yourself. Nothing we're discussing can or should change that. The
>>>>>>>
>>>>>> value
>>>>> of
>>>>>>> backfill is that it preserves the ability for consumers to avoid
>>>>>>> re-partitioning before consuming, in the case where they don't need
>>>>>>>
>>>>>> to
>>>>> today.
>>>>>> Regarding shared "hash functions", note that it's a bit inaccurate to
>>>>>> talk
>>>>>>
>>>>>>> about the "hash function" of the producer. Properly speaking, the
>>>>>>>
>>>>>> producer
>>>>>>
>>>>>>> has only a "partition function". We do not know that it is a hash.
>>>>>>>
>>>>>> The
>>>>> producer can use any method at their disposal to assign a partition
>>>>>> to
>>>>> a
>>>>>
>>>>>> record. The partition function obviously may we written in any
>>>>>> programming
>>>>>>
>>>>>>> language, so in general it's not something that can be shared around
>>>>>>> without a formal spec or the ability to execute arbitrary executables
>>>>>>>
>>>>>> in
>>>>>> arbitrary runtime environments.
>>>>>>> Yeah it is probably better to say partition algorithm. I guess it
>>>>> should
>>>>> not be difficult to implement same partition algorithms in different
>>>>>> languages, right? Yes we would need a formal specification of the
>>>>>>
>>>>> default
>>>>> partition algorithm in the producer. I think that can be documented as
>>>>> part
>>>>>
>>>>>> of the producer interface.
>>>>>>
>>>>>>
>>>>>> Why would a producer want a custom partition function? I don't
>>>>>> know...
>>>>> why
>>>>>>> did we design the interface so that our users can provide one? In
>>>>>>>
>>>>>> general,
>>>>>>
>>>>>>> such systems provide custom partitioners because some data sets may
>>>>>>>
>>>>>> be
>>>>> unbalanced under the default or because they can provide some
>>>>>> interesting
>>>>>> functionality built on top of the partitioning scheme, etc. Having
>>>>>> provided
>>>>>>
>>>>>>> this ability, I don't know why we would remove it.
>>>>>>>
>>>>>>> Yeah it is reasonable to assume that there was reason to support
>>>>>> custom
>>>>>> partition function in producer. On the other hand it may also be
>>>>>>
>>>>> reasonable
>>>>>
>>>>>> to revisit this interface and discuss whether we actually need to
>>>>>>
>>>>> support
>>>>> custom partition function. If we don't have a good reason, we can
>>>>> choose
>>>>> not to support custom partition function in this KIP in a backward
>>>>>> compatible manner, i.e. user can still use custom partition function
>>>>>>
>>>>> but
>>>>> they would not get the benefit of in-order delivery when there is
>>>>> partition
>>>>>
>>>>>> expansion. What do you think?
>>>>>>
>>>>>>
>>>>>> - Besides the assumption that consumer needs to share the hash
>>>>>> function
>>>>> of
>>>>>>> producer, is there other organization overhead of the proposal in
>>>>>>> the
>>>>> current KIP?
>>>>>>>> It wasn't clear to me that KIP-253 currently required the producer
>>>>>> and
>>>>> consumer to share the partition function, or in fact that it had a
>>>>>> hard
>>>>> requirement to abandon the general partition function and use a
>>>>>> linear
>>>>> hash
>>>>>>> function instead.
>>>>>>>
>>>>>> In my reading, there is a requirement to track the metadata about
>>>>>> what
>>>>> partitions split into what other partitions during an expansion
>>>>>> operation.
>>>>>>
>>>>>>> If the partition function is linear, this is easy. If not, you can
>>>>>>>
>>>>>> always
>>>>>> just record that all old partitions split into all new partitions.
>>>>>> This
>>>>> has
>>>>>>> the effect of forcing all consumers to wait until the old epoch is
>>>>>>> completely consumed before starting on the new epoch. But this may
>>>>>>>
>>>>>> be a
>>>>> reasonable tradeoff, and it doesn't otherwise alter your design.
>>>>>>> You only mention the consumer needing to know that the partition
>>>>>>>
>>>>>> function
>>>>>> is linear, not what the actual function is, so I don't think your
>>>>>> design
>>>>>> actually calls for sharing the function. Plus, really all the
>>>>>> consumer
>>>>> needs is the metadata about what old-epoch partitions to wait for
>>>>>> before
>>>>>> consuming a new-epoch partition. This information is directly
>>>>>> captured
>>>>> in
>>>>>
>>>>>> metadata, so I don't think it actually even cares whether the
>>>>>> partition
>>>>> function is linear or not.
>>>>>>> You are right that the current KIP does not mention it. My comment
>>>>> related
>>>>>
>>>>>> to the partition function coordination was related to support the
>>>>>> stream-use case which we have been discussing so far.
>>>>>>
>>>>>>
>>>>>> So, no, I really think KIP-253 is in good shape. I was really more
>>>>>> talking
>>>>>>
>>>>>>> about the part of this thread that's outside of KIP-253's scope,
>>>>>>>
>>>>>> namely,
>>>>>> creating the possibility of backfilling partitions after expansion.
>>>>>>> Great! Can you also confirm that the main motivation for backfilling
>>>>>> partitions after expansion is to support the stream use-case?
>>>>>>
>>>>>>
>>>>>> - Currently producer can forget about the message that has been
>>>>>>>> acknowledged by the broker. Thus the producer probably does not
>>>>>>>>
>>>>>>> know
>>>>> most
>>>>>>> of the exiting messages in topic, including those messages produced
>>>>>>> by
>>>>>> other producers. We can have the owner of the producer to
>>>>>>> split+backfill.
>>>>>>> In my opion it will be a new program that wraps around the existing
>>>>>>>> producer and consumer classes.
>>>>>>>>
>>>>>>>> This sounds fine by me!
>>>>>>> Really, I was just emphasizing that the part of the organization that
>>>>>>> produces a topic shouldn't have to export their partition function to
>>>>>>>
>>>>>> the
>>>>>> part(s) of the organization (or other organizations) that consume the
>>>>>>> topic. Whether the backfill operation goes into the Producer
>>>>>>>
>>>>>> interface
>>>>> is
>>>>>
>>>>>> secondary, I think.
>>>>>>> - Regarding point 5. The argument is in favor of the split+backfill
>>>>>>>
>>>>>> but
>>>>> for
>>>>>>> changelog topic. And it intends to address the problem for stream
>>>>>>> use-case
>>>>>>>
>>>>>>>> in general. In this KIP we will provide interface (i.e.
>>>>>>>> PartitionKeyRebalanceListener in the KIP) to be used by sream
>>>>>>>>
>>>>>>> use-case
>>>>>> and
>>>>>>>> the goal is that user can flush/re-consume the state as part of the
>>>>>>>> interface implementation regardless of whether there is change log
>>>>>>>>
>>>>>>> topic.
>>>>>>> Maybe you are suggesting that the main reason to do split+backfill
>>>>>>> of
>>>>> input
>>>>>>>> topic is to support log compacted topics? You mentioned in Point 1
>>>>>>>>
>>>>>>> that
>>>>>> log
>>>>>>>> compacted topics is out of the scope of this KIP. Maybe I could
>>>>>>>>
>>>>>>> understand
>>>>>>>
>>>>>>>> your position better. Regarding Jan's proposal to split partitions
>>>>>>>>
>>>>>>> with
>>>>>> backfill, do you think this should replace the proposal in the
>>>>>>> existing
>>>>>> KIP, or do you think this is something that we should do in
>>>>>>> addition
>>>>> to
>>>>>
>>>>>> the
>>>>>>>> existing KIP?
>>>>>>>>
>>>>>>>> I think that interface is a good/necessary component of KIP-253.
>>>>>>> I personally (FWIW) feel that KIP-253 is appropriately scoped, but I
>>>>>>>
>>>>>> do
>>>>> think its utility will be limited unless there is a later KIP
>>>>>> offering
>>>>> backfill. But, maybe unlike Jan, I think it makes sense to try and
>>>>>> tackle
>>>>>> the ordering problem independently of backfill, so I'm in support of
>>>>>> the
>>>>>> current KIP.
>>>>>>> - Regarding point 6. I guess we can agree that it is better not to
>>>>>>>
>>>>>> have
>>>>> the
>>>>>>> performance overhread of copying the input data. Before we discuss
>>>>>>> more
>>>>>> on
>>>>>>>> whether the performance overhead is acceptable or not, I am trying
>>>>>>>>
>>>>>>> to
>>>>> figure out what is the benefit of introducing this overhread. You
>>>>>>> mentioned
>>>>>>>
>>>>>>>> that the benefit is the loose organizational coupling. By
>>>>>>>>
>>>>>>> "organizational
>>>>>>> coupling", are you referring to the requirement that consumer needs
>>>>>>> to
>>>>>> know
>>>>>>>> the hash function of producer? If so, maybe we can discuss the
>>>>>>>>
>>>>>>> use-case
>>>>>> of
>>>>>>>> custom partiton function and see whether we can find a way to
>>>>>>>>
>>>>>>> support
>>>>> such
>>>>>>>> use-case without having to copy the input data.
>>>>>>>>
>>>>>>>> I'm not too sure about what an "input" is in this sense, since we are
>>>>>> just
>>>>>>
>>>>>>> talking about topics. Actually the point I was making there is that
>>>>>>>
>>>>>> AKAICT
>>>>>>
>>>>>>> the performance overhead of a backfill is less than any other option,
>>>>>>> assuming you split partitions rarely.
>>>>>>>
>>>>>>> By "input" I was referring to source Kafka topic of a stream
>>>>>> processing
>>>>>> job.
>>>>>>
>>>>>>
>>>>>> Separately, yes, "organizational coupling" increases if producers and
>>>>>>> consumers have to share code, such as the partition function. This
>>>>>>>
>>>>>> would
>>>>>> not be the case if producers could only pick from a menu of a few
>>>>>>> well-known partition functions, but I think this is a poor tradeoff.
>>>>>>>
>>>>>>> Maybe we can revisit the custom partition function and see whether we
>>>>>> actually need it? Otherwise, I am concerned that every user will pay
>>>>>>
>>>>> the
>>>>> overhead of data movement to support something that was not really
>>>>> needed
>>>>> for most users.
>>>>>>
>>>>>> To me, this is two strong arguments in favor of backfill being less
>>>>>>> expensive than no backfill, but again, I think that particular debate
>>>>>>>
>>>>>> comes
>>>>>>
>>>>>>> after KIP-253, so I don't want to create the impression of opposition
>>>>>>>
>>>>>> to
>>>>>> your proposal.
>>>>>>>
>>>>>>> Finally, to respond to a new email I just noticed:
>>>>>>>
>>>>>>> BTW, here is my understanding of the scope of this KIP. We want to
>>>>>>> allow
>>>>>>> consumers to always consume messages with the same key from the
>>>>>>> same
>>>>> producer in the order they are produced. And we need to provide a
>>>>>>> way
>>>>> for
>>>>>>> stream use-case to be able to flush/load state when messages with
>>>>>>> the
>>>>> same
>>>>>>>> key are migrated between consumers. In addition to ensuring that
>>>>>>>>
>>>>>>> this
>>>>> goal
>>>>>>>> is correctly supported, we should do our best to keep the
>>>>>>>>
>>>>>>> performance
>>>>> and
>>>>>>> organization overhead of this KIP as low as possible.
>>>>>>>> I think we're on the same page there! In fact, I would generalize a
>>>>>> little
>>>>>>
>>>>>>> more and say that the mechanism you've designed provides *all
>>>>>>>
>>>>>> consumers*
>>>>>> the ability "to flush/load state when messages with the same key are
>>>>>>> migrated between consumers", not just Streams.
>>>>>>>
>>>>>>> Thanks for all the comment!
>>>>>>
>>>>>> Thanks for the discussion,
>>>>>>> -John
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> On Tue, Mar 27, 2018 at 3:14 PM, Dong Lin <li...@gmail.com>
>>>>>>>
>>>>>> wrote:
>>>>> Hey John,
>>>>>>>> Thanks much for the detailed comments. Here are my thoughts:
>>>>>>>>
>>>>>>>> - The need to delete messages from log compacted topics is mainly
>>>>>>>>
>>>>>>> for
>>>>> performance (e.g. storage space) optimization than for correctness
>>>>>>> for
>>>>>> this
>>>>>>>> KIP. I agree that we probably don't need to focus on this in our
>>>>>>>>
>>>>>>> discussion
>>>>>>>
>>>>>>>> since it is mostly for performance optimization.
>>>>>>>>
>>>>>>>> - "Asking producers and consumers, or even two different producers,
>>>>>>>>
>>>>>>> to
>>>>>> share code like the partition function is a pretty huge ask. What
>>>>>>> if
>>>>> they
>>>>>>> are using different languages?". It seems that today we already
>>>>>>> require
>>>>>> different producer's to use the same hash function -- otherwise
>>>>>>> messages
>>>>>>> with the same key will go to different partitions of the same topic
>>>>>>> which
>>>>>>> may cause problem for downstream consumption. So not sure if it
>>>>>>> adds
>>>>> any
>>>>>>> more constraint by assuming consumers know the hash function of
>>>>>>> producer.
>>>>>>> Could you explain more why user would want to use a cusmtom
>>>>>>> partition
>>>>> function? Maybe we can check if this is something that can be
>>>>>>> supported
>>>>>> in
>>>>>>>> the default Kafka hash function. Also, can you explain more why it
>>>>>>>>
>>>>>>> is
>>>>> difficuilt to implement the same hash function in different
>>>>>>> languages?
>>>>>> - Besides the assumption that consumer needs to share the hash
>>>>>>> function
>>>>>> of
>>>>>>>> producer, is there other organization overhead of the proposal in
>>>>>>>>
>>>>>>> the
>>>>> current KIP?
>>>>>>>> - Currently producer can forget about the message that has been
>>>>>>>> acknowledged by the broker. Thus the producer probably does not
>>>>>>>>
>>>>>>> know
>>>>> most
>>>>>>> of the exiting messages in topic, including those messages produced
>>>>>>> by
>>>>>> other producers. We can have the owner of the producer to
>>>>>>> split+backfill.
>>>>>>> In my opion it will be a new program that wraps around the existing
>>>>>>>> producer and consumer classes.
>>>>>>>>
>>>>>>>> - Regarding point 5. The argument is in favor of the split+backfill
>>>>>>>>
>>>>>>> but
>>>>>> for
>>>>>>>> changelog topic. And it intends to address the problem for stream
>>>>>>>>
>>>>>>> use-case
>>>>>>>
>>>>>>>> in general. In this KIP we will provide interface (i.e.
>>>>>>>> PartitionKeyRebalanceListener in the KIP) to be used by sream
>>>>>>>>
>>>>>>> use-case
>>>>>> and
>>>>>>>> the goal is that user can flush/re-consume the state as part of the
>>>>>>>> interface implementation regardless of whether there is change log
>>>>>>>>
>>>>>>> topic.
>>>>>>> Maybe you are suggesting that the main reason to do split+backfill
>>>>>>> of
>>>>> input
>>>>>>>> topic is to support log compacted topics? You mentioned in Point 1
>>>>>>>>
>>>>>>> that
>>>>>> log
>>>>>>>> compacted topics is out of the scope of this KIP. Maybe I could
>>>>>>>>
>>>>>>> understand
>>>>>>>
>>>>>>>> your position better. Regarding Jan's proposal to split partitions
>>>>>>>>
>>>>>>> with
>>>>>> backfill, do you think this should replace the proposal in the
>>>>>>> existing
>>>>>> KIP, or do you think this is something that we should do in
>>>>>>> addition
>>>>> to
>>>>>
>>>>>> the
>>>>>>>> existing KIP?
>>>>>>>>
>>>>>>>> - Regarding point 6. I guess we can agree that it is better not to
>>>>>>>>
>>>>>>> have
>>>>>> the
>>>>>>>> performance overhread of copying the input data. Before we discuss
>>>>>>>>
>>>>>>> more
>>>>>> on
>>>>>>>> whether the performance overhead is acceptable or not, I am trying
>>>>>>>>
>>>>>>> to
>>>>> figure out what is the benefit of introducing this overhread. You
>>>>>>> mentioned
>>>>>>>
>>>>>>>> that the benefit is the loose organizational coupling. By
>>>>>>>>
>>>>>>> "organizational
>>>>>>> coupling", are you referring to the requirement that consumer needs
>>>>>>> to
>>>>>> know
>>>>>>>> the hash function of producer? If so, maybe we can discuss the
>>>>>>>>
>>>>>>> use-case
>>>>>> of
>>>>>>>> custom partiton function and see whether we can find a way to
>>>>>>>>
>>>>>>> support
>>>>> such
>>>>>>>> use-case without having to copy the input data.
>>>>>>>>
>>>>>>>> Thanks,
>>>>>>>> Dong
>>>>>>>>
>>>>>>>>
>>>>>>>> On Tue, Mar 27, 2018 at 11:34 AM, John Roesler <jo...@confluent.io>
>>>>>>>>
>>>>>>> wrote:
>>>>>>>
>>>>>>>> Hey Dong and Jun,
>>>>>>>>> Thanks for the thoughtful responses. If you don't mind, I'll mix
>>>>>>>>>
>>>>>>>> my
>>>>> replies
>>>>>>>>> together to try for a coherent response. I'm not too familiar
>>>>>>>>>
>>>>>>>> with
>>>>> mailing-list etiquette, though.
>>>>>>>>> I'm going to keep numbering my points because it makes it easy
>>>>>>>>>
>>>>>>>> for
>>>>> you
>>>>>>> all
>>>>>>>>> to respond.
>>>>>>>>>
>>>>>>>>> Point 1:
>>>>>>>>> As I read it, KIP-253 is *just* about properly fencing the
>>>>>>>>>
>>>>>>>> producers
>>>>>> and
>>>>>>>> consumers so that you preserve the correct ordering of records
>>>>>>>> during
>>>>>> partition expansion. This is clearly necessary regardless of
>>>>>>>> anything
>>>>>> else
>>>>>>>>> we discuss. I think this whole discussion about backfill,
>>>>>>>>>
>>>>>>>> consumers,
>>>>>> streams, etc., is beyond the scope of KIP-253. But it would be
>>>>>>>> cumbersome
>>>>>>>> to start a new thread at this point.
>>>>>>>>> I had missed KIP-253's Proposed Change #9 among all the
>>>>>>>>>
>>>>>>>> details...
>>>>> I
>>>>>
>>>>>> think
>>>>>>>>> this is a nice addition to the proposal. One thought is that it's
>>>>>>>>>
>>>>>>>> actually
>>>>>>>>
>>>>>>>>> irrelevant whether the hash function is linear. This is simply an
>>>>>>>>>
>>>>>>>> algorithm
>>>>>>>>
>>>>>>>>> for moving a key from one partition to another, so the type of
>>>>>>>>>
>>>>>>>> hash
>>>>> function need not be a precondition. In fact, it also doesn't
>>>>>>>> matter
>>>>>> whether the topic is compacted or not, the algorithm works
>>>>>>>> regardless.
>>>>>>> I think this is a good algorithm to keep in mind, as it might
>>>>>>>> solve a
>>>>>> variety of problems, but it does have a downside: that the
>>>>>>>> producer
>>>>> won't
>>>>>>>> know whether or not K1 was actually in P1, it just knows that K1
>>>>>>>> was
>>>>>> in
>>>>>>
>>>>>>> P1's keyspace before the new epoch. Therefore, it will have to
>>>>>>>>> pessimistically send (K1,null) to P1 just in case. But the next
>>>>>>>>>
>>>>>>>> time
>>>>>> K1
>>>>>>
>>>>>>> comes along, the producer *also* won't remember that it already
>>>>>>>> retracted
>>>>>>>> K1 from P1, so it will have to send (K1,null) *again*. By
>>>>>>>> extension,
>>>>>> every
>>>>>>>>> time the producer sends to P2, it will also have to send a
>>>>>>>>>
>>>>>>>> tombstone
>>>>>> to
>>>>>>
>>>>>>> P1,
>>>>>>>>> which is a pretty big burden. To make the situation worse, if
>>>>>>>>>
>>>>>>>> there
>>>>> is
>>>>>>> a
>>>>>>>
>>>>>>>> second split, say P2 becomes P2 and P3, then any key Kx belonging
>>>>>>>> to
>>>>>> P3
>>>>>>
>>>>>>> will also have to be retracted from P2 *and* P1, since the
>>>>>>>> producer
>>>>> can't
>>>>>>>> know whether Kx had been last written to P2 or P1. Over a long
>>>>>>>> period
>>>>>> of
>>>>>>>> time, this clearly becomes a issue, as the producer must send an
>>>>>>>> arbitrary
>>>>>>>>
>>>>>>>>> number of retractions along with every update.
>>>>>>>>>
>>>>>>>>> In contrast, the proposed backfill operation has an end, and
>>>>>>>>>
>>>>>>>> after
>>>>> it
>>>>>
>>>>>> ends,
>>>>>>>>> everyone can afford to forget that there ever was a different
>>>>>>>>>
>>>>>>>> partition
>>>>>>> layout.
>>>>>>>>> Really, though, figuring out how to split compacted topics is
>>>>>>>>>
>>>>>>>> beyond
>>>>>> the
>>>>>>>> scope of KIP-253, so I'm not sure #9 really even needs to be in
>>>>>>>> this
>>>>>> KIP...
>>>>>>>>> We do need in-order delivery during partition expansion. It would
>>>>>>>>>
>>>>>>>> be
>>>>>> fine
>>>>>>>> by me to say that you *cannot* expand partitions of a
>>>>>>>> log-compacted
>>>>> topic
>>>>>>>> and call it a day. I think it would be better to tackle that in
>>>>>>>> another
>>>>>>> KIP.
>>>>>>>>>
>>>>>>>>> Point 2:
>>>>>>>>> Regarding whether the consumer re-shuffles its inputs, this is
>>>>>>>>>
>>>>>>>> always
>>>>>> on
>>>>>>>> the table; any consumer who wants to re-shuffle its input is free
>>>>>>>> to
>>>>>> do
>>>>>>
>>>>>>> so.
>>>>>>>>> But this is currently not required. It's just that the current
>>>>>>>>>
>>>>>>>> high-level
>>>>>>>> story with Kafka encourages the use of partitions as a unit of
>>>>>>>> concurrency.
>>>>>>>>
>>>>>>>>> As long as consumers are single-threaded, they can happily
>>>>>>>>>
>>>>>>>> consume
>>>>> a
>>>>>
>>>>>> single
>>>>>>>>> partition without concurrency control of any kind. This is a key
>>>>>>>>>
>>>>>>>> aspect
>>>>>>> to
>>>>>>>>> this system that lets folks design high-throughput systems on top
>>>>>>>>>
>>>>>>>> of
>>>>>> it
>>>>>>
>>>>>>> surprisingly easily. If all consumers were instead
>>>>>>>> encouraged/required
>>>>>>> to
>>>>>>>
>>>>>>>> implement a repartition of their own, then the consumer becomes
>>>>>>>>> significantly more complex, requiring either the consumer to
>>>>>>>>>
>>>>>>>> first
>>>>> produce
>>>>>>>>> to its own intermediate repartition topic or to ensure that
>>>>>>>>>
>>>>>>>> consumer
>>>>>> threads have a reliable, high-bandwith channel of communication
>>>>>>>> with
>>>>>> every
>>>>>>>>> other consumer thread.
>>>>>>>>>
>>>>>>>>> Either of those tradeoffs may be reasonable for a particular user
>>>>>>>>>
>>>>>>>> of
>>>>>> Kafka,
>>>>>>>>> but I don't know if we're in a position to say that they are
>>>>>>>>>
>>>>>>>> reasonable
>>>>>>> for
>>>>>>>>> *every* user of Kafka.
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> Point 3:
>>>>>>>>> Regarding Jun's point about this use case, "(3) stateful and
>>>>>>>>>
>>>>>>>> maintaining
>>>>>>>> the
>>>>>>>>> states in a local store", I agree that they may use a framework
>>>>>>>>>
>>>>>>>> *like*
>>>>>>> Kafka Streams, but that is not the same as using Kafka Streams.
>>>>>>>> This
>>>>>> is
>>>>>>
>>>>>>> why
>>>>>>>>> I think it's better to solve it in Core: because it is then
>>>>>>>>>
>>>>>>>> solved
>>>>> for
>>>>>>> KStreams and also for everything else that facilitates local
>>>>>>>> state
>>>>> maintenance. To me, Streams is a member of the category of
>>>>>>>> "stream
>>>>> processing frameworks", which is itself a subcategory of "things
>>>>>>>> requiring
>>>>>>>>
>>>>>>>>> local state maintenence". I'm not sure if it makes sense to
>>>>>>>>



Re: [DISCUSS] KIP-253: Support in-order message delivery with partition expansion

Posted by Jun Rao <ju...@confluent.io>.
Hi, Jan, Dong, John, Guozhang,

Perhaps it will be useful to have a KIP meeting to discuss this together as
a group. Would Apr. 9 (Monday) at 9:00am PDT work? If so, I will send out
an invite to the mailing list.

Thanks,

Jun


On Wed, Apr 4, 2018 at 1:25 AM, Jan Filipiak <Ja...@trivago.com>
wrote:

> Want to quickly step in here again because it is going places again.
>
> The last part of the discussion is just a pain to read and completely
> diverged from what I suggested without making the reasons clear to me.
>
> I don't know why this happens.... here are my comments anyway.
>
> @Guozhang: That Streams is working on automatic creating
> copartition-usuable topics: great for streams, has literally nothing todo
> with the KIP as we want to grow the
> input topic. Everyone can reshuffle rel. easily but that is not what we
> need todo, we need to grow the topic in question. After streams
> automatically reshuffled the input topic
> still has the same size and it didn't help a bit. I fail to see why this
> is relevant. What am i missing here?
>
> @Dong
> I am still on the position that the current proposal brings us into the
> wrong direction. Especially introducing PartitionKeyRebalanceListener
> From this point we can never move away to proper state full handling
> without completely deprecating this creature from hell again.
> Linear hashing is not the optimising step we have todo here. An interface
> that when a topic is a topic its always the same even after it had
> grown or shrunk is important. So from my POV I have major concerns that
> this KIP is benefitial in its current state.
>
> What is it that makes everyone so addicted to the idea of linear hashing?
> not attractive at all for me.
> And with statefull consumers still a complete mess. Why not stick with the
> Kappa architecture???
>
>
>
>
>
> On 03.04.2018 17:38, Dong Lin wrote:
>
>> Hey John,
>>
>> Thanks much for your comments!!
>>
>> I have yet to go through the emails of John/Jun/Guozhang in detail. But
>> let
>> me present my idea for how to minimize the delay for state loading for
>> stream use-case.
>>
>> For ease of understanding, let's assume that the initial partition number
>> of input topics and change log topic are both 10. And initial number of
>> stream processor is also 10. If we only increase initial partition number
>> of input topics to 15 without changing number of stream processor, the
>> current KIP already guarantees in-order delivery and no state needs to be
>> moved between consumers for stream use-case. Next, let's say we want to
>> increase the number of processor to expand the processing capacity for
>> stream use-case. This requires us to move state between processors which
>> will take time. Our goal is to minimize the impact (i.e. delay) for
>> processing while we increase the number of processors.
>>
>> Note that stream processor generally includes both consumer and producer.
>> In addition to consume from the input topic, consumer may also need to
>> consume from change log topic on startup for recovery. And producer may
>> produce state to the change log topic.
>>
>>
> The solution will include the following steps:
>>
>> 1) Increase partition number of the input topic from 10 to 15. Since the
>> messages with the same key will still go to the same consume before and
>> after the partition expansion, this step can be done without having to
>> move
>> state between processors.
>>
>> 2) Increase partition number of the change log topic from 10 to 15. Note
>> that this step can also be done without impacting existing workflow. After
>> we increase partition number of the change log topic, key space may split
>> and some key will be produced to the newly-added partition. But the same
>> key will still go to the same processor (i.e. consumer) before and after
>> the partition. Thus this step can also be done without having to move
>> state
>> between processors.
>>
>> 3) Now, let's add 5 new consumers whose groupId is different from the
>> existing processor's groupId. Thus these new consumers will not impact
>> existing workflow. Each of these new consumers should consume two
>> partitions from the earliest offset, where these two partitions are the
>> same partitions that will be consumed if the consumers have the same
>> groupId as the existing processor's groupId. For example, the first of the
>> five consumers will consume partition 0 and partition 10. The purpose of
>> these consumers is to rebuild the state (e.g. RocksDB) for the processors
>> in advance. Also note that, by design of the current KIP, each consume
>> will
>> consume the existing partition of the change log topic up to the offset
>> before the partition expansion. Then they will only need to consume the
>> state of the new partition of the change log topic.
>>
>> 4) After consumers have caught up in step 3), we should stop these
>> consumers and add 5 new processors to the stream processing job. These 5
>> new processors should run in the same location as the previous 5 consumers
>> to re-use the state (e.g. RocksDB). And these processors' consumers should
>> consume partitions of the change log topic from the committed offset the
>> previous 5 consumers so that no state is missed.
>>
>> One important trick to note here is that, the mapping from partition to
>> consumer should also use linear hashing. And we need to remember the
>> initial number of processors in the job, 10 in this example, and use this
>> number in the linear hashing algorithm. This is pretty much the same as
>> how
>> we use linear hashing to map key to partition. In this case, we get an
>> identity map from partition -> processor, for both input topic and the
>> change log topic. For example, processor 12 will consume partition 12 of
>> the input topic and produce state to the partition 12 of the change log
>> topic.
>>
>> There are a few important properties of this solution to note:
>>
>> - We can increase the number of partitions for input topic and the change
>> log topic in any order asynchronously.
>> - The expansion of the processors in a given job in step 4) only requires
>> the step 3) for the same job. It does not require coordination across
>> different jobs for step 3) and 4). Thus different jobs can independently
>> expand there capacity without waiting for each other.
>> - The logic for 1) and 2) is already supported in the current KIP. The
>> logic for 3) and 4) appears to be independent of the core Kafka logic and
>> can be implemented separately outside core Kafka. Thus the current KIP is
>> probably sufficient after we agree on the efficiency and the correctness
>> of
>> the solution. We can have a separate KIP for Kafka Stream to support 3)
>> and
>> 4).
>>
>>
>> Cheers,
>> Dong
>>
>>
>> On Mon, Apr 2, 2018 at 3:25 PM, Guozhang Wang <wa...@gmail.com> wrote:
>>
>> Hey guys, just sharing my two cents here (I promise it will be shorter
>>> than
>>> John's article :).
>>>
>>> 0. Just to quickly recap, the main discussion point now is how to support
>>> "key partitioning preservation" (John's #4 in topic characteristics
>>> above)
>>> beyond the "single-key ordering preservation" that KIP-253 was originally
>>> proposed to maintain (John's #6 above).
>>>
>>> 1. From the streams project, we are actively working on improving the
>>> elastic scalability of the library. One of the key features is to
>>> decouple
>>> the input topics from the parallelism model of Streams: i.e. not
>>> enforcing
>>> the topic to be partitioned by the key, not enforcing joining topics to
>>> be
>>> co-partitioned, not relying the number of parallel tasks on the input
>>> topic
>>> partitions. This can be achieved by re-shuffling on the input topics to
>>> make sure key-partitioning / co-partitioning on the internal topics. Note
>>> the re-shuffling task is purely stateless and hence does not require "key
>>> partitioning preservation". Operational-wise it is similar to the
>>> "creating
>>> a new topic with new number of partitions, pipe the data to the new topic
>>> and cut over consumers from old topics" idea, just that users can
>>> optionally let Streams to handle such rather than doing it manually
>>> themselves. There are a few more details on that regard but I will skip
>>> since they are not directly related to this discussion.
>>>
>>> 2. Assuming that 1) above is done, then the only topics involved in the
>>> scaling events are all input topics. For these topics the only producers
>>> /
>>> consumers of these topics are controlled by Streams clients themselves,
>>> and
>>> hence achieving "key partitioning preservation" is simpler than
>>> non-Streams
>>> scenarios: consumers know the partitioning scheme that producers are
>>> using,
>>> so that for their stateful operations it is doable to split the local
>>> state
>>> stores accordingly or execute backfilling on its own. Of course, if we
>>> decide to do server-side backfilling, it can still help Streams to
>>> directly
>>> rely on that functionality.
>>>
>>> 3. As John mentioned, another way inside Streams is to do
>>> over-partitioning
>>> on all internal topics; then with 1) Streams would not rely on KIP-253 at
>>> all. But personally I'd like to avoid it if possible to reduce Kafka side
>>> footprint: say we overpartition each input topic up to 1k, with a
>>> reasonable sized stateful topology it can still contribute to tens of
>>> thousands of topics to the topic partition capacity of a single cluster.
>>>
>>> 4. Summing up 1/2/3, I think we should focus more on non-Streams users
>>> writing their stateful computations with local states, and think whether
>>> /
>>> how we could enable "key partitioning preservation" for them easily, than
>>> to think heavily for Streams library. People may have different opinion
>>> on
>>> how common of a usage pattern it is (I think Jun might be suggesting that
>>> for DIY apps people may more likely use remote states so that it is not a
>>> problem for them). My opinion is that for non-Streams users such usage
>>> pattern could still be large (think: if you are piping data from Kafka to
>>> an external data storage which has single-writer requirements for each
>>> single shard, even though it is not a stateful computational application
>>> it
>>> may still require "key partitioning preservation"), so I prefer to have
>>> backfilling in our KIP than only exposing the API for expansion and
>>> requires consumers to have pre-knowledge of the producer's partitioning
>>> scheme.
>>>
>>>
>>>
>>> Guozhang
>>>
>>>
>>>
>>> On Thu, Mar 29, 2018 at 2:33 PM, John Roesler <jo...@confluent.io> wrote:
>>>
>>> Hey Dong,
>>>>
>>>> Congrats on becoming a committer!!!
>>>>
>>>> Since I just sent a novel-length email, I'll try and keep this one brief
>>>>
>>> ;)
>>>
>>>> Regarding producer coordination, I'll grant that in that case, producers
>>>> may coordinate among themselves to produce into the same topic or to
>>>> produce co-partitioned topics. Nothing in KStreams or the Kafka
>>>> ecosystem
>>>> in general requires such coordination for correctness or in fact for any
>>>> optional features, though, so I would not say that we require producer
>>>> coordination of partition logic. If producers currently coordinate, it's
>>>> completely optional and their own choice.
>>>>
>>>> Regarding the portability of partition algorithms, my observation is
>>>> that
>>>> systems requiring independent implementations of the same algorithm with
>>>> 100% correctness are a large source of risk and also a burden on those
>>>>
>>> who
>>>
>>>> have to maintain them. If people could flawlessly implement algorithms
>>>> in
>>>> actual software, the world would be a wonderful place indeed! For a
>>>>
>>> system
>>>
>>>> as important and widespread as Kafka, I would recommend restricting
>>>> limiting such requirements as aggressively as possible.
>>>>
>>>> I'd agree that we can always revisit decisions like allowing arbitrary
>>>> partition functions, but of course, we shouldn't do that in a vacuum.
>>>>
>>> That
>>>
>>>> feels like the kind of thing we'd need to proactively seek guidance from
>>>> the users list about. I do think that the general approach of saying
>>>> that
>>>> "if you use a custom partitioner, you cannot do partition expansion" is
>>>> very reasonable (but I don't think we need to go that far with the
>>>>
>>> current
>>>
>>>> proposal). It's similar to my statement in my email to Jun that in
>>>> principle KStreams doesn't *need* backfill, we only need it if we want
>>>> to
>>>> employ partition expansion.
>>>>
>>>> I reckon that the main motivation for backfill is to support KStreams
>>>> use
>>>> cases and also any other use cases involving stateful consumers.
>>>>
>>>> Thanks for your response, and congrats again!
>>>> -John
>>>>
>>>>
>>>> On Wed, Mar 28, 2018 at 1:34 AM, Dong Lin <li...@gmail.com> wrote:
>>>>
>>>> Hey John,
>>>>>
>>>>> Great! Thanks for all the comment. It seems that we agree that the
>>>>>
>>>> current
>>>>
>>>>> KIP is in good shape for core Kafka. IMO, what we have been discussing
>>>>>
>>>> in
>>>
>>>> the recent email exchanges is mostly about the second step, i.e. how to
>>>>> address problem for the stream use-case (or stateful processing in
>>>>> general).
>>>>>
>>>>> I will comment inline.
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> On Tue, Mar 27, 2018 at 4:38 PM, John Roesler <jo...@confluent.io>
>>>>>
>>>> wrote:
>>>
>>>> Thanks for the response, Dong.
>>>>>>
>>>>>> Here are my answers to your questions:
>>>>>>
>>>>>> - "Asking producers and consumers, or even two different producers,
>>>>>>
>>>>> to
>>>
>>>> share code like the partition function is a pretty huge ask. What
>>>>>>>
>>>>>> if
>>>
>>>> they
>>>>>
>>>>>> are using different languages?". It seems that today we already
>>>>>>>
>>>>>> require
>>>>
>>>>> different producer's to use the same hash function -- otherwise
>>>>>>>
>>>>>> messages
>>>>>
>>>>>> with the same key will go to different partitions of the same topic
>>>>>>>
>>>>>> which
>>>>>
>>>>>> may cause problem for downstream consumption. So not sure if it
>>>>>>>
>>>>>> adds
>>>
>>>> any
>>>>>
>>>>>> more constraint by assuming consumers know the hash function of
>>>>>>>
>>>>>> producer.
>>>>>
>>>>>> Could you explain more why user would want to use a cusmtom
>>>>>>>
>>>>>> partition
>>>
>>>> function? Maybe we can check if this is something that can be
>>>>>>>
>>>>>> supported
>>>>
>>>>> in
>>>>>>
>>>>>>> the default Kafka hash function. Also, can you explain more why it
>>>>>>>
>>>>>> is
>>>
>>>> difficuilt to implement the same hash function in different
>>>>>>>
>>>>>> languages?
>>>>
>>>>>
>>>>>> Sorry, I meant two different producers as in producers to two
>>>>>>
>>>>> different
>>>
>>>> topics. This was in response to the suggestion that we already
>>>>>>
>>>>> require
>>>
>>>> coordination among producers to different topics in order to achieve
>>>>>> co-partitioning. I was saying that we do not (and should not).
>>>>>>
>>>>>
>>>>> It is probably common for producers of different team to produce
>>>>>
>>>> message
>>>
>>>> to
>>>>
>>>>> the same topic. In order to ensure that messages with the same key go
>>>>>
>>>> to
>>>
>>>> same partition, we need producers of different team to share the same
>>>>> partition algorithm, which by definition requires coordination among
>>>>> producers of different teams in an organization. Even for producers of
>>>>> different topics, it may be common to require producers to use the same
>>>>> partition algorithm in order to join two topics for stream processing.
>>>>>
>>>> Does
>>>>
>>>>> this make it reasonable to say we already require coordination across
>>>>> producers?
>>>>>
>>>>>
>>>>> By design, consumers are currently ignorant of the partitioning
>>>>>>
>>>>> scheme.
>>>
>>>> It
>>>>>
>>>>>> suffices to trust that the producer has partitioned the topic by key,
>>>>>>
>>>>> if
>>>>
>>>>> they claim to have done so. If you don't trust that, or even if you
>>>>>>
>>>>> just
>>>>
>>>>> need some other partitioning scheme, then you must re-partition it
>>>>>> yourself. Nothing we're discussing can or should change that. The
>>>>>>
>>>>> value
>>>
>>>> of
>>>>>
>>>>>> backfill is that it preserves the ability for consumers to avoid
>>>>>> re-partitioning before consuming, in the case where they don't need
>>>>>>
>>>>> to
>>>
>>>> today.
>>>>>>
>>>>>
>>>>> Regarding shared "hash functions", note that it's a bit inaccurate to
>>>>>>
>>>>> talk
>>>>>
>>>>>> about the "hash function" of the producer. Properly speaking, the
>>>>>>
>>>>> producer
>>>>>
>>>>>> has only a "partition function". We do not know that it is a hash.
>>>>>>
>>>>> The
>>>
>>>> producer can use any method at their disposal to assign a partition
>>>>>>
>>>>> to
>>>
>>>> a
>>>>
>>>>> record. The partition function obviously may we written in any
>>>>>>
>>>>> programming
>>>>>
>>>>>> language, so in general it's not something that can be shared around
>>>>>> without a formal spec or the ability to execute arbitrary executables
>>>>>>
>>>>> in
>>>>
>>>>> arbitrary runtime environments.
>>>>>>
>>>>>> Yeah it is probably better to say partition algorithm. I guess it
>>>>>
>>>> should
>>>
>>>> not be difficult to implement same partition algorithms in different
>>>>> languages, right? Yes we would need a formal specification of the
>>>>>
>>>> default
>>>
>>>> partition algorithm in the producer. I think that can be documented as
>>>>>
>>>> part
>>>>
>>>>> of the producer interface.
>>>>>
>>>>>
>>>>> Why would a producer want a custom partition function? I don't
>>>>>>
>>>>> know...
>>>
>>>> why
>>>>>
>>>>>> did we design the interface so that our users can provide one? In
>>>>>>
>>>>> general,
>>>>>
>>>>>> such systems provide custom partitioners because some data sets may
>>>>>>
>>>>> be
>>>
>>>> unbalanced under the default or because they can provide some
>>>>>>
>>>>> interesting
>>>>
>>>>> functionality built on top of the partitioning scheme, etc. Having
>>>>>>
>>>>> provided
>>>>>
>>>>>> this ability, I don't know why we would remove it.
>>>>>>
>>>>>> Yeah it is reasonable to assume that there was reason to support
>>>>> custom
>>>>> partition function in producer. On the other hand it may also be
>>>>>
>>>> reasonable
>>>>
>>>>> to revisit this interface and discuss whether we actually need to
>>>>>
>>>> support
>>>
>>>> custom partition function. If we don't have a good reason, we can
>>>>>
>>>> choose
>>>
>>>> not to support custom partition function in this KIP in a backward
>>>>> compatible manner, i.e. user can still use custom partition function
>>>>>
>>>> but
>>>
>>>> they would not get the benefit of in-order delivery when there is
>>>>>
>>>> partition
>>>>
>>>>> expansion. What do you think?
>>>>>
>>>>>
>>>>> - Besides the assumption that consumer needs to share the hash
>>>>>>
>>>>> function
>>>
>>>> of
>>>>>
>>>>>> producer, is there other organization overhead of the proposal in
>>>>>>>
>>>>>> the
>>>
>>>> current KIP?
>>>>>>>
>>>>>>> It wasn't clear to me that KIP-253 currently required the producer
>>>>>>
>>>>> and
>>>
>>>> consumer to share the partition function, or in fact that it had a
>>>>>>
>>>>> hard
>>>
>>>> requirement to abandon the general partition function and use a
>>>>>>
>>>>> linear
>>>
>>>> hash
>>>>>
>>>>>> function instead.
>>>>>>
>>>>>
>>>>> In my reading, there is a requirement to track the metadata about
>>>>>>
>>>>> what
>>>
>>>> partitions split into what other partitions during an expansion
>>>>>>
>>>>> operation.
>>>>>
>>>>>> If the partition function is linear, this is easy. If not, you can
>>>>>>
>>>>> always
>>>>
>>>>> just record that all old partitions split into all new partitions.
>>>>>>
>>>>> This
>>>
>>>> has
>>>>>
>>>>>> the effect of forcing all consumers to wait until the old epoch is
>>>>>> completely consumed before starting on the new epoch. But this may
>>>>>>
>>>>> be a
>>>
>>>> reasonable tradeoff, and it doesn't otherwise alter your design.
>>>>>>
>>>>>> You only mention the consumer needing to know that the partition
>>>>>>
>>>>> function
>>>>
>>>>> is linear, not what the actual function is, so I don't think your
>>>>>>
>>>>> design
>>>>
>>>>> actually calls for sharing the function. Plus, really all the
>>>>>>
>>>>> consumer
>>>
>>>> needs is the metadata about what old-epoch partitions to wait for
>>>>>>
>>>>> before
>>>>
>>>>> consuming a new-epoch partition. This information is directly
>>>>>>
>>>>> captured
>>>
>>>> in
>>>>
>>>>> metadata, so I don't think it actually even cares whether the
>>>>>>
>>>>> partition
>>>
>>>> function is linear or not.
>>>>>>
>>>>>> You are right that the current KIP does not mention it. My comment
>>>>>
>>>> related
>>>>
>>>>> to the partition function coordination was related to support the
>>>>> stream-use case which we have been discussing so far.
>>>>>
>>>>>
>>>>> So, no, I really think KIP-253 is in good shape. I was really more
>>>>>>
>>>>> talking
>>>>>
>>>>>> about the part of this thread that's outside of KIP-253's scope,
>>>>>>
>>>>> namely,
>>>>
>>>>> creating the possibility of backfilling partitions after expansion.
>>>>>>
>>>>>> Great! Can you also confirm that the main motivation for backfilling
>>>>> partitions after expansion is to support the stream use-case?
>>>>>
>>>>>
>>>>> - Currently producer can forget about the message that has been
>>>>>>
>>>>>>> acknowledged by the broker. Thus the producer probably does not
>>>>>>>
>>>>>> know
>>>
>>>> most
>>>>>
>>>>>> of the exiting messages in topic, including those messages produced
>>>>>>>
>>>>>> by
>>>>
>>>>> other producers. We can have the owner of the producer to
>>>>>>>
>>>>>> split+backfill.
>>>>>
>>>>>> In my opion it will be a new program that wraps around the existing
>>>>>>> producer and consumer classes.
>>>>>>>
>>>>>>> This sounds fine by me!
>>>>>>
>>>>>> Really, I was just emphasizing that the part of the organization that
>>>>>> produces a topic shouldn't have to export their partition function to
>>>>>>
>>>>> the
>>>>
>>>>> part(s) of the organization (or other organizations) that consume the
>>>>>> topic. Whether the backfill operation goes into the Producer
>>>>>>
>>>>> interface
>>>
>>>> is
>>>>
>>>>> secondary, I think.
>>>>>>
>>>>>> - Regarding point 5. The argument is in favor of the split+backfill
>>>>>>
>>>>> but
>>>
>>>> for
>>>>>
>>>>>> changelog topic. And it intends to address the problem for stream
>>>>>>>
>>>>>> use-case
>>>>>>
>>>>>>> in general. In this KIP we will provide interface (i.e.
>>>>>>> PartitionKeyRebalanceListener in the KIP) to be used by sream
>>>>>>>
>>>>>> use-case
>>>>
>>>>> and
>>>>>>
>>>>>>> the goal is that user can flush/re-consume the state as part of the
>>>>>>> interface implementation regardless of whether there is change log
>>>>>>>
>>>>>> topic.
>>>>>
>>>>>> Maybe you are suggesting that the main reason to do split+backfill
>>>>>>>
>>>>>> of
>>>
>>>> input
>>>>>>
>>>>>>> topic is to support log compacted topics? You mentioned in Point 1
>>>>>>>
>>>>>> that
>>>>
>>>>> log
>>>>>>
>>>>>>> compacted topics is out of the scope of this KIP. Maybe I could
>>>>>>>
>>>>>> understand
>>>>>>
>>>>>>> your position better. Regarding Jan's proposal to split partitions
>>>>>>>
>>>>>> with
>>>>
>>>>> backfill, do you think this should replace the proposal in the
>>>>>>>
>>>>>> existing
>>>>
>>>>> KIP, or do you think this is something that we should do in
>>>>>>>
>>>>>> addition
>>>
>>>> to
>>>>
>>>>> the
>>>>>>
>>>>>>> existing KIP?
>>>>>>>
>>>>>>> I think that interface is a good/necessary component of KIP-253.
>>>>>>
>>>>>> I personally (FWIW) feel that KIP-253 is appropriately scoped, but I
>>>>>>
>>>>> do
>>>
>>>> think its utility will be limited unless there is a later KIP
>>>>>>
>>>>> offering
>>>
>>>> backfill. But, maybe unlike Jan, I think it makes sense to try and
>>>>>>
>>>>> tackle
>>>>
>>>>> the ordering problem independently of backfill, so I'm in support of
>>>>>>
>>>>> the
>>>>
>>>>> current KIP.
>>>>>>
>>>>>> - Regarding point 6. I guess we can agree that it is better not to
>>>>>>
>>>>> have
>>>
>>>> the
>>>>>
>>>>>> performance overhread of copying the input data. Before we discuss
>>>>>>>
>>>>>> more
>>>>
>>>>> on
>>>>>>
>>>>>>> whether the performance overhead is acceptable or not, I am trying
>>>>>>>
>>>>>> to
>>>
>>>> figure out what is the benefit of introducing this overhread. You
>>>>>>>
>>>>>> mentioned
>>>>>>
>>>>>>> that the benefit is the loose organizational coupling. By
>>>>>>>
>>>>>> "organizational
>>>>>
>>>>>> coupling", are you referring to the requirement that consumer needs
>>>>>>>
>>>>>> to
>>>>
>>>>> know
>>>>>>
>>>>>>> the hash function of producer? If so, maybe we can discuss the
>>>>>>>
>>>>>> use-case
>>>>
>>>>> of
>>>>>>
>>>>>>> custom partiton function and see whether we can find a way to
>>>>>>>
>>>>>> support
>>>
>>>> such
>>>>>>
>>>>>>> use-case without having to copy the input data.
>>>>>>>
>>>>>>> I'm not too sure about what an "input" is in this sense, since we are
>>>>>>
>>>>> just
>>>>>
>>>>>> talking about topics. Actually the point I was making there is that
>>>>>>
>>>>> AKAICT
>>>>>
>>>>>> the performance overhead of a backfill is less than any other option,
>>>>>> assuming you split partitions rarely.
>>>>>>
>>>>>> By "input" I was referring to source Kafka topic of a stream
>>>>> processing
>>>>> job.
>>>>>
>>>>>
>>>>> Separately, yes, "organizational coupling" increases if producers and
>>>>>> consumers have to share code, such as the partition function. This
>>>>>>
>>>>> would
>>>>
>>>>> not be the case if producers could only pick from a menu of a few
>>>>>> well-known partition functions, but I think this is a poor tradeoff.
>>>>>>
>>>>>> Maybe we can revisit the custom partition function and see whether we
>>>>> actually need it? Otherwise, I am concerned that every user will pay
>>>>>
>>>> the
>>>
>>>> overhead of data movement to support something that was not really
>>>>>
>>>> needed
>>>
>>>> for most users.
>>>>>
>>>>>
>>>>> To me, this is two strong arguments in favor of backfill being less
>>>>>> expensive than no backfill, but again, I think that particular debate
>>>>>>
>>>>> comes
>>>>>
>>>>>> after KIP-253, so I don't want to create the impression of opposition
>>>>>>
>>>>> to
>>>>
>>>>> your proposal.
>>>>>>
>>>>>>
>>>>>> Finally, to respond to a new email I just noticed:
>>>>>>
>>>>>> BTW, here is my understanding of the scope of this KIP. We want to
>>>>>>>
>>>>>> allow
>>>>>
>>>>>> consumers to always consume messages with the same key from the
>>>>>>>
>>>>>> same
>>>
>>>> producer in the order they are produced. And we need to provide a
>>>>>>>
>>>>>> way
>>>
>>>> for
>>>>>
>>>>>> stream use-case to be able to flush/load state when messages with
>>>>>>>
>>>>>> the
>>>
>>>> same
>>>>>>
>>>>>>> key are migrated between consumers. In addition to ensuring that
>>>>>>>
>>>>>> this
>>>
>>>> goal
>>>>>>
>>>>>>> is correctly supported, we should do our best to keep the
>>>>>>>
>>>>>> performance
>>>
>>>> and
>>>>>
>>>>>> organization overhead of this KIP as low as possible.
>>>>>>>
>>>>>>> I think we're on the same page there! In fact, I would generalize a
>>>>>>
>>>>> little
>>>>>
>>>>>> more and say that the mechanism you've designed provides *all
>>>>>>
>>>>> consumers*
>>>>
>>>>> the ability "to flush/load state when messages with the same key are
>>>>>> migrated between consumers", not just Streams.
>>>>>>
>>>>>> Thanks for all the comment!
>>>>>
>>>>>
>>>>> Thanks for the discussion,
>>>>>> -John
>>>>>>
>>>>>>
>>>>>>
>>>>>> On Tue, Mar 27, 2018 at 3:14 PM, Dong Lin <li...@gmail.com>
>>>>>>
>>>>> wrote:
>>>
>>>> Hey John,
>>>>>>>
>>>>>>> Thanks much for the detailed comments. Here are my thoughts:
>>>>>>>
>>>>>>> - The need to delete messages from log compacted topics is mainly
>>>>>>>
>>>>>> for
>>>
>>>> performance (e.g. storage space) optimization than for correctness
>>>>>>>
>>>>>> for
>>>>
>>>>> this
>>>>>>
>>>>>>> KIP. I agree that we probably don't need to focus on this in our
>>>>>>>
>>>>>> discussion
>>>>>>
>>>>>>> since it is mostly for performance optimization.
>>>>>>>
>>>>>>> - "Asking producers and consumers, or even two different producers,
>>>>>>>
>>>>>> to
>>>>
>>>>> share code like the partition function is a pretty huge ask. What
>>>>>>>
>>>>>> if
>>>
>>>> they
>>>>>
>>>>>> are using different languages?". It seems that today we already
>>>>>>>
>>>>>> require
>>>>
>>>>> different producer's to use the same hash function -- otherwise
>>>>>>>
>>>>>> messages
>>>>>
>>>>>> with the same key will go to different partitions of the same topic
>>>>>>>
>>>>>> which
>>>>>
>>>>>> may cause problem for downstream consumption. So not sure if it
>>>>>>>
>>>>>> adds
>>>
>>>> any
>>>>>
>>>>>> more constraint by assuming consumers know the hash function of
>>>>>>>
>>>>>> producer.
>>>>>
>>>>>> Could you explain more why user would want to use a cusmtom
>>>>>>>
>>>>>> partition
>>>
>>>> function? Maybe we can check if this is something that can be
>>>>>>>
>>>>>> supported
>>>>
>>>>> in
>>>>>>
>>>>>>> the default Kafka hash function. Also, can you explain more why it
>>>>>>>
>>>>>> is
>>>
>>>> difficuilt to implement the same hash function in different
>>>>>>>
>>>>>> languages?
>>>>
>>>>> - Besides the assumption that consumer needs to share the hash
>>>>>>>
>>>>>> function
>>>>
>>>>> of
>>>>>>
>>>>>>> producer, is there other organization overhead of the proposal in
>>>>>>>
>>>>>> the
>>>
>>>> current KIP?
>>>>>>>
>>>>>>> - Currently producer can forget about the message that has been
>>>>>>> acknowledged by the broker. Thus the producer probably does not
>>>>>>>
>>>>>> know
>>>
>>>> most
>>>>>
>>>>>> of the exiting messages in topic, including those messages produced
>>>>>>>
>>>>>> by
>>>>
>>>>> other producers. We can have the owner of the producer to
>>>>>>>
>>>>>> split+backfill.
>>>>>
>>>>>> In my opion it will be a new program that wraps around the existing
>>>>>>> producer and consumer classes.
>>>>>>>
>>>>>>> - Regarding point 5. The argument is in favor of the split+backfill
>>>>>>>
>>>>>> but
>>>>
>>>>> for
>>>>>>
>>>>>>> changelog topic. And it intends to address the problem for stream
>>>>>>>
>>>>>> use-case
>>>>>>
>>>>>>> in general. In this KIP we will provide interface (i.e.
>>>>>>> PartitionKeyRebalanceListener in the KIP) to be used by sream
>>>>>>>
>>>>>> use-case
>>>>
>>>>> and
>>>>>>
>>>>>>> the goal is that user can flush/re-consume the state as part of the
>>>>>>> interface implementation regardless of whether there is change log
>>>>>>>
>>>>>> topic.
>>>>>
>>>>>> Maybe you are suggesting that the main reason to do split+backfill
>>>>>>>
>>>>>> of
>>>
>>>> input
>>>>>>
>>>>>>> topic is to support log compacted topics? You mentioned in Point 1
>>>>>>>
>>>>>> that
>>>>
>>>>> log
>>>>>>
>>>>>>> compacted topics is out of the scope of this KIP. Maybe I could
>>>>>>>
>>>>>> understand
>>>>>>
>>>>>>> your position better. Regarding Jan's proposal to split partitions
>>>>>>>
>>>>>> with
>>>>
>>>>> backfill, do you think this should replace the proposal in the
>>>>>>>
>>>>>> existing
>>>>
>>>>> KIP, or do you think this is something that we should do in
>>>>>>>
>>>>>> addition
>>>
>>>> to
>>>>
>>>>> the
>>>>>>
>>>>>>> existing KIP?
>>>>>>>
>>>>>>> - Regarding point 6. I guess we can agree that it is better not to
>>>>>>>
>>>>>> have
>>>>
>>>>> the
>>>>>>
>>>>>>> performance overhread of copying the input data. Before we discuss
>>>>>>>
>>>>>> more
>>>>
>>>>> on
>>>>>>
>>>>>>> whether the performance overhead is acceptable or not, I am trying
>>>>>>>
>>>>>> to
>>>
>>>> figure out what is the benefit of introducing this overhread. You
>>>>>>>
>>>>>> mentioned
>>>>>>
>>>>>>> that the benefit is the loose organizational coupling. By
>>>>>>>
>>>>>> "organizational
>>>>>
>>>>>> coupling", are you referring to the requirement that consumer needs
>>>>>>>
>>>>>> to
>>>>
>>>>> know
>>>>>>
>>>>>>> the hash function of producer? If so, maybe we can discuss the
>>>>>>>
>>>>>> use-case
>>>>
>>>>> of
>>>>>>
>>>>>>> custom partiton function and see whether we can find a way to
>>>>>>>
>>>>>> support
>>>
>>>> such
>>>>>>
>>>>>>> use-case without having to copy the input data.
>>>>>>>
>>>>>>> Thanks,
>>>>>>> Dong
>>>>>>>
>>>>>>>
>>>>>>> On Tue, Mar 27, 2018 at 11:34 AM, John Roesler <jo...@confluent.io>
>>>>>>>
>>>>>> wrote:
>>>>>>
>>>>>>> Hey Dong and Jun,
>>>>>>>>
>>>>>>>> Thanks for the thoughtful responses. If you don't mind, I'll mix
>>>>>>>>
>>>>>>> my
>>>
>>>> replies
>>>>>>>
>>>>>>>> together to try for a coherent response. I'm not too familiar
>>>>>>>>
>>>>>>> with
>>>
>>>> mailing-list etiquette, though.
>>>>>>>>
>>>>>>>> I'm going to keep numbering my points because it makes it easy
>>>>>>>>
>>>>>>> for
>>>
>>>> you
>>>>>
>>>>>> all
>>>>>>>
>>>>>>>> to respond.
>>>>>>>>
>>>>>>>> Point 1:
>>>>>>>> As I read it, KIP-253 is *just* about properly fencing the
>>>>>>>>
>>>>>>> producers
>>>>
>>>>> and
>>>>>>
>>>>>>> consumers so that you preserve the correct ordering of records
>>>>>>>>
>>>>>>> during
>>>>
>>>>> partition expansion. This is clearly necessary regardless of
>>>>>>>>
>>>>>>> anything
>>>>
>>>>> else
>>>>>>>
>>>>>>>> we discuss. I think this whole discussion about backfill,
>>>>>>>>
>>>>>>> consumers,
>>>>
>>>>> streams, etc., is beyond the scope of KIP-253. But it would be
>>>>>>>>
>>>>>>> cumbersome
>>>>>>
>>>>>>> to start a new thread at this point.
>>>>>>>>
>>>>>>>> I had missed KIP-253's Proposed Change #9 among all the
>>>>>>>>
>>>>>>> details...
>>>
>>>> I
>>>>
>>>>> think
>>>>>>>
>>>>>>>> this is a nice addition to the proposal. One thought is that it's
>>>>>>>>
>>>>>>> actually
>>>>>>>
>>>>>>>> irrelevant whether the hash function is linear. This is simply an
>>>>>>>>
>>>>>>> algorithm
>>>>>>>
>>>>>>>> for moving a key from one partition to another, so the type of
>>>>>>>>
>>>>>>> hash
>>>
>>>> function need not be a precondition. In fact, it also doesn't
>>>>>>>>
>>>>>>> matter
>>>>
>>>>> whether the topic is compacted or not, the algorithm works
>>>>>>>>
>>>>>>> regardless.
>>>>>
>>>>>> I think this is a good algorithm to keep in mind, as it might
>>>>>>>>
>>>>>>> solve a
>>>>
>>>>> variety of problems, but it does have a downside: that the
>>>>>>>>
>>>>>>> producer
>>>
>>>> won't
>>>>>>
>>>>>>> know whether or not K1 was actually in P1, it just knows that K1
>>>>>>>>
>>>>>>> was
>>>>
>>>>> in
>>>>>
>>>>>> P1's keyspace before the new epoch. Therefore, it will have to
>>>>>>>> pessimistically send (K1,null) to P1 just in case. But the next
>>>>>>>>
>>>>>>> time
>>>>
>>>>> K1
>>>>>
>>>>>> comes along, the producer *also* won't remember that it already
>>>>>>>>
>>>>>>> retracted
>>>>>>
>>>>>>> K1 from P1, so it will have to send (K1,null) *again*. By
>>>>>>>>
>>>>>>> extension,
>>>>
>>>>> every
>>>>>>>
>>>>>>>> time the producer sends to P2, it will also have to send a
>>>>>>>>
>>>>>>> tombstone
>>>>
>>>>> to
>>>>>
>>>>>> P1,
>>>>>>>
>>>>>>>> which is a pretty big burden. To make the situation worse, if
>>>>>>>>
>>>>>>> there
>>>
>>>> is
>>>>>
>>>>>> a
>>>>>>
>>>>>>> second split, say P2 becomes P2 and P3, then any key Kx belonging
>>>>>>>>
>>>>>>> to
>>>>
>>>>> P3
>>>>>
>>>>>> will also have to be retracted from P2 *and* P1, since the
>>>>>>>>
>>>>>>> producer
>>>
>>>> can't
>>>>>>
>>>>>>> know whether Kx had been last written to P2 or P1. Over a long
>>>>>>>>
>>>>>>> period
>>>>
>>>>> of
>>>>>>
>>>>>>> time, this clearly becomes a issue, as the producer must send an
>>>>>>>>
>>>>>>> arbitrary
>>>>>>>
>>>>>>>> number of retractions along with every update.
>>>>>>>>
>>>>>>>> In contrast, the proposed backfill operation has an end, and
>>>>>>>>
>>>>>>> after
>>>
>>>> it
>>>>
>>>>> ends,
>>>>>>>
>>>>>>>> everyone can afford to forget that there ever was a different
>>>>>>>>
>>>>>>> partition
>>>>>
>>>>>> layout.
>>>>>>>>
>>>>>>>> Really, though, figuring out how to split compacted topics is
>>>>>>>>
>>>>>>> beyond
>>>>
>>>>> the
>>>>>>
>>>>>>> scope of KIP-253, so I'm not sure #9 really even needs to be in
>>>>>>>>
>>>>>>> this
>>>>
>>>>> KIP...
>>>>>>>
>>>>>>>> We do need in-order delivery during partition expansion. It would
>>>>>>>>
>>>>>>> be
>>>>
>>>>> fine
>>>>>>
>>>>>>> by me to say that you *cannot* expand partitions of a
>>>>>>>>
>>>>>>> log-compacted
>>>
>>>> topic
>>>>>>
>>>>>>> and call it a day. I think it would be better to tackle that in
>>>>>>>>
>>>>>>> another
>>>>>
>>>>>> KIP.
>>>>>>>>
>>>>>>>>
>>>>>>>> Point 2:
>>>>>>>> Regarding whether the consumer re-shuffles its inputs, this is
>>>>>>>>
>>>>>>> always
>>>>
>>>>> on
>>>>>>
>>>>>>> the table; any consumer who wants to re-shuffle its input is free
>>>>>>>>
>>>>>>> to
>>>>
>>>>> do
>>>>>
>>>>>> so.
>>>>>>>
>>>>>>>> But this is currently not required. It's just that the current
>>>>>>>>
>>>>>>> high-level
>>>>>>
>>>>>>> story with Kafka encourages the use of partitions as a unit of
>>>>>>>>
>>>>>>> concurrency.
>>>>>>>
>>>>>>>> As long as consumers are single-threaded, they can happily
>>>>>>>>
>>>>>>> consume
>>>
>>>> a
>>>>
>>>>> single
>>>>>>>
>>>>>>>> partition without concurrency control of any kind. This is a key
>>>>>>>>
>>>>>>> aspect
>>>>>
>>>>>> to
>>>>>>>
>>>>>>>> this system that lets folks design high-throughput systems on top
>>>>>>>>
>>>>>>> of
>>>>
>>>>> it
>>>>>
>>>>>> surprisingly easily. If all consumers were instead
>>>>>>>>
>>>>>>> encouraged/required
>>>>>
>>>>>> to
>>>>>>
>>>>>>> implement a repartition of their own, then the consumer becomes
>>>>>>>> significantly more complex, requiring either the consumer to
>>>>>>>>
>>>>>>> first
>>>
>>>> produce
>>>>>>>
>>>>>>>> to its own intermediate repartition topic or to ensure that
>>>>>>>>
>>>>>>> consumer
>>>>
>>>>> threads have a reliable, high-bandwith channel of communication
>>>>>>>>
>>>>>>> with
>>>>
>>>>> every
>>>>>>>
>>>>>>>> other consumer thread.
>>>>>>>>
>>>>>>>> Either of those tradeoffs may be reasonable for a particular user
>>>>>>>>
>>>>>>> of
>>>>
>>>>> Kafka,
>>>>>>>
>>>>>>>> but I don't know if we're in a position to say that they are
>>>>>>>>
>>>>>>> reasonable
>>>>>
>>>>>> for
>>>>>>>
>>>>>>>> *every* user of Kafka.
>>>>>>>>
>>>>>>>>
>>>>>>>> Point 3:
>>>>>>>> Regarding Jun's point about this use case, "(3) stateful and
>>>>>>>>
>>>>>>> maintaining
>>>>>>
>>>>>>> the
>>>>>>>> states in a local store", I agree that they may use a framework
>>>>>>>>
>>>>>>> *like*
>>>>>
>>>>>> Kafka Streams, but that is not the same as using Kafka Streams.
>>>>>>>>
>>>>>>> This
>>>>
>>>>> is
>>>>>
>>>>>> why
>>>>>>>
>>>>>>>> I think it's better to solve it in Core: because it is then
>>>>>>>>
>>>>>>> solved
>>>
>>>> for
>>>>>
>>>>>> KStreams and also for everything else that facilitates local
>>>>>>>>
>>>>>>> state
>>>
>>>> maintenance. To me, Streams is a member of the category of
>>>>>>>>
>>>>>>> "stream
>>>
>>>> processing frameworks", which is itself a subcategory of "things
>>>>>>>>
>>>>>>> requiring
>>>>>>>
>>>>>>>> local state maintenence". I'm not sure if it makes sense to
>>>>>>>
>>>>>>>

Re: [DISCUSS] KIP-253: Support in-order message delivery with partition expansion

Posted by Jan Filipiak <Ja...@trivago.com>.
Want to quickly step in here again because it is going places again.

The last part of the discussion is just a pain to read and completely 
diverged from what I suggested without making the reasons clear to me.

I don't know why this happens.... here are my comments anyway.

@Guozhang: That Streams is working on automatic creating 
copartition-usuable topics: great for streams, has literally nothing 
todo with the KIP as we want to grow the
input topic. Everyone can reshuffle rel. easily but that is not what we 
need todo, we need to grow the topic in question. After streams 
automatically reshuffled the input topic
still has the same size and it didn't help a bit. I fail to see why this 
is relevant. What am i missing here?

@Dong
I am still on the position that the current proposal brings us into the 
wrong direction. Especially introducing PartitionKeyRebalanceListener
 From this point we can never move away to proper state full handling 
without completely deprecating this creature from hell again.
Linear hashing is not the optimising step we have todo here. An 
interface that when a topic is a topic its always the same even after it had
grown or shrunk is important. So from my POV I have major concerns that 
this KIP is benefitial in its current state.

What is it that makes everyone so addicted to the idea of linear 
hashing? not attractive at all for me.
And with statefull consumers still a complete mess. Why not stick with 
the Kappa architecture???





On 03.04.2018 17:38, Dong Lin wrote:
> Hey John,
>
> Thanks much for your comments!!
>
> I have yet to go through the emails of John/Jun/Guozhang in detail. But let
> me present my idea for how to minimize the delay for state loading for
> stream use-case.
>
> For ease of understanding, let's assume that the initial partition number
> of input topics and change log topic are both 10. And initial number of
> stream processor is also 10. If we only increase initial partition number
> of input topics to 15 without changing number of stream processor, the
> current KIP already guarantees in-order delivery and no state needs to be
> moved between consumers for stream use-case. Next, let's say we want to
> increase the number of processor to expand the processing capacity for
> stream use-case. This requires us to move state between processors which
> will take time. Our goal is to minimize the impact (i.e. delay) for
> processing while we increase the number of processors.
>
> Note that stream processor generally includes both consumer and producer.
> In addition to consume from the input topic, consumer may also need to
> consume from change log topic on startup for recovery. And producer may
> produce state to the change log topic.
>

> The solution will include the following steps:
>
> 1) Increase partition number of the input topic from 10 to 15. Since the
> messages with the same key will still go to the same consume before and
> after the partition expansion, this step can be done without having to move
> state between processors.
>
> 2) Increase partition number of the change log topic from 10 to 15. Note
> that this step can also be done without impacting existing workflow. After
> we increase partition number of the change log topic, key space may split
> and some key will be produced to the newly-added partition. But the same
> key will still go to the same processor (i.e. consumer) before and after
> the partition. Thus this step can also be done without having to move state
> between processors.
>
> 3) Now, let's add 5 new consumers whose groupId is different from the
> existing processor's groupId. Thus these new consumers will not impact
> existing workflow. Each of these new consumers should consume two
> partitions from the earliest offset, where these two partitions are the
> same partitions that will be consumed if the consumers have the same
> groupId as the existing processor's groupId. For example, the first of the
> five consumers will consume partition 0 and partition 10. The purpose of
> these consumers is to rebuild the state (e.g. RocksDB) for the processors
> in advance. Also note that, by design of the current KIP, each consume will
> consume the existing partition of the change log topic up to the offset
> before the partition expansion. Then they will only need to consume the
> state of the new partition of the change log topic.
>
> 4) After consumers have caught up in step 3), we should stop these
> consumers and add 5 new processors to the stream processing job. These 5
> new processors should run in the same location as the previous 5 consumers
> to re-use the state (e.g. RocksDB). And these processors' consumers should
> consume partitions of the change log topic from the committed offset the
> previous 5 consumers so that no state is missed.
>
> One important trick to note here is that, the mapping from partition to
> consumer should also use linear hashing. And we need to remember the
> initial number of processors in the job, 10 in this example, and use this
> number in the linear hashing algorithm. This is pretty much the same as how
> we use linear hashing to map key to partition. In this case, we get an
> identity map from partition -> processor, for both input topic and the
> change log topic. For example, processor 12 will consume partition 12 of
> the input topic and produce state to the partition 12 of the change log
> topic.
>
> There are a few important properties of this solution to note:
>
> - We can increase the number of partitions for input topic and the change
> log topic in any order asynchronously.
> - The expansion of the processors in a given job in step 4) only requires
> the step 3) for the same job. It does not require coordination across
> different jobs for step 3) and 4). Thus different jobs can independently
> expand there capacity without waiting for each other.
> - The logic for 1) and 2) is already supported in the current KIP. The
> logic for 3) and 4) appears to be independent of the core Kafka logic and
> can be implemented separately outside core Kafka. Thus the current KIP is
> probably sufficient after we agree on the efficiency and the correctness of
> the solution. We can have a separate KIP for Kafka Stream to support 3) and
> 4).
>
>
> Cheers,
> Dong
>
>
> On Mon, Apr 2, 2018 at 3:25 PM, Guozhang Wang <wa...@gmail.com> wrote:
>
>> Hey guys, just sharing my two cents here (I promise it will be shorter than
>> John's article :).
>>
>> 0. Just to quickly recap, the main discussion point now is how to support
>> "key partitioning preservation" (John's #4 in topic characteristics above)
>> beyond the "single-key ordering preservation" that KIP-253 was originally
>> proposed to maintain (John's #6 above).
>>
>> 1. From the streams project, we are actively working on improving the
>> elastic scalability of the library. One of the key features is to decouple
>> the input topics from the parallelism model of Streams: i.e. not enforcing
>> the topic to be partitioned by the key, not enforcing joining topics to be
>> co-partitioned, not relying the number of parallel tasks on the input topic
>> partitions. This can be achieved by re-shuffling on the input topics to
>> make sure key-partitioning / co-partitioning on the internal topics. Note
>> the re-shuffling task is purely stateless and hence does not require "key
>> partitioning preservation". Operational-wise it is similar to the "creating
>> a new topic with new number of partitions, pipe the data to the new topic
>> and cut over consumers from old topics" idea, just that users can
>> optionally let Streams to handle such rather than doing it manually
>> themselves. There are a few more details on that regard but I will skip
>> since they are not directly related to this discussion.
>>
>> 2. Assuming that 1) above is done, then the only topics involved in the
>> scaling events are all input topics. For these topics the only producers /
>> consumers of these topics are controlled by Streams clients themselves, and
>> hence achieving "key partitioning preservation" is simpler than non-Streams
>> scenarios: consumers know the partitioning scheme that producers are using,
>> so that for their stateful operations it is doable to split the local state
>> stores accordingly or execute backfilling on its own. Of course, if we
>> decide to do server-side backfilling, it can still help Streams to directly
>> rely on that functionality.
>>
>> 3. As John mentioned, another way inside Streams is to do over-partitioning
>> on all internal topics; then with 1) Streams would not rely on KIP-253 at
>> all. But personally I'd like to avoid it if possible to reduce Kafka side
>> footprint: say we overpartition each input topic up to 1k, with a
>> reasonable sized stateful topology it can still contribute to tens of
>> thousands of topics to the topic partition capacity of a single cluster.
>>
>> 4. Summing up 1/2/3, I think we should focus more on non-Streams users
>> writing their stateful computations with local states, and think whether /
>> how we could enable "key partitioning preservation" for them easily, than
>> to think heavily for Streams library. People may have different opinion on
>> how common of a usage pattern it is (I think Jun might be suggesting that
>> for DIY apps people may more likely use remote states so that it is not a
>> problem for them). My opinion is that for non-Streams users such usage
>> pattern could still be large (think: if you are piping data from Kafka to
>> an external data storage which has single-writer requirements for each
>> single shard, even though it is not a stateful computational application it
>> may still require "key partitioning preservation"), so I prefer to have
>> backfilling in our KIP than only exposing the API for expansion and
>> requires consumers to have pre-knowledge of the producer's partitioning
>> scheme.
>>
>>
>>
>> Guozhang
>>
>>
>>
>> On Thu, Mar 29, 2018 at 2:33 PM, John Roesler <jo...@confluent.io> wrote:
>>
>>> Hey Dong,
>>>
>>> Congrats on becoming a committer!!!
>>>
>>> Since I just sent a novel-length email, I'll try and keep this one brief
>> ;)
>>> Regarding producer coordination, I'll grant that in that case, producers
>>> may coordinate among themselves to produce into the same topic or to
>>> produce co-partitioned topics. Nothing in KStreams or the Kafka ecosystem
>>> in general requires such coordination for correctness or in fact for any
>>> optional features, though, so I would not say that we require producer
>>> coordination of partition logic. If producers currently coordinate, it's
>>> completely optional and their own choice.
>>>
>>> Regarding the portability of partition algorithms, my observation is that
>>> systems requiring independent implementations of the same algorithm with
>>> 100% correctness are a large source of risk and also a burden on those
>> who
>>> have to maintain them. If people could flawlessly implement algorithms in
>>> actual software, the world would be a wonderful place indeed! For a
>> system
>>> as important and widespread as Kafka, I would recommend restricting
>>> limiting such requirements as aggressively as possible.
>>>
>>> I'd agree that we can always revisit decisions like allowing arbitrary
>>> partition functions, but of course, we shouldn't do that in a vacuum.
>> That
>>> feels like the kind of thing we'd need to proactively seek guidance from
>>> the users list about. I do think that the general approach of saying that
>>> "if you use a custom partitioner, you cannot do partition expansion" is
>>> very reasonable (but I don't think we need to go that far with the
>> current
>>> proposal). It's similar to my statement in my email to Jun that in
>>> principle KStreams doesn't *need* backfill, we only need it if we want to
>>> employ partition expansion.
>>>
>>> I reckon that the main motivation for backfill is to support KStreams use
>>> cases and also any other use cases involving stateful consumers.
>>>
>>> Thanks for your response, and congrats again!
>>> -John
>>>
>>>
>>> On Wed, Mar 28, 2018 at 1:34 AM, Dong Lin <li...@gmail.com> wrote:
>>>
>>>> Hey John,
>>>>
>>>> Great! Thanks for all the comment. It seems that we agree that the
>>> current
>>>> KIP is in good shape for core Kafka. IMO, what we have been discussing
>> in
>>>> the recent email exchanges is mostly about the second step, i.e. how to
>>>> address problem for the stream use-case (or stateful processing in
>>>> general).
>>>>
>>>> I will comment inline.
>>>>
>>>>
>>>>
>>>>
>>>> On Tue, Mar 27, 2018 at 4:38 PM, John Roesler <jo...@confluent.io>
>> wrote:
>>>>> Thanks for the response, Dong.
>>>>>
>>>>> Here are my answers to your questions:
>>>>>
>>>>> - "Asking producers and consumers, or even two different producers,
>> to
>>>>>> share code like the partition function is a pretty huge ask. What
>> if
>>>> they
>>>>>> are using different languages?". It seems that today we already
>>> require
>>>>>> different producer's to use the same hash function -- otherwise
>>>> messages
>>>>>> with the same key will go to different partitions of the same topic
>>>> which
>>>>>> may cause problem for downstream consumption. So not sure if it
>> adds
>>>> any
>>>>>> more constraint by assuming consumers know the hash function of
>>>> producer.
>>>>>> Could you explain more why user would want to use a cusmtom
>> partition
>>>>>> function? Maybe we can check if this is something that can be
>>> supported
>>>>> in
>>>>>> the default Kafka hash function. Also, can you explain more why it
>> is
>>>>>> difficuilt to implement the same hash function in different
>>> languages?
>>>>>
>>>>> Sorry, I meant two different producers as in producers to two
>> different
>>>>> topics. This was in response to the suggestion that we already
>> require
>>>>> coordination among producers to different topics in order to achieve
>>>>> co-partitioning. I was saying that we do not (and should not).
>>>>
>>>> It is probably common for producers of different team to produce
>> message
>>> to
>>>> the same topic. In order to ensure that messages with the same key go
>> to
>>>> same partition, we need producers of different team to share the same
>>>> partition algorithm, which by definition requires coordination among
>>>> producers of different teams in an organization. Even for producers of
>>>> different topics, it may be common to require producers to use the same
>>>> partition algorithm in order to join two topics for stream processing.
>>> Does
>>>> this make it reasonable to say we already require coordination across
>>>> producers?
>>>>
>>>>
>>>>> By design, consumers are currently ignorant of the partitioning
>> scheme.
>>>> It
>>>>> suffices to trust that the producer has partitioned the topic by key,
>>> if
>>>>> they claim to have done so. If you don't trust that, or even if you
>>> just
>>>>> need some other partitioning scheme, then you must re-partition it
>>>>> yourself. Nothing we're discussing can or should change that. The
>> value
>>>> of
>>>>> backfill is that it preserves the ability for consumers to avoid
>>>>> re-partitioning before consuming, in the case where they don't need
>> to
>>>>> today.
>>>>
>>>>> Regarding shared "hash functions", note that it's a bit inaccurate to
>>>> talk
>>>>> about the "hash function" of the producer. Properly speaking, the
>>>> producer
>>>>> has only a "partition function". We do not know that it is a hash.
>> The
>>>>> producer can use any method at their disposal to assign a partition
>> to
>>> a
>>>>> record. The partition function obviously may we written in any
>>>> programming
>>>>> language, so in general it's not something that can be shared around
>>>>> without a formal spec or the ability to execute arbitrary executables
>>> in
>>>>> arbitrary runtime environments.
>>>>>
>>>> Yeah it is probably better to say partition algorithm. I guess it
>> should
>>>> not be difficult to implement same partition algorithms in different
>>>> languages, right? Yes we would need a formal specification of the
>> default
>>>> partition algorithm in the producer. I think that can be documented as
>>> part
>>>> of the producer interface.
>>>>
>>>>
>>>>> Why would a producer want a custom partition function? I don't
>> know...
>>>> why
>>>>> did we design the interface so that our users can provide one? In
>>>> general,
>>>>> such systems provide custom partitioners because some data sets may
>> be
>>>>> unbalanced under the default or because they can provide some
>>> interesting
>>>>> functionality built on top of the partitioning scheme, etc. Having
>>>> provided
>>>>> this ability, I don't know why we would remove it.
>>>>>
>>>> Yeah it is reasonable to assume that there was reason to support custom
>>>> partition function in producer. On the other hand it may also be
>>> reasonable
>>>> to revisit this interface and discuss whether we actually need to
>> support
>>>> custom partition function. If we don't have a good reason, we can
>> choose
>>>> not to support custom partition function in this KIP in a backward
>>>> compatible manner, i.e. user can still use custom partition function
>> but
>>>> they would not get the benefit of in-order delivery when there is
>>> partition
>>>> expansion. What do you think?
>>>>
>>>>
>>>>> - Besides the assumption that consumer needs to share the hash
>> function
>>>> of
>>>>>> producer, is there other organization overhead of the proposal in
>> the
>>>>>> current KIP?
>>>>>>
>>>>> It wasn't clear to me that KIP-253 currently required the producer
>> and
>>>>> consumer to share the partition function, or in fact that it had a
>> hard
>>>>> requirement to abandon the general partition function and use a
>> linear
>>>> hash
>>>>> function instead.
>>>>
>>>>> In my reading, there is a requirement to track the metadata about
>> what
>>>>> partitions split into what other partitions during an expansion
>>>> operation.
>>>>> If the partition function is linear, this is easy. If not, you can
>>> always
>>>>> just record that all old partitions split into all new partitions.
>> This
>>>> has
>>>>> the effect of forcing all consumers to wait until the old epoch is
>>>>> completely consumed before starting on the new epoch. But this may
>> be a
>>>>> reasonable tradeoff, and it doesn't otherwise alter your design.
>>>>>
>>>>> You only mention the consumer needing to know that the partition
>>> function
>>>>> is linear, not what the actual function is, so I don't think your
>>> design
>>>>> actually calls for sharing the function. Plus, really all the
>> consumer
>>>>> needs is the metadata about what old-epoch partitions to wait for
>>> before
>>>>> consuming a new-epoch partition. This information is directly
>> captured
>>> in
>>>>> metadata, so I don't think it actually even cares whether the
>> partition
>>>>> function is linear or not.
>>>>>
>>>> You are right that the current KIP does not mention it. My comment
>>> related
>>>> to the partition function coordination was related to support the
>>>> stream-use case which we have been discussing so far.
>>>>
>>>>
>>>>> So, no, I really think KIP-253 is in good shape. I was really more
>>>> talking
>>>>> about the part of this thread that's outside of KIP-253's scope,
>>> namely,
>>>>> creating the possibility of backfilling partitions after expansion.
>>>>>
>>>> Great! Can you also confirm that the main motivation for backfilling
>>>> partitions after expansion is to support the stream use-case?
>>>>
>>>>
>>>>> - Currently producer can forget about the message that has been
>>>>>> acknowledged by the broker. Thus the producer probably does not
>> know
>>>> most
>>>>>> of the exiting messages in topic, including those messages produced
>>> by
>>>>>> other producers. We can have the owner of the producer to
>>>> split+backfill.
>>>>>> In my opion it will be a new program that wraps around the existing
>>>>>> producer and consumer classes.
>>>>>>
>>>>> This sounds fine by me!
>>>>>
>>>>> Really, I was just emphasizing that the part of the organization that
>>>>> produces a topic shouldn't have to export their partition function to
>>> the
>>>>> part(s) of the organization (or other organizations) that consume the
>>>>> topic. Whether the backfill operation goes into the Producer
>> interface
>>> is
>>>>> secondary, I think.
>>>>>
>>>>> - Regarding point 5. The argument is in favor of the split+backfill
>> but
>>>> for
>>>>>> changelog topic. And it intends to address the problem for stream
>>>>> use-case
>>>>>> in general. In this KIP we will provide interface (i.e.
>>>>>> PartitionKeyRebalanceListener in the KIP) to be used by sream
>>> use-case
>>>>> and
>>>>>> the goal is that user can flush/re-consume the state as part of the
>>>>>> interface implementation regardless of whether there is change log
>>>> topic.
>>>>>> Maybe you are suggesting that the main reason to do split+backfill
>> of
>>>>> input
>>>>>> topic is to support log compacted topics? You mentioned in Point 1
>>> that
>>>>> log
>>>>>> compacted topics is out of the scope of this KIP. Maybe I could
>>>>> understand
>>>>>> your position better. Regarding Jan's proposal to split partitions
>>> with
>>>>>> backfill, do you think this should replace the proposal in the
>>> existing
>>>>>> KIP, or do you think this is something that we should do in
>> addition
>>> to
>>>>> the
>>>>>> existing KIP?
>>>>>>
>>>>> I think that interface is a good/necessary component of KIP-253.
>>>>>
>>>>> I personally (FWIW) feel that KIP-253 is appropriately scoped, but I
>> do
>>>>> think its utility will be limited unless there is a later KIP
>> offering
>>>>> backfill. But, maybe unlike Jan, I think it makes sense to try and
>>> tackle
>>>>> the ordering problem independently of backfill, so I'm in support of
>>> the
>>>>> current KIP.
>>>>>
>>>>> - Regarding point 6. I guess we can agree that it is better not to
>> have
>>>> the
>>>>>> performance overhread of copying the input data. Before we discuss
>>> more
>>>>> on
>>>>>> whether the performance overhead is acceptable or not, I am trying
>> to
>>>>>> figure out what is the benefit of introducing this overhread. You
>>>>> mentioned
>>>>>> that the benefit is the loose organizational coupling. By
>>>> "organizational
>>>>>> coupling", are you referring to the requirement that consumer needs
>>> to
>>>>> know
>>>>>> the hash function of producer? If so, maybe we can discuss the
>>> use-case
>>>>> of
>>>>>> custom partiton function and see whether we can find a way to
>> support
>>>>> such
>>>>>> use-case without having to copy the input data.
>>>>>>
>>>>> I'm not too sure about what an "input" is in this sense, since we are
>>>> just
>>>>> talking about topics. Actually the point I was making there is that
>>>> AKAICT
>>>>> the performance overhead of a backfill is less than any other option,
>>>>> assuming you split partitions rarely.
>>>>>
>>>> By "input" I was referring to source Kafka topic of a stream processing
>>>> job.
>>>>
>>>>
>>>>> Separately, yes, "organizational coupling" increases if producers and
>>>>> consumers have to share code, such as the partition function. This
>>> would
>>>>> not be the case if producers could only pick from a menu of a few
>>>>> well-known partition functions, but I think this is a poor tradeoff.
>>>>>
>>>> Maybe we can revisit the custom partition function and see whether we
>>>> actually need it? Otherwise, I am concerned that every user will pay
>> the
>>>> overhead of data movement to support something that was not really
>> needed
>>>> for most users.
>>>>
>>>>
>>>>> To me, this is two strong arguments in favor of backfill being less
>>>>> expensive than no backfill, but again, I think that particular debate
>>>> comes
>>>>> after KIP-253, so I don't want to create the impression of opposition
>>> to
>>>>> your proposal.
>>>>>
>>>>>
>>>>> Finally, to respond to a new email I just noticed:
>>>>>
>>>>>> BTW, here is my understanding of the scope of this KIP. We want to
>>>> allow
>>>>>> consumers to always consume messages with the same key from the
>> same
>>>>>> producer in the order they are produced. And we need to provide a
>> way
>>>> for
>>>>>> stream use-case to be able to flush/load state when messages with
>> the
>>>>> same
>>>>>> key are migrated between consumers. In addition to ensuring that
>> this
>>>>> goal
>>>>>> is correctly supported, we should do our best to keep the
>> performance
>>>> and
>>>>>> organization overhead of this KIP as low as possible.
>>>>>>
>>>>> I think we're on the same page there! In fact, I would generalize a
>>>> little
>>>>> more and say that the mechanism you've designed provides *all
>>> consumers*
>>>>> the ability "to flush/load state when messages with the same key are
>>>>> migrated between consumers", not just Streams.
>>>>>
>>>> Thanks for all the comment!
>>>>
>>>>
>>>>> Thanks for the discussion,
>>>>> -John
>>>>>
>>>>>
>>>>>
>>>>> On Tue, Mar 27, 2018 at 3:14 PM, Dong Lin <li...@gmail.com>
>> wrote:
>>>>>> Hey John,
>>>>>>
>>>>>> Thanks much for the detailed comments. Here are my thoughts:
>>>>>>
>>>>>> - The need to delete messages from log compacted topics is mainly
>> for
>>>>>> performance (e.g. storage space) optimization than for correctness
>>> for
>>>>> this
>>>>>> KIP. I agree that we probably don't need to focus on this in our
>>>>> discussion
>>>>>> since it is mostly for performance optimization.
>>>>>>
>>>>>> - "Asking producers and consumers, or even two different producers,
>>> to
>>>>>> share code like the partition function is a pretty huge ask. What
>> if
>>>> they
>>>>>> are using different languages?". It seems that today we already
>>> require
>>>>>> different producer's to use the same hash function -- otherwise
>>>> messages
>>>>>> with the same key will go to different partitions of the same topic
>>>> which
>>>>>> may cause problem for downstream consumption. So not sure if it
>> adds
>>>> any
>>>>>> more constraint by assuming consumers know the hash function of
>>>> producer.
>>>>>> Could you explain more why user would want to use a cusmtom
>> partition
>>>>>> function? Maybe we can check if this is something that can be
>>> supported
>>>>> in
>>>>>> the default Kafka hash function. Also, can you explain more why it
>> is
>>>>>> difficuilt to implement the same hash function in different
>>> languages?
>>>>>> - Besides the assumption that consumer needs to share the hash
>>> function
>>>>> of
>>>>>> producer, is there other organization overhead of the proposal in
>> the
>>>>>> current KIP?
>>>>>>
>>>>>> - Currently producer can forget about the message that has been
>>>>>> acknowledged by the broker. Thus the producer probably does not
>> know
>>>> most
>>>>>> of the exiting messages in topic, including those messages produced
>>> by
>>>>>> other producers. We can have the owner of the producer to
>>>> split+backfill.
>>>>>> In my opion it will be a new program that wraps around the existing
>>>>>> producer and consumer classes.
>>>>>>
>>>>>> - Regarding point 5. The argument is in favor of the split+backfill
>>> but
>>>>> for
>>>>>> changelog topic. And it intends to address the problem for stream
>>>>> use-case
>>>>>> in general. In this KIP we will provide interface (i.e.
>>>>>> PartitionKeyRebalanceListener in the KIP) to be used by sream
>>> use-case
>>>>> and
>>>>>> the goal is that user can flush/re-consume the state as part of the
>>>>>> interface implementation regardless of whether there is change log
>>>> topic.
>>>>>> Maybe you are suggesting that the main reason to do split+backfill
>> of
>>>>> input
>>>>>> topic is to support log compacted topics? You mentioned in Point 1
>>> that
>>>>> log
>>>>>> compacted topics is out of the scope of this KIP. Maybe I could
>>>>> understand
>>>>>> your position better. Regarding Jan's proposal to split partitions
>>> with
>>>>>> backfill, do you think this should replace the proposal in the
>>> existing
>>>>>> KIP, or do you think this is something that we should do in
>> addition
>>> to
>>>>> the
>>>>>> existing KIP?
>>>>>>
>>>>>> - Regarding point 6. I guess we can agree that it is better not to
>>> have
>>>>> the
>>>>>> performance overhread of copying the input data. Before we discuss
>>> more
>>>>> on
>>>>>> whether the performance overhead is acceptable or not, I am trying
>> to
>>>>>> figure out what is the benefit of introducing this overhread. You
>>>>> mentioned
>>>>>> that the benefit is the loose organizational coupling. By
>>>> "organizational
>>>>>> coupling", are you referring to the requirement that consumer needs
>>> to
>>>>> know
>>>>>> the hash function of producer? If so, maybe we can discuss the
>>> use-case
>>>>> of
>>>>>> custom partiton function and see whether we can find a way to
>> support
>>>>> such
>>>>>> use-case without having to copy the input data.
>>>>>>
>>>>>> Thanks,
>>>>>> Dong
>>>>>>
>>>>>>
>>>>>> On Tue, Mar 27, 2018 at 11:34 AM, John Roesler <jo...@confluent.io>
>>>>> wrote:
>>>>>>> Hey Dong and Jun,
>>>>>>>
>>>>>>> Thanks for the thoughtful responses. If you don't mind, I'll mix
>> my
>>>>>> replies
>>>>>>> together to try for a coherent response. I'm not too familiar
>> with
>>>>>>> mailing-list etiquette, though.
>>>>>>>
>>>>>>> I'm going to keep numbering my points because it makes it easy
>> for
>>>> you
>>>>>> all
>>>>>>> to respond.
>>>>>>>
>>>>>>> Point 1:
>>>>>>> As I read it, KIP-253 is *just* about properly fencing the
>>> producers
>>>>> and
>>>>>>> consumers so that you preserve the correct ordering of records
>>> during
>>>>>>> partition expansion. This is clearly necessary regardless of
>>> anything
>>>>>> else
>>>>>>> we discuss. I think this whole discussion about backfill,
>>> consumers,
>>>>>>> streams, etc., is beyond the scope of KIP-253. But it would be
>>>>> cumbersome
>>>>>>> to start a new thread at this point.
>>>>>>>
>>>>>>> I had missed KIP-253's Proposed Change #9 among all the
>> details...
>>> I
>>>>>> think
>>>>>>> this is a nice addition to the proposal. One thought is that it's
>>>>>> actually
>>>>>>> irrelevant whether the hash function is linear. This is simply an
>>>>>> algorithm
>>>>>>> for moving a key from one partition to another, so the type of
>> hash
>>>>>>> function need not be a precondition. In fact, it also doesn't
>>> matter
>>>>>>> whether the topic is compacted or not, the algorithm works
>>>> regardless.
>>>>>>> I think this is a good algorithm to keep in mind, as it might
>>> solve a
>>>>>>> variety of problems, but it does have a downside: that the
>> producer
>>>>> won't
>>>>>>> know whether or not K1 was actually in P1, it just knows that K1
>>> was
>>>> in
>>>>>>> P1's keyspace before the new epoch. Therefore, it will have to
>>>>>>> pessimistically send (K1,null) to P1 just in case. But the next
>>> time
>>>> K1
>>>>>>> comes along, the producer *also* won't remember that it already
>>>>> retracted
>>>>>>> K1 from P1, so it will have to send (K1,null) *again*. By
>>> extension,
>>>>>> every
>>>>>>> time the producer sends to P2, it will also have to send a
>>> tombstone
>>>> to
>>>>>> P1,
>>>>>>> which is a pretty big burden. To make the situation worse, if
>> there
>>>> is
>>>>> a
>>>>>>> second split, say P2 becomes P2 and P3, then any key Kx belonging
>>> to
>>>> P3
>>>>>>> will also have to be retracted from P2 *and* P1, since the
>> producer
>>>>> can't
>>>>>>> know whether Kx had been last written to P2 or P1. Over a long
>>> period
>>>>> of
>>>>>>> time, this clearly becomes a issue, as the producer must send an
>>>>>> arbitrary
>>>>>>> number of retractions along with every update.
>>>>>>>
>>>>>>> In contrast, the proposed backfill operation has an end, and
>> after
>>> it
>>>>>> ends,
>>>>>>> everyone can afford to forget that there ever was a different
>>>> partition
>>>>>>> layout.
>>>>>>>
>>>>>>> Really, though, figuring out how to split compacted topics is
>>> beyond
>>>>> the
>>>>>>> scope of KIP-253, so I'm not sure #9 really even needs to be in
>>> this
>>>>>> KIP...
>>>>>>> We do need in-order delivery during partition expansion. It would
>>> be
>>>>> fine
>>>>>>> by me to say that you *cannot* expand partitions of a
>> log-compacted
>>>>> topic
>>>>>>> and call it a day. I think it would be better to tackle that in
>>>> another
>>>>>>> KIP.
>>>>>>>
>>>>>>>
>>>>>>> Point 2:
>>>>>>> Regarding whether the consumer re-shuffles its inputs, this is
>>> always
>>>>> on
>>>>>>> the table; any consumer who wants to re-shuffle its input is free
>>> to
>>>> do
>>>>>> so.
>>>>>>> But this is currently not required. It's just that the current
>>>>> high-level
>>>>>>> story with Kafka encourages the use of partitions as a unit of
>>>>>> concurrency.
>>>>>>> As long as consumers are single-threaded, they can happily
>> consume
>>> a
>>>>>> single
>>>>>>> partition without concurrency control of any kind. This is a key
>>>> aspect
>>>>>> to
>>>>>>> this system that lets folks design high-throughput systems on top
>>> of
>>>> it
>>>>>>> surprisingly easily. If all consumers were instead
>>>> encouraged/required
>>>>> to
>>>>>>> implement a repartition of their own, then the consumer becomes
>>>>>>> significantly more complex, requiring either the consumer to
>> first
>>>>>> produce
>>>>>>> to its own intermediate repartition topic or to ensure that
>>> consumer
>>>>>>> threads have a reliable, high-bandwith channel of communication
>>> with
>>>>>> every
>>>>>>> other consumer thread.
>>>>>>>
>>>>>>> Either of those tradeoffs may be reasonable for a particular user
>>> of
>>>>>> Kafka,
>>>>>>> but I don't know if we're in a position to say that they are
>>>> reasonable
>>>>>> for
>>>>>>> *every* user of Kafka.
>>>>>>>
>>>>>>>
>>>>>>> Point 3:
>>>>>>> Regarding Jun's point about this use case, "(3) stateful and
>>>>> maintaining
>>>>>>> the
>>>>>>> states in a local store", I agree that they may use a framework
>>>> *like*
>>>>>>> Kafka Streams, but that is not the same as using Kafka Streams.
>>> This
>>>> is
>>>>>> why
>>>>>>> I think it's better to solve it in Core: because it is then
>> solved
>>>> for
>>>>>>> KStreams and also for everything else that facilitates local
>> state
>>>>>>> maintenance. To me, Streams is a member of the category of
>> "stream
>>>>>>> processing frameworks", which is itself a subcategory of "things
>>>>>> requiring
>>>>>>> local state maintenence". I'm not sure if it makes sense to
>> assert
>>>> that
>>>>>>> Streams is a sufficient and practical replacement for everything
>> in
>>>>>> "things
>>>>>>> requiring local state maintenence".
>>>>>>>
>>>>>>> But, yes, I do agree that per-key ordering is an absolute
>>>> requirement,
>>>>>>> therefore I think that KIP-253 itself is a necessary step.
>>> Regarding
>>>>> the
>>>>>>> coupling of the state store partitioning to the topic
>> partitioning,
>>>>> yes,
>>>>>>> this is an issue we are discussing solutions to right now. We may
>>> go
>>>>>> ahead
>>>>>>> and introduce an overpartition layer on our inputs to solve it,
>> but
>>>>> then
>>>>>>> again, if we get the ability to split partitions with backfill,
>> we
>>>> may
>>>>>> not
>>>>>>> need to!
>>>>>>>
>>>>>>>
>>>>>>> Point 4:
>>>>>>> On this:
>>>>>>>
>>>>>>>> Regarding thought 2: If we don't care about the stream
>> use-case,
>>>> then
>>>>>> the
>>>>>>>> current KIP probably has already addressed problem without
>>>> requiring
>>>>>>>> consumer to know the partition function. If we care about the
>>>> stream
>>>>>>>> use-case, we already need coordination across producers of
>>>> different
>>>>>>>> topics, i.e. the same partition function needs to be used by
>>>>> producers
>>>>>> of
>>>>>>>> topics A and B in order to join topics A and B. Thus, it might
>> be
>>>>>>>> reasonable to extend coordination a bit and say we need
>>>> coordination
>>>>>>> across
>>>>>>>> clients (i.e. producer and consumer), such that consumer knows
>>> the
>>>>>>>> partition function used by producer. If we do so, then we can
>> let
>>>>>>> consumer
>>>>>>>> re-copy data for the change log topic using the same partition
>>>>> function
>>>>>>> as
>>>>>>>> producer. This approach has lower overhead as compared to
>> having
>>>>>> producer
>>>>>>>> re-copy data of the input topic.
>>>>>>>> Also, producer currently does not need to know the data already
>>>>>> produced
>>>>>>> to
>>>>>>>> the topic. If we let producer split/merge partition, it would
>>>> require
>>>>>>>> producer to consume the existing data, which intuitively is the
>>>> task
>>>>> of
>>>>>>>> consumer.
>>>>>>>
>>>>>>> I think we do care about use cases *like* Streams, I just don't
>>> think
>>>>> we
>>>>>>> should rely on Streams to implement a feature of Core like
>>> partition
>>>>>>> expansion.
>>>>>>>
>>>>>>> Note, though, that we (Streams) do not require coordination
>> across
>>>>>>> producers. If two topics are certified to be co-partitioned, then
>>>>> Streams
>>>>>>> apps can make use of that knowledge to optimize their topology
>>>>> (skipping
>>>>>> a
>>>>>>> repartition). But if they don't know whether they are
>>> co-partitioned,
>>>>>> then
>>>>>>> they'd better go ahead and repartition within the topology. This
>> is
>>>> the
>>>>>>> current state.
>>>>>>>
>>>>>>> A huge selling point of Kafka is enabling different parts of
>>> loosely
>>>>>>> coupled organizations to produce and consume data independently.
>>> Some
>>>>>>> coordination between producers and consumers is necessary, like
>>>>>>> coordinating on the names of topics and their schemas. But
>> Kafka's
>>>>> value
>>>>>>> proposition w.r.t. ESBs, etc. is inversely proportional to the
>>> amount
>>>>> of
>>>>>>> coordination required. I think it behooves us to be extremely
>>>> skeptical
>>>>>>> about introducing any coordination beyond correctness protocols.
>>>>>>>
>>>>>>> Asking producers and consumers, or even two different producers,
>> to
>>>>> share
>>>>>>> code like the partition function is a pretty huge ask. What if
>> they
>>>> are
>>>>>>> using different languages?
>>>>>>>
>>>>>>> Comparing organizational overhead vs computational overhead,
>> there
>>>> are
>>>>>>> maybe two orders of magnitude difference between them. In other
>>>> words,
>>>>> I
>>>>>>> would happily take on the (linear) overhead of having the
>> producer
>>>>>> re-copy
>>>>>>> the data once during a re-partition in order to save the
>>>> organizational
>>>>>>> overhead of tying all the producers and consumers together across
>>>>>> multiple
>>>>>>> boundaries.
>>>>>>>
>>>>>>> On that last paragraph: note that the producer *did* know the
>> data
>>> it
>>>>>>> already produced. It handled it the first time around. Asking it
>> to
>>>>>>> re-produce it into a new partition layout is squarely within its
>>>> scope
>>>>> of
>>>>>>> capabilities. Contrast this with the alternative, asking the
>>> consumer
>>>>> to
>>>>>>> re-partition the data. I think this is even less intuitive, when
>>> the
>>>>>>> partition function belongs to the producer.
>>>>>>>
>>>>>>>
>>>>>>> Point 5:
>>>>>>> Dong asked this:
>>>>>>>
>>>>>>>> For stream use-case that needs to increase consumer number, the
>>>>>>>> existing consumer can backfill the existing data in the change
>>> log
>>>>>> topic
>>>>>>> to
>>>>>>>> the same change log topic with the new partition number, before
>>> the
>>>>> new
>>>>>>> set
>>>>>>>> of consumers bootstrap state from the new partitions of the
>>> change
>>>>> log
>>>>>>>> topic, right?
>>>>>>>
>>>>>>> In this sense, the "consumer" is actually the producer of the
>>>> changelog
>>>>>>> topic, so if we support partition expansion + backfill as a
>>>>>> producer/broker
>>>>>>> operation, then it would be very straightforward for Streams to
>>>> split a
>>>>>>> state store. As you say, they would simply instruct the broker to
>>>> split
>>>>>> the
>>>>>>> changelog topic's partitions, then backfill. Once the backfill is
>>>>> ready,
>>>>>>> they can create a new crop of StandbyTasks to bootstrap the more
>>>>> granular
>>>>>>> state stores and finally switch over to them when they are ready.
>>>>>>>
>>>>>>> But this actually seems to be an argument in favor of
>>> split+backfill,
>>>>> so
>>>>>>> maybe I missed the point.
>>>>>>>
>>>>>>> You also asked me to explain why copying the "input" topic is
>>> better
>>>>> than
>>>>>>> copying the "changelog" topic. I think they are totally
>>> independent,
>>>>>>> actually. For one thing, you can't depend on the existence of a
>>>>>> "changelog"
>>>>>>> topic in general, only within Streams, but Kafka's user base
>>> clearly
>>>>>>> exceeds Streams's user base. Plus, you actually also can't depend
>>> on
>>>>> the
>>>>>>> existence of a changelog topic within Streams, since that is an
>>>>> optional
>>>>>>> feature of *some* state store implementations. Even in the
>>> situation
>>>>>> where
>>>>>>> you do have a changelog topic in Streams, there may be use cases
>>>> where
>>>>> it
>>>>>>> makes sense to expand the partitions of just the input, or just
>> the
>>>>>>> changelog.
>>>>>>>
>>>>>>> The ask for a Core feature of split+backfill is really about
>>>> supporting
>>>>>> the
>>>>>>> use case of splitting partitions in log-compacted topics,
>>> regardless
>>>> of
>>>>>>> whether that topic is an "input" or a "changelog" or anything
>> else
>>>> for
>>>>>> that
>>>>>>> matter.
>>>>>>>
>>>>>>>
>>>>>>> Point 6:
>>>>>>> On the concern about the performance overhead of copying data
>>> between
>>>>> the
>>>>>>> brokers, I think it's actually a bit overestimated. Splitting a
>>>> topic's
>>>>>>> partition is probably rare, certainly rarer in general than
>>>>> bootstrapping
>>>>>>> new consumers on that topic. If "bootstrapping new consumers"
>> means
>>>>> that
>>>>>>> they have to re-shuffle the data before they consume it, then you
>>>> wind
>>>>> up
>>>>>>> copying the same record multiple times:
>>>>>>>
>>>>>>> (broker: input topic) -> (initial consumer) -> (broker:
>> repartition
>>>>>> topic)
>>>>>>> -> (real consumer)
>>>>>>>
>>>>>>> That's 3x, and it's also 3x for every new record after the split
>> as
>>>>> well,
>>>>>>> since you don't get to stop repartitioning/reshuffling once you
>>>> start.
>>>>>>> Whereas if you do a backfill in something like the procedure I
>>>>> outlined,
>>>>>>> you only copy the prefix of the partition before the split, and
>> you
>>>>> send
>>>>>> it
>>>>>>> once to the producer and then once to the new generation
>> partition.
>>>>> Plus,
>>>>>>> assuming we're splitting the partition for the benefit of
>>> consumers,
>>>>>>> there's no reason we can't co-locate the post-split partitions
> on
>>> the
>>>>>> same
>>>>>>> host as the pre-split partition, making the second copy a local
>>>>>> filesystem
>>>>>>> operation.
>>>>>>>
>>>>>>> Even if you follow these two copies up with bootstrapping a new
>>>>> consumer,
>>>>>>> it's still rare for this to occur, so you get to amortize these
>>>> copies
>>>>>> over
>>>>>>> the lifetime of the topic, whereas a reshuffle just keeps making
>>>> copies
>>>>>> for
>>>>>>> every new event.
>>>>>>>
>>>>>>> And finally, I really do think that regardless of any performance
>>>>>> concerns
>>>>>>> about this operation, if it preserves loose organizational
>>> coupling,
>>>> it
>>>>>> is
>>>>>>> certainly worth it.
>>>>>>>
>>>>>>>
>>>>>>> In conclusion:
>>>>>>> It might actually be a good idea for us to clarify the scope of
>>>>> KIP-253.
>>>>>> If
>>>>>>> we're all agreed that it's a good algorithm for allowing in-order
>>>>> message
>>>>>>> delivery during partition expansion, then we can continue this
>>>>> discussion
>>>>>>> as a new KIP, something like "backfill with partition expansion".
>>>> This
>>>>>>> would let Dong proceed with KIP-253. On the other hand, if it
>> seems
>>>>> like
>>>>>>> this conversation may alter the design of KIP-253, then maybe we
>>>>> *should*
>>>>>>> just finish working it out.
>>>>>>>
>>>>>>> For my part, my only concern about KIP-253 is the one I raised
>>>> earlier.
>>>>>>> Thanks again, all, for considering these points,
>>>>>>> -John
>>>>>>>
>>>>>>>
>>>>>>> On Tue, Mar 27, 2018 at 2:10 AM, Dong Lin <li...@gmail.com>
>>>> wrote:
>>>>>>>> On Tue, Mar 27, 2018 at 12:04 AM, Dong Lin <
>> lindong28@gmail.com>
>>>>>> wrote:
>>>>>>>>> Hey Jan,
>>>>>>>>>
>>>>>>>>> Thanks for the enthusiasm in improving Kafka's design. Now
>>> that I
>>>>>> have
>>>>>>>>> read through your discussion with Jun, here are my thoughts:
>>>>>>>>>
>>>>>>>>> - The latest proposal should with log compacted topics by
>>>> properly
>>>>>>>>> deleting old messages after a new message with the same key
>> is
>>>>>>> produced.
>>>>>>>> So
>>>>>>>>> it is probably not a concern anymore. Could you comment if
>>> there
>>>> is
>>>>>>> still
>>>>>>>>> issue?
>>>>>>>>>
>>>>>>>>> - I wrote the SEP-5 and I am pretty familiar with the
>>> motivation
>>>>> and
>>>>>>> the
>>>>>>>>> design of SEP-5. SEP-5 is probably orthornal to the
>> motivation
>>> of
>>>>>> this
>>>>>>>> KIP.
>>>>>>>>> The goal of SEP-5 is to allow user to increase task number of
>>> an
>>>>>>> existing
>>>>>>>>> Samza job. But if we increase the partition number of input
>>>> topics,
>>>>>>>>> messages may still be consumed out-of-order by tasks in Samza
>>>> which
>>>>>>> cause
>>>>>>>>> incorrect result. Similarly, the approach you proposed does
>> not
>>>>> seem
>>>>>> to
>>>>>>>>> ensure that the messages can be delivered in order, even if
>> we
>>>> can
>>>>>> make
>>>>>>>>> sure that each consumer instance is assigned the set of new
>>>>>> partitions
>>>>>>>>> covering the same set of keys.
>>>>>>>>>
>>>>>>>> Let me correct this comment. The approach of copying data to a
>>> new
>>>>>> topic
>>>>>>>> can ensure in-order message delivery suppose we properly
>> migrate
>>>>>> offsets
>>>>>>>> from old topic to new topic.
>>>>>>>>
>>>>>>>>
>>>>>>>>> - I am trying to understand why it is better to copy the data
>>>>> instead
>>>>>>> of
>>>>>>>>> copying the change log topic for streaming use-case. For core
>>>> Kafka
>>>>>>>>> use-case, and for the stream use-case that does not need to
>>>>> increase
>>>>>>>>> consumers, the current KIP already supports in-order delivery
>>>>> without
>>>>>>> the
>>>>>>>>> overhead of copying the data. For stream use-case that needs
>> to
>>>>>>> increase
>>>>>>>>> consumer number, the existing consumer can backfill the
>>> existing
>>>>> data
>>>>>>> in
>>>>>>>>> the change log topic to the same change log topic with the
>> new
>>>>>>> partition
>>>>>>>>> number, before the new set of consumers bootstrap state from
>>> the
>>>>> new
>>>>>>>>> partitions of the change log topic. If this solution works,
>>> then
>>>>>> could
>>>>>>>> you
>>>>>>>>> summarize the advantage of copying the data of input topic as
>>>>>> compared
>>>>>>> to
>>>>>>>>> copying the change log topic? For example, does it enable
>> more
>>>>>>> use-case,
>>>>>>>>> simplify the implementation of Kafka library, or reduce the
>>>>> operation
>>>>>>>>> overhead etc?
>>>>>>>>>
>>>>>>>>> Thanks,
>>>>>>>>> Dong
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> On Wed, Mar 21, 2018 at 6:57 AM, Jan Filipiak <
>>>>>>> Jan.Filipiak@trivago.com>
>>>>>>>>> wrote:
>>>>>>>>>
>>>>>>>>>> Hi Jun,
>>>>>>>>>>
>>>>>>>>>> I was really seeing progress in our conversation but your
>>> latest
>>>>>> reply
>>>>>>>> is
>>>>>>>>>> just devastating.
>>>>>>>>>> I though we were getting close being on the same page now it
>>>> feels
>>>>>>> like
>>>>>>>>>> we are in different libraries.
>>>>>>>>>>
>>>>>>>>>> I just quickly slam my answers in here. If they are to
>> brief I
>>>> am
>>>>>>> sorry
>>>>>>>>>> give me a ping and try to go into details more.
>>>>>>>>>> Just want to show that your pro/cons listing is broken.
>>>>>>>>>>
>>>>>>>>>> Best Jan
>>>>>>>>>>
>>>>>>>>>> and want to get rid of this horrible compromise
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> On 19.03.2018 05:48, Jun Rao wrote:
>>>>>>>>>>
>>>>>>>>>>> Hi, Jan,
>>>>>>>>>>>
>>>>>>>>>>> Thanks for the discussion. Great points.
>>>>>>>>>>>
>>>>>>>>>>> Let me try to summarize the approach that you are
>> proposing.
>>> On
>>>>> the
>>>>>>>>>>> broker
>>>>>>>>>>> side, we reshuffle the existing data in a topic from
>> current
>>>>>>> partitions
>>>>>>>>>>> to
>>>>>>>>>>> the new partitions. Once the reshuffle fully catches up,
>>> switch
>>>>> the
>>>>>>>>>>> consumers to start consuming from the new partitions. If a
>>>>> consumer
>>>>>>>> needs
>>>>>>>>>>> to rebuild its local state (due to partition changes), let
>>> the
>>>>>>> consumer
>>>>>>>>>>> rebuild its state by reading all existing data from the new
>>>>>>> partitions.
>>>>>>>>>>> Once all consumers have switches over, cut over the
>> producer
>>> to
>>>>> the
>>>>>>> new
>>>>>>>>>>> partitions.
>>>>>>>>>>>
>>>>>>>>>>> The pros for this approach are that :
>>>>>>>>>>> 1. There is just one way to rebuild the local state, which
>> is
>>>>>>> simpler.
>>>>>>>>>> true thanks
>>>>>>>>>>
>>>>>>>>>>> The cons for this approach are:
>>>>>>>>>>> 1. Need to copy existing data.
>>>>>>>>>>>
>>>>>>>>>> Very unfair and not correct. It does not require you to copy
>>>> over
>>>>>>>>>> existing data. It _allows_ you to copy all existing data.
>>>>>>>>>>
>>>>>>>>>> 2. The cutover of the producer is a bit complicated since it
>>>> needs
>>>>>> to
>>>>>>>>>>> coordinate with all consumer groups.
>>>>>>>>>>>
>>>>>>>>>> Also not true. I explicitly tried to make clear that there
>> is
>>>> only
>>>>>> one
>>>>>>>>>> special consumer (in the case of actually copying data)
>>>>> coordination
>>>>>>> is
>>>>>>>>>> required.
>>>>>>>>>>
>>>>>>>>>>> 3. The rebuilding of the state in the consumer is from the
>>>> input
>>>>>>> topic,
>>>>>>>>>>> which can be more expensive than rebuilding from the
>> existing
>>>>>> state.
>>>>>>>>>> true, but rebuilding state is only required if you want to
>>>>> increase
>>>>>>>>>> processing power, so we assume this is at hand.
>>>>>>>>>>
>>>>>>>>>>> 4. The broker potentially has to know the partitioning
>>>> function.
>>>>> If
>>>>>>>> this
>>>>>>>>>>> needs to be customized at the topic level, it can be a bit
>>>> messy.
>>>>>>>>>> I would argue against having the operation being performed
>> by
>>>> the
>>>>>>>> broker.
>>>>>>>>>> This was not discussed yet but if you see my original email
>> i
>>>>>>> suggested
>>>>>>>>>> otherwise from the beginning.
>>>>>>>>>>
>>>>>>>>>>> Here is an alternative approach by applying your idea not
>> in
>>>> the
>>>>>>>> broker,
>>>>>>>>>>> but in the consumer. When new partitions are added, we
>> don't
>>>> move
>>>>>>>>>>> existing
>>>>>>>>>>> data. In KStreams, we first reshuffle the new input data
>> to a
>>>> new
>>>>>>> topic
>>>>>>>>>>> T1
>>>>>>>>>>> with the old number of partitions and feed T1's data to the
>>>> rest
>>>>> of
>>>>>>> the
>>>>>>>>>>> pipeline. In the meantime, KStreams reshuffles all existing
>>>> data
>>>>> of
>>>>>>> the
>>>>>>>>>>> change capture topic to another topic C1 with the new
>> number
>>> of
>>>>>>>>>>> partitions.
>>>>>>>>>>> We can then build the state of the new tasks from C1. Once
>>> the
>>>>> new
>>>>>>>> states
>>>>>>>>>>> have been fully built, we can cut over the consumption to
>> the
>>>>> input
>>>>>>>> topic
>>>>>>>>>>> and delete T1. This approach works with compacted topic
>> too.
>>> If
>>>>> an
>>>>>>>>>>> application reads from the beginning of a compacted topic,
>>> the
>>>>>>> consumer
>>>>>>>>>>> will reshuffle the portion of the input when the number of
>>>>>> partitions
>>>>>>>>>>> doesn't match the number of tasks.
>>>>>>>>>>>
>>>>>>>>>> We all wipe this idea from our heads instantly. Mixing Ideas
>>>> from
>>>>> an
>>>>>>>>>> argument is not a resolution strategy
>>>>>>>>>> just leads to horrible horrible software.
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>> The pros of this approach are:
>>>>>>>>>>> 1. No need to copy existing data.
>>>>>>>>>>> 2. Each consumer group can cut over to the new partitions
>>>>>>>> independently.
>>>>>>>>>>> 3. The state is rebuilt from the change capture topic,
>> which
>>> is
>>>>>>> cheaper
>>>>>>>>>>> than rebuilding from the input topic.
>>>>>>>>>>> 4. Only the KStreams job needs to know the partitioning
>>>> function.
>>>>>>>>>>> The cons of this approach are:
>>>>>>>>>>> 1. Potentially the same input topic needs to be reshuffled
>>> more
>>>>>> than
>>>>>>>> once
>>>>>>>>>>> in different consumer groups during the transition phase.
>>>>>>>>>>>
>>>>>>>>>>> What do you think?
>>>>>>>>>>>
>>>>>>>>>>> Thanks,
>>>>>>>>>>>
>>>>>>>>>>> Jun
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> On Thu, Mar 15, 2018 at 1:04 AM, Jan Filipiak <
>>>>>>>> Jan.Filipiak@trivago.com>
>>>>>>>>>>> wrote:
>>>>>>>>>>>
>>>>>>>>>>> Hi Jun,
>>>>>>>>>>>> thank you for following me on these thoughts. It was
>>> important
>>>>> to
>>>>>> me
>>>>>>>> to
>>>>>>>>>>>> feel that kind of understanding for my arguments.
>>>>>>>>>>>>
>>>>>>>>>>>> What I was hoping for (I mentioned this earlier) is that
>> we
>>>> can
>>>>>>> model
>>>>>>>>>>>> the
>>>>>>>>>>>> case where we do not want to copy the data the exact same
>>> way
>>>> as
>>>>>> the
>>>>>>>>>>>> case
>>>>>>>>>>>> when we do copy the data. Maybe you can peek into the
>> mails
>>>>> before
>>>>>>> to
>>>>>>>>>>>> see
>>>>>>>>>>>> more details for this.
>>>>>>>>>>>>
>>>>>>>>>>>> This means we have the same mechanism to transfer consumer
>>>>> groups
>>>>>> to
>>>>>>>>>>>> switch topic. The offset mapping that would be generated
>>> would
>>>>>> even
>>>>>>> be
>>>>>>>>>>>> simpler End Offset of the Old topic => offset 0 off all
>> the
>>>>>>> partitions
>>>>>>>>>>>> of
>>>>>>>>>>>> the new topic. Then we could model the transition of a
>>>> non-copy
>>>>>>>>>>>> expansion
>>>>>>>>>>>> the exact same way as a copy-expansion.
>>>>>>>>>>>>
>>>>>>>>>>>> I know this only works when topic growth by a factor. But
>>> the
>>>>>>> benefits
>>>>>>>>>>>> of
>>>>>>>>>>>> only growing by a factor are to strong anyways. See
>>> Clemens's
>>>>> hint
>>>>>>> and
>>>>>>>>>>>> remember that state reshuffling is entirely not needed if
>>> one
>>>>>>> doesn't
>>>>>>>>>>>> want
>>>>>>>>>>>> to grow processing power.
>>>>>>>>>>>>
>>>>>>>>>>>> I think these benefits should be clear, and that there is
>>>>>> basically
>>>>>>> no
>>>>>>>>>>>> downside to what is currently at hand but just makes
>>>> everything
>>>>>>> easy.
>>>>>>>>>>>> One thing you need to know is. that if you do not offer
>>>>>> rebuilding a
>>>>>>>> log
>>>>>>>>>>>> compacted topic like i suggest that even if you have
>>> consumer
>>>>>> state
>>>>>>>>>>>> reshuffling. The topic is broken and can not be used to
>>>>> bootstrap
>>>>>>> new
>>>>>>>>>>>> consumers. They don't know if they need to apply a key
>> from
>>>> and
>>>>>> old
>>>>>>>>>>>> partition or not. This is a horrible downside I haven't
>>> seen a
>>>>>>>> solution
>>>>>>>>>>>> for
>>>>>>>>>>>> in the email conversation.
>>>>>>>>>>>>
>>>>>>>>>>>> I argue to:
>>>>>>>>>>>>
>>>>>>>>>>>> Only grow topic by a factor always.
>>>>>>>>>>>> Have the "no copy consumer" transition as the trivial case
>>> of
>>>>> the
>>>>>>>> "copy
>>>>>>>>>>>> consumer transition".
>>>>>>>>>>>> If processors needs to be scaled, let them rebuild from
>> the
>>>> new
>>>>>>> topic
>>>>>>>>>>>> and
>>>>>>>>>>>> leave the old running in the mean time.
>>>>>>>>>>>> Do not implement key shuffling in streams.
>>>>>>>>>>>>
>>>>>>>>>>>> I hope I can convince you especially with the fact how I
>>> want
>>>> to
>>>>>>>> handle
>>>>>>>>>>>> consumer transition. I think
>>>>>>>>>>>> you didn't quite understood me there before. I think the
>>> term
>>>>> "new
>>>>>>>>>>>> topic"
>>>>>>>>>>>> intimidated you a little.
>>>>>>>>>>>> How we solve this on disc doesn't really matter, If the
>> data
>>>>> goes
>>>>>>> into
>>>>>>>>>>>> the
>>>>>>>>>>>> same Dir or a different Dir or anything. I do think that
>> it
>>>>> needs
>>>>>> to
>>>>>>>>>>>> involve at least rolling a new segment for the existing
>>>>>> partitions.
>>>>>>>>>>>> But most of the transitions should work without restarting
>>>>>>> consumers.
>>>>>>>>>>>> (newer consumers with support for this). But with new
>> topic
>>> i
>>>>> just
>>>>>>>> meant
>>>>>>>>>>>> the topic that now has a different partition count. Plenty
>>> of
>>>>> ways
>>>>>>> to
>>>>>>>>>>>> handle that (versions, aliases)
>>>>>>>>>>>>
>>>>>>>>>>>> Hope I can further get my idea across.
>>>>>>>>>>>>
>>>>>>>>>>>> Best Jan
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>> On 14.03.2018 02:45, Jun Rao wrote:
>>>>>>>>>>>>
>>>>>>>>>>>> Hi, Jan,
>>>>>>>>>>>>> Thanks for sharing your view.
>>>>>>>>>>>>>
>>>>>>>>>>>>> I agree with you that recopying the data potentially
>> makes
>>>> the
>>>>>>> state
>>>>>>>>>>>>> management easier since the consumer can just rebuild its
>>>> state
>>>>>>> from
>>>>>>>>>>>>> scratch (i.e., no need for state reshuffling).
>>>>>>>>>>>>>
>>>>>>>>>>>>> On the flip slide, I saw a few disadvantages of the
>>> approach
>>>>> that
>>>>>>> you
>>>>>>>>>>>>> suggested. (1) Building the state from the input topic
>> from
>>>>>> scratch
>>>>>>>> is
>>>>>>>>>>>>> in
>>>>>>>>>>>>> general less efficient than state reshuffling. Let's say
>>> one
>>>>>>>> computes a
>>>>>>>>>>>>> count per key from an input topic. The former requires
>>>> reading
>>>>>> all
>>>>>>>>>>>>> existing
>>>>>>>>>>>>> records in the input topic whereas the latter only
>> requires
>>>>>> reading
>>>>>>>>>>>>> data
>>>>>>>>>>>>> proportional to the number of unique keys. (2) The
>>> switching
>>>> of
>>>>>> the
>>>>>>>>>>>>> topic
>>>>>>>>>>>>> needs modification to the application. If there are many
>>>>>>> applications
>>>>>>>>>>>>> on a
>>>>>>>>>>>>> topic, coordinating such an effort may not be easy. Also,
>>>> it's
>>>>>> not
>>>>>>>>>>>>> clear
>>>>>>>>>>>>> how to enforce exactly-once semantic during the switch.
>> (3)
>>>> If
>>>>> a
>>>>>>>> topic
>>>>>>>>>>>>> doesn't need any state management, recopying the data
>> seems
>>>>>>> wasteful.
>>>>>>>>>>>>> In
>>>>>>>>>>>>> that case, in place partition expansion seems more
>>> desirable.
>>>>>>>>>>>>> I understand your concern about adding complexity in
>>>> KStreams.
>>>>>> But,
>>>>>>>>>>>>> perhaps
>>>>>>>>>>>>> we could iterate on that a bit more to see if it can be
>>>>>> simplified.
>>>>>>>>>>>>> Jun
>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>> On Mon, Mar 12, 2018 at 11:21 PM, Jan Filipiak <
>>>>>>>>>>>>> Jan.Filipiak@trivago.com>
>>>>>>>>>>>>> wrote:
>>>>>>>>>>>>>
>>>>>>>>>>>>> Hi Jun,
>>>>>>>>>>>>>
>>>>>>>>>>>>>> I will focus on point 61 as I think its _the_
>> fundamental
>>>> part
>>>>>>> that
>>>>>>>> I
>>>>>>>>>>>>>> cant
>>>>>>>>>>>>>> get across at the moment.
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> Kafka is the platform to have state materialized
>> multiple
>>>>> times
>>>>>>> from
>>>>>>>>>>>>>> one
>>>>>>>>>>>>>> input. I emphasize this: It is the building block in
>>>>>> architectures
>>>>>>>>>>>>>> that
>>>>>>>>>>>>>> allow you to
>>>>>>>>>>>>>> have your state maintained multiple times. You put a
>>> message
>>>>> in
>>>>>>>> once,
>>>>>>>>>>>>>> and
>>>>>>>>>>>>>> you have it pop out as often as you like. I believe you
>>>>>> understand
>>>>>>>>>>>>>> this.
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> Now! The path of thinking goes the following: I am using
>>>>> apache
>>>>>>>> kafka
>>>>>>>>>>>>>> and
>>>>>>>>>>>>>> I _want_ my state multiple times. What am I going todo?
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> A) Am I going to take my state that I build up, plunge
>>> some
>>>>> sort
>>>>>>> of
>>>>>>>>>>>>>> RPC
>>>>>>>>>>>>>> layer ontop of it, use that RPC layer to throw my
>> records
>>>>> across
>>>>>>>>>>>>>> instances?
>>>>>>>>>>>>>> B) Am I just going to read the damn message twice?
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> Approach A is fundamentally flawed and a violation of
>> all
>>>> that
>>>>>> is
>>>>>>>> good
>>>>>>>>>>>>>> and
>>>>>>>>>>>>>> holy in kafka deployments. I can not understand how this
>>>> Idea
>>>>>> can
>>>>>>>>>>>>>> come in
>>>>>>>>>>>>>> the first place.
>>>>>>>>>>>>>> (I do understand: IQ in streams, they polluted the kafka
>>>>> streams
>>>>>>>>>>>>>> codebase
>>>>>>>>>>>>>> really bad already. It is not funny! I think they are
>>>> equally
>>>>>>> flawed
>>>>>>>>>>>>>> as
>>>>>>>>>>>>>> A)
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> I say, we do what Kafka is good at. We repartition the
>>> topic
>>>>>> once.
>>>>>>>> We
>>>>>>>>>>>>>> switch the consumers.
>>>>>>>>>>>>>> (Those that need more partitions are going to rebuild
>>> their
>>>>>> state
>>>>>>> in
>>>>>>>>>>>>>> multiple partitions by reading the new topic, those that
>>>> don't
>>>>>>> just
>>>>>>>>>>>>>> assign
>>>>>>>>>>>>>> the new partitions properly)
>>>>>>>>>>>>>> We switch producers. Done!
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> The best thing! It is trivial, hipster stream processor
>>> will
>>>>>> have
>>>>>>> an
>>>>>>>>>>>>>> easy
>>>>>>>>>>>>>> time with that aswell. Its so super simple. And simple
>> IS
>>>>> good!
>>>>>>>>>>>>>> It is what kafka was build todo. It is how we do it
>> today.
>>>>> All I
>>>>>>> am
>>>>>>>>>>>>>> saying
>>>>>>>>>>>>>> is that a little broker help doing the producer swap is
>>>> super
>>>>>>>> useful.
>>>>>>>>>>>>>> For everyone interested in why kafka is so powerful with
>>>>>> approach
>>>>>>> B,
>>>>>>>>>>>>>> please watch https://youtu.be/bEbeZPVo98c?t=1633
>>>>>>>>>>>>>> I already looked up a good point in time, I think after
>> 5
>>>>>> minutes
>>>>>>>> the
>>>>>>>>>>>>>> "state" topic is handled and you should be able to
>>>> understand
>>>>> me
>>>>>>>>>>>>>> and inch better.
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> Please do not do A to the project, it deserves better!
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> Best Jan
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> On 13.03.2018 02:40, Jun Rao wrote:
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> Hi, Jan,
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> Thanks for the reply. A few more comments below.
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> 50. Ok, we can think a bit harder for supporting
>>> compacted
>>>>>>> topics.
>>>>>>>>>>>>>>> 51. This is a fundamental design question. In the more
>>>> common
>>>>>>> case,
>>>>>>>>>>>>>>> the
>>>>>>>>>>>>>>> reason why someone wants to increase the number of
>>>> partitions
>>>>>> is
>>>>>>>> that
>>>>>>>>>>>>>>> the
>>>>>>>>>>>>>>> consumer application is slow and one wants to run more
>>>>> consumer
>>>>>>>>>>>>>>> instances
>>>>>>>>>>>>>>> to increase the degree of parallelism. So, fixing the
>>>> number
>>>>> of
>>>>>>>>>>>>>>> running
>>>>>>>>>>>>>>> consumer instances when expanding the partitions won't
>>> help
>>>>>> this
>>>>>>>>>>>>>>> case.
>>>>>>>>>>>>>>> If
>>>>>>>>>>>>>>> we do need to increase the number of consumer
>> instances,
>>> we
>>>>>> need
>>>>>>> to
>>>>>>>>>>>>>>> somehow
>>>>>>>>>>>>>>> reshuffle the state of the consumer across instances.
>>> What
>>>> we
>>>>>>> have
>>>>>>>>>>>>>>> been
>>>>>>>>>>>>>>> discussing in this KIP is whether we can do this more
>>>>>> effectively
>>>>>>>>>>>>>>> through
>>>>>>>>>>>>>>> the KStream library (e.g. through a 2-phase partition
>>>>>> expansion).
>>>>>>>>>>>>>>> This
>>>>>>>>>>>>>>> will
>>>>>>>>>>>>>>> add some complexity, but it's probably better than
>>> everyone
>>>>>> doing
>>>>>>>>>>>>>>> this
>>>>>>>>>>>>>>> in
>>>>>>>>>>>>>>> the application space. The recopying approach that you
>>>>>> mentioned
>>>>>>>>>>>>>>> doesn't
>>>>>>>>>>>>>>> seem to address the consumer state management issue
>> when
>>>> the
>>>>>>>> consumer
>>>>>>>>>>>>>>> switches from an old to a new topic.
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> 52. As for your example, it depends on whether the join
>>> key
>>>>> is
>>>>>>> the
>>>>>>>>>>>>>>> same
>>>>>>>>>>>>>>> between (A,B) and (B,C). If the join key is the same,
>> we
>>>> can
>>>>>> do a
>>>>>>>>>>>>>>> 2-phase
>>>>>>>>>>>>>>> partition expansion of A, B, and C together. If the
>> join
>>>> keys
>>>>>> are
>>>>>>>>>>>>>>> different, one would need to repartition the data on a
>>>>>> different
>>>>>>>> key
>>>>>>>>>>>>>>> for
>>>>>>>>>>>>>>> the second join, then the partition expansion can be
>> done
>>>>>>>>>>>>>>> independently
>>>>>>>>>>>>>>> between (A,B) and (B,C).
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> 53. If you always fix the number of consumer instances,
>>> we
>>>>> you
>>>>>>>>>>>>>>> described
>>>>>>>>>>>>>>> works. However, as I mentioned in #51, I am not sure
>> how
>>>> your
>>>>>>>>>>>>>>> proposal
>>>>>>>>>>>>>>> deals with consumer states when the number of consumer
>>>>>> instances
>>>>>>>>>>>>>>> grows.
>>>>>>>>>>>>>>> Also, it just seems that it's better to avoid
>> re-copying
>>>> the
>>>>>>>> existing
>>>>>>>>>>>>>>> data.
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> 60. "just want to throw in my question from the longer
>>>> email
>>>>> in
>>>>>>> the
>>>>>>>>>>>>>>> other
>>>>>>>>>>>>>>> Thread here. How will the bloom filter help a new
>>> consumer
>>>> to
>>>>>>>> decide
>>>>>>>>>>>>>>> to
>>>>>>>>>>>>>>> apply the key or not?" Not sure that I fully understood
>>>> your
>>>>>>>>>>>>>>> question.
>>>>>>>>>>>>>>> The
>>>>>>>>>>>>>>> consumer just reads whatever key is in the log. The
>> bloom
>>>>>> filter
>>>>>>>> just
>>>>>>>>>>>>>>> helps
>>>>>>>>>>>>>>> clean up the old keys.
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> 61. "Why can we afford having a topic where its
>>> apparently
>>>>> not
>>>>>>>>>>>>>>> possible
>>>>>>>>>>>>>>> to
>>>>>>>>>>>>>>> start a new application on? I think this is an overall
>>> flaw
>>>>> of
>>>>>>> the
>>>>>>>>>>>>>>> discussed idea here. Not playing attention to the
>> overall
>>>>>>>>>>>>>>> architecture."
>>>>>>>>>>>>>>> Could you explain a bit more when one can't start a new
>>>>>>>> application?
>>>>>>>>>>>>>>> Jun
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> On Sat, Mar 10, 2018 at 1:40 AM, Jan Filipiak <
>>>>>>>>>>>>>>> Jan.Filipiak@trivago.com
>>>>>>>>>>>>>>> wrote:
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> Hi Jun, thanks for your mail.
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> Thank you for your questions!
>>>>>>>>>>>>>>>> I think they are really good and tackle the core of
>> the
>>>>>> problem
>>>>>>> I
>>>>>>>>>>>>>>>> see.
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> I will answer inline, mostly but still want to set the
>>>> tone
>>>>>>> here.
>>>>>>>>>>>>>>>> The core strength of kafka is what Martin once called
>>> the
>>>>>>>>>>>>>>>> kappa-Architecture. How does this work?
>>>>>>>>>>>>>>>> You have everything as a log as in kafka. When you
>> need
>>> to
>>>>>>> change
>>>>>>>>>>>>>>>> something.
>>>>>>>>>>>>>>>> You create the new version of your application and
>> leave
>>>> it
>>>>>>>> running
>>>>>>>>>>>>>>>> in
>>>>>>>>>>>>>>>> parallel.
>>>>>>>>>>>>>>>> Once the new version is good you switch your users to
>>> use
>>>>> the
>>>>>>> new
>>>>>>>>>>>>>>>> application.
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> The online reshuffling effectively breaks this
>>>> architecture
>>>>>> and
>>>>>>> I
>>>>>>>>>>>>>>>> think
>>>>>>>>>>>>>>>> the switch in thinking here is more harmful
>>>>>>>>>>>>>>>> than any details about the partitioning function to
>>> allow
>>>>>> such a
>>>>>>>>>>>>>>>> change.
>>>>>>>>>>>>>>>> I
>>>>>>>>>>>>>>>> feel with my suggestion we are the closest to
>>>>>>>>>>>>>>>> the original and battle proven architecture and I can
>>> only
>>>>>> warn
>>>>>>> to
>>>>>>>>>>>>>>>> move
>>>>>>>>>>>>>>>> away from it.
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> I might have forgotten something, sometimes its hard
>> for
>>>> me
>>>>> to
>>>>>>>>>>>>>>>> getting
>>>>>>>>>>>>>>>> all
>>>>>>>>>>>>>>>> the thoughts captured in a mail, but I hope the
>> comments
>>>>>> inline
>>>>>>>> will
>>>>>>>>>>>>>>>> further make my concern clear, and put some emphasis
>> on
>>>> why
>>>>> I
>>>>>>>>>>>>>>>> prefer my
>>>>>>>>>>>>>>>> solution ;)
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> One thing we should all be aware of when discussing
>>> this,
>>>>> and
>>>>>> I
>>>>>>>>>>>>>>>> think
>>>>>>>>>>>>>>>> Dong
>>>>>>>>>>>>>>>> should have mentioned it (maybe he did).
>>>>>>>>>>>>>>>> We are not discussing all of this out of thin air but
>>>> there
>>>>> is
>>>>>>> an
>>>>>>>>>>>>>>>> effort
>>>>>>>>>>>>>>>> in the Samza project.
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> https://cwiki.apache.org/confl
>> uence/display/SAMZA/SEP-
>>>> 5%3A+
>>>>>>>>>>>>>>>> Enable+partition+expansion+of+input+streams
>>>>>>>>>>>>>>>> https://issues.apache.org/jira/browse/SAMZA-1293
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> To be clear. I think SEP-5 (state of last week, dont
>>> know
>>>> if
>>>>>> it
>>>>>>>>>>>>>>>> adapted
>>>>>>>>>>>>>>>> to
>>>>>>>>>>>>>>>> this discussion) is on a way better path than KIP-253,
>>>> and I
>>>>>>> can't
>>>>>>>>>>>>>>>> really
>>>>>>>>>>>>>>>> explain why.
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> Best Jan,
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> nice weekend everyone
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> On 09.03.2018 03:36, Jun Rao wrote:
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> Hi, Jan,
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> Thanks for the feedback. Just some comments on the
>>> earlier
>>>>>>> points
>>>>>>>>>>>>>>>>> that
>>>>>>>>>>>>>>>>> you
>>>>>>>>>>>>>>>>> mentioned.
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> 50. You brought up the question of whether existing
>>> data
>>>>>> needs
>>>>>>> to
>>>>>>>>>>>>>>>>> be
>>>>>>>>>>>>>>>>> copied
>>>>>>>>>>>>>>>>> during partition expansion. My understand of your
>> view
>>> is
>>>>>> that
>>>>>>>>>>>>>>>>> avoid
>>>>>>>>>>>>>>>>> copying existing data will be more efficient, but it
>>>>> doesn't
>>>>>>> work
>>>>>>>>>>>>>>>>> well
>>>>>>>>>>>>>>>>> with
>>>>>>>>>>>>>>>>> compacted topics since some keys in the original
>>>> partitions
>>>>>>> will
>>>>>>>>>>>>>>>>> never
>>>>>>>>>>>>>>>>> be
>>>>>>>>>>>>>>>>> cleaned. It would be useful to understand your use
>> case
>>>> of
>>>>>>>>>>>>>>>>> compacted
>>>>>>>>>>>>>>>>> topics
>>>>>>>>>>>>>>>>> a bit more. In the common use case, the data volume
>> in
>>> a
>>>>>>>> compacted
>>>>>>>>>>>>>>>>> topic
>>>>>>>>>>>>>>>>> may not be large. So, I am not sure if there is a
>>> strong
>>>>> need
>>>>>>> to
>>>>>>>>>>>>>>>>> expand
>>>>>>>>>>>>>>>>> partitions in a compacted topic, at least initially.
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> I do agree. State is usually smaller. Update rates
>>> might
>>>> be
>>>>>>> also
>>>>>>>>>>>>>>>>> competitively high.
>>>>>>>>>>>>>>>> Doing Log-compaction (even beeing very efficient and
>>>>>>> configurable)
>>>>>>>>>>>>>>>> is
>>>>>>>>>>>>>>>> also
>>>>>>>>>>>>>>>> a more expensive operation than
>>>>>>>>>>>>>>>> just discarding old segments. Further if you want to
>> use
>>>>> more
>>>>>>>>>>>>>>>> consumers
>>>>>>>>>>>>>>>> processing the events
>>>>>>>>>>>>>>>> you also have to grow the number of partitions.
>>> Especially
>>>>> for
>>>>>>>>>>>>>>>> use-cases
>>>>>>>>>>>>>>>> we do (KIP-213) a tiny state full
>>>>>>>>>>>>>>>> table might be very expensive to process if it joins
>>>>> against a
>>>>>>>> huge
>>>>>>>>>>>>>>>> table.
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> I can just say we have been in the spot of needing to
>>> grow
>>>>> log
>>>>>>>>>>>>>>>> compacted
>>>>>>>>>>>>>>>> topics. Mainly for processing power we can bring to
>> the
>>>>> table.
>>>>>>>>>>>>>>>> Further i am not at all concerned about the extra
>> spaced
>>>>> used
>>>>>> by
>>>>>>>>>>>>>>>> "garbage
>>>>>>>>>>>>>>>> keys". I am more concerned about the correctness of
>>>> innocent
>>>>>>>>>>>>>>>> consumers.
>>>>>>>>>>>>>>>> The
>>>>>>>>>>>>>>>> logic becomes complicated. Say for streams one would
>>> need
>>>> to
>>>>>>> load
>>>>>>>>>>>>>>>> the
>>>>>>>>>>>>>>>> record into state but not forward it the topology ( to
>>>> have
>>>>> it
>>>>>>>>>>>>>>>> available
>>>>>>>>>>>>>>>> for shuffeling). I rather have it simple and a topic
>>> clean
>>>>>>>>>>>>>>>> regardless
>>>>>>>>>>>>>>>> if
>>>>>>>>>>>>>>>> it
>>>>>>>>>>>>>>>> still has its old partition count. Especially with
>>>> multiple
>>>>>>>>>>>>>>>> partitions
>>>>>>>>>>>>>>>> growth's I think it becomes insanely hard to to this
>>>> shuffle
>>>>>>>>>>>>>>>> correct.
>>>>>>>>>>>>>>>> Maybe
>>>>>>>>>>>>>>>> Streams and Samza can do it. Especially if you do
>>> "hipster
>>>>>>> stream
>>>>>>>>>>>>>>>> processing" <https://www.confluent.io/blog
>>>>>>>>>>>>>>>> /introducing-kafka-streams-
>>>>>>>>>>>>>>>> stream-processing-made-simple/>. This makes kafka way
>>> to
>>>>>>>>>>>>>>>> complicated.
>>>>>>>>>>>>>>>> With my approach I think its way simpler because the
>>> topic
>>>>> has
>>>>>>> no
>>>>>>>>>>>>>>>> "history"
>>>>>>>>>>>>>>>> in terms of partitioning but is always clean.
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> 51. "Growing the topic by an integer factor does not
>>>> require
>>>>>> any
>>>>>>>>>>>>>>>> state
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> redistribution at all." Could you clarify this a bit
>>> more?
>>>>>> Let's
>>>>>>>> say
>>>>>>>>>>>>>>>>> you
>>>>>>>>>>>>>>>>> have a consumer app that computes the windowed count
>>> per
>>>>> key.
>>>>>>> If
>>>>>>>>>>>>>>>>> you
>>>>>>>>>>>>>>>>> double
>>>>>>>>>>>>>>>>> the number of partitions from 1 to 2 and grow the
>>>> consumer
>>>>>>>>>>>>>>>>> instances
>>>>>>>>>>>>>>>>> from
>>>>>>>>>>>>>>>>> 1
>>>>>>>>>>>>>>>>> to 2, we would need to redistribute some of the
>> counts
>>> to
>>>>> the
>>>>>>> new
>>>>>>>>>>>>>>>>> consumer
>>>>>>>>>>>>>>>>> instance. Regarding to linear hashing, it's true that
>>> it
>>>>>> won't
>>>>>>>>>>>>>>>>> solve
>>>>>>>>>>>>>>>>> the
>>>>>>>>>>>>>>>>> problem with compacted topics. The main benefit is
>> that
>>>> it
>>>>>>>>>>>>>>>>> redistributes
>>>>>>>>>>>>>>>>> the keys in one partition to no more than two
>>> partitions,
>>>>>> which
>>>>>>>>>>>>>>>>> could
>>>>>>>>>>>>>>>>> help
>>>>>>>>>>>>>>>>> redistribute the state.
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> You don't need to spin up a new consumer in this
>> case.
>>>>> every
>>>>>>>>>>>>>>>>> consumer
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> would just read every partition with the (partition %
>>>>>> num_task)
>>>>>>>>>>>>>>>> task.
>>>>>>>>>>>>>>>> it
>>>>>>>>>>>>>>>> will still have the previous data right there and can
>> go
>>>> on.
>>>>>>>>>>>>>>>> This sounds contradictory to what I said before, but
>>>> please
>>>>>> bear
>>>>>>>>>>>>>>>> with
>>>>>>>>>>>>>>>> me.
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> 52. Good point on coordinating the expansion of 2
>> topics
>>>>> that
>>>>>>> need
>>>>>>>>>>>>>>>> to
>>>>>>>>>>>>>>>> be
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> joined together. This is where the 2-phase partition
>>>>> expansion
>>>>>>>> could
>>>>>>>>>>>>>>>>> potentially help. In the first phase, we could add
>> new
>>>>>>> partitions
>>>>>>>>>>>>>>>>> to
>>>>>>>>>>>>>>>>> the 2
>>>>>>>>>>>>>>>>> topics one at a time but without publishing to the
>> new
>>>>>>> patitions.
>>>>>>>>>>>>>>>>> Then,
>>>>>>>>>>>>>>>>> we
>>>>>>>>>>>>>>>>> can add new consumer instances to pick up the new
>>>>> partitions.
>>>>>>> In
>>>>>>>>>>>>>>>>> this
>>>>>>>>>>>>>>>>> transition phase, no reshuffling is needed since no
>>> data
>>>> is
>>>>>>>> coming
>>>>>>>>>>>>>>>>> from
>>>>>>>>>>>>>>>>> the
>>>>>>>>>>>>>>>>> new partitions. Finally, we can enable the publishing
>>> to
>>>>> the
>>>>>>> new
>>>>>>>>>>>>>>>>> partitions.
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> I think its even worse than you think. I would like
>> to
>>>>>>> introduce
>>>>>>>>>>>>>>>>> the
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> Term
>>>>>>>>>>>>>>>> transitive copartitioning. Imagine
>>>>>>>>>>>>>>>> 2 streams application. One joins (A,B) the other (B,C)
>>>> then
>>>>>>> there
>>>>>>>>>>>>>>>> is a
>>>>>>>>>>>>>>>> transitive copartition requirement for
>>>>>>>>>>>>>>>> (A,C) to be copartitioned aswell. This can spread
>>>>>> significantly
>>>>>>>> and
>>>>>>>>>>>>>>>> require many consumers to adapt at the same time.
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> It is also not entirely clear to me how you not need
>>>>>> reshuffling
>>>>>>>> in
>>>>>>>>>>>>>>>> this
>>>>>>>>>>>>>>>> case. If A has a record that never gets updated after
>>> the
>>>>>>>> expansion
>>>>>>>>>>>>>>>> and
>>>>>>>>>>>>>>>> the
>>>>>>>>>>>>>>>> coresponding B record moves to a new partition. How
>>> shall
>>>>> they
>>>>>>>> meet
>>>>>>>>>>>>>>>> w/o
>>>>>>>>>>>>>>>> shuffle?
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> 53. "Migrating consumer is a step that might be made
>>>>> completly
>>>>>>>>>>>>>>>> unnecessary
>>>>>>>>>>>>>>>>> if - for example streams - takes the gcd as
>>> partitioning
>>>>>> scheme
>>>>>>>>>>>>>>>>> instead
>>>>>>>>>>>>>>>>> of
>>>>>>>>>>>>>>>>> enforcing 1 to 1." Not sure that I fully understand
>>>> this. I
>>>>>>> think
>>>>>>>>>>>>>>>>> you
>>>>>>>>>>>>>>>>> mean
>>>>>>>>>>>>>>>>> that a consumer application can run more instances
>> than
>>>> the
>>>>>>>> number
>>>>>>>>>>>>>>>>> of
>>>>>>>>>>>>>>>>> partitions. In that case, the consumer can just
>>>>>> repartitioning
>>>>>>>> the
>>>>>>>>>>>>>>>>> input
>>>>>>>>>>>>>>>>> data according to the number of instances. This is
>>>>> possible,
>>>>>>> but
>>>>>>>>>>>>>>>>> just
>>>>>>>>>>>>>>>>> has
>>>>>>>>>>>>>>>>> the overhead of reshuffling the data.
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> No what I meant is ( that is also your question i
>> think
>>>>>>> Mathias)
>>>>>>>>>>>>>>>>> that
>>>>>>>>>>>>>>>>> if
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> you grow a topic by a factor.
>>>>>>>>>>>>>>>> Even if your processor is statefull you can can just
>>>> assign
>>>>>> all
>>>>>>>> the
>>>>>>>>>>>>>>>> multiples of the previous partition to
>>>>>>>>>>>>>>>> this consumer and the state to keep processing
>> correctly
>>>>> will
>>>>>> be
>>>>>>>>>>>>>>>> present
>>>>>>>>>>>>>>>> w/o any shuffling.
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> Say you have an assignment
>>>>>>>>>>>>>>>> Statefull consumer => partition
>>>>>>>>>>>>>>>> 0 => 0
>>>>>>>>>>>>>>>> 1 => 1
>>>>>>>>>>>>>>>> 2 => 2
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> and you grow you topic by 4 you get,
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> 0 => 0,3,6,9
>>>>>>>>>>>>>>>> 1 => 1,4,7,10
>>>>>>>>>>>>>>>> 2 => 2,5,8,11
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> Say your hashcode is 8. 8%3 => 2  before so consumer
>> for
>>>>>>>> partition 2
>>>>>>>>>>>>>>>> has
>>>>>>>>>>>>>>>> it.
>>>>>>>>>>>>>>>> Now you you have 12 partitions so 8%12 => 8, so it
>> goes
>>>> into
>>>>>>>>>>>>>>>> partition
>>>>>>>>>>>>>>>> 8
>>>>>>>>>>>>>>>> which is assigned to the same consumer
>>>>>>>>>>>>>>>> who had 2 before and therefore knows the key.
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> Userland reshuffeling is there as an options. And it
>>> does
>>>>>>> exactly
>>>>>>>>>>>>>>>> what
>>>>>>>>>>>>>>>> I
>>>>>>>>>>>>>>>> suggest. And I think its the perfect strategie. All I
>> am
>>>>>>>> suggestion
>>>>>>>>>>>>>>>> is
>>>>>>>>>>>>>>>> broker side support to switch the producers to the
>> newly
>>>>>>>> partitioned
>>>>>>>>>>>>>>>> topic.
>>>>>>>>>>>>>>>> Then the old (to few partition topic) can go away.
>>>> Remember
>>>>>> the
>>>>>>>>>>>>>>>> list
>>>>>>>>>>>>>>>> of
>>>>>>>>>>>>>>>> steps in the beginning of this thread. If one has
>> broker
>>>>>> support
>>>>>>>> for
>>>>>>>>>>>>>>>> all
>>>>>>>>>>>>>>>> where its required and streams support for those that
>>>> aren’t
>>>>>>>>>>>>>>>> necessarily.
>>>>>>>>>>>>>>>> Then one has solved the problem.
>>>>>>>>>>>>>>>> I repeat it because I think its important. I am really
>>>> happy
>>>>>>> that
>>>>>>>>>>>>>>>> you
>>>>>>>>>>>>>>>> brought that up! because its 100% what I want just
>> with
>>>> the
>>>>>>>>>>>>>>>> differences
>>>>>>>>>>>>>>>> to
>>>>>>>>>>>>>>>> have an option to discard the to small topic later
>>> (after
>>>>> all
>>>>>>>>>>>>>>>> consumers
>>>>>>>>>>>>>>>> adapted). And to have order correct there. I need
>> broker
>>>>>> support
>>>>>>>>>>>>>>>> managing
>>>>>>>>>>>>>>>> the copy process + the produces and fence them against
>>>> each
>>>>>>>> other. I
>>>>>>>>>>>>>>>> also
>>>>>>>>>>>>>>>> repeat. the copy process can run for weeks in the
>> worst
>>>>> case.
>>>>>>>>>>>>>>>> Copying
>>>>>>>>>>>>>>>> the
>>>>>>>>>>>>>>>> data is not the longest task migrating consumers might
>>>> very
>>>>>> well
>>>>>>>> be.
>>>>>>>>>>>>>>>> Once all consumers switched and copying is really up
>> to
>>>> date
>>>>>>>> (think
>>>>>>>>>>>>>>>> ISR
>>>>>>>>>>>>>>>> like up to date) only then we stop the producer, wait
>>> for
>>>>> the
>>>>>>> copy
>>>>>>>>>>>>>>>> to
>>>>>>>>>>>>>>>> finish and use the new topic for producing.
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> After this the topic is perfect in shape. and no one
>>> needs
>>>>> to
>>>>>>>> worry
>>>>>>>>>>>>>>>> about
>>>>>>>>>>>>>>>> complicated stuff. (old keys hanging around might
>> arrive
>>>> in
>>>>>> some
>>>>>>>>>>>>>>>> other
>>>>>>>>>>>>>>>> topic later.....). can only imagine how many tricky
>> bugs
>>>>> gonna
>>>>>>>>>>>>>>>> arrive
>>>>>>>>>>>>>>>> after
>>>>>>>>>>>>>>>> someone had grown and shrunken is topic 10 times.
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> 54. "The other thing I wanted to mention is that I
>>> believe
>>>>> the
>>>>>>>>>>>>>>>> current
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> suggestion (without copying data over) can be
>>> implemented
>>>> in
>>>>>>> pure
>>>>>>>>>>>>>>>>> userland
>>>>>>>>>>>>>>>>> with a custom partitioner and a small feedbackloop
>> from
>>>>>>>>>>>>>>>>> ProduceResponse
>>>>>>>>>>>>>>>>> =>
>>>>>>>>>>>>>>>>> Partitionier in coorporation with a change management
>>>>>> system."
>>>>>>> I
>>>>>>>> am
>>>>>>>>>>>>>>>>> not
>>>>>>>>>>>>>>>>> sure a customized partitioner itself solves the
>>> problem.
>>>> We
>>>>>>>>>>>>>>>>> probably
>>>>>>>>>>>>>>>>> need
>>>>>>>>>>>>>>>>> some broker side support to enforce when the new
>>>> partitions
>>>>>> can
>>>>>>>> be
>>>>>>>>>>>>>>>>> used.
>>>>>>>>>>>>>>>>> We
>>>>>>>>>>>>>>>>> also need some support on the consumer/kstream side
>> to
>>>>>> preserve
>>>>>>>> the
>>>>>>>>>>>>>>>>> per
>>>>>>>>>>>>>>>>> key
>>>>>>>>>>>>>>>>> ordering and potentially migrate the processing
>> state.
>>>> This
>>>>>> is
>>>>>>>> not
>>>>>>>>>>>>>>>>> trivial
>>>>>>>>>>>>>>>>> and I am not sure if it's ideal to fully push to the
>>>>>>> application
>>>>>>>>>>>>>>>>> space.
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> Broker support is defenitly the preferred way here. I
>>>> have
>>>>>>>> nothing
>>>>>>>>>>>>>>>>> against
>>>>>>>>>>>>>>>> broker support.
>>>>>>>>>>>>>>>> I tried to say that for what I would preffer - copying
>>> the
>>>>>> data
>>>>>>>>>>>>>>>> over,
>>>>>>>>>>>>>>>> at
>>>>>>>>>>>>>>>> least for log compacted topics -
>>>>>>>>>>>>>>>> I would require more broker support than the KIP
>>> currently
>>>>>>> offers.
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> Jun
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> On Tue, Mar 6, 2018 at 10:33 PM, Jan Filipiak <
>>>>>>>>>>>>>>>>> Jan.Filipiak@trivago.com
>>>>>>>>>>>>>>>>> wrote:
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> Hi Dong,
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> are you actually reading my emails, or are you just
>>> using
>>>>> the
>>>>>>>>>>>>>>>>> thread I
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> started for general announcements regarding the KIP?
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> I tried to argue really hard against linear hashing.
>>>>> Growing
>>>>>>> the
>>>>>>>>>>>>>>>>>> topic
>>>>>>>>>>>>>>>>>> by
>>>>>>>>>>>>>>>>>> an integer factor does not require any state
>>>>> redistribution
>>>>>> at
>>>>>>>>>>>>>>>>>> all. I
>>>>>>>>>>>>>>>>>> fail
>>>>>>>>>>>>>>>>>> to see completely where linear hashing helps on log
>>>>>> compacted
>>>>>>>>>>>>>>>>>> topics.
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> If you are not willing to explain to me what I might
>>> be
>>>>>>>>>>>>>>>>>> overlooking:
>>>>>>>>>>>>>>>>>> that
>>>>>>>>>>>>>>>>>> is fine.
>>>>>>>>>>>>>>>>>> But I ask you to not reply to my emails then. Please
>>>>>>> understand
>>>>>>>> my
>>>>>>>>>>>>>>>>>> frustration with this.
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> Best Jan
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> On 06.03.2018 19:38, Dong Lin wrote:
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> Hi everyone,
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> Thanks for all the comments! It appears that
>> everyone
>>>>>> prefers
>>>>>>>>>>>>>>>>>> linear
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>> hashing because it reduces the amount of state that
>>>> needs
>>>>>> to
>>>>>>> be
>>>>>>>>>>>>>>>>>>> moved
>>>>>>>>>>>>>>>>>>> between consumers (for stream processing). The KIP
>>> has
>>>>> been
>>>>>>>>>>>>>>>>>>> updated
>>>>>>>>>>>>>>>>>>> to
>>>>>>>>>>>>>>>>>>> use
>>>>>>>>>>>>>>>>>>> linear hashing.
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>> Regarding the migration endeavor: it seems that
>>>> migrating
>>>>>>>>>>>>>>>>>>> producer
>>>>>>>>>>>>>>>>>>> library
>>>>>>>>>>>>>>>>>>> to use linear hashing should be pretty
>>> straightforward
>>>>>>> without
>>>>>>>>>>>>>>>>>>> much operational endeavor. If we don't upgrade
>> client
>>>>>> library
>>>>>>>> to
>>>>>>>>>>>>>>>>>>> use
>>>>>>>>>>>>>>>>>>> this
>>>>>>>>>>>>>>>>>>> KIP, we can not support in-order delivery after
>>>> partition
>>>>>> is
>>>>>>>>>>>>>>>>>>> changed
>>>>>>>>>>>>>>>>>>> anyway. Suppose we upgrade client library to use
>> this
>>>>> KIP,
>>>>>> if
>>>>>>>>>>>>>>>>>>> partition
>>>>>>>>>>>>>>>>>>> number is not changed, the key -> partition mapping
>>>> will
>>>>> be
>>>>>>>>>>>>>>>>>>> exactly
>>>>>>>>>>>>>>>>>>> the
>>>>>>>>>>>>>>>>>>> same as it is now because it is still determined
>>> using
>>>>>>>>>>>>>>>>>>> murmur_hash(key)
>>>>>>>>>>>>>>>>>>> %
>>>>>>>>>>>>>>>>>>> original_partition_num. In other words, this change
>>> is
>>>>>>> backward
>>>>>>>>>>>>>>>>>>> compatible.
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>> Regarding the load distribution: if we use linear
>>>>> hashing,
>>>>>>> the
>>>>>>>>>>>>>>>>>>> load
>>>>>>>>>>>>>>>>>>> may
>>>>>>>>>>>>>>>>>>> be
>>>>>>>>>>>>>>>>>>> unevenly distributed because those partitions which
>>> are
>>>>> not
>>>>>>>> split
>>>>>>>>>>>>>>>>>>> may
>>>>>>>>>>>>>>>>>>> receive twice as much traffic as other partitions
>>> that
>>>>> are
>>>>>>>> split.
>>>>>>>>>>>>>>>>>>> This
>>>>>>>>>>>>>>>>>>> issue can be mitigated by creating topic with
>>>> partitions
>>>>>> that
>>>>>>>> are
>>>>>>>>>>>>>>>>>>> several
>>>>>>>>>>>>>>>>>>> times the number of consumers. And there will be no
>>>>>> imbalance
>>>>>>>> if
>>>>>>>>>>>>>>>>>>> the
>>>>>>>>>>>>>>>>>>> partition number is always doubled. So this
>> imbalance
>>>>> seems
>>>>>>>>>>>>>>>>>>> acceptable.
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>> Regarding storing the partition strategy as
>> per-topic
>>>>>> config:
>>>>>>>> It
>>>>>>>>>>>>>>>>>>> seems
>>>>>>>>>>>>>>>>>>> not
>>>>>>>>>>>>>>>>>>> necessary since we can still use murmur_hash as the
>>>>> default
>>>>>>>> hash
>>>>>>>>>>>>>>>>>>> function
>>>>>>>>>>>>>>>>>>> and additionally apply the linear hashing algorithm
>>> if
>>>>> the
>>>>>>>>>>>>>>>>>>> partition
>>>>>>>>>>>>>>>>>>> number
>>>>>>>>>>>>>>>>>>> has increased. Not sure if there is any use-case
>> for
>>>>>> producer
>>>>>>>> to
>>>>>>>>>>>>>>>>>>> use a
>>>>>>>>>>>>>>>>>>> different hash function. Jason, can you check if
>>> there
>>>> is
>>>>>>> some
>>>>>>>>>>>>>>>>>>> use-case
>>>>>>>>>>>>>>>>>>> that I missed for using the per-topic partition
>>>> strategy?
>>>>>>>>>>>>>>>>>>> Regarding how to reduce latency (due to state
>>>> store/load)
>>>>>> in
>>>>>>>>>>>>>>>>>>> stream
>>>>>>>>>>>>>>>>>>> processing consumer when partition number changes:
>> I
>>>> need
>>>>>> to
>>>>>>>> read
>>>>>>>>>>>>>>>>>>> the
>>>>>>>>>>>>>>>>>>> Kafka
>>>>>>>>>>>>>>>>>>> Stream code to understand how Kafka Stream
>> currently
>>>>>> migrate
>>>>>>>>>>>>>>>>>>> state
>>>>>>>>>>>>>>>>>>> between
>>>>>>>>>>>>>>>>>>> consumers when the application is added/removed
>> for a
>>>>> given
>>>>>>>> job.
>>>>>>>>>>>>>>>>>>> I
>>>>>>>>>>>>>>>>>>> will
>>>>>>>>>>>>>>>>>>> reply after I finish reading the documentation and
>>>> code.
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>> Thanks,
>>>>>>>>>>>>>>>>>>> Dong
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>> On Mon, Mar 5, 2018 at 10:43 AM, Jason Gustafson <
>>>>>>>>>>>>>>>>>>> jason@confluent.io>
>>>>>>>>>>>>>>>>>>> wrote:
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>> Great discussion. I think I'm wondering whether we
>>> can
>>>>>>> continue
>>>>>>>>>>>>>>>>>>> to
>>>>>>>>>>>>>>>>>>> leave
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>> Kafka agnostic to the partitioning strategy. The
>>>>> challenge
>>>>>> is
>>>>>>>>>>>>>>>>>>> communicating
>>>>>>>>>>>>>>>>>>>> the partitioning logic from producers to consumers
>>> so
>>>>> that
>>>>>>> the
>>>>>>>>>>>>>>>>>>>> dependencies
>>>>>>>>>>>>>>>>>>>> between each epoch can be determined. For the sake
>>> of
>>>>>>>>>>>>>>>>>>>> discussion,
>>>>>>>>>>>>>>>>>>>> imagine
>>>>>>>>>>>>>>>>>>>> you did something like the following:
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>> 1. The name (and perhaps version) of a
>> partitioning
>>>>>> strategy
>>>>>>>> is
>>>>>>>>>>>>>>>>>>>> stored
>>>>>>>>>>>>>>>>>>>> in
>>>>>>>>>>>>>>>>>>>> topic configuration when a topic is created.
>>>>>>>>>>>>>>>>>>>> 2. The producer looks up the partitioning strategy
>>>>> before
>>>>>>>>>>>>>>>>>>>> writing
>>>>>>>>>>>>>>>>>>>> to
>>>>>>>>>>>>>>>>>>>> a
>>>>>>>>>>>>>>>>>>>> topic and includes it in the produce request (for
>>>>>> fencing).
>>>>>>> If
>>>>>>>>>>>>>>>>>>>> it
>>>>>>>>>>>>>>>>>>>> doesn't
>>>>>>>>>>>>>>>>>>>> have an implementation for the configured
>> strategy,
>>> it
>>>>>>> fails.
>>>>>>>>>>>>>>>>>>>> 3. The consumer also looks up the partitioning
>>>> strategy
>>>>>> and
>>>>>>>>>>>>>>>>>>>> uses it
>>>>>>>>>>>>>>>>>>>> to
>>>>>>>>>>>>>>>>>>>> determine dependencies when reading a new epoch.
>> It
>>>>> could
>>>>>>>> either
>>>>>>>>>>>>>>>>>>>> fail
>>>>>>>>>>>>>>>>>>>> or
>>>>>>>>>>>>>>>>>>>> make the most conservative dependency assumptions
>> if
>>>> it
>>>>>>>> doesn't
>>>>>>>>>>>>>>>>>>>> know
>>>>>>>>>>>>>>>>>>>> how
>>>>>>>>>>>>>>>>>>>> to
>>>>>>>>>>>>>>>>>>>> implement the partitioning strategy. For the
>>> consumer,
>>>>> the
>>>>>>> new
>>>>>>>>>>>>>>>>>>>> interface
>>>>>>>>>>>>>>>>>>>> might look something like this:
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>> // Return the partition dependencies following an
>>>> epoch
>>>>>> bump
>>>>>>>>>>>>>>>>>>>> Map<Integer, List<Integer>> dependencies(int
>>>>>>>>>>>>>>>>>>>> numPartitionsBeforeEpochBump,
>>>>>>>>>>>>>>>>>>>> int numPartitionsAfterEpochBump)
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>> The unordered case then is just a particular
>>>>>> implementation
>>>>>>>>>>>>>>>>>>>> which
>>>>>>>>>>>>>>>>>>>> never
>>>>>>>>>>>>>>>>>>>> has
>>>>>>>>>>>>>>>>>>>> any epoch dependencies. To implement this, we
>> would
>>>> need
>>>>>>> some
>>>>>>>>>>>>>>>>>>>> way
>>>>>>>>>>>>>>>>>>>> for
>>>>>>>>>>>>>>>>>>>> the
>>>>>>>>>>>>>>>>>>>> consumer to find out how many partitions there
>> were
>>> in
>>>>>> each
>>>>>>>>>>>>>>>>>>>> epoch,
>>>>>>>>>>>>>>>>>>>> but
>>>>>>>>>>>>>>>>>>>> maybe that's not too unreasonable.
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>> Thanks,
>>>>>>>>>>>>>>>>>>>> Jason
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>> On Mon, Mar 5, 2018 at 4:51 AM, Jan Filipiak <
>>>>>>>>>>>>>>>>>>>> Jan.Filipiak@trivago.com
>>>>>>>>>>>>>>>>>>>> wrote:
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>> Hi Dong
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>> thank you very much for your questions.
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>> regarding the time spend copying data across:
>>>>>>>>>>>>>>>>>>>>> It is correct that copying data from a topic with
>>> one
>>>>>>>> partition
>>>>>>>>>>>>>>>>>>>>> mapping
>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>> to
>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>> a topic with a different partition mapping takes
>>> way
>>>>>> longer
>>>>>>>>>>>>>>>>>>>>> than
>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>> we
>>>>>>>>>>>>>>>>>>>> can
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>> stop producers. Tens of minutes is a very
>> optimistic
>>>>>>> estimate
>>>>>>>>>>>>>>>>>>>> here.
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>> Many
>>>>>>>>>>>>>>>>>>>>> people can not afford copy full steam and
>> therefore
>>>>> will
>>>>>>> have
>>>>>>>>>>>>>>>>>>>>> some
>>>>>>>>>>>>>>>>>>>>> rate
>>>>>>>>>>>>>>>>>>>>> limiting in place, this can bump the timespan
>> into
>>>> the
>>>>>>> day's.
>>>>>>>>>>>>>>>>>>>>> The
>>>>>>>>>>>>>>>>>>>>> good
>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>> part
>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>> is that the vast majority of the data can be
>> copied
>>>>> while
>>>>>>> the
>>>>>>>>>>>>>>>>>>>> producers
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>> are
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>> still going. One can then, piggyback the
>> consumers
>>>>> ontop
>>>>>> of
>>>>>>>>>>>>>>>>>>>>> this
>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>> timeframe,
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>> by the method mentioned (provide them an mapping
>>> from
>>>>>> their
>>>>>>>> old
>>>>>>>>>>>>>>>>>>>> offsets
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>> to
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>> new offsets in their repartitioned topics. In
>> that
>>>> way
>>>>> we
>>>>>>>>>>>>>>>>>>>>> separate
>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>> migration of consumers from migration of producers
>>>>>>> (decoupling
>>>>>>>>>>>>>>>>>>>>> these
>>>>>>>>>>>>>>>>>>>>> is
>>>>>>>>>>>>>>>>>>>>> what kafka is strongest at). The time to actually
>>>> swap
>>>>>> over
>>>>>>>> the
>>>>>>>>>>>>>>>>>>>>> producers
>>>>>>>>>>>>>>>>>>>>> should be kept minimal by ensuring that when a
>> swap
>>>>>> attempt
>>>>>>>> is
>>>>>>>>>>>>>>>>>>>>> started
>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>> the
>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>> consumer copying over should be very close to the
>>> log
>>>>> end
>>>>>>> and
>>>>>>>>>>>>>>>>>>>>> is
>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>> expected
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>> to finish within the next fetch. The operation
>>> should
>>>>>> have
>>>>>>> a
>>>>>>>>>>>>>>>>>>>>> time-out
>>>>>>>>>>>>>>>>>>>>> and
>>>>>>>>>>>>>>>>>>>>> should be "reattemtable".
>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>> Importance of logcompaction:
>>>>>>>>>>>>>>>>>>>>> If a producer produces key A, to partiton 0, its
>>>>> forever
>>>>>>>> gonna
>>>>>>>>>>>>>>>>>>>>> be
>>>>>>>>>>>>>>>>>>>>> there,
>>>>>>>>>>>>>>>>>>>>> unless it gets deleted. The record might sit in
>>> there
>>>>> for
>>>>>>>>>>>>>>>>>>>>> years. A
>>>>>>>>>>>>>>>>>>>>> new
>>>>>>>>>>>>>>>>>>>>> producer started with the new partitions will
>> fail
>>> to
>>>>>>> delete
>>>>>>>>>>>>>>>>>>>>> the
>>>>>>>>>>>>>>>>>>>>> record
>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>> in
>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>> the correct partition. Th record will be there
>>>> forever
>>>>>> and
>>>>>>>> one
>>>>>>>>>>>>>>>>>>>>> can
>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>> not
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>> reliable bootstrap new consumers. I cannot see how
>>>>> linear
>>>>>>>>>>>>>>>>>>>> hashing
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>> can
>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>> solve
>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>> this.
>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>> Regarding your skipping of userland copying:
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>> 100%, copying the data across in userland is, as
>>> far
>>>>> as i
>>>>>>> can
>>>>>>>>>>>>>>>>>>>>> see,
>>>>>>>>>>>>>>>>>>>>> only
>>>>>>>>>>>>>>>>>>>>> a
>>>>>>>>>>>>>>>>>>>>> usecase for log compacted topics. Even for
>>>>> logcompaction
>>>>>> +
>>>>>>>>>>>>>>>>>>>>> retentions
>>>>>>>>>>>>>>>>>>>>> it
>>>>>>>>>>>>>>>>>>>>> should only be opt-in. Why did I bring it up? I
>>> think
>>>>> log
>>>>>>>>>>>>>>>>>>>>> compaction
>>>>>>>>>>>>>>>>>>>>> is
>>>>>>>>>>>>>>>>>>>>> a
>>>>>>>>>>>>>>>>>>>>> very important feature to really embrace kafka
>> as a
>>>>> "data
>>>>>>>>>>>>>>>>>>>>> plattform".
>>>>>>>>>>>>>>>>>>>>> The
>>>>>>>>>>>>>>>>>>>>> point I also want to make is that copying data
>> this
>>>> way
>>>>>> is
>>>>>>>>>>>>>>>>>>>>> completely
>>>>>>>>>>>>>>>>>>>>> inline with the kafka architecture. it only
>>> consists
>>>> of
>>>>>>>> reading
>>>>>>>>>>>>>>>>>>>>> and
>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>> writing
>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>> to topics.
>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>> I hope it clarifies more why I think we should aim
>>> for
>>>>>> more
>>>>>>>> than
>>>>>>>>>>>>>>>>>>>>> the
>>>>>>>>>>>>>>>>>>>>> current KIP. I fear that once the KIP is done not
>>>> much
>>>>>> more
>>>>>>>>>>>>>>>>>>>>> effort
>>>>>>>>>>>>>>>>>>>>> will
>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>> be
>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>> taken.
>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>> On 04.03.2018 02:28, Dong Lin wrote:
>>>>>>>>>>>>>>>>>>>>> Hey Jan,
>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>> In the current proposal, the consumer will be
>>> blocked
>>>>> on
>>>>>>>>>>>>>>>>>>>>> waiting
>>>>>>>>>>>>>>>>>>>>> for
>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>> other
>>>>>>>>>>>>>>>>>>>>>> consumers of the group to consume up to a given
>>>>> offset.
>>>>>> In
>>>>>>>>>>>>>>>>>>>>>> most
>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>> cases,
>>>>>>>>>>>>>>>>>>>>> all
>>>>>>>>>>>>>>>>>>>>> consumers should be close to the LEO of the
>>>> partitions
>>>>>> when
>>>>>>>> the
>>>>>>>>>>>>>>>>>>>>> partition
>>>>>>>>>>>>>>>>>>>>> expansion happens. Thus the time waiting should
>> not
>>>> be
>>>>>> long
>>>>>>>>>>>>>>>>>>>>> e.g.
>>>>>>>>>>>>>>>>>>>>> on
>>>>>>>>>>>>>>>>>>>>> the
>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>> order of seconds. On the other hand, it may take
>> a
>>>> long
>>>>>>> time
>>>>>>>> to
>>>>>>>>>>>>>>>>>>>>> wait
>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>> for
>>>>>>>>>>>>>>>>>>>>>> the entire partition to be copied -- the amount
>> of
>>>>> time
>>>>>> is
>>>>>>>>>>>>>>>>>>>>>> proportional
>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>> to
>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>> the amount of existing data in the partition,
>>> which
>>>>> can
>>>>>>> take
>>>>>>>>>>>>>>>>>>>>> tens of
>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>> minutes. So the amount of time that we stop
>>> consumers
>>>>> may
>>>>>>> not
>>>>>>>>>>>>>>>>>>>>> be
>>>>>>>>>>>>>>>>>>>>> on
>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>> the
>>>>>>>>>>>>>>>>>>>>>> same order of magnitude.
>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>> If we can implement this suggestion without
>>> copying
>>>>> data
>>>>>>>> over
>>>>>>>>>>>>>>>>>>>>>> in
>>>>>>>>>>>>>>>>>>>>>> purse
>>>>>>>>>>>>>>>>>>>>>> userland, it will be much more valuable. Do you
>>> have
>>>>>> ideas
>>>>>>>> on
>>>>>>>>>>>>>>>>>>>>>> how
>>>>>>>>>>>>>>>>>>>>>> this
>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>> can
>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>> be done?
>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>> Not sure why the current KIP not help people who
>>>> depend
>>>>>> on
>>>>>>>> log
>>>>>>>>>>>>>>>>>>>>> compaction.
>>>>>>>>>>>>>>>>>>>>>> Could you elaborate more on this point?
>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>> Thanks,
>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>> Dong
>>>>>>>>>>>>>>>>>>>>>> On Wed, Feb 28, 2018 at 10:55 PM, Jan
>>>>>>>>>>>>>>>>>>>>>> Filipiak<Jan.Filipiak@trivago.
>>>>>>>>>>>>>>>>>>>>>> com
>>>>>>>>>>>>>>>>>>>>>> wrote:
>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>> Hi Dong,
>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>> I tried to focus on what the steps are one can
>>>>> currently
>>>>>>>>>>>>>>>>>>>>>> perform
>>>>>>>>>>>>>>>>>>>>>> to
>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>> expand
>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>> or shrink a keyed topic while maintaining a top
>>>> notch
>>>>>>>>>>>>>>>>>>>>>>> semantics.
>>>>>>>>>>>>>>>>>>>>>>> I can understand that there might be confusion
>>>> about
>>>>>>>>>>>>>>>>>>>>>>> "stopping
>>>>>>>>>>>>>>>>>>>>>>> the
>>>>>>>>>>>>>>>>>>>>>>> consumer". It is exactly the same as proposed
>> in
>>>> the
>>>>>> KIP.
>>>>>>>>>>>>>>>>>>>>>>> there
>>>>>>>>>>>>>>>>>>>>>>> needs
>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>> to
>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>> be
>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>> a time the producers agree on the new
>>> partitioning.
>>>>> The
>>>>>>>> extra
>>>>>>>>>>>>>>>>>>>>> semantics I
>>>>>>>>>>>>>>>>>>>>>>> want to put in there is that we have a
>>> possibility
>>>> to
>>>>>>> wait
>>>>>>>>>>>>>>>>>>>>>>> until
>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>> all
>>>>>>>>>>>>>>>>>>>>> the
>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>> existing data
>>>>>>>>>>>>>>>>>>>>>> is copied over into the new partitioning scheme.
>>>> When
>>>>> I
>>>>>>> say
>>>>>>>>>>>>>>>>>>>>> stopping
>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>> I
>>>>>>>>>>>>>>>>>>>>>>> think more of having a memory barrier that
>>> ensures
>>>>> the
>>>>>>>>>>>>>>>>>>>>>>> ordering. I
>>>>>>>>>>>>>>>>>>>>>>> am
>>>>>>>>>>>>>>>>>>>>>>> still
>>>>>>>>>>>>>>>>>>>>>>> aming for latencies  on the scale of leader
>>>>> failovers.
>>>>>>>>>>>>>>>>>>>>>>> Consumers have to explicitly adapt the new
>>>>> partitioning
>>>>>>>>>>>>>>>>>>>>>>> scheme
>>>>>>>>>>>>>>>>>>>>>>> in
>>>>>>>>>>>>>>>>>>>>>>> the
>>>>>>>>>>>>>>>>>>>>>>> above scenario. The reason is that in these
>> cases
>>>>> where
>>>>>>> you
>>>>>>>>>>>>>>>>>>>>>>> are
>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>> dependent
>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>> on a particular partitioning scheme, you also
>>> have
>>>>>> other
>>>>>>>>>>>>>>>>>>>>>>> topics
>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>> that
>>>>>>>>>>>>>>>>>>>>> have
>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>> co-partition enforcements or the kind
>> -frequently.
>>>>>>> Therefore
>>>>>>>>>>>>>>>>>>>>>> all
>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>> your
>>>>>>>>>>>>>>>>>>>>> other
>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>> input topics might need to grow accordingly.
>>>>>>>>>>>>>>>>>>>>>>> What I was suggesting was to streamline all
>> these
>>>>>>>> operations
>>>>>>>>>>>>>>>>>>>>>>> as
>>>>>>>>>>>>>>>>>>>>>>> best
>>>>>>>>>>>>>>>>>>>>>>> as
>>>>>>>>>>>>>>>>>>>>>>> possible to have "real" partition grow and
>>>> shrinkage
>>>>>>> going
>>>>>>>>>>>>>>>>>>>>>>> on.
>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>> Migrating
>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>> the producers to a new partitioning scheme can
>> be
>>>>> much
>>>>>>> more
>>>>>>>>>>>>>>>>>>>>>> streamlined
>>>>>>>>>>>>>>>>>>>>> with proper broker support for this. Migrating
>>>> consumer
>>>>>> is
>>>>>>> a
>>>>>>>>>>>>>>>>>>>>> step
>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>> that
>>>>>>>>>>>>>>>>>>>>>>> might be made completly unnecessary if - for
>>>> example
>>>>>>>> streams
>>>>>>>>>>>>>>>>>>>>>>> -
>>>>>>>>>>>>>>>>>>>>>>> takes
>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>> the
>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>> gcd as partitioning scheme instead of
>> enforcing 1
>>>> to
>>>>> 1.
>>>>>>>>>>>>>>>>>>>>>>> Connect
>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>> consumers
>>>>>>>>>>>>>>>>>>>>> and other consumers should be fine anyways.
>>>>>>>>>>>>>>>>>>>>>> I hope this makes more clear where I was aiming
>>> at.
>>>>> The
>>>>>>> rest
>>>>>>>>>>>>>>>>>>>>> needs
>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>> to
>>>>>>>>>>>>>>>>>>>>>> be
>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>> figured out. The only danger i see is that when
>>> we
>>>>> are
>>>>>>>>>>>>>>>>>>>>>> introducing
>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>> this
>>>>>>>>>>>>>>>>>>>>> feature as supposed in the KIP, it wont help any
>>>> people
>>>>>>>>>>>>>>>>>>>>> depending
>>>>>>>>>>>>>>>>>>>>> on
>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>> log
>>>>>>>>>>>>>>>>>>>>>>> compaction.
>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>> The other thing I wanted to mention is that I
>>>> believe
>>>>>> the
>>>>>>>>>>>>>>>>>>>>> current
>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>> suggestion (without copying data over) can be
>>>>> implemented
>>>>>>> in
>>>>>>>>>>>>>>>>>>>>>> pure
>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>> userland
>>>>>>>>>>>>>>>>>>>>>>> with a custom partitioner and a small
>>> feedbackloop
>>>>> from
>>>>>>>>>>>>>>>>>>>>>>> ProduceResponse
>>>>>>>>>>>>>>>>>>>>>>> =>
>>>>>>>>>>>>>>>>>>>>>>> Partitionier in coorporation with a change
>>>> management
>>>>>>>> system.
>>>>>>>>>>>>>>>>>>>>>>> Best Jan
>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>> On 28.02.2018 07:13, Dong Lin wrote:
>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>> Hey Jan,
>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>> I am not sure if it is acceptable for producer
>> to
>>>> be
>>>>>>>> stopped
>>>>>>>>>>>>>>>>>>>>>>> for a
>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>> while,
>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>> particularly for online application which
>>> requires
>>>>> low
>>>>>>>>>>>>>>>>>>>>>>>> latency. I
>>>>>>>>>>>>>>>>>>>>>>>> am
>>>>>>>>>>>>>>>>>>>>>>>> also
>>>>>>>>>>>>>>>>>>>>>>>> not sure how consumers can switch to a new
>>> topic.
>>>>> Does
>>>>>>>> user
>>>>>>>>>>>>>>>>>>>>>>>> application
>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>> needs to explicitly specify a different topic
>>> for
>>>>>>>>>>>>>>>>>>>>>>> producer/consumer
>>>>>>>>>>>>>>>>>>>>>> to
>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>> subscribe to? It will be helpful for discussion
>> if
>>>> you
>>>>>> can
>>>>>>>>>>>>>>>>>>>>> provide
>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>> more
>>>>>>>>>>>>>>>>>>>>>>> detail on the interface change for this
>> solution.
>>>>>>>>>>>>>>>>>>>>>>> Thanks,
>>>>>>>>>>>>>>>>>>>>>> Dong
>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>> On Mon, Feb 26, 2018 at 12:48 AM, Jan
>>>>>>>>>>>>>>>>>>>>>>>> Filipiak<Jan.Filipiak@trivago.
>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>> com
>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>> wrote:
>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>> Hi,
>>>>>>>>>>>>>>>>>>>>>> just want to throw my though in. In general the
>>>>>>>> functionality
>>>>>>>>>>>>>>>>>>>>>> is
>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>> very
>>>>>>>>>>>>>>>>>>>>>>>> usefull, we should though not try to find the
>>>>>>> architecture
>>>>>>>>>>>>>>>>>>>>>>>> to
>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>> hard
>>>>>>>>>>>>>>>>>>>>>>>>> while
>>>>>>>>>>>>>>>>>>>>>>>>> implementing.
>>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>>> The manual steps would be to
>>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>>> create a new topic
>>>>>>>>>>>>>>>>>>>>>>>>> the mirrormake from the new old topic to the
>>> new
>>>>>> topic
>>>>>>>>>>>>>>>>>>>>>>>>> wait for mirror making to catch up.
>>>>>>>>>>>>>>>>>>>>>>>>> then put the consumers onto the new topic
>>>>>>>>>>>>>>>>>>>>>>>>>             (having mirrormaker spit out a
>>> mapping
>>>>>> from
>>>>>>>> old
>>>>>>>>>>>>>>>>>>>>>>>>> offsets to
>>>>>>>>>>>>>>>>>>>>>>>>> new
>>>>>>>>>>>>>>>>>>>>>>>>> offsets:
>>>>>>>>>>>>>>>>>>>>>>>>>                 if topic is increased by
>> factor
>>> X
>>>>>> there
>>>>>>> is
>>>>>>>>>>>>>>>>>>>>>>>>> gonna
>>>>>>>>>>>>>>>>>>>>>>>>> be a
>>>>>>>>>>>>>>>>>>>>>>>>> clean
>>>>>>>>>>>>>>>>>>>>>>>>> mapping from 1 offset in the old topic to X
>>>> offsets
>>>>>> in
>>>>>>>> the
>>>>>>>>>>>>>>>>>>>>>>>>> new
>>>>>>>>>>>>>>>>>>>>>>>>> topic,
>>>>>>>>>>>>>>>>>>>>>>>>>                 if there is no factor then
>> there
>>>> is
>>>>> no
>>>>>>>>>>>>>>>>>>>>>>>>> chance to
>>>>>>>>>>>>>>>>>>>>>>>>> generate a
>>>>>>>>>>>>>>>>>>>>>>>>> mapping that can be reasonable used for
>>>> continuing)
>>>>>>>>>>>>>>>>>>>>>>>>>             make consumers stop at appropriate
>>>>> points
>>>>>>> and
>>>>>>>>>>>>>>>>>>>>>>>>> continue
>>>>>>>>>>>>>>>>>>>>>>>>> consumption
>>>>>>>>>>>>>>>>>>>>>>>>> with offsets from the mapping.
>>>>>>>>>>>>>>>>>>>>>>>>> have the producers stop for a minimal time.
>>>>>>>>>>>>>>>>>>>>>>>>> wait for mirrormaker to finish
>>>>>>>>>>>>>>>>>>>>>>>>> let producer produce with the new metadata.
>>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>>> Instead of implementing the approach suggest
>> in
>>>> the
>>>>>> KIP
>>>>>>>>>>>>>>>>>>>>>>>>> which
>>>>>>>>>>>>>>>>>>>>>>>>> will
>>>>>>>>>>>>>>>>>>>>>>>>> leave
>>>>>>>>>>>>>>>>>>>>>>>>> log compacted topic completely crumbled and
>>>>> unusable.
>>>>>>>>>>>>>>>>>>>>>>>>> I would much rather try to build
>> infrastructure
>>>> to
>>>>>>>> support
>>>>>>>>>>>>>>>>>>>>>>>>> the
>>>>>>>>>>>>>>>>>>>>>>>>> mentioned
>>>>>>>>>>>>>>>>>>>>>>>>> above operations more smoothly.
>>>>>>>>>>>>>>>>>>>>>>>>> Especially having producers stop and use
>>> another
>>>>>> topic
>>>>>>> is
>>>>>>>>>>>>>>>>>>>>>>>>> difficult
>>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>>> and
>>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>>> it would be nice if one can trigger "invalid
>>>>>> metadata"
>>>>>>>>>>>>>>>>>>>>>>>> exceptions
>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>> for
>>>>>>>>>>>>>>>>>>>>>> them
>>>>>>>>>>>>>>>>>>>>> and
>>>>>>>>>>>>>>>>>>>>>>> if one could give topics aliases so that their
>>>>> produces
>>>>>>>> with
>>>>>>>>>>>>>>>>>>>>>>>>> the
>>>>>>>>>>>>>>>>>>>>>>>>> old
>>>>>>>>>>>>>>>>>>>>>>>>> topic
>>>>>>>>>>>>>>>>>>>>>>>>> will arrive in the new topic.
>>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>>> The downsides are obvious I guess ( having
>> the
>>>> same
>>>>>>> data
>>>>>>>>>>>>>>>>>>>>>>>>> twice
>>>>>>>>>>>>>>>>>>>>>>>>> for
>>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>>> the
>>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>>> transition period, but kafka tends to scale
>>> well
>>>>> with
>>>>>>>>>>>>>>>>>>>>>>>> datasize).
>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>> So
>>>>>>>>>>>>>>>>>>>>>>> its a
>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>> nicer fit into the architecture.
>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>> I further want to argument that the
>> functionality
>>>> by
>>>>>> the
>>>>>>>> KIP
>>>>>>>>>>>>>>>>>>>>>>>>> can
>>>>>>>>>>>>>>>>>>>>>>>>> completely be implementing in "userland"
>> with a
>>>>>> custom
>>>>>>>>>>>>>>>>>>>>>>>>> partitioner
>>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>>> that
>>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>>> handles the transition as needed. I would
>>>>> appreciate
>>>>>> if
>>>>>>>>>>>>>>>>>>>>>>>> someone
>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>> could
>>>>>>>>>>>>>>>>>>>>>> point
>>>>>>>>>>>>>>>>>>>>> out what a custom partitioner couldn't handle in
>>> this
>>>>>> case?
>>>>>>>>>>>>>>>>>>>>>>> With the above approach, shrinking a topic
>>> becomes
>>>>> the
>>>>>>> same
>>>>>>>>>>>>>>>>>>>>>>>>> steps.
>>>>>>>>>>>>>>>>>>>>>>>>> Without
>>>>>>>>>>>>>>>>>>>>>>>>> loosing keys in the discontinued partitions.
>>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>>> Would love to hear what everyone thinks.
>>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>>> Best Jan
>>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>>> On 11.02.2018 00:35, Dong Lin wrote:
>>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>>> Hi all,
>>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>>> I have created KIP-253: Support in-order
>>> message
>>>>>>> delivery
>>>>>>>>>>>>>>>>>>>>>>>>> with
>>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>>> partition
>>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>>> expansion. See
>>>>>>>>>>>>>>>>>>>>>>>>>> https://cwiki.apache.org/confl
>>>>>>>>>>>>>>>>>>>>>>>>>> uence/display/KAFKA/KIP-253%
>>>>>>>>>>>>>>>>>>>>>>>>>> 3A+Support+in-order+message+de
>>>>>>>>>>>>>>>>>>>>>>>>>> livery+with+partition+expansio
>>>>>>>>>>>>>>>>>>>>>>>>>> n
>>>>>>>>>>>>>>>>>>>>>>>>>> .
>>>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>>>> This KIP provides a way to allow messages of
>>> the
>>>>>> same
>>>>>>>> key
>>>>>>>>>>>>>>>>>>>>>>>>>> from
>>>>>>>>>>>>>>>>>>>>>>>>>> the
>>>>>>>>>>>>>>>>>>>>>>>>>> same
>>>>>>>>>>>>>>>>>>>>>>>>>> producer to be consumed in the same order
>> they
>>>> are
>>>>>>>>>>>>>>>>>>>>>>>>>> produced
>>>>>>>>>>>>>>>>>>>>>>>>>> even
>>>>>>>>>>>>>>>>>>>>>>>>>> if
>>>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>>>> we
>>>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>>>> expand partition of the topic.
>>>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>>> Thanks,
>>>>>>>>>>>>>>>>>>>>>>> Dong
>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>
>>
>>
>> --
>> -- Guozhang
>>


Re: [DISCUSS] KIP-253: Support in-order message delivery with partition expansion

Posted by Dong Lin <li...@gmail.com>.
Hi all,

Not sure if there is further concern with this KIP. And the vote for
KIP-232 is also blocked on the discussion of this KIP. I am happy to
continue the discussion and move forward the progress of this KIP.

Thanks,
Dong

On Tue, Apr 17, 2018 at 8:58 PM, Jeff Chao <jc...@salesforce.com> wrote:

> Hi Dong, I took a look at KIP-287. Producers writing using the new scheme
> prior to processor catch up and cut-over makes sense. Thanks.
>
> On Sat, Apr 14, 2018 at 7:09 PM, Dong Lin <li...@gmail.com> wrote:
>
> > Hey Jeff,
> >
> > Thanks for the review. The scheme for expanding processors of the
> stateful
> > processing job is described in "Support processor expansion" section in
> > KIP-287 (link
> > <https://cwiki.apache.org/confluence/display/KAFKA/KIP-
> > 287%3A+Support+partition+and+processor+expansion+for+
> > stateful+processing+jobs#KIP-287:Supportpartitionandprocessorex
> > pansionforstatefulprocessingjobs-Supportprocessorexpansion>).
> > In particular, we will expand the partitions of the input topics before
> > expanding processors of the processing job. While the new processor is
> > catching up, the producer would already be producing using the new
> > partitioning scheme. Does this answer your question?
> >
> > Thanks,
> > Dong
> >
> >
> > On Sat, Apr 14, 2018 at 1:44 PM, Jeff Chao <jc...@salesforce.com> wrote:
> >
> > > Hi, I had a question from Monday's meeting. The current mechanism, as
> > Ray's
> > > notes points out, is to create a copy consumer in which a switch over
> > > happens when it catches up. Meanwhile, it looks like a producer would
> > still
> > > be writing using the old partitioning scheme. Wouldn't there be a case
> > > where the copy consumer never catches up given a high enough produce
> > rate?
> > > I'm imagining this to work similarly to Kinesis's resharding mechanism,
> > > though I may be missing something from the current proposal. Anyway,
> with
> > > Kinesis as an example, this would mean a producer would stop writing
> > using
> > > the old scheme and start writing using the new scheme. That way, the
> > > consumer will be able to catch up in which it will start consuming
> using
> > > the new scheme afterwards.
> > >
> > > Thanks,
> > > Jeff Chao
> > >
> > > On Sat, Apr 14, 2018 at 6:44 AM, Dong Lin <li...@gmail.com> wrote:
> > >
> > > > Thanks for the notes by Jun and Ray. I have read through the notes.
> It
> > > > seems that there are a few questions for the alternative solution by
> > Jan
> > > > and maybe Jan will answer these questions later?
> > > >
> > > > I have summarized the solution, which I previously provided in this
> > > thread,
> > > > in KIP-287, to hopefully show that we may have a promising direction
> to
> > > > solve the partition and processor expansion problem for stateful
> > > processing
> > > > jobs. Maybe we can continue the discussion related to stateful
> > processing
> > > > in that discussion thread. If that looks good, maybe we can conclude
> > the
> > > > discussion for KIP-253.
> > > >
> > > > Not sure if I missed some ideas or questions in the notes. Is there
> > > > specific concern for the latest KIP-253?
> > > >
> > > >
> > > > On Mon, Apr 9, 2018 at 11:18 AM, Ray Chiang <rc...@apache.org>
> > wrote:
> > > >
> > > > > My notes from today's meeting.  Sorry if I got anyone's name wrong.
> > > Plus
> > > > I
> > > > > missed a few moments with noise at home and/or dropped video.
> > > > >
> > > > > -Ray
> > > > >
> > > > > =====
> > > > >
> > > > > KIP-253 Discussion
> > > > >
> > > > > - Currently, adding partitions can cause keys to be read
> > out-of-order.
> > > > >   This KIP is trying to preserve the key ordering when adding
> > > partitions.
> > > > >
> > > > > - State management in applications (i.e. Kafka Streams) can
> maintain
> > > > >   local state via caching.  If the number of partitions changes,
> how
> > > > >   would those applications update their local state.  This is the
> > > current
> > > > >   point of discussion/disagreement.
> > > > >
> > > > > - Jan Filipiak is mostly worried about log compacted topics.  Not
> as
> > > > >   concerned about producer swapping.  Worried about the consumer
> > design
> > > > is
> > > > >   a bit contradictory compared to the architecture.
> > > > >
> > > > >   Current design is to start up a new consumer in parallel with old
> > > > >   topic/consumer.  Run until consumer finishes "copying" to the new
> > > > topic.
> > > > >   Once the consumer is caught up, point the producer at the new
> > topic.
> > > > >
> > > > >   Would like to have this technique as a "core primitive" to Kafka.
> > > > >   - Is this a useful primitive?
> > > > >   - What's the best way to support it?
> > > > >
> > > > >   - Topic expansion as it currently exists just "adds partitions".
> > But
> > > > >     how does this affect bootstrapping applications?  How to deal
> > with
> > > > >     "moved" (from "old partition" to "new expanded partition")
> keys?
> > > > >
> > > > >   - Dong's proposal example.  10 partitions growing to 15.  5 of
> the
> > > > >     first 10 partitions are split into 2 each.  Say Kafka remembers
> > > > >     parent->child relationship.  Then for each parent partition,
> > there
> > > > >     are two child partitions.  Initially, there were 10 states to
> > > > >     manage.  Then bootstrapping new application would have 15
> states.
> > > > >     Need to know which "generation" of partition you are consuming
> > > > >     from.  Until you get to "newer" generation of data, then the
> keys
> > > > >     will be find (i.e. reading from old partition).
> > > > >
> > > > >   - Scheme works well for transient events.  Any stateful processor
> > > will
> > > > >     likely break.
> > > > >
> > > > >   - Tracking can become extremely complicated, since each split
> > > requires
> > > > >     potentially more and more offset/partition combos.
> > > > >
> > > > >   - Need to support continuation for consumers to read the new
> > > > partitions.
> > > > >
> > > > >   - With linear hashing, integral multiple increase (2x, 3x, 4x,
> > etc).
> > > > >     Easier mapping from old partition sets to new partition sets.
> > > > >     Keys end up with a clean hierarchy instead of a major
> > reshuffling.
> > > > >
> > > > >   - Dong's approach piggyback on existing leader epoch.  Log
> segment
> > > > >     could be tagged with version in linear hashing case.
> > > > >
> > > > >   - In Jan's case, existing consumers bootstrap from the beginning.
> > > > >
> > > > >   - James' use case.  Using Kafka as a long term persistent data
> > store.
> > > > >     Putting "source of truth" information into Kafka.  Bootstrap
> case
> > > > >     is very important.  New applications could be bootstrapping as
> > they
> > > > >     come up.
> > > > >
> > > > >     - Increasing partitions will help with load from prodcuer and
> > > > >       increasing consumer parallelism.
> > > > >     - How does Kinesis handling partition splits?  They don't have
> > > > >       compacted logs, so no issue with bootstrapping.  Kinesis uses
> > > > >       MD5 and splits results based on md5sum into bucket ranges.
> > > > >     - Is it useful for the server to know the partitioning
> function?
> > > > >       Consumer has some implicit assumptions about keyed
> partitions,
> > > > >       but not strongly enforced on server side.
> > > > >
> > > > >     - KIP-213 (one to many joins in Kafka Streams)
> > > > >
> > > > >       - MySQL case.  Primary key forced to be used as Kafka key.
> > > > >
> > > > >         (Sorry had some audio and video drop at this point)
> > > > >
> > > > >       - Mirror Maker.  Source cluster has custom partitioning
> > function.
> > > > >         Producer won't duplicate to same partitioning setup as
> > source.
> > > > >         Need to provide same partitioning function to producer.
> > > > >         Would need to determine partitioning function based on
> topic.
> > > > >
> > > > >         - Should server validate partitioning?
> > > > >         - Who does actual determination of which key goes to which
> > > > > partition.
> > > > >
> > > > >       - How to implement backfill?
> > > > >
> > > > >         - Who will do it?  In producer?  Hard to do.  Every client
> > > would
> > > > >           need to add this functionality.  Better to do on server
> > side.
> > > > >         - Add a type of "copy consumer"?  Add backoff to producer?
> > > > >           Benefit of doing in consumer vs. producer?
> > > > >
> > > > >   - Still TBD
> > > > >     - How to dedupe control messages?
> > > > >     - How to deal with subtle cases during transition?
> > > > >     - Is it useful for the server to have the option to validate
> the
> > > key
> > > > >       distribution?
> > > > >     - Jan concerned about how a consumer application would look
> with
> > > the
> > > > >       new "split partition" design.
> > > > >     - KIP introduced callback.  Jan doesn't think is useful.
> Callback
> > > > >       for switching "between Partition 1 and can start on Partition
> > > 11".
> > > > >       Rely on marker in Partition 1 instead.  Intent for callback
> is
> > > > >       for possibility that delivery of messages for given key is
> > moved
> > > > >       to a different consumer instance.
> > > > >
> > > > >
> > > > >
> > > > > On 4/6/18 9:44 AM, Dong Lin wrote:
> > > > >
> > > > >> Hey John,
> > > > >>
> > > > >> Thanks much for your super-detailed explanation. This is very
> > helpful.
> > > > >>
> > > > >> Now that I have finished reading through your email, I think the
> > > > proposed
> > > > >> solution in my previous email probably meets the requirement #6
> > > without
> > > > >> requiring additional coordination (w.r.t. partition function)
> among
> > > > >> clients. My understanding of requirement #6 is that, after
> partition
> > > > >> expansion, messages with the given key will go to the same
> consumer
> > > > before
> > > > >> and after the partition expansion such that stream processing jobs
> > > won't
> > > > >> be
> > > > >> affected. Thus this approach seems to be better than backfilling
> > since
> > > > it
> > > > >> does not require data copy for input topics.
> > > > >>
> > > > >> In order for the proposed solution to meet requirements #6, we
> need
> > > two
> > > > >> extra requirements in addition to what has been described in the
> > > > previous
> > > > >> email: 1) stream processing job starts with the same number of
> > > > processors
> > > > >> as the initial number of partitions of the input topics; and 2) at
> > any
> > > > >> given time the number of partitions of the input topic >= the
> number
> > > of
> > > > >> processors of the given stream processing job.
> > > > >>
> > > > >> Could you take a look at the proposed solution and see if any of
> the
> > > > >> claims
> > > > >> above is false?
> > > > >>
> > > > >>
> > > > >> Hey Jan,
> > > > >>
> > > > >> Maybe it is more efficient for us to discuss your concern in the
> KIP
> > > > >> Meeting.
> > > > >>
> > > > >>
> > > > >> Thanks,
> > > > >> Dong
> > > > >>
> > > > >>
> > > > >> On Thu, Mar 29, 2018 at 2:05 PM, John Roesler <jo...@confluent.io>
> > > > wrote:
> > > > >>
> > > > >> Hi Jun,
> > > > >>>
> > > > >>> Thanks for the response. I'm very new to this project, but I will
> > > share
> > > > >>> my
> > > > >>> perspective. I'm going to say a bunch of stuff that I know you
> know
> > > > >>> already, but just so we're on the same page...
> > > > >>>
> > > > >>> This may also be a good time to get feedback from the other
> > KStreams
> > > > >>> folks.
> > > > >>>
> > > > >>> Using KStreams as a reference implementation for how stream
> > > processing
> > > > >>> frameworks may interact with Kafka, I think it's important to
> > eschew
> > > > >>> knowledge about how KStreams currently handles internal
> > > communication,
> > > > >>> making state durable, etc. Both because these details may change,
> > and
> > > > >>> because they won't be shared with other stream processors.
> > > > >>>
> > > > >>> =================================
> > > > >>> Background
> > > > >>>
> > > > >>> We are looking at a picture like this:
> > > > >>>
> > > > >>>       input input input
> > > > >>>           \   |   /
> > > > >>>        +-------------+
> > > > >>> +-----+ Consumer(s) +-------+
> > > > >>> |     +-------------+       |
> > > > >>> |                           |
> > > > >>> |    KStreams Application   |
> > > > >>> |                           |
> > > > >>> |     +-------------+       |
> > > > >>> +-----+ Producer(s) +-------+
> > > > >>>        +-------------+
> > > > >>>             /    \
> > > > >>>          output output
> > > > >>>
> > > > >>> The inputs and outputs are Kafka topics (and therefore have 1 or
> > more
> > > > >>> partitions). We'd have at least 1 input and 0 or more outputs.
> The
> > > > >>> Consumers and Producers are both the official KafkaConsumer and
> > > > >>> KafkaProducer.
> > > > >>>
> > > > >>> In general, we'll assume that the input topics are provided by
> > actors
> > > > >>> over
> > > > >>> which we have no control, although we may as well assume they are
> > > > >>> friendly
> > > > >>> and amenable to requests, and also that their promises are
> > > trustworthy.
> > > > >>> This is important because we must depend on them to uphold some
> > > > promises:
> > > > >>> * That they tell us the schema of the data they publish, and
> abide
> > by
> > > > >>> that
> > > > >>> schema. Without this, the inputs are essentially garbage.
> > > > >>> * That they tell us some defining characteristics of the topics
> > (more
> > > > on
> > > > >>> this in a sec.) and again strictly abide by that promise.
> > > > >>>
> > > > >>> What are the topic characteristics we care about?
> > > > >>> 1. The name (or name pattern)
> > > > >>> 2. How the messages are keyed (if at all)
> > > > >>> 3. Whether the message timestamps are meaningful, and if so, what
> > > their
> > > > >>> meaning is
> > > > >>> 4. Assuming the records have identity, whether the partitions
> > > partition
> > > > >>> the
> > > > >>> records' identity space
> > > > >>> 5. Whether the topic completely contains the data set
> > > > >>> 6. Whether the messages in the topic are ordered
> > > > >>>
> > > > >>> #1 is obvious: without this information, we cannot access the
> data
> > at
> > > > >>> all.
> > > > >>>
> > > > >>> For #2, #3, #4, and #6, we may or may not need this information,
> > > > >>> depending
> > > > >>> on the logic of the application. For example, a trivial
> application
> > > > that
> > > > >>> simply counts all events it sees doesn't care about #2, #3, #4,
> or
> > > #6.
> > > > >>> But
> > > > >>> an application that groups by some attribute can take advantage
> of
> > #2
> > > > and
> > > > >>> #4 if the topic data is already keyed and partitioned over that
> > > > >>> attribute.
> > > > >>> Likewise, if the application includes some temporal semantics on
> a
> > > > >>> temporal
> > > > >>> dimension that is already captured in #3, it may take advantage
> of
> > > that
> > > > >>> fact.
> > > > >>>
> > > > >>> Note that #2, #3, #4, and #6 are all optional. If they are not
> > > > promised,
> > > > >>> we
> > > > >>> can do extra work inside the application to accomplish what we
> > need.
> > > > >>> However, if they are promised (and if we depend on that promise),
> > it
> > > is
> > > > >>> essential that the topic providers uphold those promises, as we
> may
> > > not
> > > > >>> be
> > > > >>> in a position to verify them.
> > > > >>>
> > > > >>> Note also that if they make a promise, but it doesn't happen to
> > line
> > > up
> > > > >>> with our needs (data is keyed by attr1, but we need it by attr2,
> or
> > > > >>> timestamp is produce-time, but we need it by event-time, etc.),
> > then
> > > we
> > > > >>> will have to go ahead and do that extra work internally anyway.
> > This
> > > > also
> > > > >>> captures the situation in which two inputs are produced by
> > different
> > > > >>> providers, one of which meets our needs, and the other does not.
> > The
> > > > fact
> > > > >>> that we can cope with this situation is the basis for my
> statement
> > > that
> > > > >>> we
> > > > >>> do not require coordination among producers.
> > > > >>>
> > > > >>> (Key Point A): In terms of optimization, #4 and #6 are the most
> > > > valuable.
> > > > >>> If these characteristics happen to line up with our needs, then
> > > > KStreams
> > > > >>> can be incredibly efficient in both time and computational
> > resources.
> > > > >>>
> > > > >>>   #5 is similar to knowing the schema in that it tells us whether
> > the
> > > > >>> computation we want to do is possible or not. For example,
> suppose
> > we
> > > > >>> have
> > > > >>> a topic of "users", and we want to construct a table for
> querying.
> > If
> > > > the
> > > > >>> user topic doesn't completely contain the dataset, we cannot
> > > construct
> > > > >>> the
> > > > >>> table. Note that it doesn't matter whether the topic is compacted
> > or
> > > > not.
> > > > >>> If the topic is complete, I can consume it starting at "earliest"
> > and
> > > > >>> build
> > > > >>> my table. If it is not complete, I can do other computations on
> it.
> > > In
> > > > >>> both
> > > > >>> cases, it may or may not be compacted; it just doesn't matter.
> > > > >>>
> > > > >>> On the output side, the roles are reversed. We provide (or not)
> > > exactly
> > > > >>> the
> > > > >>> same set of guarantees to consumers of our outputs, and we
> likewise
> > > > must
> > > > >>> abide by the promises we make.
> > > > >>>
> > > > >>>
> > > > >>> =================================
> > > > >>> Partition Expansion
> > > > >>>
> > > > >>> With this formation in place, let's talk about partition
> expansion.
> > > > >>>
> > > > >>> Why do we have partitions in the first place? (let me know if I
> > miss
> > > > >>> something here)
> > > > >>> * For logical data streams that are themselves partitionable, it
> > > allows
> > > > >>> producers to operate concurrently without coordination. For
> > example,
> > > > >>> streaming data from a sensor in a particle accelerator, the
> sensor
> > > can
> > > > be
> > > > >>> subdivided into a grid and each grid square can produce
> > independently
> > > > to
> > > > >>> a
> > > > >>> different topic. This may be valuable because the total rate of
> > data
> > > > >>> exceeds the throughput to a single broker node or just because it
> > > > allows
> > > > >>> for failure of a single producer to cause the loss of only part
> of
> > > the
> > > > >>> data.
> > > > >>> * The brokers can offer linearly scaling throughput on the number
> > of
> > > > >>> partitions by hosting each partition on a separate broker node
> > > > >>> * The brokers can host topics that are too large to fit on a
> single
> > > > >>> broker's storage by hosting some partitions on separate broker
> > nodes
> > > > >>> * In cases where the use case permits handling partitions
> > > > independently,
> > > > >>> consumers can have algorithmic simplicity by processing the data
> > for
> > > > >>> separate partitions in separate threads, avoiding costly and
> > > > error-prone
> > > > >>> concurrent coordination code
> > > > >>> * In cases where the use case permits handling partitions
> > > > independently,
> > > > >>> consumers can exceed the total throughput of a single
> > broker-consumer
> > > > >>> pair
> > > > >>> * Just to throw this in as well, in cases where some network
> links
> > > are
> > > > >>> less
> > > > >>> costly than others (or lower latency or more reliable), such as
> > when
> > > > >>> brokers, producers, and consumers are running in racks: producer
> > and
> > > > >>> consumers can both benefit (independently) by locating work on
> each
> > > > >>> partition in the same rack as the broker hosting that partition.
> > > > >>>
> > > > >>> In other words, we have three actors in this system: producers,
> > > > brokers,
> > > > >>> and consumers, and they all benefit from partitioning for
> different
> > > > (but
> > > > >>> sometimes related) reasons.
> > > > >>>
> > > > >>> This leads naturally to the conclusion that any of these actors
> may
> > > > find
> > > > >>> themselves in a sub-optimal or even dangerous situation in which
> > > > >>> partition
> > > > >>> expansion would be the solution. For example, the producer may
> find
> > > > that
> > > > >>> the existing throughput to the brokers is insufficient to match
> the
> > > > data
> > > > >>> rate, forcing them to drop data. Or a broker hosting a single
> > > partition
> > > > >>> may
> > > > >>> be running out of disk space. Or a consumer node handling a
> single
> > > > >>> partition cannot match the rate of production for that partition,
> > > > causing
> > > > >>> it to fall behind.
> > > > >>>
> > > > >>> I think it's reasonable to assume that all the actors in the
> system
> > > > can't
> > > > >>> just arbitrarily expand a topic's partition. I think it's
> > reasonable
> > > to
> > > > >>> align this responsibility with the provider of the data, namely
> the
> > > > >>> producer (the logical producer, not the KafkaProducer class).
> > > > Therefore,
> > > > >>> the producer who finds themselves in trouble can unilaterally
> > expand
> > > > >>> partitions to solve their problem.
> > > > >>>
> > > > >>> For the broker or a consumer in trouble, they have only one
> resort:
> > > to
> > > > >>> request the producer to expand partitions. This is where it's
> > helpful
> > > > to
> > > > >>> assume the producer is friendly.
> > > > >>>
> > > > >>>
> > > > >>> Now, let's look at how a KStreams application fits into this
> > > scenario.
> > > > >>>
> > > > >>> (Key Point B1): As a consumer, we may find that the producer
> > expands
> > > > the
> > > > >>> partitions of a topic, either for their own benefit or for the
> > > brokers.
> > > > >>> In
> > > > >>> this situation, the expand operation MUST NOT violate any
> promises
> > > that
> > > > >>> have previously been made to us. This is the essence of KIP-253,
> to
> > > > >>> ensure
> > > > >>> the maintenance of promises #6 and #4. It would be great if the
> > > > mechanics
> > > > >>> of the expansion required no major disruption to processing or
> > human
> > > > >>> intervention.
> > > > >>>
> > > > >>> Specifically, let's say that input partition X splits into X1 and
> > X2.
> > > > #6
> > > > >>> requires that the same old ordering guarantees of Kafka continue
> to
> > > > hold.
> > > > >>> Obviously, this is what KIP-253's title is about. #4 requires
> that
> > we
> > > > >>> either ensure that X1 and X2 are assigned to the same thread that
> > was
> > > > >>> previously assigned X OR that we immediately pause processing and
> > > split
> > > > >>> any
> > > > >>> state such that it appears X1 and X2 were *always* separate
> > > partitions.
> > > > >>>
> > > > >>> In other words, Option 1 is we treat X1 and X2 as still logically
> > one
> > > > >>> partition, equal to X. This is ideal, since in this scenario,
> > > > partitions
> > > > >>> are expanding for external reasons. We don't need to expand our
> > > > >>> processing
> > > > >>> to match. Option 2 requires a major disruption, since we'd have
> to
> > > > pause
> > > > >>> processing while we split our state. Clearly, KStreams or any
> other
> > > > >>> stateful consumer would advocate for Option 1.
> > > > >>>
> > > > >>>
> > > > >>> (Corollary to Key Point A): Still on the consumer side, we may
> find
> > > > that
> > > > >>> we
> > > > >>> ourselves can benefit from partition expansion of an input. Since
> > we
> > > > can
> > > > >>> cope with the absence of promise #4, partition expansion is not a
> > > hard
> > > > >>> requirement for us, but assuming we were already benefiting from
> > the
> > > > >>> major
> > > > >>> performance optimizations afforded by #4, it would be nice to be
> > able
> > > > to
> > > > >>> request the producer satisfy our request for partition expansion
> > > **and
> > > > to
> > > > >>> be able to benefit from it**.
> > > > >>>
> > > > >>> What does it mean to be able to benefit from partition expansion?
> > > > >>> Assuming
> > > > >>> input topic partition X splits into X1 and X2, in this scenario,
> we
> > > > >>> *would*
> > > > >>> wish to be able to split our state such that it appears X1 and X2
> > > were
> > > > >>> *always* separate partitions. Of course, the conclusion of Key
> > Point
> > > B1
> > > > >>> still applies: we should be able to continue operating on (X1+X2
> =
> > X)
> > > > as
> > > > >>> one partition while asynchronously building the state of X1 and
> X2
> > > > >>> separately.
> > > > >>>
> > > > >>> When it comes to the mechanics of building the state of X1 and X2
> > > > >>> separately, we have really just two high-level options. Either
> this
> > > > >>> problem
> > > > >>> is solved by Kafka itself, giving me a view in which X1 and X2
> were
> > > > >>> always
> > > > >>> separate partitions, or I have to do it myself. The latter means
> > > that I
> > > > >>> have to take on substantially more complexity than I do today:
> > > > >>> Bummer 1: My state has to be splittable to begin with, implying
> at
> > > the
> > > > >>> least that I need to be able to scan every record in my state, a
> > > > >>> requirement that otherwise does not exist.
> > > > >>> Bummer 2: After splitting the state  of X1 and X2, I need to be
> > able
> > > to
> > > > >>> send at least one of those tasks, state included, to another
> > > > application
> > > > >>> node (in order to realize the benefit of the split). This is
> also a
> > > > >>> requirement that does not currently exist.
> > > > >>> Bummer 3: In order to actually perform the split, I must know and
> > be
> > > > able
> > > > >>> to execute the exact same partition function the producer of my
> > topic
> > > > >>> uses.
> > > > >>> This introduces a brand-new a priori commitment from my input
> > > > producers:
> > > > >>> (would-be #7: convey the partition function and abide by it).
> This
> > > is a
> > > > >>> big
> > > > >>> restriction over #4, which only requires them to guarantee *that
> > > there
> > > > >>> is a
> > > > >>> partition function*. Now they actually have to share the function
> > > with
> > > > >>> me.
> > > > >>> And I have to be able to implement and execute it myself. And if
> > the
> > > > >>> producer wishes to refine the partition function for an existing
> > > topic,
> > > > >>> we
> > > > >>> have another round of coordination, as they have to be sure that
> I,
> > > and
> > > > >>> all
> > > > >>> other consumers, begin using the new function *before* they do.
> > This
> > > is
> > > > >>> similar to the schema problem, with a similar set of solutions.
> We
> > > > would
> > > > >>> likely need a partition function registry and another magic byte
> on
> > > > every
> > > > >>> record to be sure we do this right. Not to mention some way to
> > > express
> > > > >>> arbitrary partitioning logic over arbitrary data in a way that is
> > > > >>> portable
> > > > >>> across programming languages.
> > > > >>>
> > > > >>> Alternatively, if Kafka gives me a view in which X1 and X2 were
> > > always
> > > > >>> separate, then I can create tasks for X1 and X2 and allow them to
> > > > >>> bootstrap
> > > > >>> while I continue to process X. Once they are ready, I can
> > coordinate
> > > a
> > > > >>> transition to stop X's task and switch to X1 and X2. None of
> those
> > > > >>> bummers
> > > > >>> are present, so this is a significantly better option for me.
> > > > >>>
> > > > >>> (Key Point B2): As a (friendly) producer, we may once again want
> on
> > > our
> > > > >>> own
> > > > >>> to expand partitions, or we may want to satisfy a request from
> the
> > > > broker
> > > > >>> or our consumers to do so. Again, we MUST NOT violate any
> promises
> > we
> > > > >>> have
> > > > >>> previously given, and it would be great if the expansion required
> > no
> > > > >>> major
> > > > >>> disruption to processing or human intervention. Additionally,
> since
> > > we
> > > > >>> are
> > > > >>> actually driving the expansion, it would also be great if we
> could
> > > > avoid
> > > > >>> Bummer 3's coordination problems from the producer's perspective.
> > > > >>>
> > > > >>>
> > > > >>> ======================================
> > > > >>> Briefly: KStreams internals
> > > > >>>
> > > > >>> I'm pretty sure you were asking me to comment on the
> implementation
> > > > >>> details
> > > > >>> of KStreams, so I'll say a few words about it. The most important
> > > thing
> > > > >>> is
> > > > >>> that KStreams is still very early in its development. Maybe
> > > > "early-middle
> > > > >>> maturity" is a good way to put it. We are actively discussing
> > > > >>> more-or-less
> > > > >>> major implementation changes to improve performance, footprint,
> > > > >>> scalability, and ergonomics. So it may actually be misleading to
> > > > discuss
> > > > >>> deeply how KStreams internally uses Kafka topics.
> > > > >>>
> > > > >>> Nevertheless, it is currently true that KStreams uses Kafka
> topics
> > > for
> > > > >>> communication between some internal computation nodes. We
> partition
> > > > these
> > > > >>> topics as the base unit of concurrency granularity, so it would
> > > > >>> potentially
> > > > >>> be beneficial to be able to expand partitions for some of these
> > > > internal
> > > > >>> topics at some point. However, we can alternatively just
> > > overpartition
> > > > >>> these internal topics, creating in the low 100s of partitions
> > instead
> > > > of
> > > > >>> the low 10s, for example. (Side note: if Kafka were someday to
> > > support
> > > > >>> higher numbers of partitions, we could expand this scheme to
> > > > >>> overpartition
> > > > >>> in the 1000s of partitions.) With the option to overpartition, we
> > > don't
> > > > >>> have a strong need for partition expansion internally.
> > > > >>>
> > > > >>> It is also currently true that KStreams uses Kafka to store a
> > durable
> > > > >>> changelog for some of our internal state stores. But we *only*
> read
> > > > from
> > > > >>> this topic *if* we need to restore a state store after node loss
> > (or
> > > to
> > > > >>> maintain a hot mirror of the state store), so I think it's
> unlikely
> > > > that
> > > > >>> we
> > > > >>> would ever make use of partition expansion on the changelog
> topics.
> > > > >>>
> > > > >>> But once again, I'd like to emphasize that we may choose an
> > > alternative
> > > > >>> implementation for either interprocess communication or state
> > > > durability.
> > > > >>>
> > > > >>>
> > > > >>> ======================================
> > > > >>> Concluding thoughts
> > > > >>>
> > > > >>> I know this is a very long email, and I really appreciate you
> > > sticking
> > > > >>> with
> > > > >>> me this long. I hope it was useful for syncing our mental picture
> > of
> > > > this
> > > > >>> system. Also, you're far more knowledgeable than I am about this
> > > system
> > > > >>> and
> > > > >>> this domain, so please correct me if I've said anything wrong.
> > > > >>>
> > > > >>> To me the key takeaways are that:
> > > > >>> - KIP-253 satisfies all we need for correctness, since it
> contains
> > > > >>> solutions to guarantee producers can abide by their promises
> w.r.t.
> > > #4
> > > > >>> and
> > > > >>> #6.
> > > > >>> - From Key Point A: #4 is actually optional for KIP-253, but
> > without
> > > > it,
> > > > >>> we
> > > > >>> lose a potentially valuable optimization in KStreams (and all
> other
> > > > >>> consumer applications)
> > > > >>> - From Corollary to Point A: Without low-level support for
> > partition
> > > > >>> expansion with backfill, we cannot employ requesting partition
> > > > expansion
> > > > >>> as
> > > > >>> a consumer to improve application performance. In that case, to
> > > ensure
> > > > >>> performance scalability, we would have to discard for all
> KStreams
> > > > >>> applications the performance optimization afforded by #4.
> > > > >>> - From Key Point B1: After a partition split, we really need to
> be
> > > able
> > > > >>> to
> > > > >>> seamlessly continue operating as if it had not split.
> > > > >>> - From Key Point B2: Since KIP-253 allows us to maintain all our
> > > > >>> promises,
> > > > >>> we have the option of expanding partitions in the topics we
> > produce.
> > > > >>> Without a backfill operation, though, our consumers may not be
> able
> > > to
> > > > >>> realize the benefits of that split, if they were hoping to.
> > > > >>>
> > > > >>> In general, faced with the possibility of having to coordinate
> the
> > > > >>> partition function with our inputs' producers or with our
> outputs'
> > > > >>> consumers, I would personally lean toward overprovisioning and
> > > > completely
> > > > >>> avoiding resize for our use case. This doesn't mean that it's not
> > > > useful
> > > > >>> in
> > > > >>> the ecosystem at large without backfill, just that it loses its
> > > luster
> > > > >>> for
> > > > >>> me. It also means that we can no longer take advantage of some of
> > our
> > > > >>> current optimizations, and in fact that we must introduce an
> extra
> > > hop
> > > > of
> > > > >>> repartitioning on every single input.
> > > > >>>
> > > > >>> I think this is actually a pretty good picture of the
> opportunities
> > > and
> > > > >>> challenges that other consumers and producers in the Kafka
> > ecosystem
> > > > will
> > > > >>> face.
> > > > >>>
> > > > >>> I hope this helps!
> > > > >>>
> > > > >>> Thanks,
> > > > >>> -John
> > > > >>>
> > > > >>> On Wed, Mar 28, 2018 at 11:51 AM, Jun Rao <ju...@confluent.io>
> > wrote:
> > > > >>>
> > > > >>> Hi, John,
> > > > >>>>
> > > > >>>> I actually think it's important to think through how KStreams
> > > handles
> > > > >>>> partition expansion in this KIP. If we do decide that we truly
> > need
> > > > >>>> backfilling, it's much better to think through how to add it
> now,
> > > > >>>> instead
> > > > >>>> of retrofitting it later. It would be useful to outline how both
> > > > >>>> existing
> > > > >>>> KStreams jobs and new KStreams jobs work to see if backfilling
> is
> > > > really
> > > > >>>> needed.
> > > > >>>>
> > > > >>>> If we can figure out how KStreams works, at least we have one
> > > > reference
> > > > >>>> implementation for other stream processing frameworks that face
> > the
> > > > same
> > > > >>>> issue.
> > > > >>>>
> > > > >>>> Thanks,
> > > > >>>>
> > > > >>>> Jun
> > > > >>>>
> > > > >>>>
> > > > >>>> On Tue, Mar 27, 2018 at 4:56 PM, John Roesler <
> john@confluent.io>
> > > > >>>> wrote:
> > > > >>>>
> > > > >>>> Hi Jun,
> > > > >>>>>
> > > > >>>>> That's a good point.
> > > > >>>>>
> > > > >>>>> Yeah, I don't think it would work too well for existing
> consumers
> > > in
> > > > >>>>>
> > > > >>>> the
> > > > >>>
> > > > >>>> middle of gen 0 to try and switch to a newly backfilled prefix
> of
> > > gen
> > > > >>>>>
> > > > >>>> 1.
> > > > >>>
> > > > >>>> They probably just need to finish up until they get to the end
> of
> > > gen
> > > > 0
> > > > >>>>>
> > > > >>>> and
> > > > >>>>
> > > > >>>>> transition just as if there were no backfill available yet.
> > > > >>>>>
> > > > >>>>> This isn't terrible, since consumer applications that care
> about
> > > > >>>>>
> > > > >>>> scaling
> > > > >>>
> > > > >>>> up
> > > > >>>>
> > > > >>>>> to match a freshly split partition would wait until after the
> > > > backfill
> > > > >>>>>
> > > > >>>> is
> > > > >>>
> > > > >>>> available to scale up. The consumer that starts out in gen=0,
> > part=0
> > > > is
> > > > >>>>> going to be stuck with part=0 and part=3 in gen=1 in my example
> > > > >>>>>
> > > > >>>> regardless
> > > > >>>>
> > > > >>>>> of whether they finish scanning gen=0 before or after the
> > backfill
> > > is
> > > > >>>>> available.
> > > > >>>>>
> > > > >>>>> The broker knowing when it's ok to delete gen 0, including its
> > > offset
> > > > >>>>> mappings, is a big issue, though. I don't have any immediate
> > ideas
> > > > for
> > > > >>>>> solving it, but it doesn't feel impossible. Hopefully, you
> agree
> > > this
> > > > >>>>>
> > > > >>>> is
> > > > >>>
> > > > >>>> outside of KIP-253's scope, so maybe we don't need to worry
> about
> > it
> > > > >>>>>
> > > > >>>> right
> > > > >>>>
> > > > >>>>> now.
> > > > >>>>>
> > > > >>>>> I do agree that reshuffling in KStreams effectively solves the
> > > > >>>>>
> > > > >>>> scalability
> > > > >>>>
> > > > >>>>> problem as well, as it decouples the partition count (and the
> > > > partition
> > > > >>>>> scheme) upstream from the parallelism of the streams
> application.
> > > > >>>>>
> > > > >>>> Likely,
> > > > >>>
> > > > >>>> we will do this in any case. I'm predominantly advocating for
> > > > follow-on
> > > > >>>>> work to enable backfill for the *other* Kafka users that are
> not
> > > > >>>>>
> > > > >>>> KStreams.
> > > > >>>>
> > > > >>>>> Thanks for your consideration,
> > > > >>>>> -John
> > > > >>>>>
> > > > >>>>> On Tue, Mar 27, 2018 at 6:19 PM, Jun Rao <ju...@confluent.io>
> > wrote:
> > > > >>>>>
> > > > >>>>> Hi, John,
> > > > >>>>>>
> > > > >>>>>> Thanks for the reply. I agree that the backfill approach works
> > > > >>>>>>
> > > > >>>>> cleaner
> > > > >>>
> > > > >>>> for
> > > > >>>>>
> > > > >>>>>> newly started consumers. I am just not sure if it's a good
> > > primitive
> > > > >>>>>>
> > > > >>>>> to
> > > > >>>
> > > > >>>> support for existing consumers. One of the challenges that I see
> > is
> > > > >>>>>>
> > > > >>>>> the
> > > > >>>
> > > > >>>> remapping of the offsets. In your approach, we need to copy the
> > > > >>>>>>
> > > > >>>>> existing
> > > > >>>>
> > > > >>>>> records from the partitions in generation 0 to generation 1.
> > Those
> > > > >>>>>>
> > > > >>>>> records
> > > > >>>>>
> > > > >>>>>> will get different offsets in the new generation. The broker
> > will
> > > > >>>>>>
> > > > >>>>> have
> > > > >>>
> > > > >>>> to
> > > > >>>>
> > > > >>>>> store those offset mappings somewhere. When the backfill
> > completes,
> > > > >>>>>>
> > > > >>>>> you
> > > > >>>
> > > > >>>> can
> > > > >>>>>
> > > > >>>>>> delete generation 0's data. However, the broker can't throw
> away
> > > the
> > > > >>>>>>
> > > > >>>>> offset
> > > > >>>>>
> > > > >>>>>> mappings immediately since it doesn't know if there is any
> > > existing
> > > > >>>>>> consumer still consuming generation 0's records. In a
> compacted
> > > > >>>>>>
> > > > >>>>> topic,
> > > > >>>
> > > > >>>> the
> > > > >>>>>
> > > > >>>>>> broker probably can only safely remove the offset mappings
> when
> > > all
> > > > >>>>>>
> > > > >>>>> records
> > > > >>>>>
> > > > >>>>>> in generation 0 are removed by the cleaner. This may never
> > happen
> > > > >>>>>>
> > > > >>>>> though.
> > > > >>>>
> > > > >>>>> If we reshuffle the input inside a KStreams job, it obviates
> the
> > > need
> > > > >>>>>>
> > > > >>>>> for
> > > > >>>>
> > > > >>>>> offset remapping on the broker.
> > > > >>>>>>
> > > > >>>>>> Jun
> > > > >>>>>>
> > > > >>>>>> On Tue, Mar 27, 2018 at 11:34 AM, John Roesler <
> > john@confluent.io
> > > >
> > > > >>>>>>
> > > > >>>>> wrote:
> > > > >>>>>
> > > > >>>>>> Hey Dong and Jun,
> > > > >>>>>>>
> > > > >>>>>>> Thanks for the thoughtful responses. If you don't mind, I'll
> > mix
> > > my
> > > > >>>>>>>
> > > > >>>>>> replies
> > > > >>>>>>
> > > > >>>>>>> together to try for a coherent response. I'm not too familiar
> > > with
> > > > >>>>>>> mailing-list etiquette, though.
> > > > >>>>>>>
> > > > >>>>>>> I'm going to keep numbering my points because it makes it
> easy
> > > for
> > > > >>>>>>>
> > > > >>>>>> you
> > > > >>>>
> > > > >>>>> all
> > > > >>>>>>
> > > > >>>>>>> to respond.
> > > > >>>>>>>
> > > > >>>>>>> Point 1:
> > > > >>>>>>> As I read it, KIP-253 is *just* about properly fencing the
> > > > >>>>>>>
> > > > >>>>>> producers
> > > > >>>
> > > > >>>> and
> > > > >>>>>
> > > > >>>>>> consumers so that you preserve the correct ordering of records
> > > > >>>>>>>
> > > > >>>>>> during
> > > > >>>
> > > > >>>> partition expansion. This is clearly necessary regardless of
> > > > >>>>>>>
> > > > >>>>>> anything
> > > > >>>
> > > > >>>> else
> > > > >>>>>>
> > > > >>>>>>> we discuss. I think this whole discussion about backfill,
> > > > >>>>>>>
> > > > >>>>>> consumers,
> > > > >>>
> > > > >>>> streams, etc., is beyond the scope of KIP-253. But it would be
> > > > >>>>>>>
> > > > >>>>>> cumbersome
> > > > >>>>>
> > > > >>>>>> to start a new thread at this point.
> > > > >>>>>>>
> > > > >>>>>>> I had missed KIP-253's Proposed Change #9 among all the
> > > details...
> > > > >>>>>>>
> > > > >>>>>> I
> > > > >>>
> > > > >>>> think
> > > > >>>>>>
> > > > >>>>>>> this is a nice addition to the proposal. One thought is that
> > it's
> > > > >>>>>>>
> > > > >>>>>> actually
> > > > >>>>>>
> > > > >>>>>>> irrelevant whether the hash function is linear. This is
> simply
> > an
> > > > >>>>>>>
> > > > >>>>>> algorithm
> > > > >>>>>>
> > > > >>>>>>> for moving a key from one partition to another, so the type
> of
> > > hash
> > > > >>>>>>> function need not be a precondition. In fact, it also doesn't
> > > > >>>>>>>
> > > > >>>>>> matter
> > > > >>>
> > > > >>>> whether the topic is compacted or not, the algorithm works
> > > > >>>>>>>
> > > > >>>>>> regardless.
> > > > >>>>
> > > > >>>>> I think this is a good algorithm to keep in mind, as it might
> > > > >>>>>>>
> > > > >>>>>> solve a
> > > > >>>
> > > > >>>> variety of problems, but it does have a downside: that the
> > producer
> > > > >>>>>>>
> > > > >>>>>> won't
> > > > >>>>>
> > > > >>>>>> know whether or not K1 was actually in P1, it just knows that
> K1
> > > > >>>>>>>
> > > > >>>>>> was
> > > > >>>
> > > > >>>> in
> > > > >>>>
> > > > >>>>> P1's keyspace before the new epoch. Therefore, it will have to
> > > > >>>>>>> pessimistically send (K1,null) to P1 just in case. But the
> next
> > > > >>>>>>>
> > > > >>>>>> time
> > > > >>>
> > > > >>>> K1
> > > > >>>>
> > > > >>>>> comes along, the producer *also* won't remember that it already
> > > > >>>>>>>
> > > > >>>>>> retracted
> > > > >>>>>
> > > > >>>>>> K1 from P1, so it will have to send (K1,null) *again*. By
> > > > >>>>>>>
> > > > >>>>>> extension,
> > > > >>>
> > > > >>>> every
> > > > >>>>>>
> > > > >>>>>>> time the producer sends to P2, it will also have to send a
> > > > >>>>>>>
> > > > >>>>>> tombstone
> > > > >>>
> > > > >>>> to
> > > > >>>>
> > > > >>>>> P1,
> > > > >>>>>>
> > > > >>>>>>> which is a pretty big burden. To make the situation worse, if
> > > there
> > > > >>>>>>>
> > > > >>>>>> is
> > > > >>>>
> > > > >>>>> a
> > > > >>>>>
> > > > >>>>>> second split, say P2 becomes P2 and P3, then any key Kx
> > belonging
> > > > >>>>>>>
> > > > >>>>>> to
> > > > >>>
> > > > >>>> P3
> > > > >>>>
> > > > >>>>> will also have to be retracted from P2 *and* P1, since the
> > producer
> > > > >>>>>>>
> > > > >>>>>> can't
> > > > >>>>>
> > > > >>>>>> know whether Kx had been last written to P2 or P1. Over a long
> > > > >>>>>>>
> > > > >>>>>> period
> > > > >>>
> > > > >>>> of
> > > > >>>>>
> > > > >>>>>> time, this clearly becomes a issue, as the producer must send
> an
> > > > >>>>>>>
> > > > >>>>>> arbitrary
> > > > >>>>>>
> > > > >>>>>>> number of retractions along with every update.
> > > > >>>>>>>
> > > > >>>>>>> In contrast, the proposed backfill operation has an end, and
> > > after
> > > > >>>>>>>
> > > > >>>>>> it
> > > > >>>
> > > > >>>> ends,
> > > > >>>>>>
> > > > >>>>>>> everyone can afford to forget that there ever was a different
> > > > >>>>>>>
> > > > >>>>>> partition
> > > > >>>>
> > > > >>>>> layout.
> > > > >>>>>>>
> > > > >>>>>>> Really, though, figuring out how to split compacted topics is
> > > > >>>>>>>
> > > > >>>>>> beyond
> > > > >>>
> > > > >>>> the
> > > > >>>>>
> > > > >>>>>> scope of KIP-253, so I'm not sure #9 really even needs to be
> in
> > > > >>>>>>>
> > > > >>>>>> this
> > > > >>>
> > > > >>>> KIP...
> > > > >>>>>>
> > > > >>>>>>> We do need in-order delivery during partition expansion. It
> > would
> > > > >>>>>>>
> > > > >>>>>> be
> > > > >>>
> > > > >>>> fine
> > > > >>>>>
> > > > >>>>>> by me to say that you *cannot* expand partitions of a
> > > log-compacted
> > > > >>>>>>>
> > > > >>>>>> topic
> > > > >>>>>
> > > > >>>>>> and call it a day. I think it would be better to tackle that
> in
> > > > >>>>>>>
> > > > >>>>>> another
> > > > >>>>
> > > > >>>>> KIP.
> > > > >>>>>>>
> > > > >>>>>>>
> > > > >>>>>>> Point 2:
> > > > >>>>>>> Regarding whether the consumer re-shuffles its inputs, this
> is
> > > > >>>>>>>
> > > > >>>>>> always
> > > > >>>
> > > > >>>> on
> > > > >>>>>
> > > > >>>>>> the table; any consumer who wants to re-shuffle its input is
> > free
> > > > >>>>>>>
> > > > >>>>>> to
> > > > >>>
> > > > >>>> do
> > > > >>>>
> > > > >>>>> so.
> > > > >>>>>>
> > > > >>>>>>> But this is currently not required. It's just that the
> current
> > > > >>>>>>>
> > > > >>>>>> high-level
> > > > >>>>>
> > > > >>>>>> story with Kafka encourages the use of partitions as a unit of
> > > > >>>>>>>
> > > > >>>>>> concurrency.
> > > > >>>>>>
> > > > >>>>>>> As long as consumers are single-threaded, they can happily
> > > consume
> > > > >>>>>>>
> > > > >>>>>> a
> > > > >>>
> > > > >>>> single
> > > > >>>>>>
> > > > >>>>>>> partition without concurrency control of any kind. This is a
> > key
> > > > >>>>>>>
> > > > >>>>>> aspect
> > > > >>>>
> > > > >>>>> to
> > > > >>>>>>
> > > > >>>>>>> this system that lets folks design high-throughput systems on
> > top
> > > > >>>>>>>
> > > > >>>>>> of
> > > > >>>
> > > > >>>> it
> > > > >>>>
> > > > >>>>> surprisingly easily. If all consumers were instead
> > > > >>>>>>>
> > > > >>>>>> encouraged/required
> > > > >>>>
> > > > >>>>> to
> > > > >>>>>
> > > > >>>>>> implement a repartition of their own, then the consumer
> becomes
> > > > >>>>>>> significantly more complex, requiring either the consumer to
> > > first
> > > > >>>>>>>
> > > > >>>>>> produce
> > > > >>>>>>
> > > > >>>>>>> to its own intermediate repartition topic or to ensure that
> > > > >>>>>>>
> > > > >>>>>> consumer
> > > > >>>
> > > > >>>> threads have a reliable, high-bandwith channel of communication
> > > > >>>>>>>
> > > > >>>>>> with
> > > > >>>
> > > > >>>> every
> > > > >>>>>>
> > > > >>>>>>> other consumer thread.
> > > > >>>>>>>
> > > > >>>>>>> Either of those tradeoffs may be reasonable for a particular
> > user
> > > > >>>>>>>
> > > > >>>>>> of
> > > > >>>
> > > > >>>> Kafka,
> > > > >>>>>>
> > > > >>>>>>> but I don't know if we're in a position to say that they are
> > > > >>>>>>>
> > > > >>>>>> reasonable
> > > > >>>>
> > > > >>>>> for
> > > > >>>>>>
> > > > >>>>>>> *every* user of Kafka.
> > > > >>>>>>>
> > > > >>>>>>>
> > > > >>>>>>> Point 3:
> > > > >>>>>>> Regarding Jun's point about this use case, "(3) stateful and
> > > > >>>>>>>
> > > > >>>>>> maintaining
> > > > >>>>>
> > > > >>>>>> the
> > > > >>>>>>> states in a local store", I agree that they may use a
> framework
> > > > >>>>>>>
> > > > >>>>>> *like*
> > > > >>>>
> > > > >>>>> Kafka Streams, but that is not the same as using Kafka Streams.
> > > > >>>>>>>
> > > > >>>>>> This
> > > > >>>
> > > > >>>> is
> > > > >>>>
> > > > >>>>> why
> > > > >>>>>>
> > > > >>>>>>> I think it's better to solve it in Core: because it is then
> > > solved
> > > > >>>>>>>
> > > > >>>>>> for
> > > > >>>>
> > > > >>>>> KStreams and also for everything else that facilitates local
> > state
> > > > >>>>>>> maintenance. To me, Streams is a member of the category of
> > > "stream
> > > > >>>>>>> processing frameworks", which is itself a subcategory of
> > "things
> > > > >>>>>>>
> > > > >>>>>> requiring
> > > > >>>>>>
> > > > >>>>>>> local state maintenence". I'm not sure if it makes sense to
> > > assert
> > > > >>>>>>>
> > > > >>>>>> that
> > > > >>>>
> > > > >>>>> Streams is a sufficient and practical replacement for
> everything
> > in
> > > > >>>>>>>
> > > > >>>>>> "things
> > > > >>>>>>
> > > > >>>>>>> requiring local state maintenence".
> > > > >>>>>>>
> > > > >>>>>>> But, yes, I do agree that per-key ordering is an absolute
> > > > >>>>>>>
> > > > >>>>>> requirement,
> > > > >>>>
> > > > >>>>> therefore I think that KIP-253 itself is a necessary step.
> > > > >>>>>>>
> > > > >>>>>> Regarding
> > > > >>>
> > > > >>>> the
> > > > >>>>>
> > > > >>>>>> coupling of the state store partitioning to the topic
> > > partitioning,
> > > > >>>>>>>
> > > > >>>>>> yes,
> > > > >>>>>
> > > > >>>>>> this is an issue we are discussing solutions to right now. We
> > may
> > > > >>>>>>>
> > > > >>>>>> go
> > > > >>>
> > > > >>>> ahead
> > > > >>>>>>
> > > > >>>>>>> and introduce an overpartition layer on our inputs to solve
> it,
> > > but
> > > > >>>>>>>
> > > > >>>>>> then
> > > > >>>>>
> > > > >>>>>> again, if we get the ability to split partitions with
> backfill,
> > we
> > > > >>>>>>>
> > > > >>>>>> may
> > > > >>>>
> > > > >>>>> not
> > > > >>>>>>
> > > > >>>>>>> need to!
> > > > >>>>>>>
> > > > >>>>>>>
> > > > >>>>>>> Point 4:
> > > > >>>>>>> On this:
> > > > >>>>>>>
> > > > >>>>>>> Regarding thought 2: If we don't care about the stream
> > use-case,
> > > > >>>>>>>>
> > > > >>>>>>> then
> > > > >>>>
> > > > >>>>> the
> > > > >>>>>>
> > > > >>>>>>> current KIP probably has already addressed problem without
> > > > >>>>>>>>
> > > > >>>>>>> requiring
> > > > >>>>
> > > > >>>>> consumer to know the partition function. If we care about the
> > > > >>>>>>>>
> > > > >>>>>>> stream
> > > > >>>>
> > > > >>>>> use-case, we already need coordination across producers of
> > > > >>>>>>>>
> > > > >>>>>>> different
> > > > >>>>
> > > > >>>>> topics, i.e. the same partition function needs to be used by
> > > > >>>>>>>>
> > > > >>>>>>> producers
> > > > >>>>>
> > > > >>>>>> of
> > > > >>>>>>
> > > > >>>>>>> topics A and B in order to join topics A and B. Thus, it
> might
> > be
> > > > >>>>>>>> reasonable to extend coordination a bit and say we need
> > > > >>>>>>>>
> > > > >>>>>>> coordination
> > > > >>>>
> > > > >>>>> across
> > > > >>>>>>>
> > > > >>>>>>>> clients (i.e. producer and consumer), such that consumer
> knows
> > > > >>>>>>>>
> > > > >>>>>>> the
> > > > >>>
> > > > >>>> partition function used by producer. If we do so, then we can
> let
> > > > >>>>>>>>
> > > > >>>>>>> consumer
> > > > >>>>>>>
> > > > >>>>>>>> re-copy data for the change log topic using the same
> partition
> > > > >>>>>>>>
> > > > >>>>>>> function
> > > > >>>>>
> > > > >>>>>> as
> > > > >>>>>>>
> > > > >>>>>>>> producer. This approach has lower overhead as compared to
> > having
> > > > >>>>>>>>
> > > > >>>>>>> producer
> > > > >>>>>>
> > > > >>>>>>> re-copy data of the input topic.
> > > > >>>>>>>> Also, producer currently does not need to know the data
> > already
> > > > >>>>>>>>
> > > > >>>>>>> produced
> > > > >>>>>>
> > > > >>>>>>> to
> > > > >>>>>>>
> > > > >>>>>>>> the topic. If we let producer split/merge partition, it
> would
> > > > >>>>>>>>
> > > > >>>>>>> require
> > > > >>>>
> > > > >>>>> producer to consume the existing data, which intuitively is the
> > > > >>>>>>>>
> > > > >>>>>>> task
> > > > >>>>
> > > > >>>>> of
> > > > >>>>>
> > > > >>>>>> consumer.
> > > > >>>>>>>>
> > > > >>>>>>>
> > > > >>>>>>> I think we do care about use cases *like* Streams, I just
> don't
> > > > >>>>>>>
> > > > >>>>>> think
> > > > >>>
> > > > >>>> we
> > > > >>>>>
> > > > >>>>>> should rely on Streams to implement a feature of Core like
> > > > >>>>>>>
> > > > >>>>>> partition
> > > > >>>
> > > > >>>> expansion.
> > > > >>>>>>>
> > > > >>>>>>> Note, though, that we (Streams) do not require coordination
> > > across
> > > > >>>>>>> producers. If two topics are certified to be co-partitioned,
> > then
> > > > >>>>>>>
> > > > >>>>>> Streams
> > > > >>>>>
> > > > >>>>>> apps can make use of that knowledge to optimize their topology
> > > > >>>>>>>
> > > > >>>>>> (skipping
> > > > >>>>>
> > > > >>>>>> a
> > > > >>>>>>
> > > > >>>>>>> repartition). But if they don't know whether they are
> > > > >>>>>>>
> > > > >>>>>> co-partitioned,
> > > > >>>
> > > > >>>> then
> > > > >>>>>>
> > > > >>>>>>> they'd better go ahead and repartition within the topology.
> > This
> > > is
> > > > >>>>>>>
> > > > >>>>>> the
> > > > >>>>
> > > > >>>>> current state.
> > > > >>>>>>>
> > > > >>>>>>> A huge selling point of Kafka is enabling different parts of
> > > > >>>>>>>
> > > > >>>>>> loosely
> > > > >>>
> > > > >>>> coupled organizations to produce and consume data independently.
> > > > >>>>>>>
> > > > >>>>>> Some
> > > > >>>
> > > > >>>> coordination between producers and consumers is necessary, like
> > > > >>>>>>> coordinating on the names of topics and their schemas. But
> > > Kafka's
> > > > >>>>>>>
> > > > >>>>>> value
> > > > >>>>>
> > > > >>>>>> proposition w.r.t. ESBs, etc. is inversely proportional to the
> > > > >>>>>>>
> > > > >>>>>> amount
> > > > >>>
> > > > >>>> of
> > > > >>>>>
> > > > >>>>>> coordination required. I think it behooves us to be extremely
> > > > >>>>>>>
> > > > >>>>>> skeptical
> > > > >>>>
> > > > >>>>> about introducing any coordination beyond correctness
> protocols.
> > > > >>>>>>>
> > > > >>>>>>> Asking producers and consumers, or even two different
> > producers,
> > > to
> > > > >>>>>>>
> > > > >>>>>> share
> > > > >>>>>
> > > > >>>>>> code like the partition function is a pretty huge ask. What if
> > > they
> > > > >>>>>>>
> > > > >>>>>> are
> > > > >>>>
> > > > >>>>> using different languages?
> > > > >>>>>>>
> > > > >>>>>>> Comparing organizational overhead vs computational overhead,
> > > there
> > > > >>>>>>>
> > > > >>>>>> are
> > > > >>>>
> > > > >>>>> maybe two orders of magnitude difference between them. In other
> > > > >>>>>>>
> > > > >>>>>> words,
> > > > >>>>
> > > > >>>>> I
> > > > >>>>>
> > > > >>>>>> would happily take on the (linear) overhead of having the
> > producer
> > > > >>>>>>>
> > > > >>>>>> re-copy
> > > > >>>>>>
> > > > >>>>>>> the data once during a re-partition in order to save the
> > > > >>>>>>>
> > > > >>>>>> organizational
> > > > >>>>
> > > > >>>>> overhead of tying all the producers and consumers together
> across
> > > > >>>>>>>
> > > > >>>>>> multiple
> > > > >>>>>>
> > > > >>>>>>> boundaries.
> > > > >>>>>>>
> > > > >>>>>>> On that last paragraph: note that the producer *did* know the
> > > data
> > > > >>>>>>>
> > > > >>>>>> it
> > > > >>>
> > > > >>>> already produced. It handled it the first time around. Asking it
> > to
> > > > >>>>>>> re-produce it into a new partition layout is squarely within
> > its
> > > > >>>>>>>
> > > > >>>>>> scope
> > > > >>>>
> > > > >>>>> of
> > > > >>>>>
> > > > >>>>>> capabilities. Contrast this with the alternative, asking the
> > > > >>>>>>>
> > > > >>>>>> consumer
> > > > >>>
> > > > >>>> to
> > > > >>>>>
> > > > >>>>>> re-partition the data. I think this is even less intuitive,
> when
> > > > >>>>>>>
> > > > >>>>>> the
> > > > >>>
> > > > >>>> partition function belongs to the producer.
> > > > >>>>>>>
> > > > >>>>>>>
> > > > >>>>>>> Point 5:
> > > > >>>>>>> Dong asked this:
> > > > >>>>>>>
> > > > >>>>>>> For stream use-case that needs to increase consumer number,
> the
> > > > >>>>>>>> existing consumer can backfill the existing data in the
> change
> > > > >>>>>>>>
> > > > >>>>>>> log
> > > > >>>
> > > > >>>> topic
> > > > >>>>>>
> > > > >>>>>>> to
> > > > >>>>>>>
> > > > >>>>>>>> the same change log topic with the new partition number,
> > before
> > > > >>>>>>>>
> > > > >>>>>>> the
> > > > >>>
> > > > >>>> new
> > > > >>>>>
> > > > >>>>>> set
> > > > >>>>>>>
> > > > >>>>>>>> of consumers bootstrap state from the new partitions of the
> > > > >>>>>>>>
> > > > >>>>>>> change
> > > > >>>
> > > > >>>> log
> > > > >>>>>
> > > > >>>>>> topic, right?
> > > > >>>>>>>>
> > > > >>>>>>>
> > > > >>>>>>> In this sense, the "consumer" is actually the producer of the
> > > > >>>>>>>
> > > > >>>>>> changelog
> > > > >>>>
> > > > >>>>> topic, so if we support partition expansion + backfill as a
> > > > >>>>>>>
> > > > >>>>>> producer/broker
> > > > >>>>>>
> > > > >>>>>>> operation, then it would be very straightforward for Streams
> to
> > > > >>>>>>>
> > > > >>>>>> split a
> > > > >>>>
> > > > >>>>> state store. As you say, they would simply instruct the broker
> to
> > > > >>>>>>>
> > > > >>>>>> split
> > > > >>>>
> > > > >>>>> the
> > > > >>>>>>
> > > > >>>>>>> changelog topic's partitions, then backfill. Once the
> backfill
> > is
> > > > >>>>>>>
> > > > >>>>>> ready,
> > > > >>>>>
> > > > >>>>>> they can create a new crop of StandbyTasks to bootstrap the
> more
> > > > >>>>>>>
> > > > >>>>>> granular
> > > > >>>>>
> > > > >>>>>> state stores and finally switch over to them when they are
> > ready.
> > > > >>>>>>>
> > > > >>>>>>> But this actually seems to be an argument in favor of
> > > > >>>>>>>
> > > > >>>>>> split+backfill,
> > > > >>>
> > > > >>>> so
> > > > >>>>>
> > > > >>>>>> maybe I missed the point.
> > > > >>>>>>>
> > > > >>>>>>> You also asked me to explain why copying the "input" topic is
> > > > >>>>>>>
> > > > >>>>>> better
> > > > >>>
> > > > >>>> than
> > > > >>>>>
> > > > >>>>>> copying the "changelog" topic. I think they are totally
> > > > >>>>>>>
> > > > >>>>>> independent,
> > > > >>>
> > > > >>>> actually. For one thing, you can't depend on the existence of a
> > > > >>>>>>>
> > > > >>>>>> "changelog"
> > > > >>>>>>
> > > > >>>>>>> topic in general, only within Streams, but Kafka's user base
> > > > >>>>>>>
> > > > >>>>>> clearly
> > > > >>>
> > > > >>>> exceeds Streams's user base. Plus, you actually also can't
> depend
> > > > >>>>>>>
> > > > >>>>>> on
> > > > >>>
> > > > >>>> the
> > > > >>>>>
> > > > >>>>>> existence of a changelog topic within Streams, since that is
> an
> > > > >>>>>>>
> > > > >>>>>> optional
> > > > >>>>>
> > > > >>>>>> feature of *some* state store implementations. Even in the
> > > > >>>>>>>
> > > > >>>>>> situation
> > > > >>>
> > > > >>>> where
> > > > >>>>>>
> > > > >>>>>>> you do have a changelog topic in Streams, there may be use
> > cases
> > > > >>>>>>>
> > > > >>>>>> where
> > > > >>>>
> > > > >>>>> it
> > > > >>>>>
> > > > >>>>>> makes sense to expand the partitions of just the input, or
> just
> > > the
> > > > >>>>>>> changelog.
> > > > >>>>>>>
> > > > >>>>>>> The ask for a Core feature of split+backfill is really about
> > > > >>>>>>>
> > > > >>>>>> supporting
> > > > >>>>
> > > > >>>>> the
> > > > >>>>>>
> > > > >>>>>>> use case of splitting partitions in log-compacted topics,
> > > > >>>>>>>
> > > > >>>>>> regardless
> > > > >>>
> > > > >>>> of
> > > > >>>>
> > > > >>>>> whether that topic is an "input" or a "changelog" or anything
> > else
> > > > >>>>>>>
> > > > >>>>>> for
> > > > >>>>
> > > > >>>>> that
> > > > >>>>>>
> > > > >>>>>>> matter.
> > > > >>>>>>>
> > > > >>>>>>>
> > > > >>>>>>> Point 6:
> > > > >>>>>>> On the concern about the performance overhead of copying data
> > > > >>>>>>>
> > > > >>>>>> between
> > > > >>>
> > > > >>>> the
> > > > >>>>>
> > > > >>>>>> brokers, I think it's actually a bit overestimated. Splitting
> a
> > > > >>>>>>>
> > > > >>>>>> topic's
> > > > >>>>
> > > > >>>>> partition is probably rare, certainly rarer in general than
> > > > >>>>>>>
> > > > >>>>>> bootstrapping
> > > > >>>>>
> > > > >>>>>> new consumers on that topic. If "bootstrapping new consumers"
> > > means
> > > > >>>>>>>
> > > > >>>>>> that
> > > > >>>>>
> > > > >>>>>> they have to re-shuffle the data before they consume it, then
> > you
> > > > >>>>>>>
> > > > >>>>>> wind
> > > > >>>>
> > > > >>>>> up
> > > > >>>>>
> > > > >>>>>> copying the same record multiple times:
> > > > >>>>>>>
> > > > >>>>>>> (broker: input topic) -> (initial consumer) -> (broker:
> > > repartition
> > > > >>>>>>>
> > > > >>>>>> topic)
> > > > >>>>>>
> > > > >>>>>>> -> (real consumer)
> > > > >>>>>>>
> > > > >>>>>>> That's 3x, and it's also 3x for every new record after the
> > split
> > > as
> > > > >>>>>>>
> > > > >>>>>> well,
> > > > >>>>>
> > > > >>>>>> since you don't get to stop repartitioning/reshuffling once
> you
> > > > >>>>>>>
> > > > >>>>>> start.
> > > > >>>>
> > > > >>>>> Whereas if you do a backfill in something like the procedure I
> > > > >>>>>>>
> > > > >>>>>> outlined,
> > > > >>>>>
> > > > >>>>>> you only copy the prefix of the partition before the split,
> and
> > > you
> > > > >>>>>>>
> > > > >>>>>> send
> > > > >>>>>
> > > > >>>>>> it
> > > > >>>>>>
> > > > >>>>>>> once to the producer and then once to the new generation
> > > partition.
> > > > >>>>>>>
> > > > >>>>>> Plus,
> > > > >>>>>
> > > > >>>>>> assuming we're splitting the partition for the benefit of
> > > > >>>>>>>
> > > > >>>>>> consumers,
> > > > >>>
> > > > >>>> there's no reason we can't co-locate the post-split partitions
> on
> > > > >>>>>>>
> > > > >>>>>> the
> > > > >>>
> > > > >>>> same
> > > > >>>>>>
> > > > >>>>>>> host as the pre-split partition, making the second copy a
> local
> > > > >>>>>>>
> > > > >>>>>> filesystem
> > > > >>>>>>
> > > > >>>>>>> operation.
> > > > >>>>>>>
> > > > >>>>>>> Even if you follow these two copies up with bootstrapping a
> new
> > > > >>>>>>>
> > > > >>>>>> consumer,
> > > > >>>>>
> > > > >>>>>> it's still rare for this to occur, so you get to amortize
> these
> > > > >>>>>>>
> > > > >>>>>> copies
> > > > >>>>
> > > > >>>>> over
> > > > >>>>>>
> > > > >>>>>>> the lifetime of the topic, whereas a reshuffle just keeps
> > making
> > > > >>>>>>>
> > > > >>>>>> copies
> > > > >>>>
> > > > >>>>> for
> > > > >>>>>>
> > > > >>>>>>> every new event.
> > > > >>>>>>>
> > > > >>>>>>> And finally, I really do think that regardless of any
> > performance
> > > > >>>>>>>
> > > > >>>>>> concerns
> > > > >>>>>>
> > > > >>>>>>> about this operation, if it preserves loose organizational
> > > > >>>>>>>
> > > > >>>>>> coupling,
> > > > >>>
> > > > >>>> it
> > > > >>>>
> > > > >>>>> is
> > > > >>>>>>
> > > > >>>>>>> certainly worth it.
> > > > >>>>>>>
> > > > >>>>>>>
> > > > >>>>>>> In conclusion:
> > > > >>>>>>> It might actually be a good idea for us to clarify the scope
> of
> > > > >>>>>>>
> > > > >>>>>> KIP-253.
> > > > >>>>>
> > > > >>>>>> If
> > > > >>>>>>
> > > > >>>>>>> we're all agreed that it's a good algorithm for allowing
> > in-order
> > > > >>>>>>>
> > > > >>>>>> message
> > > > >>>>>
> > > > >>>>>> delivery during partition expansion, then we can continue this
> > > > >>>>>>>
> > > > >>>>>> discussion
> > > > >>>>>
> > > > >>>>>> as a new KIP, something like "backfill with partition
> > expansion".
> > > > >>>>>>>
> > > > >>>>>> This
> > > > >>>>
> > > > >>>>> would let Dong proceed with KIP-253. On the other hand, if it
> > seems
> > > > >>>>>>>
> > > > >>>>>> like
> > > > >>>>>
> > > > >>>>>> this conversation may alter the design of KIP-253, then maybe
> we
> > > > >>>>>>>
> > > > >>>>>> *should*
> > > > >>>>>
> > > > >>>>>> just finish working it out.
> > > > >>>>>>>
> > > > >>>>>>> For my part, my only concern about KIP-253 is the one I
> raised
> > > > >>>>>>>
> > > > >>>>>> earlier.
> > > > >>>>
> > > > >>>>> Thanks again, all, for considering these points,
> > > > >>>>>>> -John
> > > > >>>>>>>
> > > > >>>>>>>
> > > > >>>>>>> On Tue, Mar 27, 2018 at 2:10 AM, Dong Lin <
> lindong28@gmail.com
> > >
> > > > >>>>>>>
> > > > >>>>>> wrote:
> > > > >>>>
> > > > >>>>> On Tue, Mar 27, 2018 at 12:04 AM, Dong Lin <
> lindong28@gmail.com>
> > > > >>>>>>>>
> > > > >>>>>>> wrote:
> > > > >>>>>>
> > > > >>>>>>> Hey Jan,
> > > > >>>>>>>>>
> > > > >>>>>>>>> Thanks for the enthusiasm in improving Kafka's design. Now
> > > > >>>>>>>>>
> > > > >>>>>>>> that I
> > > > >>>
> > > > >>>> have
> > > > >>>>>>
> > > > >>>>>>> read through your discussion with Jun, here are my thoughts:
> > > > >>>>>>>>>
> > > > >>>>>>>>> - The latest proposal should with log compacted topics by
> > > > >>>>>>>>>
> > > > >>>>>>>> properly
> > > > >>>>
> > > > >>>>> deleting old messages after a new message with the same key is
> > > > >>>>>>>>>
> > > > >>>>>>>> produced.
> > > > >>>>>>>
> > > > >>>>>>>> So
> > > > >>>>>>>>
> > > > >>>>>>>>> it is probably not a concern anymore. Could you comment if
> > > > >>>>>>>>>
> > > > >>>>>>>> there
> > > > >>>
> > > > >>>> is
> > > > >>>>
> > > > >>>>> still
> > > > >>>>>>>
> > > > >>>>>>>> issue?
> > > > >>>>>>>>>
> > > > >>>>>>>>> - I wrote the SEP-5 and I am pretty familiar with the
> > > > >>>>>>>>>
> > > > >>>>>>>> motivation
> > > > >>
> > > > >>
> > > >
> > >
> >
>

Re: [DISCUSS] KIP-253: Support in-order message delivery with partition expansion

Posted by Jeff Chao <jc...@salesforce.com>.
Hi Dong, I took a look at KIP-287. Producers writing using the new scheme
prior to processor catch up and cut-over makes sense. Thanks.

On Sat, Apr 14, 2018 at 7:09 PM, Dong Lin <li...@gmail.com> wrote:

> Hey Jeff,
>
> Thanks for the review. The scheme for expanding processors of the stateful
> processing job is described in "Support processor expansion" section in
> KIP-287 (link
> <https://cwiki.apache.org/confluence/display/KAFKA/KIP-
> 287%3A+Support+partition+and+processor+expansion+for+
> stateful+processing+jobs#KIP-287:Supportpartitionandprocessorex
> pansionforstatefulprocessingjobs-Supportprocessorexpansion>).
> In particular, we will expand the partitions of the input topics before
> expanding processors of the processing job. While the new processor is
> catching up, the producer would already be producing using the new
> partitioning scheme. Does this answer your question?
>
> Thanks,
> Dong
>
>
> On Sat, Apr 14, 2018 at 1:44 PM, Jeff Chao <jc...@salesforce.com> wrote:
>
> > Hi, I had a question from Monday's meeting. The current mechanism, as
> Ray's
> > notes points out, is to create a copy consumer in which a switch over
> > happens when it catches up. Meanwhile, it looks like a producer would
> still
> > be writing using the old partitioning scheme. Wouldn't there be a case
> > where the copy consumer never catches up given a high enough produce
> rate?
> > I'm imagining this to work similarly to Kinesis's resharding mechanism,
> > though I may be missing something from the current proposal. Anyway, with
> > Kinesis as an example, this would mean a producer would stop writing
> using
> > the old scheme and start writing using the new scheme. That way, the
> > consumer will be able to catch up in which it will start consuming using
> > the new scheme afterwards.
> >
> > Thanks,
> > Jeff Chao
> >
> > On Sat, Apr 14, 2018 at 6:44 AM, Dong Lin <li...@gmail.com> wrote:
> >
> > > Thanks for the notes by Jun and Ray. I have read through the notes. It
> > > seems that there are a few questions for the alternative solution by
> Jan
> > > and maybe Jan will answer these questions later?
> > >
> > > I have summarized the solution, which I previously provided in this
> > thread,
> > > in KIP-287, to hopefully show that we may have a promising direction to
> > > solve the partition and processor expansion problem for stateful
> > processing
> > > jobs. Maybe we can continue the discussion related to stateful
> processing
> > > in that discussion thread. If that looks good, maybe we can conclude
> the
> > > discussion for KIP-253.
> > >
> > > Not sure if I missed some ideas or questions in the notes. Is there
> > > specific concern for the latest KIP-253?
> > >
> > >
> > > On Mon, Apr 9, 2018 at 11:18 AM, Ray Chiang <rc...@apache.org>
> wrote:
> > >
> > > > My notes from today's meeting.  Sorry if I got anyone's name wrong.
> > Plus
> > > I
> > > > missed a few moments with noise at home and/or dropped video.
> > > >
> > > > -Ray
> > > >
> > > > =====
> > > >
> > > > KIP-253 Discussion
> > > >
> > > > - Currently, adding partitions can cause keys to be read
> out-of-order.
> > > >   This KIP is trying to preserve the key ordering when adding
> > partitions.
> > > >
> > > > - State management in applications (i.e. Kafka Streams) can maintain
> > > >   local state via caching.  If the number of partitions changes, how
> > > >   would those applications update their local state.  This is the
> > current
> > > >   point of discussion/disagreement.
> > > >
> > > > - Jan Filipiak is mostly worried about log compacted topics.  Not as
> > > >   concerned about producer swapping.  Worried about the consumer
> design
> > > is
> > > >   a bit contradictory compared to the architecture.
> > > >
> > > >   Current design is to start up a new consumer in parallel with old
> > > >   topic/consumer.  Run until consumer finishes "copying" to the new
> > > topic.
> > > >   Once the consumer is caught up, point the producer at the new
> topic.
> > > >
> > > >   Would like to have this technique as a "core primitive" to Kafka.
> > > >   - Is this a useful primitive?
> > > >   - What's the best way to support it?
> > > >
> > > >   - Topic expansion as it currently exists just "adds partitions".
> But
> > > >     how does this affect bootstrapping applications?  How to deal
> with
> > > >     "moved" (from "old partition" to "new expanded partition") keys?
> > > >
> > > >   - Dong's proposal example.  10 partitions growing to 15.  5 of the
> > > >     first 10 partitions are split into 2 each.  Say Kafka remembers
> > > >     parent->child relationship.  Then for each parent partition,
> there
> > > >     are two child partitions.  Initially, there were 10 states to
> > > >     manage.  Then bootstrapping new application would have 15 states.
> > > >     Need to know which "generation" of partition you are consuming
> > > >     from.  Until you get to "newer" generation of data, then the keys
> > > >     will be find (i.e. reading from old partition).
> > > >
> > > >   - Scheme works well for transient events.  Any stateful processor
> > will
> > > >     likely break.
> > > >
> > > >   - Tracking can become extremely complicated, since each split
> > requires
> > > >     potentially more and more offset/partition combos.
> > > >
> > > >   - Need to support continuation for consumers to read the new
> > > partitions.
> > > >
> > > >   - With linear hashing, integral multiple increase (2x, 3x, 4x,
> etc).
> > > >     Easier mapping from old partition sets to new partition sets.
> > > >     Keys end up with a clean hierarchy instead of a major
> reshuffling.
> > > >
> > > >   - Dong's approach piggyback on existing leader epoch.  Log segment
> > > >     could be tagged with version in linear hashing case.
> > > >
> > > >   - In Jan's case, existing consumers bootstrap from the beginning.
> > > >
> > > >   - James' use case.  Using Kafka as a long term persistent data
> store.
> > > >     Putting "source of truth" information into Kafka.  Bootstrap case
> > > >     is very important.  New applications could be bootstrapping as
> they
> > > >     come up.
> > > >
> > > >     - Increasing partitions will help with load from prodcuer and
> > > >       increasing consumer parallelism.
> > > >     - How does Kinesis handling partition splits?  They don't have
> > > >       compacted logs, so no issue with bootstrapping.  Kinesis uses
> > > >       MD5 and splits results based on md5sum into bucket ranges.
> > > >     - Is it useful for the server to know the partitioning function?
> > > >       Consumer has some implicit assumptions about keyed partitions,
> > > >       but not strongly enforced on server side.
> > > >
> > > >     - KIP-213 (one to many joins in Kafka Streams)
> > > >
> > > >       - MySQL case.  Primary key forced to be used as Kafka key.
> > > >
> > > >         (Sorry had some audio and video drop at this point)
> > > >
> > > >       - Mirror Maker.  Source cluster has custom partitioning
> function.
> > > >         Producer won't duplicate to same partitioning setup as
> source.
> > > >         Need to provide same partitioning function to producer.
> > > >         Would need to determine partitioning function based on topic.
> > > >
> > > >         - Should server validate partitioning?
> > > >         - Who does actual determination of which key goes to which
> > > > partition.
> > > >
> > > >       - How to implement backfill?
> > > >
> > > >         - Who will do it?  In producer?  Hard to do.  Every client
> > would
> > > >           need to add this functionality.  Better to do on server
> side.
> > > >         - Add a type of "copy consumer"?  Add backoff to producer?
> > > >           Benefit of doing in consumer vs. producer?
> > > >
> > > >   - Still TBD
> > > >     - How to dedupe control messages?
> > > >     - How to deal with subtle cases during transition?
> > > >     - Is it useful for the server to have the option to validate the
> > key
> > > >       distribution?
> > > >     - Jan concerned about how a consumer application would look with
> > the
> > > >       new "split partition" design.
> > > >     - KIP introduced callback.  Jan doesn't think is useful. Callback
> > > >       for switching "between Partition 1 and can start on Partition
> > 11".
> > > >       Rely on marker in Partition 1 instead.  Intent for callback is
> > > >       for possibility that delivery of messages for given key is
> moved
> > > >       to a different consumer instance.
> > > >
> > > >
> > > >
> > > > On 4/6/18 9:44 AM, Dong Lin wrote:
> > > >
> > > >> Hey John,
> > > >>
> > > >> Thanks much for your super-detailed explanation. This is very
> helpful.
> > > >>
> > > >> Now that I have finished reading through your email, I think the
> > > proposed
> > > >> solution in my previous email probably meets the requirement #6
> > without
> > > >> requiring additional coordination (w.r.t. partition function) among
> > > >> clients. My understanding of requirement #6 is that, after partition
> > > >> expansion, messages with the given key will go to the same consumer
> > > before
> > > >> and after the partition expansion such that stream processing jobs
> > won't
> > > >> be
> > > >> affected. Thus this approach seems to be better than backfilling
> since
> > > it
> > > >> does not require data copy for input topics.
> > > >>
> > > >> In order for the proposed solution to meet requirements #6, we need
> > two
> > > >> extra requirements in addition to what has been described in the
> > > previous
> > > >> email: 1) stream processing job starts with the same number of
> > > processors
> > > >> as the initial number of partitions of the input topics; and 2) at
> any
> > > >> given time the number of partitions of the input topic >= the number
> > of
> > > >> processors of the given stream processing job.
> > > >>
> > > >> Could you take a look at the proposed solution and see if any of the
> > > >> claims
> > > >> above is false?
> > > >>
> > > >>
> > > >> Hey Jan,
> > > >>
> > > >> Maybe it is more efficient for us to discuss your concern in the KIP
> > > >> Meeting.
> > > >>
> > > >>
> > > >> Thanks,
> > > >> Dong
> > > >>
> > > >>
> > > >> On Thu, Mar 29, 2018 at 2:05 PM, John Roesler <jo...@confluent.io>
> > > wrote:
> > > >>
> > > >> Hi Jun,
> > > >>>
> > > >>> Thanks for the response. I'm very new to this project, but I will
> > share
> > > >>> my
> > > >>> perspective. I'm going to say a bunch of stuff that I know you know
> > > >>> already, but just so we're on the same page...
> > > >>>
> > > >>> This may also be a good time to get feedback from the other
> KStreams
> > > >>> folks.
> > > >>>
> > > >>> Using KStreams as a reference implementation for how stream
> > processing
> > > >>> frameworks may interact with Kafka, I think it's important to
> eschew
> > > >>> knowledge about how KStreams currently handles internal
> > communication,
> > > >>> making state durable, etc. Both because these details may change,
> and
> > > >>> because they won't be shared with other stream processors.
> > > >>>
> > > >>> =================================
> > > >>> Background
> > > >>>
> > > >>> We are looking at a picture like this:
> > > >>>
> > > >>>       input input input
> > > >>>           \   |   /
> > > >>>        +-------------+
> > > >>> +-----+ Consumer(s) +-------+
> > > >>> |     +-------------+       |
> > > >>> |                           |
> > > >>> |    KStreams Application   |
> > > >>> |                           |
> > > >>> |     +-------------+       |
> > > >>> +-----+ Producer(s) +-------+
> > > >>>        +-------------+
> > > >>>             /    \
> > > >>>          output output
> > > >>>
> > > >>> The inputs and outputs are Kafka topics (and therefore have 1 or
> more
> > > >>> partitions). We'd have at least 1 input and 0 or more outputs. The
> > > >>> Consumers and Producers are both the official KafkaConsumer and
> > > >>> KafkaProducer.
> > > >>>
> > > >>> In general, we'll assume that the input topics are provided by
> actors
> > > >>> over
> > > >>> which we have no control, although we may as well assume they are
> > > >>> friendly
> > > >>> and amenable to requests, and also that their promises are
> > trustworthy.
> > > >>> This is important because we must depend on them to uphold some
> > > promises:
> > > >>> * That they tell us the schema of the data they publish, and abide
> by
> > > >>> that
> > > >>> schema. Without this, the inputs are essentially garbage.
> > > >>> * That they tell us some defining characteristics of the topics
> (more
> > > on
> > > >>> this in a sec.) and again strictly abide by that promise.
> > > >>>
> > > >>> What are the topic characteristics we care about?
> > > >>> 1. The name (or name pattern)
> > > >>> 2. How the messages are keyed (if at all)
> > > >>> 3. Whether the message timestamps are meaningful, and if so, what
> > their
> > > >>> meaning is
> > > >>> 4. Assuming the records have identity, whether the partitions
> > partition
> > > >>> the
> > > >>> records' identity space
> > > >>> 5. Whether the topic completely contains the data set
> > > >>> 6. Whether the messages in the topic are ordered
> > > >>>
> > > >>> #1 is obvious: without this information, we cannot access the data
> at
> > > >>> all.
> > > >>>
> > > >>> For #2, #3, #4, and #6, we may or may not need this information,
> > > >>> depending
> > > >>> on the logic of the application. For example, a trivial application
> > > that
> > > >>> simply counts all events it sees doesn't care about #2, #3, #4, or
> > #6.
> > > >>> But
> > > >>> an application that groups by some attribute can take advantage of
> #2
> > > and
> > > >>> #4 if the topic data is already keyed and partitioned over that
> > > >>> attribute.
> > > >>> Likewise, if the application includes some temporal semantics on a
> > > >>> temporal
> > > >>> dimension that is already captured in #3, it may take advantage of
> > that
> > > >>> fact.
> > > >>>
> > > >>> Note that #2, #3, #4, and #6 are all optional. If they are not
> > > promised,
> > > >>> we
> > > >>> can do extra work inside the application to accomplish what we
> need.
> > > >>> However, if they are promised (and if we depend on that promise),
> it
> > is
> > > >>> essential that the topic providers uphold those promises, as we may
> > not
> > > >>> be
> > > >>> in a position to verify them.
> > > >>>
> > > >>> Note also that if they make a promise, but it doesn't happen to
> line
> > up
> > > >>> with our needs (data is keyed by attr1, but we need it by attr2, or
> > > >>> timestamp is produce-time, but we need it by event-time, etc.),
> then
> > we
> > > >>> will have to go ahead and do that extra work internally anyway.
> This
> > > also
> > > >>> captures the situation in which two inputs are produced by
> different
> > > >>> providers, one of which meets our needs, and the other does not.
> The
> > > fact
> > > >>> that we can cope with this situation is the basis for my statement
> > that
> > > >>> we
> > > >>> do not require coordination among producers.
> > > >>>
> > > >>> (Key Point A): In terms of optimization, #4 and #6 are the most
> > > valuable.
> > > >>> If these characteristics happen to line up with our needs, then
> > > KStreams
> > > >>> can be incredibly efficient in both time and computational
> resources.
> > > >>>
> > > >>>   #5 is similar to knowing the schema in that it tells us whether
> the
> > > >>> computation we want to do is possible or not. For example, suppose
> we
> > > >>> have
> > > >>> a topic of "users", and we want to construct a table for querying.
> If
> > > the
> > > >>> user topic doesn't completely contain the dataset, we cannot
> > construct
> > > >>> the
> > > >>> table. Note that it doesn't matter whether the topic is compacted
> or
> > > not.
> > > >>> If the topic is complete, I can consume it starting at "earliest"
> and
> > > >>> build
> > > >>> my table. If it is not complete, I can do other computations on it.
> > In
> > > >>> both
> > > >>> cases, it may or may not be compacted; it just doesn't matter.
> > > >>>
> > > >>> On the output side, the roles are reversed. We provide (or not)
> > exactly
> > > >>> the
> > > >>> same set of guarantees to consumers of our outputs, and we likewise
> > > must
> > > >>> abide by the promises we make.
> > > >>>
> > > >>>
> > > >>> =================================
> > > >>> Partition Expansion
> > > >>>
> > > >>> With this formation in place, let's talk about partition expansion.
> > > >>>
> > > >>> Why do we have partitions in the first place? (let me know if I
> miss
> > > >>> something here)
> > > >>> * For logical data streams that are themselves partitionable, it
> > allows
> > > >>> producers to operate concurrently without coordination. For
> example,
> > > >>> streaming data from a sensor in a particle accelerator, the sensor
> > can
> > > be
> > > >>> subdivided into a grid and each grid square can produce
> independently
> > > to
> > > >>> a
> > > >>> different topic. This may be valuable because the total rate of
> data
> > > >>> exceeds the throughput to a single broker node or just because it
> > > allows
> > > >>> for failure of a single producer to cause the loss of only part of
> > the
> > > >>> data.
> > > >>> * The brokers can offer linearly scaling throughput on the number
> of
> > > >>> partitions by hosting each partition on a separate broker node
> > > >>> * The brokers can host topics that are too large to fit on a single
> > > >>> broker's storage by hosting some partitions on separate broker
> nodes
> > > >>> * In cases where the use case permits handling partitions
> > > independently,
> > > >>> consumers can have algorithmic simplicity by processing the data
> for
> > > >>> separate partitions in separate threads, avoiding costly and
> > > error-prone
> > > >>> concurrent coordination code
> > > >>> * In cases where the use case permits handling partitions
> > > independently,
> > > >>> consumers can exceed the total throughput of a single
> broker-consumer
> > > >>> pair
> > > >>> * Just to throw this in as well, in cases where some network links
> > are
> > > >>> less
> > > >>> costly than others (or lower latency or more reliable), such as
> when
> > > >>> brokers, producers, and consumers are running in racks: producer
> and
> > > >>> consumers can both benefit (independently) by locating work on each
> > > >>> partition in the same rack as the broker hosting that partition.
> > > >>>
> > > >>> In other words, we have three actors in this system: producers,
> > > brokers,
> > > >>> and consumers, and they all benefit from partitioning for different
> > > (but
> > > >>> sometimes related) reasons.
> > > >>>
> > > >>> This leads naturally to the conclusion that any of these actors may
> > > find
> > > >>> themselves in a sub-optimal or even dangerous situation in which
> > > >>> partition
> > > >>> expansion would be the solution. For example, the producer may find
> > > that
> > > >>> the existing throughput to the brokers is insufficient to match the
> > > data
> > > >>> rate, forcing them to drop data. Or a broker hosting a single
> > partition
> > > >>> may
> > > >>> be running out of disk space. Or a consumer node handling a single
> > > >>> partition cannot match the rate of production for that partition,
> > > causing
> > > >>> it to fall behind.
> > > >>>
> > > >>> I think it's reasonable to assume that all the actors in the system
> > > can't
> > > >>> just arbitrarily expand a topic's partition. I think it's
> reasonable
> > to
> > > >>> align this responsibility with the provider of the data, namely the
> > > >>> producer (the logical producer, not the KafkaProducer class).
> > > Therefore,
> > > >>> the producer who finds themselves in trouble can unilaterally
> expand
> > > >>> partitions to solve their problem.
> > > >>>
> > > >>> For the broker or a consumer in trouble, they have only one resort:
> > to
> > > >>> request the producer to expand partitions. This is where it's
> helpful
> > > to
> > > >>> assume the producer is friendly.
> > > >>>
> > > >>>
> > > >>> Now, let's look at how a KStreams application fits into this
> > scenario.
> > > >>>
> > > >>> (Key Point B1): As a consumer, we may find that the producer
> expands
> > > the
> > > >>> partitions of a topic, either for their own benefit or for the
> > brokers.
> > > >>> In
> > > >>> this situation, the expand operation MUST NOT violate any promises
> > that
> > > >>> have previously been made to us. This is the essence of KIP-253, to
> > > >>> ensure
> > > >>> the maintenance of promises #6 and #4. It would be great if the
> > > mechanics
> > > >>> of the expansion required no major disruption to processing or
> human
> > > >>> intervention.
> > > >>>
> > > >>> Specifically, let's say that input partition X splits into X1 and
> X2.
> > > #6
> > > >>> requires that the same old ordering guarantees of Kafka continue to
> > > hold.
> > > >>> Obviously, this is what KIP-253's title is about. #4 requires that
> we
> > > >>> either ensure that X1 and X2 are assigned to the same thread that
> was
> > > >>> previously assigned X OR that we immediately pause processing and
> > split
> > > >>> any
> > > >>> state such that it appears X1 and X2 were *always* separate
> > partitions.
> > > >>>
> > > >>> In other words, Option 1 is we treat X1 and X2 as still logically
> one
> > > >>> partition, equal to X. This is ideal, since in this scenario,
> > > partitions
> > > >>> are expanding for external reasons. We don't need to expand our
> > > >>> processing
> > > >>> to match. Option 2 requires a major disruption, since we'd have to
> > > pause
> > > >>> processing while we split our state. Clearly, KStreams or any other
> > > >>> stateful consumer would advocate for Option 1.
> > > >>>
> > > >>>
> > > >>> (Corollary to Key Point A): Still on the consumer side, we may find
> > > that
> > > >>> we
> > > >>> ourselves can benefit from partition expansion of an input. Since
> we
> > > can
> > > >>> cope with the absence of promise #4, partition expansion is not a
> > hard
> > > >>> requirement for us, but assuming we were already benefiting from
> the
> > > >>> major
> > > >>> performance optimizations afforded by #4, it would be nice to be
> able
> > > to
> > > >>> request the producer satisfy our request for partition expansion
> > **and
> > > to
> > > >>> be able to benefit from it**.
> > > >>>
> > > >>> What does it mean to be able to benefit from partition expansion?
> > > >>> Assuming
> > > >>> input topic partition X splits into X1 and X2, in this scenario, we
> > > >>> *would*
> > > >>> wish to be able to split our state such that it appears X1 and X2
> > were
> > > >>> *always* separate partitions. Of course, the conclusion of Key
> Point
> > B1
> > > >>> still applies: we should be able to continue operating on (X1+X2 =
> X)
> > > as
> > > >>> one partition while asynchronously building the state of X1 and X2
> > > >>> separately.
> > > >>>
> > > >>> When it comes to the mechanics of building the state of X1 and X2
> > > >>> separately, we have really just two high-level options. Either this
> > > >>> problem
> > > >>> is solved by Kafka itself, giving me a view in which X1 and X2 were
> > > >>> always
> > > >>> separate partitions, or I have to do it myself. The latter means
> > that I
> > > >>> have to take on substantially more complexity than I do today:
> > > >>> Bummer 1: My state has to be splittable to begin with, implying at
> > the
> > > >>> least that I need to be able to scan every record in my state, a
> > > >>> requirement that otherwise does not exist.
> > > >>> Bummer 2: After splitting the state  of X1 and X2, I need to be
> able
> > to
> > > >>> send at least one of those tasks, state included, to another
> > > application
> > > >>> node (in order to realize the benefit of the split). This is also a
> > > >>> requirement that does not currently exist.
> > > >>> Bummer 3: In order to actually perform the split, I must know and
> be
> > > able
> > > >>> to execute the exact same partition function the producer of my
> topic
> > > >>> uses.
> > > >>> This introduces a brand-new a priori commitment from my input
> > > producers:
> > > >>> (would-be #7: convey the partition function and abide by it). This
> > is a
> > > >>> big
> > > >>> restriction over #4, which only requires them to guarantee *that
> > there
> > > >>> is a
> > > >>> partition function*. Now they actually have to share the function
> > with
> > > >>> me.
> > > >>> And I have to be able to implement and execute it myself. And if
> the
> > > >>> producer wishes to refine the partition function for an existing
> > topic,
> > > >>> we
> > > >>> have another round of coordination, as they have to be sure that I,
> > and
> > > >>> all
> > > >>> other consumers, begin using the new function *before* they do.
> This
> > is
> > > >>> similar to the schema problem, with a similar set of solutions. We
> > > would
> > > >>> likely need a partition function registry and another magic byte on
> > > every
> > > >>> record to be sure we do this right. Not to mention some way to
> > express
> > > >>> arbitrary partitioning logic over arbitrary data in a way that is
> > > >>> portable
> > > >>> across programming languages.
> > > >>>
> > > >>> Alternatively, if Kafka gives me a view in which X1 and X2 were
> > always
> > > >>> separate, then I can create tasks for X1 and X2 and allow them to
> > > >>> bootstrap
> > > >>> while I continue to process X. Once they are ready, I can
> coordinate
> > a
> > > >>> transition to stop X's task and switch to X1 and X2. None of those
> > > >>> bummers
> > > >>> are present, so this is a significantly better option for me.
> > > >>>
> > > >>> (Key Point B2): As a (friendly) producer, we may once again want on
> > our
> > > >>> own
> > > >>> to expand partitions, or we may want to satisfy a request from the
> > > broker
> > > >>> or our consumers to do so. Again, we MUST NOT violate any promises
> we
> > > >>> have
> > > >>> previously given, and it would be great if the expansion required
> no
> > > >>> major
> > > >>> disruption to processing or human intervention. Additionally, since
> > we
> > > >>> are
> > > >>> actually driving the expansion, it would also be great if we could
> > > avoid
> > > >>> Bummer 3's coordination problems from the producer's perspective.
> > > >>>
> > > >>>
> > > >>> ======================================
> > > >>> Briefly: KStreams internals
> > > >>>
> > > >>> I'm pretty sure you were asking me to comment on the implementation
> > > >>> details
> > > >>> of KStreams, so I'll say a few words about it. The most important
> > thing
> > > >>> is
> > > >>> that KStreams is still very early in its development. Maybe
> > > "early-middle
> > > >>> maturity" is a good way to put it. We are actively discussing
> > > >>> more-or-less
> > > >>> major implementation changes to improve performance, footprint,
> > > >>> scalability, and ergonomics. So it may actually be misleading to
> > > discuss
> > > >>> deeply how KStreams internally uses Kafka topics.
> > > >>>
> > > >>> Nevertheless, it is currently true that KStreams uses Kafka topics
> > for
> > > >>> communication between some internal computation nodes. We partition
> > > these
> > > >>> topics as the base unit of concurrency granularity, so it would
> > > >>> potentially
> > > >>> be beneficial to be able to expand partitions for some of these
> > > internal
> > > >>> topics at some point. However, we can alternatively just
> > overpartition
> > > >>> these internal topics, creating in the low 100s of partitions
> instead
> > > of
> > > >>> the low 10s, for example. (Side note: if Kafka were someday to
> > support
> > > >>> higher numbers of partitions, we could expand this scheme to
> > > >>> overpartition
> > > >>> in the 1000s of partitions.) With the option to overpartition, we
> > don't
> > > >>> have a strong need for partition expansion internally.
> > > >>>
> > > >>> It is also currently true that KStreams uses Kafka to store a
> durable
> > > >>> changelog for some of our internal state stores. But we *only* read
> > > from
> > > >>> this topic *if* we need to restore a state store after node loss
> (or
> > to
> > > >>> maintain a hot mirror of the state store), so I think it's unlikely
> > > that
> > > >>> we
> > > >>> would ever make use of partition expansion on the changelog topics.
> > > >>>
> > > >>> But once again, I'd like to emphasize that we may choose an
> > alternative
> > > >>> implementation for either interprocess communication or state
> > > durability.
> > > >>>
> > > >>>
> > > >>> ======================================
> > > >>> Concluding thoughts
> > > >>>
> > > >>> I know this is a very long email, and I really appreciate you
> > sticking
> > > >>> with
> > > >>> me this long. I hope it was useful for syncing our mental picture
> of
> > > this
> > > >>> system. Also, you're far more knowledgeable than I am about this
> > system
> > > >>> and
> > > >>> this domain, so please correct me if I've said anything wrong.
> > > >>>
> > > >>> To me the key takeaways are that:
> > > >>> - KIP-253 satisfies all we need for correctness, since it contains
> > > >>> solutions to guarantee producers can abide by their promises w.r.t.
> > #4
> > > >>> and
> > > >>> #6.
> > > >>> - From Key Point A: #4 is actually optional for KIP-253, but
> without
> > > it,
> > > >>> we
> > > >>> lose a potentially valuable optimization in KStreams (and all other
> > > >>> consumer applications)
> > > >>> - From Corollary to Point A: Without low-level support for
> partition
> > > >>> expansion with backfill, we cannot employ requesting partition
> > > expansion
> > > >>> as
> > > >>> a consumer to improve application performance. In that case, to
> > ensure
> > > >>> performance scalability, we would have to discard for all KStreams
> > > >>> applications the performance optimization afforded by #4.
> > > >>> - From Key Point B1: After a partition split, we really need to be
> > able
> > > >>> to
> > > >>> seamlessly continue operating as if it had not split.
> > > >>> - From Key Point B2: Since KIP-253 allows us to maintain all our
> > > >>> promises,
> > > >>> we have the option of expanding partitions in the topics we
> produce.
> > > >>> Without a backfill operation, though, our consumers may not be able
> > to
> > > >>> realize the benefits of that split, if they were hoping to.
> > > >>>
> > > >>> In general, faced with the possibility of having to coordinate the
> > > >>> partition function with our inputs' producers or with our outputs'
> > > >>> consumers, I would personally lean toward overprovisioning and
> > > completely
> > > >>> avoiding resize for our use case. This doesn't mean that it's not
> > > useful
> > > >>> in
> > > >>> the ecosystem at large without backfill, just that it loses its
> > luster
> > > >>> for
> > > >>> me. It also means that we can no longer take advantage of some of
> our
> > > >>> current optimizations, and in fact that we must introduce an extra
> > hop
> > > of
> > > >>> repartitioning on every single input.
> > > >>>
> > > >>> I think this is actually a pretty good picture of the opportunities
> > and
> > > >>> challenges that other consumers and producers in the Kafka
> ecosystem
> > > will
> > > >>> face.
> > > >>>
> > > >>> I hope this helps!
> > > >>>
> > > >>> Thanks,
> > > >>> -John
> > > >>>
> > > >>> On Wed, Mar 28, 2018 at 11:51 AM, Jun Rao <ju...@confluent.io>
> wrote:
> > > >>>
> > > >>> Hi, John,
> > > >>>>
> > > >>>> I actually think it's important to think through how KStreams
> > handles
> > > >>>> partition expansion in this KIP. If we do decide that we truly
> need
> > > >>>> backfilling, it's much better to think through how to add it now,
> > > >>>> instead
> > > >>>> of retrofitting it later. It would be useful to outline how both
> > > >>>> existing
> > > >>>> KStreams jobs and new KStreams jobs work to see if backfilling is
> > > really
> > > >>>> needed.
> > > >>>>
> > > >>>> If we can figure out how KStreams works, at least we have one
> > > reference
> > > >>>> implementation for other stream processing frameworks that face
> the
> > > same
> > > >>>> issue.
> > > >>>>
> > > >>>> Thanks,
> > > >>>>
> > > >>>> Jun
> > > >>>>
> > > >>>>
> > > >>>> On Tue, Mar 27, 2018 at 4:56 PM, John Roesler <jo...@confluent.io>
> > > >>>> wrote:
> > > >>>>
> > > >>>> Hi Jun,
> > > >>>>>
> > > >>>>> That's a good point.
> > > >>>>>
> > > >>>>> Yeah, I don't think it would work too well for existing consumers
> > in
> > > >>>>>
> > > >>>> the
> > > >>>
> > > >>>> middle of gen 0 to try and switch to a newly backfilled prefix of
> > gen
> > > >>>>>
> > > >>>> 1.
> > > >>>
> > > >>>> They probably just need to finish up until they get to the end of
> > gen
> > > 0
> > > >>>>>
> > > >>>> and
> > > >>>>
> > > >>>>> transition just as if there were no backfill available yet.
> > > >>>>>
> > > >>>>> This isn't terrible, since consumer applications that care about
> > > >>>>>
> > > >>>> scaling
> > > >>>
> > > >>>> up
> > > >>>>
> > > >>>>> to match a freshly split partition would wait until after the
> > > backfill
> > > >>>>>
> > > >>>> is
> > > >>>
> > > >>>> available to scale up. The consumer that starts out in gen=0,
> part=0
> > > is
> > > >>>>> going to be stuck with part=0 and part=3 in gen=1 in my example
> > > >>>>>
> > > >>>> regardless
> > > >>>>
> > > >>>>> of whether they finish scanning gen=0 before or after the
> backfill
> > is
> > > >>>>> available.
> > > >>>>>
> > > >>>>> The broker knowing when it's ok to delete gen 0, including its
> > offset
> > > >>>>> mappings, is a big issue, though. I don't have any immediate
> ideas
> > > for
> > > >>>>> solving it, but it doesn't feel impossible. Hopefully, you agree
> > this
> > > >>>>>
> > > >>>> is
> > > >>>
> > > >>>> outside of KIP-253's scope, so maybe we don't need to worry about
> it
> > > >>>>>
> > > >>>> right
> > > >>>>
> > > >>>>> now.
> > > >>>>>
> > > >>>>> I do agree that reshuffling in KStreams effectively solves the
> > > >>>>>
> > > >>>> scalability
> > > >>>>
> > > >>>>> problem as well, as it decouples the partition count (and the
> > > partition
> > > >>>>> scheme) upstream from the parallelism of the streams application.
> > > >>>>>
> > > >>>> Likely,
> > > >>>
> > > >>>> we will do this in any case. I'm predominantly advocating for
> > > follow-on
> > > >>>>> work to enable backfill for the *other* Kafka users that are not
> > > >>>>>
> > > >>>> KStreams.
> > > >>>>
> > > >>>>> Thanks for your consideration,
> > > >>>>> -John
> > > >>>>>
> > > >>>>> On Tue, Mar 27, 2018 at 6:19 PM, Jun Rao <ju...@confluent.io>
> wrote:
> > > >>>>>
> > > >>>>> Hi, John,
> > > >>>>>>
> > > >>>>>> Thanks for the reply. I agree that the backfill approach works
> > > >>>>>>
> > > >>>>> cleaner
> > > >>>
> > > >>>> for
> > > >>>>>
> > > >>>>>> newly started consumers. I am just not sure if it's a good
> > primitive
> > > >>>>>>
> > > >>>>> to
> > > >>>
> > > >>>> support for existing consumers. One of the challenges that I see
> is
> > > >>>>>>
> > > >>>>> the
> > > >>>
> > > >>>> remapping of the offsets. In your approach, we need to copy the
> > > >>>>>>
> > > >>>>> existing
> > > >>>>
> > > >>>>> records from the partitions in generation 0 to generation 1.
> Those
> > > >>>>>>
> > > >>>>> records
> > > >>>>>
> > > >>>>>> will get different offsets in the new generation. The broker
> will
> > > >>>>>>
> > > >>>>> have
> > > >>>
> > > >>>> to
> > > >>>>
> > > >>>>> store those offset mappings somewhere. When the backfill
> completes,
> > > >>>>>>
> > > >>>>> you
> > > >>>
> > > >>>> can
> > > >>>>>
> > > >>>>>> delete generation 0's data. However, the broker can't throw away
> > the
> > > >>>>>>
> > > >>>>> offset
> > > >>>>>
> > > >>>>>> mappings immediately since it doesn't know if there is any
> > existing
> > > >>>>>> consumer still consuming generation 0's records. In a compacted
> > > >>>>>>
> > > >>>>> topic,
> > > >>>
> > > >>>> the
> > > >>>>>
> > > >>>>>> broker probably can only safely remove the offset mappings when
> > all
> > > >>>>>>
> > > >>>>> records
> > > >>>>>
> > > >>>>>> in generation 0 are removed by the cleaner. This may never
> happen
> > > >>>>>>
> > > >>>>> though.
> > > >>>>
> > > >>>>> If we reshuffle the input inside a KStreams job, it obviates the
> > need
> > > >>>>>>
> > > >>>>> for
> > > >>>>
> > > >>>>> offset remapping on the broker.
> > > >>>>>>
> > > >>>>>> Jun
> > > >>>>>>
> > > >>>>>> On Tue, Mar 27, 2018 at 11:34 AM, John Roesler <
> john@confluent.io
> > >
> > > >>>>>>
> > > >>>>> wrote:
> > > >>>>>
> > > >>>>>> Hey Dong and Jun,
> > > >>>>>>>
> > > >>>>>>> Thanks for the thoughtful responses. If you don't mind, I'll
> mix
> > my
> > > >>>>>>>
> > > >>>>>> replies
> > > >>>>>>
> > > >>>>>>> together to try for a coherent response. I'm not too familiar
> > with
> > > >>>>>>> mailing-list etiquette, though.
> > > >>>>>>>
> > > >>>>>>> I'm going to keep numbering my points because it makes it easy
> > for
> > > >>>>>>>
> > > >>>>>> you
> > > >>>>
> > > >>>>> all
> > > >>>>>>
> > > >>>>>>> to respond.
> > > >>>>>>>
> > > >>>>>>> Point 1:
> > > >>>>>>> As I read it, KIP-253 is *just* about properly fencing the
> > > >>>>>>>
> > > >>>>>> producers
> > > >>>
> > > >>>> and
> > > >>>>>
> > > >>>>>> consumers so that you preserve the correct ordering of records
> > > >>>>>>>
> > > >>>>>> during
> > > >>>
> > > >>>> partition expansion. This is clearly necessary regardless of
> > > >>>>>>>
> > > >>>>>> anything
> > > >>>
> > > >>>> else
> > > >>>>>>
> > > >>>>>>> we discuss. I think this whole discussion about backfill,
> > > >>>>>>>
> > > >>>>>> consumers,
> > > >>>
> > > >>>> streams, etc., is beyond the scope of KIP-253. But it would be
> > > >>>>>>>
> > > >>>>>> cumbersome
> > > >>>>>
> > > >>>>>> to start a new thread at this point.
> > > >>>>>>>
> > > >>>>>>> I had missed KIP-253's Proposed Change #9 among all the
> > details...
> > > >>>>>>>
> > > >>>>>> I
> > > >>>
> > > >>>> think
> > > >>>>>>
> > > >>>>>>> this is a nice addition to the proposal. One thought is that
> it's
> > > >>>>>>>
> > > >>>>>> actually
> > > >>>>>>
> > > >>>>>>> irrelevant whether the hash function is linear. This is simply
> an
> > > >>>>>>>
> > > >>>>>> algorithm
> > > >>>>>>
> > > >>>>>>> for moving a key from one partition to another, so the type of
> > hash
> > > >>>>>>> function need not be a precondition. In fact, it also doesn't
> > > >>>>>>>
> > > >>>>>> matter
> > > >>>
> > > >>>> whether the topic is compacted or not, the algorithm works
> > > >>>>>>>
> > > >>>>>> regardless.
> > > >>>>
> > > >>>>> I think this is a good algorithm to keep in mind, as it might
> > > >>>>>>>
> > > >>>>>> solve a
> > > >>>
> > > >>>> variety of problems, but it does have a downside: that the
> producer
> > > >>>>>>>
> > > >>>>>> won't
> > > >>>>>
> > > >>>>>> know whether or not K1 was actually in P1, it just knows that K1
> > > >>>>>>>
> > > >>>>>> was
> > > >>>
> > > >>>> in
> > > >>>>
> > > >>>>> P1's keyspace before the new epoch. Therefore, it will have to
> > > >>>>>>> pessimistically send (K1,null) to P1 just in case. But the next
> > > >>>>>>>
> > > >>>>>> time
> > > >>>
> > > >>>> K1
> > > >>>>
> > > >>>>> comes along, the producer *also* won't remember that it already
> > > >>>>>>>
> > > >>>>>> retracted
> > > >>>>>
> > > >>>>>> K1 from P1, so it will have to send (K1,null) *again*. By
> > > >>>>>>>
> > > >>>>>> extension,
> > > >>>
> > > >>>> every
> > > >>>>>>
> > > >>>>>>> time the producer sends to P2, it will also have to send a
> > > >>>>>>>
> > > >>>>>> tombstone
> > > >>>
> > > >>>> to
> > > >>>>
> > > >>>>> P1,
> > > >>>>>>
> > > >>>>>>> which is a pretty big burden. To make the situation worse, if
> > there
> > > >>>>>>>
> > > >>>>>> is
> > > >>>>
> > > >>>>> a
> > > >>>>>
> > > >>>>>> second split, say P2 becomes P2 and P3, then any key Kx
> belonging
> > > >>>>>>>
> > > >>>>>> to
> > > >>>
> > > >>>> P3
> > > >>>>
> > > >>>>> will also have to be retracted from P2 *and* P1, since the
> producer
> > > >>>>>>>
> > > >>>>>> can't
> > > >>>>>
> > > >>>>>> know whether Kx had been last written to P2 or P1. Over a long
> > > >>>>>>>
> > > >>>>>> period
> > > >>>
> > > >>>> of
> > > >>>>>
> > > >>>>>> time, this clearly becomes a issue, as the producer must send an
> > > >>>>>>>
> > > >>>>>> arbitrary
> > > >>>>>>
> > > >>>>>>> number of retractions along with every update.
> > > >>>>>>>
> > > >>>>>>> In contrast, the proposed backfill operation has an end, and
> > after
> > > >>>>>>>
> > > >>>>>> it
> > > >>>
> > > >>>> ends,
> > > >>>>>>
> > > >>>>>>> everyone can afford to forget that there ever was a different
> > > >>>>>>>
> > > >>>>>> partition
> > > >>>>
> > > >>>>> layout.
> > > >>>>>>>
> > > >>>>>>> Really, though, figuring out how to split compacted topics is
> > > >>>>>>>
> > > >>>>>> beyond
> > > >>>
> > > >>>> the
> > > >>>>>
> > > >>>>>> scope of KIP-253, so I'm not sure #9 really even needs to be in
> > > >>>>>>>
> > > >>>>>> this
> > > >>>
> > > >>>> KIP...
> > > >>>>>>
> > > >>>>>>> We do need in-order delivery during partition expansion. It
> would
> > > >>>>>>>
> > > >>>>>> be
> > > >>>
> > > >>>> fine
> > > >>>>>
> > > >>>>>> by me to say that you *cannot* expand partitions of a
> > log-compacted
> > > >>>>>>>
> > > >>>>>> topic
> > > >>>>>
> > > >>>>>> and call it a day. I think it would be better to tackle that in
> > > >>>>>>>
> > > >>>>>> another
> > > >>>>
> > > >>>>> KIP.
> > > >>>>>>>
> > > >>>>>>>
> > > >>>>>>> Point 2:
> > > >>>>>>> Regarding whether the consumer re-shuffles its inputs, this is
> > > >>>>>>>
> > > >>>>>> always
> > > >>>
> > > >>>> on
> > > >>>>>
> > > >>>>>> the table; any consumer who wants to re-shuffle its input is
> free
> > > >>>>>>>
> > > >>>>>> to
> > > >>>
> > > >>>> do
> > > >>>>
> > > >>>>> so.
> > > >>>>>>
> > > >>>>>>> But this is currently not required. It's just that the current
> > > >>>>>>>
> > > >>>>>> high-level
> > > >>>>>
> > > >>>>>> story with Kafka encourages the use of partitions as a unit of
> > > >>>>>>>
> > > >>>>>> concurrency.
> > > >>>>>>
> > > >>>>>>> As long as consumers are single-threaded, they can happily
> > consume
> > > >>>>>>>
> > > >>>>>> a
> > > >>>
> > > >>>> single
> > > >>>>>>
> > > >>>>>>> partition without concurrency control of any kind. This is a
> key
> > > >>>>>>>
> > > >>>>>> aspect
> > > >>>>
> > > >>>>> to
> > > >>>>>>
> > > >>>>>>> this system that lets folks design high-throughput systems on
> top
> > > >>>>>>>
> > > >>>>>> of
> > > >>>
> > > >>>> it
> > > >>>>
> > > >>>>> surprisingly easily. If all consumers were instead
> > > >>>>>>>
> > > >>>>>> encouraged/required
> > > >>>>
> > > >>>>> to
> > > >>>>>
> > > >>>>>> implement a repartition of their own, then the consumer becomes
> > > >>>>>>> significantly more complex, requiring either the consumer to
> > first
> > > >>>>>>>
> > > >>>>>> produce
> > > >>>>>>
> > > >>>>>>> to its own intermediate repartition topic or to ensure that
> > > >>>>>>>
> > > >>>>>> consumer
> > > >>>
> > > >>>> threads have a reliable, high-bandwith channel of communication
> > > >>>>>>>
> > > >>>>>> with
> > > >>>
> > > >>>> every
> > > >>>>>>
> > > >>>>>>> other consumer thread.
> > > >>>>>>>
> > > >>>>>>> Either of those tradeoffs may be reasonable for a particular
> user
> > > >>>>>>>
> > > >>>>>> of
> > > >>>
> > > >>>> Kafka,
> > > >>>>>>
> > > >>>>>>> but I don't know if we're in a position to say that they are
> > > >>>>>>>
> > > >>>>>> reasonable
> > > >>>>
> > > >>>>> for
> > > >>>>>>
> > > >>>>>>> *every* user of Kafka.
> > > >>>>>>>
> > > >>>>>>>
> > > >>>>>>> Point 3:
> > > >>>>>>> Regarding Jun's point about this use case, "(3) stateful and
> > > >>>>>>>
> > > >>>>>> maintaining
> > > >>>>>
> > > >>>>>> the
> > > >>>>>>> states in a local store", I agree that they may use a framework
> > > >>>>>>>
> > > >>>>>> *like*
> > > >>>>
> > > >>>>> Kafka Streams, but that is not the same as using Kafka Streams.
> > > >>>>>>>
> > > >>>>>> This
> > > >>>
> > > >>>> is
> > > >>>>
> > > >>>>> why
> > > >>>>>>
> > > >>>>>>> I think it's better to solve it in Core: because it is then
> > solved
> > > >>>>>>>
> > > >>>>>> for
> > > >>>>
> > > >>>>> KStreams and also for everything else that facilitates local
> state
> > > >>>>>>> maintenance. To me, Streams is a member of the category of
> > "stream
> > > >>>>>>> processing frameworks", which is itself a subcategory of
> "things
> > > >>>>>>>
> > > >>>>>> requiring
> > > >>>>>>
> > > >>>>>>> local state maintenence". I'm not sure if it makes sense to
> > assert
> > > >>>>>>>
> > > >>>>>> that
> > > >>>>
> > > >>>>> Streams is a sufficient and practical replacement for everything
> in
> > > >>>>>>>
> > > >>>>>> "things
> > > >>>>>>
> > > >>>>>>> requiring local state maintenence".
> > > >>>>>>>
> > > >>>>>>> But, yes, I do agree that per-key ordering is an absolute
> > > >>>>>>>
> > > >>>>>> requirement,
> > > >>>>
> > > >>>>> therefore I think that KIP-253 itself is a necessary step.
> > > >>>>>>>
> > > >>>>>> Regarding
> > > >>>
> > > >>>> the
> > > >>>>>
> > > >>>>>> coupling of the state store partitioning to the topic
> > partitioning,
> > > >>>>>>>
> > > >>>>>> yes,
> > > >>>>>
> > > >>>>>> this is an issue we are discussing solutions to right now. We
> may
> > > >>>>>>>
> > > >>>>>> go
> > > >>>
> > > >>>> ahead
> > > >>>>>>
> > > >>>>>>> and introduce an overpartition layer on our inputs to solve it,
> > but
> > > >>>>>>>
> > > >>>>>> then
> > > >>>>>
> > > >>>>>> again, if we get the ability to split partitions with backfill,
> we
> > > >>>>>>>
> > > >>>>>> may
> > > >>>>
> > > >>>>> not
> > > >>>>>>
> > > >>>>>>> need to!
> > > >>>>>>>
> > > >>>>>>>
> > > >>>>>>> Point 4:
> > > >>>>>>> On this:
> > > >>>>>>>
> > > >>>>>>> Regarding thought 2: If we don't care about the stream
> use-case,
> > > >>>>>>>>
> > > >>>>>>> then
> > > >>>>
> > > >>>>> the
> > > >>>>>>
> > > >>>>>>> current KIP probably has already addressed problem without
> > > >>>>>>>>
> > > >>>>>>> requiring
> > > >>>>
> > > >>>>> consumer to know the partition function. If we care about the
> > > >>>>>>>>
> > > >>>>>>> stream
> > > >>>>
> > > >>>>> use-case, we already need coordination across producers of
> > > >>>>>>>>
> > > >>>>>>> different
> > > >>>>
> > > >>>>> topics, i.e. the same partition function needs to be used by
> > > >>>>>>>>
> > > >>>>>>> producers
> > > >>>>>
> > > >>>>>> of
> > > >>>>>>
> > > >>>>>>> topics A and B in order to join topics A and B. Thus, it might
> be
> > > >>>>>>>> reasonable to extend coordination a bit and say we need
> > > >>>>>>>>
> > > >>>>>>> coordination
> > > >>>>
> > > >>>>> across
> > > >>>>>>>
> > > >>>>>>>> clients (i.e. producer and consumer), such that consumer knows
> > > >>>>>>>>
> > > >>>>>>> the
> > > >>>
> > > >>>> partition function used by producer. If we do so, then we can let
> > > >>>>>>>>
> > > >>>>>>> consumer
> > > >>>>>>>
> > > >>>>>>>> re-copy data for the change log topic using the same partition
> > > >>>>>>>>
> > > >>>>>>> function
> > > >>>>>
> > > >>>>>> as
> > > >>>>>>>
> > > >>>>>>>> producer. This approach has lower overhead as compared to
> having
> > > >>>>>>>>
> > > >>>>>>> producer
> > > >>>>>>
> > > >>>>>>> re-copy data of the input topic.
> > > >>>>>>>> Also, producer currently does not need to know the data
> already
> > > >>>>>>>>
> > > >>>>>>> produced
> > > >>>>>>
> > > >>>>>>> to
> > > >>>>>>>
> > > >>>>>>>> the topic. If we let producer split/merge partition, it would
> > > >>>>>>>>
> > > >>>>>>> require
> > > >>>>
> > > >>>>> producer to consume the existing data, which intuitively is the
> > > >>>>>>>>
> > > >>>>>>> task
> > > >>>>
> > > >>>>> of
> > > >>>>>
> > > >>>>>> consumer.
> > > >>>>>>>>
> > > >>>>>>>
> > > >>>>>>> I think we do care about use cases *like* Streams, I just don't
> > > >>>>>>>
> > > >>>>>> think
> > > >>>
> > > >>>> we
> > > >>>>>
> > > >>>>>> should rely on Streams to implement a feature of Core like
> > > >>>>>>>
> > > >>>>>> partition
> > > >>>
> > > >>>> expansion.
> > > >>>>>>>
> > > >>>>>>> Note, though, that we (Streams) do not require coordination
> > across
> > > >>>>>>> producers. If two topics are certified to be co-partitioned,
> then
> > > >>>>>>>
> > > >>>>>> Streams
> > > >>>>>
> > > >>>>>> apps can make use of that knowledge to optimize their topology
> > > >>>>>>>
> > > >>>>>> (skipping
> > > >>>>>
> > > >>>>>> a
> > > >>>>>>
> > > >>>>>>> repartition). But if they don't know whether they are
> > > >>>>>>>
> > > >>>>>> co-partitioned,
> > > >>>
> > > >>>> then
> > > >>>>>>
> > > >>>>>>> they'd better go ahead and repartition within the topology.
> This
> > is
> > > >>>>>>>
> > > >>>>>> the
> > > >>>>
> > > >>>>> current state.
> > > >>>>>>>
> > > >>>>>>> A huge selling point of Kafka is enabling different parts of
> > > >>>>>>>
> > > >>>>>> loosely
> > > >>>
> > > >>>> coupled organizations to produce and consume data independently.
> > > >>>>>>>
> > > >>>>>> Some
> > > >>>
> > > >>>> coordination between producers and consumers is necessary, like
> > > >>>>>>> coordinating on the names of topics and their schemas. But
> > Kafka's
> > > >>>>>>>
> > > >>>>>> value
> > > >>>>>
> > > >>>>>> proposition w.r.t. ESBs, etc. is inversely proportional to the
> > > >>>>>>>
> > > >>>>>> amount
> > > >>>
> > > >>>> of
> > > >>>>>
> > > >>>>>> coordination required. I think it behooves us to be extremely
> > > >>>>>>>
> > > >>>>>> skeptical
> > > >>>>
> > > >>>>> about introducing any coordination beyond correctness protocols.
> > > >>>>>>>
> > > >>>>>>> Asking producers and consumers, or even two different
> producers,
> > to
> > > >>>>>>>
> > > >>>>>> share
> > > >>>>>
> > > >>>>>> code like the partition function is a pretty huge ask. What if
> > they
> > > >>>>>>>
> > > >>>>>> are
> > > >>>>
> > > >>>>> using different languages?
> > > >>>>>>>
> > > >>>>>>> Comparing organizational overhead vs computational overhead,
> > there
> > > >>>>>>>
> > > >>>>>> are
> > > >>>>
> > > >>>>> maybe two orders of magnitude difference between them. In other
> > > >>>>>>>
> > > >>>>>> words,
> > > >>>>
> > > >>>>> I
> > > >>>>>
> > > >>>>>> would happily take on the (linear) overhead of having the
> producer
> > > >>>>>>>
> > > >>>>>> re-copy
> > > >>>>>>
> > > >>>>>>> the data once during a re-partition in order to save the
> > > >>>>>>>
> > > >>>>>> organizational
> > > >>>>
> > > >>>>> overhead of tying all the producers and consumers together across
> > > >>>>>>>
> > > >>>>>> multiple
> > > >>>>>>
> > > >>>>>>> boundaries.
> > > >>>>>>>
> > > >>>>>>> On that last paragraph: note that the producer *did* know the
> > data
> > > >>>>>>>
> > > >>>>>> it
> > > >>>
> > > >>>> already produced. It handled it the first time around. Asking it
> to
> > > >>>>>>> re-produce it into a new partition layout is squarely within
> its
> > > >>>>>>>
> > > >>>>>> scope
> > > >>>>
> > > >>>>> of
> > > >>>>>
> > > >>>>>> capabilities. Contrast this with the alternative, asking the
> > > >>>>>>>
> > > >>>>>> consumer
> > > >>>
> > > >>>> to
> > > >>>>>
> > > >>>>>> re-partition the data. I think this is even less intuitive, when
> > > >>>>>>>
> > > >>>>>> the
> > > >>>
> > > >>>> partition function belongs to the producer.
> > > >>>>>>>
> > > >>>>>>>
> > > >>>>>>> Point 5:
> > > >>>>>>> Dong asked this:
> > > >>>>>>>
> > > >>>>>>> For stream use-case that needs to increase consumer number, the
> > > >>>>>>>> existing consumer can backfill the existing data in the change
> > > >>>>>>>>
> > > >>>>>>> log
> > > >>>
> > > >>>> topic
> > > >>>>>>
> > > >>>>>>> to
> > > >>>>>>>
> > > >>>>>>>> the same change log topic with the new partition number,
> before
> > > >>>>>>>>
> > > >>>>>>> the
> > > >>>
> > > >>>> new
> > > >>>>>
> > > >>>>>> set
> > > >>>>>>>
> > > >>>>>>>> of consumers bootstrap state from the new partitions of the
> > > >>>>>>>>
> > > >>>>>>> change
> > > >>>
> > > >>>> log
> > > >>>>>
> > > >>>>>> topic, right?
> > > >>>>>>>>
> > > >>>>>>>
> > > >>>>>>> In this sense, the "consumer" is actually the producer of the
> > > >>>>>>>
> > > >>>>>> changelog
> > > >>>>
> > > >>>>> topic, so if we support partition expansion + backfill as a
> > > >>>>>>>
> > > >>>>>> producer/broker
> > > >>>>>>
> > > >>>>>>> operation, then it would be very straightforward for Streams to
> > > >>>>>>>
> > > >>>>>> split a
> > > >>>>
> > > >>>>> state store. As you say, they would simply instruct the broker to
> > > >>>>>>>
> > > >>>>>> split
> > > >>>>
> > > >>>>> the
> > > >>>>>>
> > > >>>>>>> changelog topic's partitions, then backfill. Once the backfill
> is
> > > >>>>>>>
> > > >>>>>> ready,
> > > >>>>>
> > > >>>>>> they can create a new crop of StandbyTasks to bootstrap the more
> > > >>>>>>>
> > > >>>>>> granular
> > > >>>>>
> > > >>>>>> state stores and finally switch over to them when they are
> ready.
> > > >>>>>>>
> > > >>>>>>> But this actually seems to be an argument in favor of
> > > >>>>>>>
> > > >>>>>> split+backfill,
> > > >>>
> > > >>>> so
> > > >>>>>
> > > >>>>>> maybe I missed the point.
> > > >>>>>>>
> > > >>>>>>> You also asked me to explain why copying the "input" topic is
> > > >>>>>>>
> > > >>>>>> better
> > > >>>
> > > >>>> than
> > > >>>>>
> > > >>>>>> copying the "changelog" topic. I think they are totally
> > > >>>>>>>
> > > >>>>>> independent,
> > > >>>
> > > >>>> actually. For one thing, you can't depend on the existence of a
> > > >>>>>>>
> > > >>>>>> "changelog"
> > > >>>>>>
> > > >>>>>>> topic in general, only within Streams, but Kafka's user base
> > > >>>>>>>
> > > >>>>>> clearly
> > > >>>
> > > >>>> exceeds Streams's user base. Plus, you actually also can't depend
> > > >>>>>>>
> > > >>>>>> on
> > > >>>
> > > >>>> the
> > > >>>>>
> > > >>>>>> existence of a changelog topic within Streams, since that is an
> > > >>>>>>>
> > > >>>>>> optional
> > > >>>>>
> > > >>>>>> feature of *some* state store implementations. Even in the
> > > >>>>>>>
> > > >>>>>> situation
> > > >>>
> > > >>>> where
> > > >>>>>>
> > > >>>>>>> you do have a changelog topic in Streams, there may be use
> cases
> > > >>>>>>>
> > > >>>>>> where
> > > >>>>
> > > >>>>> it
> > > >>>>>
> > > >>>>>> makes sense to expand the partitions of just the input, or just
> > the
> > > >>>>>>> changelog.
> > > >>>>>>>
> > > >>>>>>> The ask for a Core feature of split+backfill is really about
> > > >>>>>>>
> > > >>>>>> supporting
> > > >>>>
> > > >>>>> the
> > > >>>>>>
> > > >>>>>>> use case of splitting partitions in log-compacted topics,
> > > >>>>>>>
> > > >>>>>> regardless
> > > >>>
> > > >>>> of
> > > >>>>
> > > >>>>> whether that topic is an "input" or a "changelog" or anything
> else
> > > >>>>>>>
> > > >>>>>> for
> > > >>>>
> > > >>>>> that
> > > >>>>>>
> > > >>>>>>> matter.
> > > >>>>>>>
> > > >>>>>>>
> > > >>>>>>> Point 6:
> > > >>>>>>> On the concern about the performance overhead of copying data
> > > >>>>>>>
> > > >>>>>> between
> > > >>>
> > > >>>> the
> > > >>>>>
> > > >>>>>> brokers, I think it's actually a bit overestimated. Splitting a
> > > >>>>>>>
> > > >>>>>> topic's
> > > >>>>
> > > >>>>> partition is probably rare, certainly rarer in general than
> > > >>>>>>>
> > > >>>>>> bootstrapping
> > > >>>>>
> > > >>>>>> new consumers on that topic. If "bootstrapping new consumers"
> > means
> > > >>>>>>>
> > > >>>>>> that
> > > >>>>>
> > > >>>>>> they have to re-shuffle the data before they consume it, then
> you
> > > >>>>>>>
> > > >>>>>> wind
> > > >>>>
> > > >>>>> up
> > > >>>>>
> > > >>>>>> copying the same record multiple times:
> > > >>>>>>>
> > > >>>>>>> (broker: input topic) -> (initial consumer) -> (broker:
> > repartition
> > > >>>>>>>
> > > >>>>>> topic)
> > > >>>>>>
> > > >>>>>>> -> (real consumer)
> > > >>>>>>>
> > > >>>>>>> That's 3x, and it's also 3x for every new record after the
> split
> > as
> > > >>>>>>>
> > > >>>>>> well,
> > > >>>>>
> > > >>>>>> since you don't get to stop repartitioning/reshuffling once you
> > > >>>>>>>
> > > >>>>>> start.
> > > >>>>
> > > >>>>> Whereas if you do a backfill in something like the procedure I
> > > >>>>>>>
> > > >>>>>> outlined,
> > > >>>>>
> > > >>>>>> you only copy the prefix of the partition before the split, and
> > you
> > > >>>>>>>
> > > >>>>>> send
> > > >>>>>
> > > >>>>>> it
> > > >>>>>>
> > > >>>>>>> once to the producer and then once to the new generation
> > partition.
> > > >>>>>>>
> > > >>>>>> Plus,
> > > >>>>>
> > > >>>>>> assuming we're splitting the partition for the benefit of
> > > >>>>>>>
> > > >>>>>> consumers,
> > > >>>
> > > >>>> there's no reason we can't co-locate the post-split partitions on
> > > >>>>>>>
> > > >>>>>> the
> > > >>>
> > > >>>> same
> > > >>>>>>
> > > >>>>>>> host as the pre-split partition, making the second copy a local
> > > >>>>>>>
> > > >>>>>> filesystem
> > > >>>>>>
> > > >>>>>>> operation.
> > > >>>>>>>
> > > >>>>>>> Even if you follow these two copies up with bootstrapping a new
> > > >>>>>>>
> > > >>>>>> consumer,
> > > >>>>>
> > > >>>>>> it's still rare for this to occur, so you get to amortize these
> > > >>>>>>>
> > > >>>>>> copies
> > > >>>>
> > > >>>>> over
> > > >>>>>>
> > > >>>>>>> the lifetime of the topic, whereas a reshuffle just keeps
> making
> > > >>>>>>>
> > > >>>>>> copies
> > > >>>>
> > > >>>>> for
> > > >>>>>>
> > > >>>>>>> every new event.
> > > >>>>>>>
> > > >>>>>>> And finally, I really do think that regardless of any
> performance
> > > >>>>>>>
> > > >>>>>> concerns
> > > >>>>>>
> > > >>>>>>> about this operation, if it preserves loose organizational
> > > >>>>>>>
> > > >>>>>> coupling,
> > > >>>
> > > >>>> it
> > > >>>>
> > > >>>>> is
> > > >>>>>>
> > > >>>>>>> certainly worth it.
> > > >>>>>>>
> > > >>>>>>>
> > > >>>>>>> In conclusion:
> > > >>>>>>> It might actually be a good idea for us to clarify the scope of
> > > >>>>>>>
> > > >>>>>> KIP-253.
> > > >>>>>
> > > >>>>>> If
> > > >>>>>>
> > > >>>>>>> we're all agreed that it's a good algorithm for allowing
> in-order
> > > >>>>>>>
> > > >>>>>> message
> > > >>>>>
> > > >>>>>> delivery during partition expansion, then we can continue this
> > > >>>>>>>
> > > >>>>>> discussion
> > > >>>>>
> > > >>>>>> as a new KIP, something like "backfill with partition
> expansion".
> > > >>>>>>>
> > > >>>>>> This
> > > >>>>
> > > >>>>> would let Dong proceed with KIP-253. On the other hand, if it
> seems
> > > >>>>>>>
> > > >>>>>> like
> > > >>>>>
> > > >>>>>> this conversation may alter the design of KIP-253, then maybe we
> > > >>>>>>>
> > > >>>>>> *should*
> > > >>>>>
> > > >>>>>> just finish working it out.
> > > >>>>>>>
> > > >>>>>>> For my part, my only concern about KIP-253 is the one I raised
> > > >>>>>>>
> > > >>>>>> earlier.
> > > >>>>
> > > >>>>> Thanks again, all, for considering these points,
> > > >>>>>>> -John
> > > >>>>>>>
> > > >>>>>>>
> > > >>>>>>> On Tue, Mar 27, 2018 at 2:10 AM, Dong Lin <lindong28@gmail.com
> >
> > > >>>>>>>
> > > >>>>>> wrote:
> > > >>>>
> > > >>>>> On Tue, Mar 27, 2018 at 12:04 AM, Dong Lin <li...@gmail.com>
> > > >>>>>>>>
> > > >>>>>>> wrote:
> > > >>>>>>
> > > >>>>>>> Hey Jan,
> > > >>>>>>>>>
> > > >>>>>>>>> Thanks for the enthusiasm in improving Kafka's design. Now
> > > >>>>>>>>>
> > > >>>>>>>> that I
> > > >>>
> > > >>>> have
> > > >>>>>>
> > > >>>>>>> read through your discussion with Jun, here are my thoughts:
> > > >>>>>>>>>
> > > >>>>>>>>> - The latest proposal should with log compacted topics by
> > > >>>>>>>>>
> > > >>>>>>>> properly
> > > >>>>
> > > >>>>> deleting old messages after a new message with the same key is
> > > >>>>>>>>>
> > > >>>>>>>> produced.
> > > >>>>>>>
> > > >>>>>>>> So
> > > >>>>>>>>
> > > >>>>>>>>> it is probably not a concern anymore. Could you comment if
> > > >>>>>>>>>
> > > >>>>>>>> there
> > > >>>
> > > >>>> is
> > > >>>>
> > > >>>>> still
> > > >>>>>>>
> > > >>>>>>>> issue?
> > > >>>>>>>>>
> > > >>>>>>>>> - I wrote the SEP-5 and I am pretty familiar with the
> > > >>>>>>>>>
> > > >>>>>>>> motivation
> > > >>
> > > >>
> > >
> >
>

Re: [DISCUSS] KIP-253: Support in-order message delivery with partition expansion

Posted by Dong Lin <li...@gmail.com>.
Hey Jeff,

Thanks for the review. The scheme for expanding processors of the stateful
processing job is described in "Support processor expansion" section in
KIP-287 (link
<https://cwiki.apache.org/confluence/display/KAFKA/KIP-287%3A+Support+partition+and+processor+expansion+for+stateful+processing+jobs#KIP-287:Supportpartitionandprocessorexpansionforstatefulprocessingjobs-Supportprocessorexpansion>).
In particular, we will expand the partitions of the input topics before
expanding processors of the processing job. While the new processor is
catching up, the producer would already be producing using the new
partitioning scheme. Does this answer your question?

Thanks,
Dong


On Sat, Apr 14, 2018 at 1:44 PM, Jeff Chao <jc...@salesforce.com> wrote:

> Hi, I had a question from Monday's meeting. The current mechanism, as Ray's
> notes points out, is to create a copy consumer in which a switch over
> happens when it catches up. Meanwhile, it looks like a producer would still
> be writing using the old partitioning scheme. Wouldn't there be a case
> where the copy consumer never catches up given a high enough produce rate?
> I'm imagining this to work similarly to Kinesis's resharding mechanism,
> though I may be missing something from the current proposal. Anyway, with
> Kinesis as an example, this would mean a producer would stop writing using
> the old scheme and start writing using the new scheme. That way, the
> consumer will be able to catch up in which it will start consuming using
> the new scheme afterwards.
>
> Thanks,
> Jeff Chao
>
> On Sat, Apr 14, 2018 at 6:44 AM, Dong Lin <li...@gmail.com> wrote:
>
> > Thanks for the notes by Jun and Ray. I have read through the notes. It
> > seems that there are a few questions for the alternative solution by Jan
> > and maybe Jan will answer these questions later?
> >
> > I have summarized the solution, which I previously provided in this
> thread,
> > in KIP-287, to hopefully show that we may have a promising direction to
> > solve the partition and processor expansion problem for stateful
> processing
> > jobs. Maybe we can continue the discussion related to stateful processing
> > in that discussion thread. If that looks good, maybe we can conclude the
> > discussion for KIP-253.
> >
> > Not sure if I missed some ideas or questions in the notes. Is there
> > specific concern for the latest KIP-253?
> >
> >
> > On Mon, Apr 9, 2018 at 11:18 AM, Ray Chiang <rc...@apache.org> wrote:
> >
> > > My notes from today's meeting.  Sorry if I got anyone's name wrong.
> Plus
> > I
> > > missed a few moments with noise at home and/or dropped video.
> > >
> > > -Ray
> > >
> > > =====
> > >
> > > KIP-253 Discussion
> > >
> > > - Currently, adding partitions can cause keys to be read out-of-order.
> > >   This KIP is trying to preserve the key ordering when adding
> partitions.
> > >
> > > - State management in applications (i.e. Kafka Streams) can maintain
> > >   local state via caching.  If the number of partitions changes, how
> > >   would those applications update their local state.  This is the
> current
> > >   point of discussion/disagreement.
> > >
> > > - Jan Filipiak is mostly worried about log compacted topics.  Not as
> > >   concerned about producer swapping.  Worried about the consumer design
> > is
> > >   a bit contradictory compared to the architecture.
> > >
> > >   Current design is to start up a new consumer in parallel with old
> > >   topic/consumer.  Run until consumer finishes "copying" to the new
> > topic.
> > >   Once the consumer is caught up, point the producer at the new topic.
> > >
> > >   Would like to have this technique as a "core primitive" to Kafka.
> > >   - Is this a useful primitive?
> > >   - What's the best way to support it?
> > >
> > >   - Topic expansion as it currently exists just "adds partitions". But
> > >     how does this affect bootstrapping applications?  How to deal with
> > >     "moved" (from "old partition" to "new expanded partition") keys?
> > >
> > >   - Dong's proposal example.  10 partitions growing to 15.  5 of the
> > >     first 10 partitions are split into 2 each.  Say Kafka remembers
> > >     parent->child relationship.  Then for each parent partition, there
> > >     are two child partitions.  Initially, there were 10 states to
> > >     manage.  Then bootstrapping new application would have 15 states.
> > >     Need to know which "generation" of partition you are consuming
> > >     from.  Until you get to "newer" generation of data, then the keys
> > >     will be find (i.e. reading from old partition).
> > >
> > >   - Scheme works well for transient events.  Any stateful processor
> will
> > >     likely break.
> > >
> > >   - Tracking can become extremely complicated, since each split
> requires
> > >     potentially more and more offset/partition combos.
> > >
> > >   - Need to support continuation for consumers to read the new
> > partitions.
> > >
> > >   - With linear hashing, integral multiple increase (2x, 3x, 4x, etc).
> > >     Easier mapping from old partition sets to new partition sets.
> > >     Keys end up with a clean hierarchy instead of a major reshuffling.
> > >
> > >   - Dong's approach piggyback on existing leader epoch.  Log segment
> > >     could be tagged with version in linear hashing case.
> > >
> > >   - In Jan's case, existing consumers bootstrap from the beginning.
> > >
> > >   - James' use case.  Using Kafka as a long term persistent data store.
> > >     Putting "source of truth" information into Kafka.  Bootstrap case
> > >     is very important.  New applications could be bootstrapping as they
> > >     come up.
> > >
> > >     - Increasing partitions will help with load from prodcuer and
> > >       increasing consumer parallelism.
> > >     - How does Kinesis handling partition splits?  They don't have
> > >       compacted logs, so no issue with bootstrapping.  Kinesis uses
> > >       MD5 and splits results based on md5sum into bucket ranges.
> > >     - Is it useful for the server to know the partitioning function?
> > >       Consumer has some implicit assumptions about keyed partitions,
> > >       but not strongly enforced on server side.
> > >
> > >     - KIP-213 (one to many joins in Kafka Streams)
> > >
> > >       - MySQL case.  Primary key forced to be used as Kafka key.
> > >
> > >         (Sorry had some audio and video drop at this point)
> > >
> > >       - Mirror Maker.  Source cluster has custom partitioning function.
> > >         Producer won't duplicate to same partitioning setup as source.
> > >         Need to provide same partitioning function to producer.
> > >         Would need to determine partitioning function based on topic.
> > >
> > >         - Should server validate partitioning?
> > >         - Who does actual determination of which key goes to which
> > > partition.
> > >
> > >       - How to implement backfill?
> > >
> > >         - Who will do it?  In producer?  Hard to do.  Every client
> would
> > >           need to add this functionality.  Better to do on server side.
> > >         - Add a type of "copy consumer"?  Add backoff to producer?
> > >           Benefit of doing in consumer vs. producer?
> > >
> > >   - Still TBD
> > >     - How to dedupe control messages?
> > >     - How to deal with subtle cases during transition?
> > >     - Is it useful for the server to have the option to validate the
> key
> > >       distribution?
> > >     - Jan concerned about how a consumer application would look with
> the
> > >       new "split partition" design.
> > >     - KIP introduced callback.  Jan doesn't think is useful. Callback
> > >       for switching "between Partition 1 and can start on Partition
> 11".
> > >       Rely on marker in Partition 1 instead.  Intent for callback is
> > >       for possibility that delivery of messages for given key is moved
> > >       to a different consumer instance.
> > >
> > >
> > >
> > > On 4/6/18 9:44 AM, Dong Lin wrote:
> > >
> > >> Hey John,
> > >>
> > >> Thanks much for your super-detailed explanation. This is very helpful.
> > >>
> > >> Now that I have finished reading through your email, I think the
> > proposed
> > >> solution in my previous email probably meets the requirement #6
> without
> > >> requiring additional coordination (w.r.t. partition function) among
> > >> clients. My understanding of requirement #6 is that, after partition
> > >> expansion, messages with the given key will go to the same consumer
> > before
> > >> and after the partition expansion such that stream processing jobs
> won't
> > >> be
> > >> affected. Thus this approach seems to be better than backfilling since
> > it
> > >> does not require data copy for input topics.
> > >>
> > >> In order for the proposed solution to meet requirements #6, we need
> two
> > >> extra requirements in addition to what has been described in the
> > previous
> > >> email: 1) stream processing job starts with the same number of
> > processors
> > >> as the initial number of partitions of the input topics; and 2) at any
> > >> given time the number of partitions of the input topic >= the number
> of
> > >> processors of the given stream processing job.
> > >>
> > >> Could you take a look at the proposed solution and see if any of the
> > >> claims
> > >> above is false?
> > >>
> > >>
> > >> Hey Jan,
> > >>
> > >> Maybe it is more efficient for us to discuss your concern in the KIP
> > >> Meeting.
> > >>
> > >>
> > >> Thanks,
> > >> Dong
> > >>
> > >>
> > >> On Thu, Mar 29, 2018 at 2:05 PM, John Roesler <jo...@confluent.io>
> > wrote:
> > >>
> > >> Hi Jun,
> > >>>
> > >>> Thanks for the response. I'm very new to this project, but I will
> share
> > >>> my
> > >>> perspective. I'm going to say a bunch of stuff that I know you know
> > >>> already, but just so we're on the same page...
> > >>>
> > >>> This may also be a good time to get feedback from the other KStreams
> > >>> folks.
> > >>>
> > >>> Using KStreams as a reference implementation for how stream
> processing
> > >>> frameworks may interact with Kafka, I think it's important to eschew
> > >>> knowledge about how KStreams currently handles internal
> communication,
> > >>> making state durable, etc. Both because these details may change, and
> > >>> because they won't be shared with other stream processors.
> > >>>
> > >>> =================================
> > >>> Background
> > >>>
> > >>> We are looking at a picture like this:
> > >>>
> > >>>       input input input
> > >>>           \   |   /
> > >>>        +-------------+
> > >>> +-----+ Consumer(s) +-------+
> > >>> |     +-------------+       |
> > >>> |                           |
> > >>> |    KStreams Application   |
> > >>> |                           |
> > >>> |     +-------------+       |
> > >>> +-----+ Producer(s) +-------+
> > >>>        +-------------+
> > >>>             /    \
> > >>>          output output
> > >>>
> > >>> The inputs and outputs are Kafka topics (and therefore have 1 or more
> > >>> partitions). We'd have at least 1 input and 0 or more outputs. The
> > >>> Consumers and Producers are both the official KafkaConsumer and
> > >>> KafkaProducer.
> > >>>
> > >>> In general, we'll assume that the input topics are provided by actors
> > >>> over
> > >>> which we have no control, although we may as well assume they are
> > >>> friendly
> > >>> and amenable to requests, and also that their promises are
> trustworthy.
> > >>> This is important because we must depend on them to uphold some
> > promises:
> > >>> * That they tell us the schema of the data they publish, and abide by
> > >>> that
> > >>> schema. Without this, the inputs are essentially garbage.
> > >>> * That they tell us some defining characteristics of the topics (more
> > on
> > >>> this in a sec.) and again strictly abide by that promise.
> > >>>
> > >>> What are the topic characteristics we care about?
> > >>> 1. The name (or name pattern)
> > >>> 2. How the messages are keyed (if at all)
> > >>> 3. Whether the message timestamps are meaningful, and if so, what
> their
> > >>> meaning is
> > >>> 4. Assuming the records have identity, whether the partitions
> partition
> > >>> the
> > >>> records' identity space
> > >>> 5. Whether the topic completely contains the data set
> > >>> 6. Whether the messages in the topic are ordered
> > >>>
> > >>> #1 is obvious: without this information, we cannot access the data at
> > >>> all.
> > >>>
> > >>> For #2, #3, #4, and #6, we may or may not need this information,
> > >>> depending
> > >>> on the logic of the application. For example, a trivial application
> > that
> > >>> simply counts all events it sees doesn't care about #2, #3, #4, or
> #6.
> > >>> But
> > >>> an application that groups by some attribute can take advantage of #2
> > and
> > >>> #4 if the topic data is already keyed and partitioned over that
> > >>> attribute.
> > >>> Likewise, if the application includes some temporal semantics on a
> > >>> temporal
> > >>> dimension that is already captured in #3, it may take advantage of
> that
> > >>> fact.
> > >>>
> > >>> Note that #2, #3, #4, and #6 are all optional. If they are not
> > promised,
> > >>> we
> > >>> can do extra work inside the application to accomplish what we need.
> > >>> However, if they are promised (and if we depend on that promise), it
> is
> > >>> essential that the topic providers uphold those promises, as we may
> not
> > >>> be
> > >>> in a position to verify them.
> > >>>
> > >>> Note also that if they make a promise, but it doesn't happen to line
> up
> > >>> with our needs (data is keyed by attr1, but we need it by attr2, or
> > >>> timestamp is produce-time, but we need it by event-time, etc.), then
> we
> > >>> will have to go ahead and do that extra work internally anyway. This
> > also
> > >>> captures the situation in which two inputs are produced by different
> > >>> providers, one of which meets our needs, and the other does not. The
> > fact
> > >>> that we can cope with this situation is the basis for my statement
> that
> > >>> we
> > >>> do not require coordination among producers.
> > >>>
> > >>> (Key Point A): In terms of optimization, #4 and #6 are the most
> > valuable.
> > >>> If these characteristics happen to line up with our needs, then
> > KStreams
> > >>> can be incredibly efficient in both time and computational resources.
> > >>>
> > >>>   #5 is similar to knowing the schema in that it tells us whether the
> > >>> computation we want to do is possible or not. For example, suppose we
> > >>> have
> > >>> a topic of "users", and we want to construct a table for querying. If
> > the
> > >>> user topic doesn't completely contain the dataset, we cannot
> construct
> > >>> the
> > >>> table. Note that it doesn't matter whether the topic is compacted or
> > not.
> > >>> If the topic is complete, I can consume it starting at "earliest" and
> > >>> build
> > >>> my table. If it is not complete, I can do other computations on it.
> In
> > >>> both
> > >>> cases, it may or may not be compacted; it just doesn't matter.
> > >>>
> > >>> On the output side, the roles are reversed. We provide (or not)
> exactly
> > >>> the
> > >>> same set of guarantees to consumers of our outputs, and we likewise
> > must
> > >>> abide by the promises we make.
> > >>>
> > >>>
> > >>> =================================
> > >>> Partition Expansion
> > >>>
> > >>> With this formation in place, let's talk about partition expansion.
> > >>>
> > >>> Why do we have partitions in the first place? (let me know if I miss
> > >>> something here)
> > >>> * For logical data streams that are themselves partitionable, it
> allows
> > >>> producers to operate concurrently without coordination. For example,
> > >>> streaming data from a sensor in a particle accelerator, the sensor
> can
> > be
> > >>> subdivided into a grid and each grid square can produce independently
> > to
> > >>> a
> > >>> different topic. This may be valuable because the total rate of data
> > >>> exceeds the throughput to a single broker node or just because it
> > allows
> > >>> for failure of a single producer to cause the loss of only part of
> the
> > >>> data.
> > >>> * The brokers can offer linearly scaling throughput on the number of
> > >>> partitions by hosting each partition on a separate broker node
> > >>> * The brokers can host topics that are too large to fit on a single
> > >>> broker's storage by hosting some partitions on separate broker nodes
> > >>> * In cases where the use case permits handling partitions
> > independently,
> > >>> consumers can have algorithmic simplicity by processing the data for
> > >>> separate partitions in separate threads, avoiding costly and
> > error-prone
> > >>> concurrent coordination code
> > >>> * In cases where the use case permits handling partitions
> > independently,
> > >>> consumers can exceed the total throughput of a single broker-consumer
> > >>> pair
> > >>> * Just to throw this in as well, in cases where some network links
> are
> > >>> less
> > >>> costly than others (or lower latency or more reliable), such as when
> > >>> brokers, producers, and consumers are running in racks: producer and
> > >>> consumers can both benefit (independently) by locating work on each
> > >>> partition in the same rack as the broker hosting that partition.
> > >>>
> > >>> In other words, we have three actors in this system: producers,
> > brokers,
> > >>> and consumers, and they all benefit from partitioning for different
> > (but
> > >>> sometimes related) reasons.
> > >>>
> > >>> This leads naturally to the conclusion that any of these actors may
> > find
> > >>> themselves in a sub-optimal or even dangerous situation in which
> > >>> partition
> > >>> expansion would be the solution. For example, the producer may find
> > that
> > >>> the existing throughput to the brokers is insufficient to match the
> > data
> > >>> rate, forcing them to drop data. Or a broker hosting a single
> partition
> > >>> may
> > >>> be running out of disk space. Or a consumer node handling a single
> > >>> partition cannot match the rate of production for that partition,
> > causing
> > >>> it to fall behind.
> > >>>
> > >>> I think it's reasonable to assume that all the actors in the system
> > can't
> > >>> just arbitrarily expand a topic's partition. I think it's reasonable
> to
> > >>> align this responsibility with the provider of the data, namely the
> > >>> producer (the logical producer, not the KafkaProducer class).
> > Therefore,
> > >>> the producer who finds themselves in trouble can unilaterally expand
> > >>> partitions to solve their problem.
> > >>>
> > >>> For the broker or a consumer in trouble, they have only one resort:
> to
> > >>> request the producer to expand partitions. This is where it's helpful
> > to
> > >>> assume the producer is friendly.
> > >>>
> > >>>
> > >>> Now, let's look at how a KStreams application fits into this
> scenario.
> > >>>
> > >>> (Key Point B1): As a consumer, we may find that the producer expands
> > the
> > >>> partitions of a topic, either for their own benefit or for the
> brokers.
> > >>> In
> > >>> this situation, the expand operation MUST NOT violate any promises
> that
> > >>> have previously been made to us. This is the essence of KIP-253, to
> > >>> ensure
> > >>> the maintenance of promises #6 and #4. It would be great if the
> > mechanics
> > >>> of the expansion required no major disruption to processing or human
> > >>> intervention.
> > >>>
> > >>> Specifically, let's say that input partition X splits into X1 and X2.
> > #6
> > >>> requires that the same old ordering guarantees of Kafka continue to
> > hold.
> > >>> Obviously, this is what KIP-253's title is about. #4 requires that we
> > >>> either ensure that X1 and X2 are assigned to the same thread that was
> > >>> previously assigned X OR that we immediately pause processing and
> split
> > >>> any
> > >>> state such that it appears X1 and X2 were *always* separate
> partitions.
> > >>>
> > >>> In other words, Option 1 is we treat X1 and X2 as still logically one
> > >>> partition, equal to X. This is ideal, since in this scenario,
> > partitions
> > >>> are expanding for external reasons. We don't need to expand our
> > >>> processing
> > >>> to match. Option 2 requires a major disruption, since we'd have to
> > pause
> > >>> processing while we split our state. Clearly, KStreams or any other
> > >>> stateful consumer would advocate for Option 1.
> > >>>
> > >>>
> > >>> (Corollary to Key Point A): Still on the consumer side, we may find
> > that
> > >>> we
> > >>> ourselves can benefit from partition expansion of an input. Since we
> > can
> > >>> cope with the absence of promise #4, partition expansion is not a
> hard
> > >>> requirement for us, but assuming we were already benefiting from the
> > >>> major
> > >>> performance optimizations afforded by #4, it would be nice to be able
> > to
> > >>> request the producer satisfy our request for partition expansion
> **and
> > to
> > >>> be able to benefit from it**.
> > >>>
> > >>> What does it mean to be able to benefit from partition expansion?
> > >>> Assuming
> > >>> input topic partition X splits into X1 and X2, in this scenario, we
> > >>> *would*
> > >>> wish to be able to split our state such that it appears X1 and X2
> were
> > >>> *always* separate partitions. Of course, the conclusion of Key Point
> B1
> > >>> still applies: we should be able to continue operating on (X1+X2 = X)
> > as
> > >>> one partition while asynchronously building the state of X1 and X2
> > >>> separately.
> > >>>
> > >>> When it comes to the mechanics of building the state of X1 and X2
> > >>> separately, we have really just two high-level options. Either this
> > >>> problem
> > >>> is solved by Kafka itself, giving me a view in which X1 and X2 were
> > >>> always
> > >>> separate partitions, or I have to do it myself. The latter means
> that I
> > >>> have to take on substantially more complexity than I do today:
> > >>> Bummer 1: My state has to be splittable to begin with, implying at
> the
> > >>> least that I need to be able to scan every record in my state, a
> > >>> requirement that otherwise does not exist.
> > >>> Bummer 2: After splitting the state  of X1 and X2, I need to be able
> to
> > >>> send at least one of those tasks, state included, to another
> > application
> > >>> node (in order to realize the benefit of the split). This is also a
> > >>> requirement that does not currently exist.
> > >>> Bummer 3: In order to actually perform the split, I must know and be
> > able
> > >>> to execute the exact same partition function the producer of my topic
> > >>> uses.
> > >>> This introduces a brand-new a priori commitment from my input
> > producers:
> > >>> (would-be #7: convey the partition function and abide by it). This
> is a
> > >>> big
> > >>> restriction over #4, which only requires them to guarantee *that
> there
> > >>> is a
> > >>> partition function*. Now they actually have to share the function
> with
> > >>> me.
> > >>> And I have to be able to implement and execute it myself. And if the
> > >>> producer wishes to refine the partition function for an existing
> topic,
> > >>> we
> > >>> have another round of coordination, as they have to be sure that I,
> and
> > >>> all
> > >>> other consumers, begin using the new function *before* they do. This
> is
> > >>> similar to the schema problem, with a similar set of solutions. We
> > would
> > >>> likely need a partition function registry and another magic byte on
> > every
> > >>> record to be sure we do this right. Not to mention some way to
> express
> > >>> arbitrary partitioning logic over arbitrary data in a way that is
> > >>> portable
> > >>> across programming languages.
> > >>>
> > >>> Alternatively, if Kafka gives me a view in which X1 and X2 were
> always
> > >>> separate, then I can create tasks for X1 and X2 and allow them to
> > >>> bootstrap
> > >>> while I continue to process X. Once they are ready, I can coordinate
> a
> > >>> transition to stop X's task and switch to X1 and X2. None of those
> > >>> bummers
> > >>> are present, so this is a significantly better option for me.
> > >>>
> > >>> (Key Point B2): As a (friendly) producer, we may once again want on
> our
> > >>> own
> > >>> to expand partitions, or we may want to satisfy a request from the
> > broker
> > >>> or our consumers to do so. Again, we MUST NOT violate any promises we
> > >>> have
> > >>> previously given, and it would be great if the expansion required no
> > >>> major
> > >>> disruption to processing or human intervention. Additionally, since
> we
> > >>> are
> > >>> actually driving the expansion, it would also be great if we could
> > avoid
> > >>> Bummer 3's coordination problems from the producer's perspective.
> > >>>
> > >>>
> > >>> ======================================
> > >>> Briefly: KStreams internals
> > >>>
> > >>> I'm pretty sure you were asking me to comment on the implementation
> > >>> details
> > >>> of KStreams, so I'll say a few words about it. The most important
> thing
> > >>> is
> > >>> that KStreams is still very early in its development. Maybe
> > "early-middle
> > >>> maturity" is a good way to put it. We are actively discussing
> > >>> more-or-less
> > >>> major implementation changes to improve performance, footprint,
> > >>> scalability, and ergonomics. So it may actually be misleading to
> > discuss
> > >>> deeply how KStreams internally uses Kafka topics.
> > >>>
> > >>> Nevertheless, it is currently true that KStreams uses Kafka topics
> for
> > >>> communication between some internal computation nodes. We partition
> > these
> > >>> topics as the base unit of concurrency granularity, so it would
> > >>> potentially
> > >>> be beneficial to be able to expand partitions for some of these
> > internal
> > >>> topics at some point. However, we can alternatively just
> overpartition
> > >>> these internal topics, creating in the low 100s of partitions instead
> > of
> > >>> the low 10s, for example. (Side note: if Kafka were someday to
> support
> > >>> higher numbers of partitions, we could expand this scheme to
> > >>> overpartition
> > >>> in the 1000s of partitions.) With the option to overpartition, we
> don't
> > >>> have a strong need for partition expansion internally.
> > >>>
> > >>> It is also currently true that KStreams uses Kafka to store a durable
> > >>> changelog for some of our internal state stores. But we *only* read
> > from
> > >>> this topic *if* we need to restore a state store after node loss (or
> to
> > >>> maintain a hot mirror of the state store), so I think it's unlikely
> > that
> > >>> we
> > >>> would ever make use of partition expansion on the changelog topics.
> > >>>
> > >>> But once again, I'd like to emphasize that we may choose an
> alternative
> > >>> implementation for either interprocess communication or state
> > durability.
> > >>>
> > >>>
> > >>> ======================================
> > >>> Concluding thoughts
> > >>>
> > >>> I know this is a very long email, and I really appreciate you
> sticking
> > >>> with
> > >>> me this long. I hope it was useful for syncing our mental picture of
> > this
> > >>> system. Also, you're far more knowledgeable than I am about this
> system
> > >>> and
> > >>> this domain, so please correct me if I've said anything wrong.
> > >>>
> > >>> To me the key takeaways are that:
> > >>> - KIP-253 satisfies all we need for correctness, since it contains
> > >>> solutions to guarantee producers can abide by their promises w.r.t.
> #4
> > >>> and
> > >>> #6.
> > >>> - From Key Point A: #4 is actually optional for KIP-253, but without
> > it,
> > >>> we
> > >>> lose a potentially valuable optimization in KStreams (and all other
> > >>> consumer applications)
> > >>> - From Corollary to Point A: Without low-level support for partition
> > >>> expansion with backfill, we cannot employ requesting partition
> > expansion
> > >>> as
> > >>> a consumer to improve application performance. In that case, to
> ensure
> > >>> performance scalability, we would have to discard for all KStreams
> > >>> applications the performance optimization afforded by #4.
> > >>> - From Key Point B1: After a partition split, we really need to be
> able
> > >>> to
> > >>> seamlessly continue operating as if it had not split.
> > >>> - From Key Point B2: Since KIP-253 allows us to maintain all our
> > >>> promises,
> > >>> we have the option of expanding partitions in the topics we produce.
> > >>> Without a backfill operation, though, our consumers may not be able
> to
> > >>> realize the benefits of that split, if they were hoping to.
> > >>>
> > >>> In general, faced with the possibility of having to coordinate the
> > >>> partition function with our inputs' producers or with our outputs'
> > >>> consumers, I would personally lean toward overprovisioning and
> > completely
> > >>> avoiding resize for our use case. This doesn't mean that it's not
> > useful
> > >>> in
> > >>> the ecosystem at large without backfill, just that it loses its
> luster
> > >>> for
> > >>> me. It also means that we can no longer take advantage of some of our
> > >>> current optimizations, and in fact that we must introduce an extra
> hop
> > of
> > >>> repartitioning on every single input.
> > >>>
> > >>> I think this is actually a pretty good picture of the opportunities
> and
> > >>> challenges that other consumers and producers in the Kafka ecosystem
> > will
> > >>> face.
> > >>>
> > >>> I hope this helps!
> > >>>
> > >>> Thanks,
> > >>> -John
> > >>>
> > >>> On Wed, Mar 28, 2018 at 11:51 AM, Jun Rao <ju...@confluent.io> wrote:
> > >>>
> > >>> Hi, John,
> > >>>>
> > >>>> I actually think it's important to think through how KStreams
> handles
> > >>>> partition expansion in this KIP. If we do decide that we truly need
> > >>>> backfilling, it's much better to think through how to add it now,
> > >>>> instead
> > >>>> of retrofitting it later. It would be useful to outline how both
> > >>>> existing
> > >>>> KStreams jobs and new KStreams jobs work to see if backfilling is
> > really
> > >>>> needed.
> > >>>>
> > >>>> If we can figure out how KStreams works, at least we have one
> > reference
> > >>>> implementation for other stream processing frameworks that face the
> > same
> > >>>> issue.
> > >>>>
> > >>>> Thanks,
> > >>>>
> > >>>> Jun
> > >>>>
> > >>>>
> > >>>> On Tue, Mar 27, 2018 at 4:56 PM, John Roesler <jo...@confluent.io>
> > >>>> wrote:
> > >>>>
> > >>>> Hi Jun,
> > >>>>>
> > >>>>> That's a good point.
> > >>>>>
> > >>>>> Yeah, I don't think it would work too well for existing consumers
> in
> > >>>>>
> > >>>> the
> > >>>
> > >>>> middle of gen 0 to try and switch to a newly backfilled prefix of
> gen
> > >>>>>
> > >>>> 1.
> > >>>
> > >>>> They probably just need to finish up until they get to the end of
> gen
> > 0
> > >>>>>
> > >>>> and
> > >>>>
> > >>>>> transition just as if there were no backfill available yet.
> > >>>>>
> > >>>>> This isn't terrible, since consumer applications that care about
> > >>>>>
> > >>>> scaling
> > >>>
> > >>>> up
> > >>>>
> > >>>>> to match a freshly split partition would wait until after the
> > backfill
> > >>>>>
> > >>>> is
> > >>>
> > >>>> available to scale up. The consumer that starts out in gen=0, part=0
> > is
> > >>>>> going to be stuck with part=0 and part=3 in gen=1 in my example
> > >>>>>
> > >>>> regardless
> > >>>>
> > >>>>> of whether they finish scanning gen=0 before or after the backfill
> is
> > >>>>> available.
> > >>>>>
> > >>>>> The broker knowing when it's ok to delete gen 0, including its
> offset
> > >>>>> mappings, is a big issue, though. I don't have any immediate ideas
> > for
> > >>>>> solving it, but it doesn't feel impossible. Hopefully, you agree
> this
> > >>>>>
> > >>>> is
> > >>>
> > >>>> outside of KIP-253's scope, so maybe we don't need to worry about it
> > >>>>>
> > >>>> right
> > >>>>
> > >>>>> now.
> > >>>>>
> > >>>>> I do agree that reshuffling in KStreams effectively solves the
> > >>>>>
> > >>>> scalability
> > >>>>
> > >>>>> problem as well, as it decouples the partition count (and the
> > partition
> > >>>>> scheme) upstream from the parallelism of the streams application.
> > >>>>>
> > >>>> Likely,
> > >>>
> > >>>> we will do this in any case. I'm predominantly advocating for
> > follow-on
> > >>>>> work to enable backfill for the *other* Kafka users that are not
> > >>>>>
> > >>>> KStreams.
> > >>>>
> > >>>>> Thanks for your consideration,
> > >>>>> -John
> > >>>>>
> > >>>>> On Tue, Mar 27, 2018 at 6:19 PM, Jun Rao <ju...@confluent.io> wrote:
> > >>>>>
> > >>>>> Hi, John,
> > >>>>>>
> > >>>>>> Thanks for the reply. I agree that the backfill approach works
> > >>>>>>
> > >>>>> cleaner
> > >>>
> > >>>> for
> > >>>>>
> > >>>>>> newly started consumers. I am just not sure if it's a good
> primitive
> > >>>>>>
> > >>>>> to
> > >>>
> > >>>> support for existing consumers. One of the challenges that I see is
> > >>>>>>
> > >>>>> the
> > >>>
> > >>>> remapping of the offsets. In your approach, we need to copy the
> > >>>>>>
> > >>>>> existing
> > >>>>
> > >>>>> records from the partitions in generation 0 to generation 1. Those
> > >>>>>>
> > >>>>> records
> > >>>>>
> > >>>>>> will get different offsets in the new generation. The broker will
> > >>>>>>
> > >>>>> have
> > >>>
> > >>>> to
> > >>>>
> > >>>>> store those offset mappings somewhere. When the backfill completes,
> > >>>>>>
> > >>>>> you
> > >>>
> > >>>> can
> > >>>>>
> > >>>>>> delete generation 0's data. However, the broker can't throw away
> the
> > >>>>>>
> > >>>>> offset
> > >>>>>
> > >>>>>> mappings immediately since it doesn't know if there is any
> existing
> > >>>>>> consumer still consuming generation 0's records. In a compacted
> > >>>>>>
> > >>>>> topic,
> > >>>
> > >>>> the
> > >>>>>
> > >>>>>> broker probably can only safely remove the offset mappings when
> all
> > >>>>>>
> > >>>>> records
> > >>>>>
> > >>>>>> in generation 0 are removed by the cleaner. This may never happen
> > >>>>>>
> > >>>>> though.
> > >>>>
> > >>>>> If we reshuffle the input inside a KStreams job, it obviates the
> need
> > >>>>>>
> > >>>>> for
> > >>>>
> > >>>>> offset remapping on the broker.
> > >>>>>>
> > >>>>>> Jun
> > >>>>>>
> > >>>>>> On Tue, Mar 27, 2018 at 11:34 AM, John Roesler <john@confluent.io
> >
> > >>>>>>
> > >>>>> wrote:
> > >>>>>
> > >>>>>> Hey Dong and Jun,
> > >>>>>>>
> > >>>>>>> Thanks for the thoughtful responses. If you don't mind, I'll mix
> my
> > >>>>>>>
> > >>>>>> replies
> > >>>>>>
> > >>>>>>> together to try for a coherent response. I'm not too familiar
> with
> > >>>>>>> mailing-list etiquette, though.
> > >>>>>>>
> > >>>>>>> I'm going to keep numbering my points because it makes it easy
> for
> > >>>>>>>
> > >>>>>> you
> > >>>>
> > >>>>> all
> > >>>>>>
> > >>>>>>> to respond.
> > >>>>>>>
> > >>>>>>> Point 1:
> > >>>>>>> As I read it, KIP-253 is *just* about properly fencing the
> > >>>>>>>
> > >>>>>> producers
> > >>>
> > >>>> and
> > >>>>>
> > >>>>>> consumers so that you preserve the correct ordering of records
> > >>>>>>>
> > >>>>>> during
> > >>>
> > >>>> partition expansion. This is clearly necessary regardless of
> > >>>>>>>
> > >>>>>> anything
> > >>>
> > >>>> else
> > >>>>>>
> > >>>>>>> we discuss. I think this whole discussion about backfill,
> > >>>>>>>
> > >>>>>> consumers,
> > >>>
> > >>>> streams, etc., is beyond the scope of KIP-253. But it would be
> > >>>>>>>
> > >>>>>> cumbersome
> > >>>>>
> > >>>>>> to start a new thread at this point.
> > >>>>>>>
> > >>>>>>> I had missed KIP-253's Proposed Change #9 among all the
> details...
> > >>>>>>>
> > >>>>>> I
> > >>>
> > >>>> think
> > >>>>>>
> > >>>>>>> this is a nice addition to the proposal. One thought is that it's
> > >>>>>>>
> > >>>>>> actually
> > >>>>>>
> > >>>>>>> irrelevant whether the hash function is linear. This is simply an
> > >>>>>>>
> > >>>>>> algorithm
> > >>>>>>
> > >>>>>>> for moving a key from one partition to another, so the type of
> hash
> > >>>>>>> function need not be a precondition. In fact, it also doesn't
> > >>>>>>>
> > >>>>>> matter
> > >>>
> > >>>> whether the topic is compacted or not, the algorithm works
> > >>>>>>>
> > >>>>>> regardless.
> > >>>>
> > >>>>> I think this is a good algorithm to keep in mind, as it might
> > >>>>>>>
> > >>>>>> solve a
> > >>>
> > >>>> variety of problems, but it does have a downside: that the producer
> > >>>>>>>
> > >>>>>> won't
> > >>>>>
> > >>>>>> know whether or not K1 was actually in P1, it just knows that K1
> > >>>>>>>
> > >>>>>> was
> > >>>
> > >>>> in
> > >>>>
> > >>>>> P1's keyspace before the new epoch. Therefore, it will have to
> > >>>>>>> pessimistically send (K1,null) to P1 just in case. But the next
> > >>>>>>>
> > >>>>>> time
> > >>>
> > >>>> K1
> > >>>>
> > >>>>> comes along, the producer *also* won't remember that it already
> > >>>>>>>
> > >>>>>> retracted
> > >>>>>
> > >>>>>> K1 from P1, so it will have to send (K1,null) *again*. By
> > >>>>>>>
> > >>>>>> extension,
> > >>>
> > >>>> every
> > >>>>>>
> > >>>>>>> time the producer sends to P2, it will also have to send a
> > >>>>>>>
> > >>>>>> tombstone
> > >>>
> > >>>> to
> > >>>>
> > >>>>> P1,
> > >>>>>>
> > >>>>>>> which is a pretty big burden. To make the situation worse, if
> there
> > >>>>>>>
> > >>>>>> is
> > >>>>
> > >>>>> a
> > >>>>>
> > >>>>>> second split, say P2 becomes P2 and P3, then any key Kx belonging
> > >>>>>>>
> > >>>>>> to
> > >>>
> > >>>> P3
> > >>>>
> > >>>>> will also have to be retracted from P2 *and* P1, since the producer
> > >>>>>>>
> > >>>>>> can't
> > >>>>>
> > >>>>>> know whether Kx had been last written to P2 or P1. Over a long
> > >>>>>>>
> > >>>>>> period
> > >>>
> > >>>> of
> > >>>>>
> > >>>>>> time, this clearly becomes a issue, as the producer must send an
> > >>>>>>>
> > >>>>>> arbitrary
> > >>>>>>
> > >>>>>>> number of retractions along with every update.
> > >>>>>>>
> > >>>>>>> In contrast, the proposed backfill operation has an end, and
> after
> > >>>>>>>
> > >>>>>> it
> > >>>
> > >>>> ends,
> > >>>>>>
> > >>>>>>> everyone can afford to forget that there ever was a different
> > >>>>>>>
> > >>>>>> partition
> > >>>>
> > >>>>> layout.
> > >>>>>>>
> > >>>>>>> Really, though, figuring out how to split compacted topics is
> > >>>>>>>
> > >>>>>> beyond
> > >>>
> > >>>> the
> > >>>>>
> > >>>>>> scope of KIP-253, so I'm not sure #9 really even needs to be in
> > >>>>>>>
> > >>>>>> this
> > >>>
> > >>>> KIP...
> > >>>>>>
> > >>>>>>> We do need in-order delivery during partition expansion. It would
> > >>>>>>>
> > >>>>>> be
> > >>>
> > >>>> fine
> > >>>>>
> > >>>>>> by me to say that you *cannot* expand partitions of a
> log-compacted
> > >>>>>>>
> > >>>>>> topic
> > >>>>>
> > >>>>>> and call it a day. I think it would be better to tackle that in
> > >>>>>>>
> > >>>>>> another
> > >>>>
> > >>>>> KIP.
> > >>>>>>>
> > >>>>>>>
> > >>>>>>> Point 2:
> > >>>>>>> Regarding whether the consumer re-shuffles its inputs, this is
> > >>>>>>>
> > >>>>>> always
> > >>>
> > >>>> on
> > >>>>>
> > >>>>>> the table; any consumer who wants to re-shuffle its input is free
> > >>>>>>>
> > >>>>>> to
> > >>>
> > >>>> do
> > >>>>
> > >>>>> so.
> > >>>>>>
> > >>>>>>> But this is currently not required. It's just that the current
> > >>>>>>>
> > >>>>>> high-level
> > >>>>>
> > >>>>>> story with Kafka encourages the use of partitions as a unit of
> > >>>>>>>
> > >>>>>> concurrency.
> > >>>>>>
> > >>>>>>> As long as consumers are single-threaded, they can happily
> consume
> > >>>>>>>
> > >>>>>> a
> > >>>
> > >>>> single
> > >>>>>>
> > >>>>>>> partition without concurrency control of any kind. This is a key
> > >>>>>>>
> > >>>>>> aspect
> > >>>>
> > >>>>> to
> > >>>>>>
> > >>>>>>> this system that lets folks design high-throughput systems on top
> > >>>>>>>
> > >>>>>> of
> > >>>
> > >>>> it
> > >>>>
> > >>>>> surprisingly easily. If all consumers were instead
> > >>>>>>>
> > >>>>>> encouraged/required
> > >>>>
> > >>>>> to
> > >>>>>
> > >>>>>> implement a repartition of their own, then the consumer becomes
> > >>>>>>> significantly more complex, requiring either the consumer to
> first
> > >>>>>>>
> > >>>>>> produce
> > >>>>>>
> > >>>>>>> to its own intermediate repartition topic or to ensure that
> > >>>>>>>
> > >>>>>> consumer
> > >>>
> > >>>> threads have a reliable, high-bandwith channel of communication
> > >>>>>>>
> > >>>>>> with
> > >>>
> > >>>> every
> > >>>>>>
> > >>>>>>> other consumer thread.
> > >>>>>>>
> > >>>>>>> Either of those tradeoffs may be reasonable for a particular user
> > >>>>>>>
> > >>>>>> of
> > >>>
> > >>>> Kafka,
> > >>>>>>
> > >>>>>>> but I don't know if we're in a position to say that they are
> > >>>>>>>
> > >>>>>> reasonable
> > >>>>
> > >>>>> for
> > >>>>>>
> > >>>>>>> *every* user of Kafka.
> > >>>>>>>
> > >>>>>>>
> > >>>>>>> Point 3:
> > >>>>>>> Regarding Jun's point about this use case, "(3) stateful and
> > >>>>>>>
> > >>>>>> maintaining
> > >>>>>
> > >>>>>> the
> > >>>>>>> states in a local store", I agree that they may use a framework
> > >>>>>>>
> > >>>>>> *like*
> > >>>>
> > >>>>> Kafka Streams, but that is not the same as using Kafka Streams.
> > >>>>>>>
> > >>>>>> This
> > >>>
> > >>>> is
> > >>>>
> > >>>>> why
> > >>>>>>
> > >>>>>>> I think it's better to solve it in Core: because it is then
> solved
> > >>>>>>>
> > >>>>>> for
> > >>>>
> > >>>>> KStreams and also for everything else that facilitates local state
> > >>>>>>> maintenance. To me, Streams is a member of the category of
> "stream
> > >>>>>>> processing frameworks", which is itself a subcategory of "things
> > >>>>>>>
> > >>>>>> requiring
> > >>>>>>
> > >>>>>>> local state maintenence". I'm not sure if it makes sense to
> assert
> > >>>>>>>
> > >>>>>> that
> > >>>>
> > >>>>> Streams is a sufficient and practical replacement for everything in
> > >>>>>>>
> > >>>>>> "things
> > >>>>>>
> > >>>>>>> requiring local state maintenence".
> > >>>>>>>
> > >>>>>>> But, yes, I do agree that per-key ordering is an absolute
> > >>>>>>>
> > >>>>>> requirement,
> > >>>>
> > >>>>> therefore I think that KIP-253 itself is a necessary step.
> > >>>>>>>
> > >>>>>> Regarding
> > >>>
> > >>>> the
> > >>>>>
> > >>>>>> coupling of the state store partitioning to the topic
> partitioning,
> > >>>>>>>
> > >>>>>> yes,
> > >>>>>
> > >>>>>> this is an issue we are discussing solutions to right now. We may
> > >>>>>>>
> > >>>>>> go
> > >>>
> > >>>> ahead
> > >>>>>>
> > >>>>>>> and introduce an overpartition layer on our inputs to solve it,
> but
> > >>>>>>>
> > >>>>>> then
> > >>>>>
> > >>>>>> again, if we get the ability to split partitions with backfill, we
> > >>>>>>>
> > >>>>>> may
> > >>>>
> > >>>>> not
> > >>>>>>
> > >>>>>>> need to!
> > >>>>>>>
> > >>>>>>>
> > >>>>>>> Point 4:
> > >>>>>>> On this:
> > >>>>>>>
> > >>>>>>> Regarding thought 2: If we don't care about the stream use-case,
> > >>>>>>>>
> > >>>>>>> then
> > >>>>
> > >>>>> the
> > >>>>>>
> > >>>>>>> current KIP probably has already addressed problem without
> > >>>>>>>>
> > >>>>>>> requiring
> > >>>>
> > >>>>> consumer to know the partition function. If we care about the
> > >>>>>>>>
> > >>>>>>> stream
> > >>>>
> > >>>>> use-case, we already need coordination across producers of
> > >>>>>>>>
> > >>>>>>> different
> > >>>>
> > >>>>> topics, i.e. the same partition function needs to be used by
> > >>>>>>>>
> > >>>>>>> producers
> > >>>>>
> > >>>>>> of
> > >>>>>>
> > >>>>>>> topics A and B in order to join topics A and B. Thus, it might be
> > >>>>>>>> reasonable to extend coordination a bit and say we need
> > >>>>>>>>
> > >>>>>>> coordination
> > >>>>
> > >>>>> across
> > >>>>>>>
> > >>>>>>>> clients (i.e. producer and consumer), such that consumer knows
> > >>>>>>>>
> > >>>>>>> the
> > >>>
> > >>>> partition function used by producer. If we do so, then we can let
> > >>>>>>>>
> > >>>>>>> consumer
> > >>>>>>>
> > >>>>>>>> re-copy data for the change log topic using the same partition
> > >>>>>>>>
> > >>>>>>> function
> > >>>>>
> > >>>>>> as
> > >>>>>>>
> > >>>>>>>> producer. This approach has lower overhead as compared to having
> > >>>>>>>>
> > >>>>>>> producer
> > >>>>>>
> > >>>>>>> re-copy data of the input topic.
> > >>>>>>>> Also, producer currently does not need to know the data already
> > >>>>>>>>
> > >>>>>>> produced
> > >>>>>>
> > >>>>>>> to
> > >>>>>>>
> > >>>>>>>> the topic. If we let producer split/merge partition, it would
> > >>>>>>>>
> > >>>>>>> require
> > >>>>
> > >>>>> producer to consume the existing data, which intuitively is the
> > >>>>>>>>
> > >>>>>>> task
> > >>>>
> > >>>>> of
> > >>>>>
> > >>>>>> consumer.
> > >>>>>>>>
> > >>>>>>>
> > >>>>>>> I think we do care about use cases *like* Streams, I just don't
> > >>>>>>>
> > >>>>>> think
> > >>>
> > >>>> we
> > >>>>>
> > >>>>>> should rely on Streams to implement a feature of Core like
> > >>>>>>>
> > >>>>>> partition
> > >>>
> > >>>> expansion.
> > >>>>>>>
> > >>>>>>> Note, though, that we (Streams) do not require coordination
> across
> > >>>>>>> producers. If two topics are certified to be co-partitioned, then
> > >>>>>>>
> > >>>>>> Streams
> > >>>>>
> > >>>>>> apps can make use of that knowledge to optimize their topology
> > >>>>>>>
> > >>>>>> (skipping
> > >>>>>
> > >>>>>> a
> > >>>>>>
> > >>>>>>> repartition). But if they don't know whether they are
> > >>>>>>>
> > >>>>>> co-partitioned,
> > >>>
> > >>>> then
> > >>>>>>
> > >>>>>>> they'd better go ahead and repartition within the topology. This
> is
> > >>>>>>>
> > >>>>>> the
> > >>>>
> > >>>>> current state.
> > >>>>>>>
> > >>>>>>> A huge selling point of Kafka is enabling different parts of
> > >>>>>>>
> > >>>>>> loosely
> > >>>
> > >>>> coupled organizations to produce and consume data independently.
> > >>>>>>>
> > >>>>>> Some
> > >>>
> > >>>> coordination between producers and consumers is necessary, like
> > >>>>>>> coordinating on the names of topics and their schemas. But
> Kafka's
> > >>>>>>>
> > >>>>>> value
> > >>>>>
> > >>>>>> proposition w.r.t. ESBs, etc. is inversely proportional to the
> > >>>>>>>
> > >>>>>> amount
> > >>>
> > >>>> of
> > >>>>>
> > >>>>>> coordination required. I think it behooves us to be extremely
> > >>>>>>>
> > >>>>>> skeptical
> > >>>>
> > >>>>> about introducing any coordination beyond correctness protocols.
> > >>>>>>>
> > >>>>>>> Asking producers and consumers, or even two different producers,
> to
> > >>>>>>>
> > >>>>>> share
> > >>>>>
> > >>>>>> code like the partition function is a pretty huge ask. What if
> they
> > >>>>>>>
> > >>>>>> are
> > >>>>
> > >>>>> using different languages?
> > >>>>>>>
> > >>>>>>> Comparing organizational overhead vs computational overhead,
> there
> > >>>>>>>
> > >>>>>> are
> > >>>>
> > >>>>> maybe two orders of magnitude difference between them. In other
> > >>>>>>>
> > >>>>>> words,
> > >>>>
> > >>>>> I
> > >>>>>
> > >>>>>> would happily take on the (linear) overhead of having the producer
> > >>>>>>>
> > >>>>>> re-copy
> > >>>>>>
> > >>>>>>> the data once during a re-partition in order to save the
> > >>>>>>>
> > >>>>>> organizational
> > >>>>
> > >>>>> overhead of tying all the producers and consumers together across
> > >>>>>>>
> > >>>>>> multiple
> > >>>>>>
> > >>>>>>> boundaries.
> > >>>>>>>
> > >>>>>>> On that last paragraph: note that the producer *did* know the
> data
> > >>>>>>>
> > >>>>>> it
> > >>>
> > >>>> already produced. It handled it the first time around. Asking it to
> > >>>>>>> re-produce it into a new partition layout is squarely within its
> > >>>>>>>
> > >>>>>> scope
> > >>>>
> > >>>>> of
> > >>>>>
> > >>>>>> capabilities. Contrast this with the alternative, asking the
> > >>>>>>>
> > >>>>>> consumer
> > >>>
> > >>>> to
> > >>>>>
> > >>>>>> re-partition the data. I think this is even less intuitive, when
> > >>>>>>>
> > >>>>>> the
> > >>>
> > >>>> partition function belongs to the producer.
> > >>>>>>>
> > >>>>>>>
> > >>>>>>> Point 5:
> > >>>>>>> Dong asked this:
> > >>>>>>>
> > >>>>>>> For stream use-case that needs to increase consumer number, the
> > >>>>>>>> existing consumer can backfill the existing data in the change
> > >>>>>>>>
> > >>>>>>> log
> > >>>
> > >>>> topic
> > >>>>>>
> > >>>>>>> to
> > >>>>>>>
> > >>>>>>>> the same change log topic with the new partition number, before
> > >>>>>>>>
> > >>>>>>> the
> > >>>
> > >>>> new
> > >>>>>
> > >>>>>> set
> > >>>>>>>
> > >>>>>>>> of consumers bootstrap state from the new partitions of the
> > >>>>>>>>
> > >>>>>>> change
> > >>>
> > >>>> log
> > >>>>>
> > >>>>>> topic, right?
> > >>>>>>>>
> > >>>>>>>
> > >>>>>>> In this sense, the "consumer" is actually the producer of the
> > >>>>>>>
> > >>>>>> changelog
> > >>>>
> > >>>>> topic, so if we support partition expansion + backfill as a
> > >>>>>>>
> > >>>>>> producer/broker
> > >>>>>>
> > >>>>>>> operation, then it would be very straightforward for Streams to
> > >>>>>>>
> > >>>>>> split a
> > >>>>
> > >>>>> state store. As you say, they would simply instruct the broker to
> > >>>>>>>
> > >>>>>> split
> > >>>>
> > >>>>> the
> > >>>>>>
> > >>>>>>> changelog topic's partitions, then backfill. Once the backfill is
> > >>>>>>>
> > >>>>>> ready,
> > >>>>>
> > >>>>>> they can create a new crop of StandbyTasks to bootstrap the more
> > >>>>>>>
> > >>>>>> granular
> > >>>>>
> > >>>>>> state stores and finally switch over to them when they are ready.
> > >>>>>>>
> > >>>>>>> But this actually seems to be an argument in favor of
> > >>>>>>>
> > >>>>>> split+backfill,
> > >>>
> > >>>> so
> > >>>>>
> > >>>>>> maybe I missed the point.
> > >>>>>>>
> > >>>>>>> You also asked me to explain why copying the "input" topic is
> > >>>>>>>
> > >>>>>> better
> > >>>
> > >>>> than
> > >>>>>
> > >>>>>> copying the "changelog" topic. I think they are totally
> > >>>>>>>
> > >>>>>> independent,
> > >>>
> > >>>> actually. For one thing, you can't depend on the existence of a
> > >>>>>>>
> > >>>>>> "changelog"
> > >>>>>>
> > >>>>>>> topic in general, only within Streams, but Kafka's user base
> > >>>>>>>
> > >>>>>> clearly
> > >>>
> > >>>> exceeds Streams's user base. Plus, you actually also can't depend
> > >>>>>>>
> > >>>>>> on
> > >>>
> > >>>> the
> > >>>>>
> > >>>>>> existence of a changelog topic within Streams, since that is an
> > >>>>>>>
> > >>>>>> optional
> > >>>>>
> > >>>>>> feature of *some* state store implementations. Even in the
> > >>>>>>>
> > >>>>>> situation
> > >>>
> > >>>> where
> > >>>>>>
> > >>>>>>> you do have a changelog topic in Streams, there may be use cases
> > >>>>>>>
> > >>>>>> where
> > >>>>
> > >>>>> it
> > >>>>>
> > >>>>>> makes sense to expand the partitions of just the input, or just
> the
> > >>>>>>> changelog.
> > >>>>>>>
> > >>>>>>> The ask for a Core feature of split+backfill is really about
> > >>>>>>>
> > >>>>>> supporting
> > >>>>
> > >>>>> the
> > >>>>>>
> > >>>>>>> use case of splitting partitions in log-compacted topics,
> > >>>>>>>
> > >>>>>> regardless
> > >>>
> > >>>> of
> > >>>>
> > >>>>> whether that topic is an "input" or a "changelog" or anything else
> > >>>>>>>
> > >>>>>> for
> > >>>>
> > >>>>> that
> > >>>>>>
> > >>>>>>> matter.
> > >>>>>>>
> > >>>>>>>
> > >>>>>>> Point 6:
> > >>>>>>> On the concern about the performance overhead of copying data
> > >>>>>>>
> > >>>>>> between
> > >>>
> > >>>> the
> > >>>>>
> > >>>>>> brokers, I think it's actually a bit overestimated. Splitting a
> > >>>>>>>
> > >>>>>> topic's
> > >>>>
> > >>>>> partition is probably rare, certainly rarer in general than
> > >>>>>>>
> > >>>>>> bootstrapping
> > >>>>>
> > >>>>>> new consumers on that topic. If "bootstrapping new consumers"
> means
> > >>>>>>>
> > >>>>>> that
> > >>>>>
> > >>>>>> they have to re-shuffle the data before they consume it, then you
> > >>>>>>>
> > >>>>>> wind
> > >>>>
> > >>>>> up
> > >>>>>
> > >>>>>> copying the same record multiple times:
> > >>>>>>>
> > >>>>>>> (broker: input topic) -> (initial consumer) -> (broker:
> repartition
> > >>>>>>>
> > >>>>>> topic)
> > >>>>>>
> > >>>>>>> -> (real consumer)
> > >>>>>>>
> > >>>>>>> That's 3x, and it's also 3x for every new record after the split
> as
> > >>>>>>>
> > >>>>>> well,
> > >>>>>
> > >>>>>> since you don't get to stop repartitioning/reshuffling once you
> > >>>>>>>
> > >>>>>> start.
> > >>>>
> > >>>>> Whereas if you do a backfill in something like the procedure I
> > >>>>>>>
> > >>>>>> outlined,
> > >>>>>
> > >>>>>> you only copy the prefix of the partition before the split, and
> you
> > >>>>>>>
> > >>>>>> send
> > >>>>>
> > >>>>>> it
> > >>>>>>
> > >>>>>>> once to the producer and then once to the new generation
> partition.
> > >>>>>>>
> > >>>>>> Plus,
> > >>>>>
> > >>>>>> assuming we're splitting the partition for the benefit of
> > >>>>>>>
> > >>>>>> consumers,
> > >>>
> > >>>> there's no reason we can't co-locate the post-split partitions on
> > >>>>>>>
> > >>>>>> the
> > >>>
> > >>>> same
> > >>>>>>
> > >>>>>>> host as the pre-split partition, making the second copy a local
> > >>>>>>>
> > >>>>>> filesystem
> > >>>>>>
> > >>>>>>> operation.
> > >>>>>>>
> > >>>>>>> Even if you follow these two copies up with bootstrapping a new
> > >>>>>>>
> > >>>>>> consumer,
> > >>>>>
> > >>>>>> it's still rare for this to occur, so you get to amortize these
> > >>>>>>>
> > >>>>>> copies
> > >>>>
> > >>>>> over
> > >>>>>>
> > >>>>>>> the lifetime of the topic, whereas a reshuffle just keeps making
> > >>>>>>>
> > >>>>>> copies
> > >>>>
> > >>>>> for
> > >>>>>>
> > >>>>>>> every new event.
> > >>>>>>>
> > >>>>>>> And finally, I really do think that regardless of any performance
> > >>>>>>>
> > >>>>>> concerns
> > >>>>>>
> > >>>>>>> about this operation, if it preserves loose organizational
> > >>>>>>>
> > >>>>>> coupling,
> > >>>
> > >>>> it
> > >>>>
> > >>>>> is
> > >>>>>>
> > >>>>>>> certainly worth it.
> > >>>>>>>
> > >>>>>>>
> > >>>>>>> In conclusion:
> > >>>>>>> It might actually be a good idea for us to clarify the scope of
> > >>>>>>>
> > >>>>>> KIP-253.
> > >>>>>
> > >>>>>> If
> > >>>>>>
> > >>>>>>> we're all agreed that it's a good algorithm for allowing in-order
> > >>>>>>>
> > >>>>>> message
> > >>>>>
> > >>>>>> delivery during partition expansion, then we can continue this
> > >>>>>>>
> > >>>>>> discussion
> > >>>>>
> > >>>>>> as a new KIP, something like "backfill with partition expansion".
> > >>>>>>>
> > >>>>>> This
> > >>>>
> > >>>>> would let Dong proceed with KIP-253. On the other hand, if it seems
> > >>>>>>>
> > >>>>>> like
> > >>>>>
> > >>>>>> this conversation may alter the design of KIP-253, then maybe we
> > >>>>>>>
> > >>>>>> *should*
> > >>>>>
> > >>>>>> just finish working it out.
> > >>>>>>>
> > >>>>>>> For my part, my only concern about KIP-253 is the one I raised
> > >>>>>>>
> > >>>>>> earlier.
> > >>>>
> > >>>>> Thanks again, all, for considering these points,
> > >>>>>>> -John
> > >>>>>>>
> > >>>>>>>
> > >>>>>>> On Tue, Mar 27, 2018 at 2:10 AM, Dong Lin <li...@gmail.com>
> > >>>>>>>
> > >>>>>> wrote:
> > >>>>
> > >>>>> On Tue, Mar 27, 2018 at 12:04 AM, Dong Lin <li...@gmail.com>
> > >>>>>>>>
> > >>>>>>> wrote:
> > >>>>>>
> > >>>>>>> Hey Jan,
> > >>>>>>>>>
> > >>>>>>>>> Thanks for the enthusiasm in improving Kafka's design. Now
> > >>>>>>>>>
> > >>>>>>>> that I
> > >>>
> > >>>> have
> > >>>>>>
> > >>>>>>> read through your discussion with Jun, here are my thoughts:
> > >>>>>>>>>
> > >>>>>>>>> - The latest proposal should with log compacted topics by
> > >>>>>>>>>
> > >>>>>>>> properly
> > >>>>
> > >>>>> deleting old messages after a new message with the same key is
> > >>>>>>>>>
> > >>>>>>>> produced.
> > >>>>>>>
> > >>>>>>>> So
> > >>>>>>>>
> > >>>>>>>>> it is probably not a concern anymore. Could you comment if
> > >>>>>>>>>
> > >>>>>>>> there
> > >>>
> > >>>> is
> > >>>>
> > >>>>> still
> > >>>>>>>
> > >>>>>>>> issue?
> > >>>>>>>>>
> > >>>>>>>>> - I wrote the SEP-5 and I am pretty familiar with the
> > >>>>>>>>>
> > >>>>>>>> motivation
> > >>
> > >>
> >
>

Re: [DISCUSS] KIP-253: Support in-order message delivery with partition expansion

Posted by Jeff Chao <jc...@salesforce.com>.
Hi, I had a question from Monday's meeting. The current mechanism, as Ray's
notes points out, is to create a copy consumer in which a switch over
happens when it catches up. Meanwhile, it looks like a producer would still
be writing using the old partitioning scheme. Wouldn't there be a case
where the copy consumer never catches up given a high enough produce rate?
I'm imagining this to work similarly to Kinesis's resharding mechanism,
though I may be missing something from the current proposal. Anyway, with
Kinesis as an example, this would mean a producer would stop writing using
the old scheme and start writing using the new scheme. That way, the
consumer will be able to catch up in which it will start consuming using
the new scheme afterwards.

Thanks,
Jeff Chao

On Sat, Apr 14, 2018 at 6:44 AM, Dong Lin <li...@gmail.com> wrote:

> Thanks for the notes by Jun and Ray. I have read through the notes. It
> seems that there are a few questions for the alternative solution by Jan
> and maybe Jan will answer these questions later?
>
> I have summarized the solution, which I previously provided in this thread,
> in KIP-287, to hopefully show that we may have a promising direction to
> solve the partition and processor expansion problem for stateful processing
> jobs. Maybe we can continue the discussion related to stateful processing
> in that discussion thread. If that looks good, maybe we can conclude the
> discussion for KIP-253.
>
> Not sure if I missed some ideas or questions in the notes. Is there
> specific concern for the latest KIP-253?
>
>
> On Mon, Apr 9, 2018 at 11:18 AM, Ray Chiang <rc...@apache.org> wrote:
>
> > My notes from today's meeting.  Sorry if I got anyone's name wrong. Plus
> I
> > missed a few moments with noise at home and/or dropped video.
> >
> > -Ray
> >
> > =====
> >
> > KIP-253 Discussion
> >
> > - Currently, adding partitions can cause keys to be read out-of-order.
> >   This KIP is trying to preserve the key ordering when adding partitions.
> >
> > - State management in applications (i.e. Kafka Streams) can maintain
> >   local state via caching.  If the number of partitions changes, how
> >   would those applications update their local state.  This is the current
> >   point of discussion/disagreement.
> >
> > - Jan Filipiak is mostly worried about log compacted topics.  Not as
> >   concerned about producer swapping.  Worried about the consumer design
> is
> >   a bit contradictory compared to the architecture.
> >
> >   Current design is to start up a new consumer in parallel with old
> >   topic/consumer.  Run until consumer finishes "copying" to the new
> topic.
> >   Once the consumer is caught up, point the producer at the new topic.
> >
> >   Would like to have this technique as a "core primitive" to Kafka.
> >   - Is this a useful primitive?
> >   - What's the best way to support it?
> >
> >   - Topic expansion as it currently exists just "adds partitions". But
> >     how does this affect bootstrapping applications?  How to deal with
> >     "moved" (from "old partition" to "new expanded partition") keys?
> >
> >   - Dong's proposal example.  10 partitions growing to 15.  5 of the
> >     first 10 partitions are split into 2 each.  Say Kafka remembers
> >     parent->child relationship.  Then for each parent partition, there
> >     are two child partitions.  Initially, there were 10 states to
> >     manage.  Then bootstrapping new application would have 15 states.
> >     Need to know which "generation" of partition you are consuming
> >     from.  Until you get to "newer" generation of data, then the keys
> >     will be find (i.e. reading from old partition).
> >
> >   - Scheme works well for transient events.  Any stateful processor will
> >     likely break.
> >
> >   - Tracking can become extremely complicated, since each split requires
> >     potentially more and more offset/partition combos.
> >
> >   - Need to support continuation for consumers to read the new
> partitions.
> >
> >   - With linear hashing, integral multiple increase (2x, 3x, 4x, etc).
> >     Easier mapping from old partition sets to new partition sets.
> >     Keys end up with a clean hierarchy instead of a major reshuffling.
> >
> >   - Dong's approach piggyback on existing leader epoch.  Log segment
> >     could be tagged with version in linear hashing case.
> >
> >   - In Jan's case, existing consumers bootstrap from the beginning.
> >
> >   - James' use case.  Using Kafka as a long term persistent data store.
> >     Putting "source of truth" information into Kafka.  Bootstrap case
> >     is very important.  New applications could be bootstrapping as they
> >     come up.
> >
> >     - Increasing partitions will help with load from prodcuer and
> >       increasing consumer parallelism.
> >     - How does Kinesis handling partition splits?  They don't have
> >       compacted logs, so no issue with bootstrapping.  Kinesis uses
> >       MD5 and splits results based on md5sum into bucket ranges.
> >     - Is it useful for the server to know the partitioning function?
> >       Consumer has some implicit assumptions about keyed partitions,
> >       but not strongly enforced on server side.
> >
> >     - KIP-213 (one to many joins in Kafka Streams)
> >
> >       - MySQL case.  Primary key forced to be used as Kafka key.
> >
> >         (Sorry had some audio and video drop at this point)
> >
> >       - Mirror Maker.  Source cluster has custom partitioning function.
> >         Producer won't duplicate to same partitioning setup as source.
> >         Need to provide same partitioning function to producer.
> >         Would need to determine partitioning function based on topic.
> >
> >         - Should server validate partitioning?
> >         - Who does actual determination of which key goes to which
> > partition.
> >
> >       - How to implement backfill?
> >
> >         - Who will do it?  In producer?  Hard to do.  Every client would
> >           need to add this functionality.  Better to do on server side.
> >         - Add a type of "copy consumer"?  Add backoff to producer?
> >           Benefit of doing in consumer vs. producer?
> >
> >   - Still TBD
> >     - How to dedupe control messages?
> >     - How to deal with subtle cases during transition?
> >     - Is it useful for the server to have the option to validate the key
> >       distribution?
> >     - Jan concerned about how a consumer application would look with the
> >       new "split partition" design.
> >     - KIP introduced callback.  Jan doesn't think is useful. Callback
> >       for switching "between Partition 1 and can start on Partition 11".
> >       Rely on marker in Partition 1 instead.  Intent for callback is
> >       for possibility that delivery of messages for given key is moved
> >       to a different consumer instance.
> >
> >
> >
> > On 4/6/18 9:44 AM, Dong Lin wrote:
> >
> >> Hey John,
> >>
> >> Thanks much for your super-detailed explanation. This is very helpful.
> >>
> >> Now that I have finished reading through your email, I think the
> proposed
> >> solution in my previous email probably meets the requirement #6 without
> >> requiring additional coordination (w.r.t. partition function) among
> >> clients. My understanding of requirement #6 is that, after partition
> >> expansion, messages with the given key will go to the same consumer
> before
> >> and after the partition expansion such that stream processing jobs won't
> >> be
> >> affected. Thus this approach seems to be better than backfilling since
> it
> >> does not require data copy for input topics.
> >>
> >> In order for the proposed solution to meet requirements #6, we need two
> >> extra requirements in addition to what has been described in the
> previous
> >> email: 1) stream processing job starts with the same number of
> processors
> >> as the initial number of partitions of the input topics; and 2) at any
> >> given time the number of partitions of the input topic >= the number of
> >> processors of the given stream processing job.
> >>
> >> Could you take a look at the proposed solution and see if any of the
> >> claims
> >> above is false?
> >>
> >>
> >> Hey Jan,
> >>
> >> Maybe it is more efficient for us to discuss your concern in the KIP
> >> Meeting.
> >>
> >>
> >> Thanks,
> >> Dong
> >>
> >>
> >> On Thu, Mar 29, 2018 at 2:05 PM, John Roesler <jo...@confluent.io>
> wrote:
> >>
> >> Hi Jun,
> >>>
> >>> Thanks for the response. I'm very new to this project, but I will share
> >>> my
> >>> perspective. I'm going to say a bunch of stuff that I know you know
> >>> already, but just so we're on the same page...
> >>>
> >>> This may also be a good time to get feedback from the other KStreams
> >>> folks.
> >>>
> >>> Using KStreams as a reference implementation for how stream processing
> >>> frameworks may interact with Kafka, I think it's important to eschew
> >>> knowledge about how KStreams currently handles internal communication,
> >>> making state durable, etc. Both because these details may change, and
> >>> because they won't be shared with other stream processors.
> >>>
> >>> =================================
> >>> Background
> >>>
> >>> We are looking at a picture like this:
> >>>
> >>>       input input input
> >>>           \   |   /
> >>>        +-------------+
> >>> +-----+ Consumer(s) +-------+
> >>> |     +-------------+       |
> >>> |                           |
> >>> |    KStreams Application   |
> >>> |                           |
> >>> |     +-------------+       |
> >>> +-----+ Producer(s) +-------+
> >>>        +-------------+
> >>>             /    \
> >>>          output output
> >>>
> >>> The inputs and outputs are Kafka topics (and therefore have 1 or more
> >>> partitions). We'd have at least 1 input and 0 or more outputs. The
> >>> Consumers and Producers are both the official KafkaConsumer and
> >>> KafkaProducer.
> >>>
> >>> In general, we'll assume that the input topics are provided by actors
> >>> over
> >>> which we have no control, although we may as well assume they are
> >>> friendly
> >>> and amenable to requests, and also that their promises are trustworthy.
> >>> This is important because we must depend on them to uphold some
> promises:
> >>> * That they tell us the schema of the data they publish, and abide by
> >>> that
> >>> schema. Without this, the inputs are essentially garbage.
> >>> * That they tell us some defining characteristics of the topics (more
> on
> >>> this in a sec.) and again strictly abide by that promise.
> >>>
> >>> What are the topic characteristics we care about?
> >>> 1. The name (or name pattern)
> >>> 2. How the messages are keyed (if at all)
> >>> 3. Whether the message timestamps are meaningful, and if so, what their
> >>> meaning is
> >>> 4. Assuming the records have identity, whether the partitions partition
> >>> the
> >>> records' identity space
> >>> 5. Whether the topic completely contains the data set
> >>> 6. Whether the messages in the topic are ordered
> >>>
> >>> #1 is obvious: without this information, we cannot access the data at
> >>> all.
> >>>
> >>> For #2, #3, #4, and #6, we may or may not need this information,
> >>> depending
> >>> on the logic of the application. For example, a trivial application
> that
> >>> simply counts all events it sees doesn't care about #2, #3, #4, or #6.
> >>> But
> >>> an application that groups by some attribute can take advantage of #2
> and
> >>> #4 if the topic data is already keyed and partitioned over that
> >>> attribute.
> >>> Likewise, if the application includes some temporal semantics on a
> >>> temporal
> >>> dimension that is already captured in #3, it may take advantage of that
> >>> fact.
> >>>
> >>> Note that #2, #3, #4, and #6 are all optional. If they are not
> promised,
> >>> we
> >>> can do extra work inside the application to accomplish what we need.
> >>> However, if they are promised (and if we depend on that promise), it is
> >>> essential that the topic providers uphold those promises, as we may not
> >>> be
> >>> in a position to verify them.
> >>>
> >>> Note also that if they make a promise, but it doesn't happen to line up
> >>> with our needs (data is keyed by attr1, but we need it by attr2, or
> >>> timestamp is produce-time, but we need it by event-time, etc.), then we
> >>> will have to go ahead and do that extra work internally anyway. This
> also
> >>> captures the situation in which two inputs are produced by different
> >>> providers, one of which meets our needs, and the other does not. The
> fact
> >>> that we can cope with this situation is the basis for my statement that
> >>> we
> >>> do not require coordination among producers.
> >>>
> >>> (Key Point A): In terms of optimization, #4 and #6 are the most
> valuable.
> >>> If these characteristics happen to line up with our needs, then
> KStreams
> >>> can be incredibly efficient in both time and computational resources.
> >>>
> >>>   #5 is similar to knowing the schema in that it tells us whether the
> >>> computation we want to do is possible or not. For example, suppose we
> >>> have
> >>> a topic of "users", and we want to construct a table for querying. If
> the
> >>> user topic doesn't completely contain the dataset, we cannot construct
> >>> the
> >>> table. Note that it doesn't matter whether the topic is compacted or
> not.
> >>> If the topic is complete, I can consume it starting at "earliest" and
> >>> build
> >>> my table. If it is not complete, I can do other computations on it. In
> >>> both
> >>> cases, it may or may not be compacted; it just doesn't matter.
> >>>
> >>> On the output side, the roles are reversed. We provide (or not) exactly
> >>> the
> >>> same set of guarantees to consumers of our outputs, and we likewise
> must
> >>> abide by the promises we make.
> >>>
> >>>
> >>> =================================
> >>> Partition Expansion
> >>>
> >>> With this formation in place, let's talk about partition expansion.
> >>>
> >>> Why do we have partitions in the first place? (let me know if I miss
> >>> something here)
> >>> * For logical data streams that are themselves partitionable, it allows
> >>> producers to operate concurrently without coordination. For example,
> >>> streaming data from a sensor in a particle accelerator, the sensor can
> be
> >>> subdivided into a grid and each grid square can produce independently
> to
> >>> a
> >>> different topic. This may be valuable because the total rate of data
> >>> exceeds the throughput to a single broker node or just because it
> allows
> >>> for failure of a single producer to cause the loss of only part of the
> >>> data.
> >>> * The brokers can offer linearly scaling throughput on the number of
> >>> partitions by hosting each partition on a separate broker node
> >>> * The brokers can host topics that are too large to fit on a single
> >>> broker's storage by hosting some partitions on separate broker nodes
> >>> * In cases where the use case permits handling partitions
> independently,
> >>> consumers can have algorithmic simplicity by processing the data for
> >>> separate partitions in separate threads, avoiding costly and
> error-prone
> >>> concurrent coordination code
> >>> * In cases where the use case permits handling partitions
> independently,
> >>> consumers can exceed the total throughput of a single broker-consumer
> >>> pair
> >>> * Just to throw this in as well, in cases where some network links are
> >>> less
> >>> costly than others (or lower latency or more reliable), such as when
> >>> brokers, producers, and consumers are running in racks: producer and
> >>> consumers can both benefit (independently) by locating work on each
> >>> partition in the same rack as the broker hosting that partition.
> >>>
> >>> In other words, we have three actors in this system: producers,
> brokers,
> >>> and consumers, and they all benefit from partitioning for different
> (but
> >>> sometimes related) reasons.
> >>>
> >>> This leads naturally to the conclusion that any of these actors may
> find
> >>> themselves in a sub-optimal or even dangerous situation in which
> >>> partition
> >>> expansion would be the solution. For example, the producer may find
> that
> >>> the existing throughput to the brokers is insufficient to match the
> data
> >>> rate, forcing them to drop data. Or a broker hosting a single partition
> >>> may
> >>> be running out of disk space. Or a consumer node handling a single
> >>> partition cannot match the rate of production for that partition,
> causing
> >>> it to fall behind.
> >>>
> >>> I think it's reasonable to assume that all the actors in the system
> can't
> >>> just arbitrarily expand a topic's partition. I think it's reasonable to
> >>> align this responsibility with the provider of the data, namely the
> >>> producer (the logical producer, not the KafkaProducer class).
> Therefore,
> >>> the producer who finds themselves in trouble can unilaterally expand
> >>> partitions to solve their problem.
> >>>
> >>> For the broker or a consumer in trouble, they have only one resort: to
> >>> request the producer to expand partitions. This is where it's helpful
> to
> >>> assume the producer is friendly.
> >>>
> >>>
> >>> Now, let's look at how a KStreams application fits into this scenario.
> >>>
> >>> (Key Point B1): As a consumer, we may find that the producer expands
> the
> >>> partitions of a topic, either for their own benefit or for the brokers.
> >>> In
> >>> this situation, the expand operation MUST NOT violate any promises that
> >>> have previously been made to us. This is the essence of KIP-253, to
> >>> ensure
> >>> the maintenance of promises #6 and #4. It would be great if the
> mechanics
> >>> of the expansion required no major disruption to processing or human
> >>> intervention.
> >>>
> >>> Specifically, let's say that input partition X splits into X1 and X2.
> #6
> >>> requires that the same old ordering guarantees of Kafka continue to
> hold.
> >>> Obviously, this is what KIP-253's title is about. #4 requires that we
> >>> either ensure that X1 and X2 are assigned to the same thread that was
> >>> previously assigned X OR that we immediately pause processing and split
> >>> any
> >>> state such that it appears X1 and X2 were *always* separate partitions.
> >>>
> >>> In other words, Option 1 is we treat X1 and X2 as still logically one
> >>> partition, equal to X. This is ideal, since in this scenario,
> partitions
> >>> are expanding for external reasons. We don't need to expand our
> >>> processing
> >>> to match. Option 2 requires a major disruption, since we'd have to
> pause
> >>> processing while we split our state. Clearly, KStreams or any other
> >>> stateful consumer would advocate for Option 1.
> >>>
> >>>
> >>> (Corollary to Key Point A): Still on the consumer side, we may find
> that
> >>> we
> >>> ourselves can benefit from partition expansion of an input. Since we
> can
> >>> cope with the absence of promise #4, partition expansion is not a hard
> >>> requirement for us, but assuming we were already benefiting from the
> >>> major
> >>> performance optimizations afforded by #4, it would be nice to be able
> to
> >>> request the producer satisfy our request for partition expansion **and
> to
> >>> be able to benefit from it**.
> >>>
> >>> What does it mean to be able to benefit from partition expansion?
> >>> Assuming
> >>> input topic partition X splits into X1 and X2, in this scenario, we
> >>> *would*
> >>> wish to be able to split our state such that it appears X1 and X2 were
> >>> *always* separate partitions. Of course, the conclusion of Key Point B1
> >>> still applies: we should be able to continue operating on (X1+X2 = X)
> as
> >>> one partition while asynchronously building the state of X1 and X2
> >>> separately.
> >>>
> >>> When it comes to the mechanics of building the state of X1 and X2
> >>> separately, we have really just two high-level options. Either this
> >>> problem
> >>> is solved by Kafka itself, giving me a view in which X1 and X2 were
> >>> always
> >>> separate partitions, or I have to do it myself. The latter means that I
> >>> have to take on substantially more complexity than I do today:
> >>> Bummer 1: My state has to be splittable to begin with, implying at the
> >>> least that I need to be able to scan every record in my state, a
> >>> requirement that otherwise does not exist.
> >>> Bummer 2: After splitting the state  of X1 and X2, I need to be able to
> >>> send at least one of those tasks, state included, to another
> application
> >>> node (in order to realize the benefit of the split). This is also a
> >>> requirement that does not currently exist.
> >>> Bummer 3: In order to actually perform the split, I must know and be
> able
> >>> to execute the exact same partition function the producer of my topic
> >>> uses.
> >>> This introduces a brand-new a priori commitment from my input
> producers:
> >>> (would-be #7: convey the partition function and abide by it). This is a
> >>> big
> >>> restriction over #4, which only requires them to guarantee *that there
> >>> is a
> >>> partition function*. Now they actually have to share the function with
> >>> me.
> >>> And I have to be able to implement and execute it myself. And if the
> >>> producer wishes to refine the partition function for an existing topic,
> >>> we
> >>> have another round of coordination, as they have to be sure that I, and
> >>> all
> >>> other consumers, begin using the new function *before* they do. This is
> >>> similar to the schema problem, with a similar set of solutions. We
> would
> >>> likely need a partition function registry and another magic byte on
> every
> >>> record to be sure we do this right. Not to mention some way to express
> >>> arbitrary partitioning logic over arbitrary data in a way that is
> >>> portable
> >>> across programming languages.
> >>>
> >>> Alternatively, if Kafka gives me a view in which X1 and X2 were always
> >>> separate, then I can create tasks for X1 and X2 and allow them to
> >>> bootstrap
> >>> while I continue to process X. Once they are ready, I can coordinate a
> >>> transition to stop X's task and switch to X1 and X2. None of those
> >>> bummers
> >>> are present, so this is a significantly better option for me.
> >>>
> >>> (Key Point B2): As a (friendly) producer, we may once again want on our
> >>> own
> >>> to expand partitions, or we may want to satisfy a request from the
> broker
> >>> or our consumers to do so. Again, we MUST NOT violate any promises we
> >>> have
> >>> previously given, and it would be great if the expansion required no
> >>> major
> >>> disruption to processing or human intervention. Additionally, since we
> >>> are
> >>> actually driving the expansion, it would also be great if we could
> avoid
> >>> Bummer 3's coordination problems from the producer's perspective.
> >>>
> >>>
> >>> ======================================
> >>> Briefly: KStreams internals
> >>>
> >>> I'm pretty sure you were asking me to comment on the implementation
> >>> details
> >>> of KStreams, so I'll say a few words about it. The most important thing
> >>> is
> >>> that KStreams is still very early in its development. Maybe
> "early-middle
> >>> maturity" is a good way to put it. We are actively discussing
> >>> more-or-less
> >>> major implementation changes to improve performance, footprint,
> >>> scalability, and ergonomics. So it may actually be misleading to
> discuss
> >>> deeply how KStreams internally uses Kafka topics.
> >>>
> >>> Nevertheless, it is currently true that KStreams uses Kafka topics for
> >>> communication between some internal computation nodes. We partition
> these
> >>> topics as the base unit of concurrency granularity, so it would
> >>> potentially
> >>> be beneficial to be able to expand partitions for some of these
> internal
> >>> topics at some point. However, we can alternatively just overpartition
> >>> these internal topics, creating in the low 100s of partitions instead
> of
> >>> the low 10s, for example. (Side note: if Kafka were someday to support
> >>> higher numbers of partitions, we could expand this scheme to
> >>> overpartition
> >>> in the 1000s of partitions.) With the option to overpartition, we don't
> >>> have a strong need for partition expansion internally.
> >>>
> >>> It is also currently true that KStreams uses Kafka to store a durable
> >>> changelog for some of our internal state stores. But we *only* read
> from
> >>> this topic *if* we need to restore a state store after node loss (or to
> >>> maintain a hot mirror of the state store), so I think it's unlikely
> that
> >>> we
> >>> would ever make use of partition expansion on the changelog topics.
> >>>
> >>> But once again, I'd like to emphasize that we may choose an alternative
> >>> implementation for either interprocess communication or state
> durability.
> >>>
> >>>
> >>> ======================================
> >>> Concluding thoughts
> >>>
> >>> I know this is a very long email, and I really appreciate you sticking
> >>> with
> >>> me this long. I hope it was useful for syncing our mental picture of
> this
> >>> system. Also, you're far more knowledgeable than I am about this system
> >>> and
> >>> this domain, so please correct me if I've said anything wrong.
> >>>
> >>> To me the key takeaways are that:
> >>> - KIP-253 satisfies all we need for correctness, since it contains
> >>> solutions to guarantee producers can abide by their promises w.r.t. #4
> >>> and
> >>> #6.
> >>> - From Key Point A: #4 is actually optional for KIP-253, but without
> it,
> >>> we
> >>> lose a potentially valuable optimization in KStreams (and all other
> >>> consumer applications)
> >>> - From Corollary to Point A: Without low-level support for partition
> >>> expansion with backfill, we cannot employ requesting partition
> expansion
> >>> as
> >>> a consumer to improve application performance. In that case, to ensure
> >>> performance scalability, we would have to discard for all KStreams
> >>> applications the performance optimization afforded by #4.
> >>> - From Key Point B1: After a partition split, we really need to be able
> >>> to
> >>> seamlessly continue operating as if it had not split.
> >>> - From Key Point B2: Since KIP-253 allows us to maintain all our
> >>> promises,
> >>> we have the option of expanding partitions in the topics we produce.
> >>> Without a backfill operation, though, our consumers may not be able to
> >>> realize the benefits of that split, if they were hoping to.
> >>>
> >>> In general, faced with the possibility of having to coordinate the
> >>> partition function with our inputs' producers or with our outputs'
> >>> consumers, I would personally lean toward overprovisioning and
> completely
> >>> avoiding resize for our use case. This doesn't mean that it's not
> useful
> >>> in
> >>> the ecosystem at large without backfill, just that it loses its luster
> >>> for
> >>> me. It also means that we can no longer take advantage of some of our
> >>> current optimizations, and in fact that we must introduce an extra hop
> of
> >>> repartitioning on every single input.
> >>>
> >>> I think this is actually a pretty good picture of the opportunities and
> >>> challenges that other consumers and producers in the Kafka ecosystem
> will
> >>> face.
> >>>
> >>> I hope this helps!
> >>>
> >>> Thanks,
> >>> -John
> >>>
> >>> On Wed, Mar 28, 2018 at 11:51 AM, Jun Rao <ju...@confluent.io> wrote:
> >>>
> >>> Hi, John,
> >>>>
> >>>> I actually think it's important to think through how KStreams handles
> >>>> partition expansion in this KIP. If we do decide that we truly need
> >>>> backfilling, it's much better to think through how to add it now,
> >>>> instead
> >>>> of retrofitting it later. It would be useful to outline how both
> >>>> existing
> >>>> KStreams jobs and new KStreams jobs work to see if backfilling is
> really
> >>>> needed.
> >>>>
> >>>> If we can figure out how KStreams works, at least we have one
> reference
> >>>> implementation for other stream processing frameworks that face the
> same
> >>>> issue.
> >>>>
> >>>> Thanks,
> >>>>
> >>>> Jun
> >>>>
> >>>>
> >>>> On Tue, Mar 27, 2018 at 4:56 PM, John Roesler <jo...@confluent.io>
> >>>> wrote:
> >>>>
> >>>> Hi Jun,
> >>>>>
> >>>>> That's a good point.
> >>>>>
> >>>>> Yeah, I don't think it would work too well for existing consumers in
> >>>>>
> >>>> the
> >>>
> >>>> middle of gen 0 to try and switch to a newly backfilled prefix of gen
> >>>>>
> >>>> 1.
> >>>
> >>>> They probably just need to finish up until they get to the end of gen
> 0
> >>>>>
> >>>> and
> >>>>
> >>>>> transition just as if there were no backfill available yet.
> >>>>>
> >>>>> This isn't terrible, since consumer applications that care about
> >>>>>
> >>>> scaling
> >>>
> >>>> up
> >>>>
> >>>>> to match a freshly split partition would wait until after the
> backfill
> >>>>>
> >>>> is
> >>>
> >>>> available to scale up. The consumer that starts out in gen=0, part=0
> is
> >>>>> going to be stuck with part=0 and part=3 in gen=1 in my example
> >>>>>
> >>>> regardless
> >>>>
> >>>>> of whether they finish scanning gen=0 before or after the backfill is
> >>>>> available.
> >>>>>
> >>>>> The broker knowing when it's ok to delete gen 0, including its offset
> >>>>> mappings, is a big issue, though. I don't have any immediate ideas
> for
> >>>>> solving it, but it doesn't feel impossible. Hopefully, you agree this
> >>>>>
> >>>> is
> >>>
> >>>> outside of KIP-253's scope, so maybe we don't need to worry about it
> >>>>>
> >>>> right
> >>>>
> >>>>> now.
> >>>>>
> >>>>> I do agree that reshuffling in KStreams effectively solves the
> >>>>>
> >>>> scalability
> >>>>
> >>>>> problem as well, as it decouples the partition count (and the
> partition
> >>>>> scheme) upstream from the parallelism of the streams application.
> >>>>>
> >>>> Likely,
> >>>
> >>>> we will do this in any case. I'm predominantly advocating for
> follow-on
> >>>>> work to enable backfill for the *other* Kafka users that are not
> >>>>>
> >>>> KStreams.
> >>>>
> >>>>> Thanks for your consideration,
> >>>>> -John
> >>>>>
> >>>>> On Tue, Mar 27, 2018 at 6:19 PM, Jun Rao <ju...@confluent.io> wrote:
> >>>>>
> >>>>> Hi, John,
> >>>>>>
> >>>>>> Thanks for the reply. I agree that the backfill approach works
> >>>>>>
> >>>>> cleaner
> >>>
> >>>> for
> >>>>>
> >>>>>> newly started consumers. I am just not sure if it's a good primitive
> >>>>>>
> >>>>> to
> >>>
> >>>> support for existing consumers. One of the challenges that I see is
> >>>>>>
> >>>>> the
> >>>
> >>>> remapping of the offsets. In your approach, we need to copy the
> >>>>>>
> >>>>> existing
> >>>>
> >>>>> records from the partitions in generation 0 to generation 1. Those
> >>>>>>
> >>>>> records
> >>>>>
> >>>>>> will get different offsets in the new generation. The broker will
> >>>>>>
> >>>>> have
> >>>
> >>>> to
> >>>>
> >>>>> store those offset mappings somewhere. When the backfill completes,
> >>>>>>
> >>>>> you
> >>>
> >>>> can
> >>>>>
> >>>>>> delete generation 0's data. However, the broker can't throw away the
> >>>>>>
> >>>>> offset
> >>>>>
> >>>>>> mappings immediately since it doesn't know if there is any existing
> >>>>>> consumer still consuming generation 0's records. In a compacted
> >>>>>>
> >>>>> topic,
> >>>
> >>>> the
> >>>>>
> >>>>>> broker probably can only safely remove the offset mappings when all
> >>>>>>
> >>>>> records
> >>>>>
> >>>>>> in generation 0 are removed by the cleaner. This may never happen
> >>>>>>
> >>>>> though.
> >>>>
> >>>>> If we reshuffle the input inside a KStreams job, it obviates the need
> >>>>>>
> >>>>> for
> >>>>
> >>>>> offset remapping on the broker.
> >>>>>>
> >>>>>> Jun
> >>>>>>
> >>>>>> On Tue, Mar 27, 2018 at 11:34 AM, John Roesler <jo...@confluent.io>
> >>>>>>
> >>>>> wrote:
> >>>>>
> >>>>>> Hey Dong and Jun,
> >>>>>>>
> >>>>>>> Thanks for the thoughtful responses. If you don't mind, I'll mix my
> >>>>>>>
> >>>>>> replies
> >>>>>>
> >>>>>>> together to try for a coherent response. I'm not too familiar with
> >>>>>>> mailing-list etiquette, though.
> >>>>>>>
> >>>>>>> I'm going to keep numbering my points because it makes it easy for
> >>>>>>>
> >>>>>> you
> >>>>
> >>>>> all
> >>>>>>
> >>>>>>> to respond.
> >>>>>>>
> >>>>>>> Point 1:
> >>>>>>> As I read it, KIP-253 is *just* about properly fencing the
> >>>>>>>
> >>>>>> producers
> >>>
> >>>> and
> >>>>>
> >>>>>> consumers so that you preserve the correct ordering of records
> >>>>>>>
> >>>>>> during
> >>>
> >>>> partition expansion. This is clearly necessary regardless of
> >>>>>>>
> >>>>>> anything
> >>>
> >>>> else
> >>>>>>
> >>>>>>> we discuss. I think this whole discussion about backfill,
> >>>>>>>
> >>>>>> consumers,
> >>>
> >>>> streams, etc., is beyond the scope of KIP-253. But it would be
> >>>>>>>
> >>>>>> cumbersome
> >>>>>
> >>>>>> to start a new thread at this point.
> >>>>>>>
> >>>>>>> I had missed KIP-253's Proposed Change #9 among all the details...
> >>>>>>>
> >>>>>> I
> >>>
> >>>> think
> >>>>>>
> >>>>>>> this is a nice addition to the proposal. One thought is that it's
> >>>>>>>
> >>>>>> actually
> >>>>>>
> >>>>>>> irrelevant whether the hash function is linear. This is simply an
> >>>>>>>
> >>>>>> algorithm
> >>>>>>
> >>>>>>> for moving a key from one partition to another, so the type of hash
> >>>>>>> function need not be a precondition. In fact, it also doesn't
> >>>>>>>
> >>>>>> matter
> >>>
> >>>> whether the topic is compacted or not, the algorithm works
> >>>>>>>
> >>>>>> regardless.
> >>>>
> >>>>> I think this is a good algorithm to keep in mind, as it might
> >>>>>>>
> >>>>>> solve a
> >>>
> >>>> variety of problems, but it does have a downside: that the producer
> >>>>>>>
> >>>>>> won't
> >>>>>
> >>>>>> know whether or not K1 was actually in P1, it just knows that K1
> >>>>>>>
> >>>>>> was
> >>>
> >>>> in
> >>>>
> >>>>> P1's keyspace before the new epoch. Therefore, it will have to
> >>>>>>> pessimistically send (K1,null) to P1 just in case. But the next
> >>>>>>>
> >>>>>> time
> >>>
> >>>> K1
> >>>>
> >>>>> comes along, the producer *also* won't remember that it already
> >>>>>>>
> >>>>>> retracted
> >>>>>
> >>>>>> K1 from P1, so it will have to send (K1,null) *again*. By
> >>>>>>>
> >>>>>> extension,
> >>>
> >>>> every
> >>>>>>
> >>>>>>> time the producer sends to P2, it will also have to send a
> >>>>>>>
> >>>>>> tombstone
> >>>
> >>>> to
> >>>>
> >>>>> P1,
> >>>>>>
> >>>>>>> which is a pretty big burden. To make the situation worse, if there
> >>>>>>>
> >>>>>> is
> >>>>
> >>>>> a
> >>>>>
> >>>>>> second split, say P2 becomes P2 and P3, then any key Kx belonging
> >>>>>>>
> >>>>>> to
> >>>
> >>>> P3
> >>>>
> >>>>> will also have to be retracted from P2 *and* P1, since the producer
> >>>>>>>
> >>>>>> can't
> >>>>>
> >>>>>> know whether Kx had been last written to P2 or P1. Over a long
> >>>>>>>
> >>>>>> period
> >>>
> >>>> of
> >>>>>
> >>>>>> time, this clearly becomes a issue, as the producer must send an
> >>>>>>>
> >>>>>> arbitrary
> >>>>>>
> >>>>>>> number of retractions along with every update.
> >>>>>>>
> >>>>>>> In contrast, the proposed backfill operation has an end, and after
> >>>>>>>
> >>>>>> it
> >>>
> >>>> ends,
> >>>>>>
> >>>>>>> everyone can afford to forget that there ever was a different
> >>>>>>>
> >>>>>> partition
> >>>>
> >>>>> layout.
> >>>>>>>
> >>>>>>> Really, though, figuring out how to split compacted topics is
> >>>>>>>
> >>>>>> beyond
> >>>
> >>>> the
> >>>>>
> >>>>>> scope of KIP-253, so I'm not sure #9 really even needs to be in
> >>>>>>>
> >>>>>> this
> >>>
> >>>> KIP...
> >>>>>>
> >>>>>>> We do need in-order delivery during partition expansion. It would
> >>>>>>>
> >>>>>> be
> >>>
> >>>> fine
> >>>>>
> >>>>>> by me to say that you *cannot* expand partitions of a log-compacted
> >>>>>>>
> >>>>>> topic
> >>>>>
> >>>>>> and call it a day. I think it would be better to tackle that in
> >>>>>>>
> >>>>>> another
> >>>>
> >>>>> KIP.
> >>>>>>>
> >>>>>>>
> >>>>>>> Point 2:
> >>>>>>> Regarding whether the consumer re-shuffles its inputs, this is
> >>>>>>>
> >>>>>> always
> >>>
> >>>> on
> >>>>>
> >>>>>> the table; any consumer who wants to re-shuffle its input is free
> >>>>>>>
> >>>>>> to
> >>>
> >>>> do
> >>>>
> >>>>> so.
> >>>>>>
> >>>>>>> But this is currently not required. It's just that the current
> >>>>>>>
> >>>>>> high-level
> >>>>>
> >>>>>> story with Kafka encourages the use of partitions as a unit of
> >>>>>>>
> >>>>>> concurrency.
> >>>>>>
> >>>>>>> As long as consumers are single-threaded, they can happily consume
> >>>>>>>
> >>>>>> a
> >>>
> >>>> single
> >>>>>>
> >>>>>>> partition without concurrency control of any kind. This is a key
> >>>>>>>
> >>>>>> aspect
> >>>>
> >>>>> to
> >>>>>>
> >>>>>>> this system that lets folks design high-throughput systems on top
> >>>>>>>
> >>>>>> of
> >>>
> >>>> it
> >>>>
> >>>>> surprisingly easily. If all consumers were instead
> >>>>>>>
> >>>>>> encouraged/required
> >>>>
> >>>>> to
> >>>>>
> >>>>>> implement a repartition of their own, then the consumer becomes
> >>>>>>> significantly more complex, requiring either the consumer to first
> >>>>>>>
> >>>>>> produce
> >>>>>>
> >>>>>>> to its own intermediate repartition topic or to ensure that
> >>>>>>>
> >>>>>> consumer
> >>>
> >>>> threads have a reliable, high-bandwith channel of communication
> >>>>>>>
> >>>>>> with
> >>>
> >>>> every
> >>>>>>
> >>>>>>> other consumer thread.
> >>>>>>>
> >>>>>>> Either of those tradeoffs may be reasonable for a particular user
> >>>>>>>
> >>>>>> of
> >>>
> >>>> Kafka,
> >>>>>>
> >>>>>>> but I don't know if we're in a position to say that they are
> >>>>>>>
> >>>>>> reasonable
> >>>>
> >>>>> for
> >>>>>>
> >>>>>>> *every* user of Kafka.
> >>>>>>>
> >>>>>>>
> >>>>>>> Point 3:
> >>>>>>> Regarding Jun's point about this use case, "(3) stateful and
> >>>>>>>
> >>>>>> maintaining
> >>>>>
> >>>>>> the
> >>>>>>> states in a local store", I agree that they may use a framework
> >>>>>>>
> >>>>>> *like*
> >>>>
> >>>>> Kafka Streams, but that is not the same as using Kafka Streams.
> >>>>>>>
> >>>>>> This
> >>>
> >>>> is
> >>>>
> >>>>> why
> >>>>>>
> >>>>>>> I think it's better to solve it in Core: because it is then solved
> >>>>>>>
> >>>>>> for
> >>>>
> >>>>> KStreams and also for everything else that facilitates local state
> >>>>>>> maintenance. To me, Streams is a member of the category of "stream
> >>>>>>> processing frameworks", which is itself a subcategory of "things
> >>>>>>>
> >>>>>> requiring
> >>>>>>
> >>>>>>> local state maintenence". I'm not sure if it makes sense to assert
> >>>>>>>
> >>>>>> that
> >>>>
> >>>>> Streams is a sufficient and practical replacement for everything in
> >>>>>>>
> >>>>>> "things
> >>>>>>
> >>>>>>> requiring local state maintenence".
> >>>>>>>
> >>>>>>> But, yes, I do agree that per-key ordering is an absolute
> >>>>>>>
> >>>>>> requirement,
> >>>>
> >>>>> therefore I think that KIP-253 itself is a necessary step.
> >>>>>>>
> >>>>>> Regarding
> >>>
> >>>> the
> >>>>>
> >>>>>> coupling of the state store partitioning to the topic partitioning,
> >>>>>>>
> >>>>>> yes,
> >>>>>
> >>>>>> this is an issue we are discussing solutions to right now. We may
> >>>>>>>
> >>>>>> go
> >>>
> >>>> ahead
> >>>>>>
> >>>>>>> and introduce an overpartition layer on our inputs to solve it, but
> >>>>>>>
> >>>>>> then
> >>>>>
> >>>>>> again, if we get the ability to split partitions with backfill, we
> >>>>>>>
> >>>>>> may
> >>>>
> >>>>> not
> >>>>>>
> >>>>>>> need to!
> >>>>>>>
> >>>>>>>
> >>>>>>> Point 4:
> >>>>>>> On this:
> >>>>>>>
> >>>>>>> Regarding thought 2: If we don't care about the stream use-case,
> >>>>>>>>
> >>>>>>> then
> >>>>
> >>>>> the
> >>>>>>
> >>>>>>> current KIP probably has already addressed problem without
> >>>>>>>>
> >>>>>>> requiring
> >>>>
> >>>>> consumer to know the partition function. If we care about the
> >>>>>>>>
> >>>>>>> stream
> >>>>
> >>>>> use-case, we already need coordination across producers of
> >>>>>>>>
> >>>>>>> different
> >>>>
> >>>>> topics, i.e. the same partition function needs to be used by
> >>>>>>>>
> >>>>>>> producers
> >>>>>
> >>>>>> of
> >>>>>>
> >>>>>>> topics A and B in order to join topics A and B. Thus, it might be
> >>>>>>>> reasonable to extend coordination a bit and say we need
> >>>>>>>>
> >>>>>>> coordination
> >>>>
> >>>>> across
> >>>>>>>
> >>>>>>>> clients (i.e. producer and consumer), such that consumer knows
> >>>>>>>>
> >>>>>>> the
> >>>
> >>>> partition function used by producer. If we do so, then we can let
> >>>>>>>>
> >>>>>>> consumer
> >>>>>>>
> >>>>>>>> re-copy data for the change log topic using the same partition
> >>>>>>>>
> >>>>>>> function
> >>>>>
> >>>>>> as
> >>>>>>>
> >>>>>>>> producer. This approach has lower overhead as compared to having
> >>>>>>>>
> >>>>>>> producer
> >>>>>>
> >>>>>>> re-copy data of the input topic.
> >>>>>>>> Also, producer currently does not need to know the data already
> >>>>>>>>
> >>>>>>> produced
> >>>>>>
> >>>>>>> to
> >>>>>>>
> >>>>>>>> the topic. If we let producer split/merge partition, it would
> >>>>>>>>
> >>>>>>> require
> >>>>
> >>>>> producer to consume the existing data, which intuitively is the
> >>>>>>>>
> >>>>>>> task
> >>>>
> >>>>> of
> >>>>>
> >>>>>> consumer.
> >>>>>>>>
> >>>>>>>
> >>>>>>> I think we do care about use cases *like* Streams, I just don't
> >>>>>>>
> >>>>>> think
> >>>
> >>>> we
> >>>>>
> >>>>>> should rely on Streams to implement a feature of Core like
> >>>>>>>
> >>>>>> partition
> >>>
> >>>> expansion.
> >>>>>>>
> >>>>>>> Note, though, that we (Streams) do not require coordination across
> >>>>>>> producers. If two topics are certified to be co-partitioned, then
> >>>>>>>
> >>>>>> Streams
> >>>>>
> >>>>>> apps can make use of that knowledge to optimize their topology
> >>>>>>>
> >>>>>> (skipping
> >>>>>
> >>>>>> a
> >>>>>>
> >>>>>>> repartition). But if they don't know whether they are
> >>>>>>>
> >>>>>> co-partitioned,
> >>>
> >>>> then
> >>>>>>
> >>>>>>> they'd better go ahead and repartition within the topology. This is
> >>>>>>>
> >>>>>> the
> >>>>
> >>>>> current state.
> >>>>>>>
> >>>>>>> A huge selling point of Kafka is enabling different parts of
> >>>>>>>
> >>>>>> loosely
> >>>
> >>>> coupled organizations to produce and consume data independently.
> >>>>>>>
> >>>>>> Some
> >>>
> >>>> coordination between producers and consumers is necessary, like
> >>>>>>> coordinating on the names of topics and their schemas. But Kafka's
> >>>>>>>
> >>>>>> value
> >>>>>
> >>>>>> proposition w.r.t. ESBs, etc. is inversely proportional to the
> >>>>>>>
> >>>>>> amount
> >>>
> >>>> of
> >>>>>
> >>>>>> coordination required. I think it behooves us to be extremely
> >>>>>>>
> >>>>>> skeptical
> >>>>
> >>>>> about introducing any coordination beyond correctness protocols.
> >>>>>>>
> >>>>>>> Asking producers and consumers, or even two different producers, to
> >>>>>>>
> >>>>>> share
> >>>>>
> >>>>>> code like the partition function is a pretty huge ask. What if they
> >>>>>>>
> >>>>>> are
> >>>>
> >>>>> using different languages?
> >>>>>>>
> >>>>>>> Comparing organizational overhead vs computational overhead, there
> >>>>>>>
> >>>>>> are
> >>>>
> >>>>> maybe two orders of magnitude difference between them. In other
> >>>>>>>
> >>>>>> words,
> >>>>
> >>>>> I
> >>>>>
> >>>>>> would happily take on the (linear) overhead of having the producer
> >>>>>>>
> >>>>>> re-copy
> >>>>>>
> >>>>>>> the data once during a re-partition in order to save the
> >>>>>>>
> >>>>>> organizational
> >>>>
> >>>>> overhead of tying all the producers and consumers together across
> >>>>>>>
> >>>>>> multiple
> >>>>>>
> >>>>>>> boundaries.
> >>>>>>>
> >>>>>>> On that last paragraph: note that the producer *did* know the data
> >>>>>>>
> >>>>>> it
> >>>
> >>>> already produced. It handled it the first time around. Asking it to
> >>>>>>> re-produce it into a new partition layout is squarely within its
> >>>>>>>
> >>>>>> scope
> >>>>
> >>>>> of
> >>>>>
> >>>>>> capabilities. Contrast this with the alternative, asking the
> >>>>>>>
> >>>>>> consumer
> >>>
> >>>> to
> >>>>>
> >>>>>> re-partition the data. I think this is even less intuitive, when
> >>>>>>>
> >>>>>> the
> >>>
> >>>> partition function belongs to the producer.
> >>>>>>>
> >>>>>>>
> >>>>>>> Point 5:
> >>>>>>> Dong asked this:
> >>>>>>>
> >>>>>>> For stream use-case that needs to increase consumer number, the
> >>>>>>>> existing consumer can backfill the existing data in the change
> >>>>>>>>
> >>>>>>> log
> >>>
> >>>> topic
> >>>>>>
> >>>>>>> to
> >>>>>>>
> >>>>>>>> the same change log topic with the new partition number, before
> >>>>>>>>
> >>>>>>> the
> >>>
> >>>> new
> >>>>>
> >>>>>> set
> >>>>>>>
> >>>>>>>> of consumers bootstrap state from the new partitions of the
> >>>>>>>>
> >>>>>>> change
> >>>
> >>>> log
> >>>>>
> >>>>>> topic, right?
> >>>>>>>>
> >>>>>>>
> >>>>>>> In this sense, the "consumer" is actually the producer of the
> >>>>>>>
> >>>>>> changelog
> >>>>
> >>>>> topic, so if we support partition expansion + backfill as a
> >>>>>>>
> >>>>>> producer/broker
> >>>>>>
> >>>>>>> operation, then it would be very straightforward for Streams to
> >>>>>>>
> >>>>>> split a
> >>>>
> >>>>> state store. As you say, they would simply instruct the broker to
> >>>>>>>
> >>>>>> split
> >>>>
> >>>>> the
> >>>>>>
> >>>>>>> changelog topic's partitions, then backfill. Once the backfill is
> >>>>>>>
> >>>>>> ready,
> >>>>>
> >>>>>> they can create a new crop of StandbyTasks to bootstrap the more
> >>>>>>>
> >>>>>> granular
> >>>>>
> >>>>>> state stores and finally switch over to them when they are ready.
> >>>>>>>
> >>>>>>> But this actually seems to be an argument in favor of
> >>>>>>>
> >>>>>> split+backfill,
> >>>
> >>>> so
> >>>>>
> >>>>>> maybe I missed the point.
> >>>>>>>
> >>>>>>> You also asked me to explain why copying the "input" topic is
> >>>>>>>
> >>>>>> better
> >>>
> >>>> than
> >>>>>
> >>>>>> copying the "changelog" topic. I think they are totally
> >>>>>>>
> >>>>>> independent,
> >>>
> >>>> actually. For one thing, you can't depend on the existence of a
> >>>>>>>
> >>>>>> "changelog"
> >>>>>>
> >>>>>>> topic in general, only within Streams, but Kafka's user base
> >>>>>>>
> >>>>>> clearly
> >>>
> >>>> exceeds Streams's user base. Plus, you actually also can't depend
> >>>>>>>
> >>>>>> on
> >>>
> >>>> the
> >>>>>
> >>>>>> existence of a changelog topic within Streams, since that is an
> >>>>>>>
> >>>>>> optional
> >>>>>
> >>>>>> feature of *some* state store implementations. Even in the
> >>>>>>>
> >>>>>> situation
> >>>
> >>>> where
> >>>>>>
> >>>>>>> you do have a changelog topic in Streams, there may be use cases
> >>>>>>>
> >>>>>> where
> >>>>
> >>>>> it
> >>>>>
> >>>>>> makes sense to expand the partitions of just the input, or just the
> >>>>>>> changelog.
> >>>>>>>
> >>>>>>> The ask for a Core feature of split+backfill is really about
> >>>>>>>
> >>>>>> supporting
> >>>>
> >>>>> the
> >>>>>>
> >>>>>>> use case of splitting partitions in log-compacted topics,
> >>>>>>>
> >>>>>> regardless
> >>>
> >>>> of
> >>>>
> >>>>> whether that topic is an "input" or a "changelog" or anything else
> >>>>>>>
> >>>>>> for
> >>>>
> >>>>> that
> >>>>>>
> >>>>>>> matter.
> >>>>>>>
> >>>>>>>
> >>>>>>> Point 6:
> >>>>>>> On the concern about the performance overhead of copying data
> >>>>>>>
> >>>>>> between
> >>>
> >>>> the
> >>>>>
> >>>>>> brokers, I think it's actually a bit overestimated. Splitting a
> >>>>>>>
> >>>>>> topic's
> >>>>
> >>>>> partition is probably rare, certainly rarer in general than
> >>>>>>>
> >>>>>> bootstrapping
> >>>>>
> >>>>>> new consumers on that topic. If "bootstrapping new consumers" means
> >>>>>>>
> >>>>>> that
> >>>>>
> >>>>>> they have to re-shuffle the data before they consume it, then you
> >>>>>>>
> >>>>>> wind
> >>>>
> >>>>> up
> >>>>>
> >>>>>> copying the same record multiple times:
> >>>>>>>
> >>>>>>> (broker: input topic) -> (initial consumer) -> (broker: repartition
> >>>>>>>
> >>>>>> topic)
> >>>>>>
> >>>>>>> -> (real consumer)
> >>>>>>>
> >>>>>>> That's 3x, and it's also 3x for every new record after the split as
> >>>>>>>
> >>>>>> well,
> >>>>>
> >>>>>> since you don't get to stop repartitioning/reshuffling once you
> >>>>>>>
> >>>>>> start.
> >>>>
> >>>>> Whereas if you do a backfill in something like the procedure I
> >>>>>>>
> >>>>>> outlined,
> >>>>>
> >>>>>> you only copy the prefix of the partition before the split, and you
> >>>>>>>
> >>>>>> send
> >>>>>
> >>>>>> it
> >>>>>>
> >>>>>>> once to the producer and then once to the new generation partition.
> >>>>>>>
> >>>>>> Plus,
> >>>>>
> >>>>>> assuming we're splitting the partition for the benefit of
> >>>>>>>
> >>>>>> consumers,
> >>>
> >>>> there's no reason we can't co-locate the post-split partitions on
> >>>>>>>
> >>>>>> the
> >>>
> >>>> same
> >>>>>>
> >>>>>>> host as the pre-split partition, making the second copy a local
> >>>>>>>
> >>>>>> filesystem
> >>>>>>
> >>>>>>> operation.
> >>>>>>>
> >>>>>>> Even if you follow these two copies up with bootstrapping a new
> >>>>>>>
> >>>>>> consumer,
> >>>>>
> >>>>>> it's still rare for this to occur, so you get to amortize these
> >>>>>>>
> >>>>>> copies
> >>>>
> >>>>> over
> >>>>>>
> >>>>>>> the lifetime of the topic, whereas a reshuffle just keeps making
> >>>>>>>
> >>>>>> copies
> >>>>
> >>>>> for
> >>>>>>
> >>>>>>> every new event.
> >>>>>>>
> >>>>>>> And finally, I really do think that regardless of any performance
> >>>>>>>
> >>>>>> concerns
> >>>>>>
> >>>>>>> about this operation, if it preserves loose organizational
> >>>>>>>
> >>>>>> coupling,
> >>>
> >>>> it
> >>>>
> >>>>> is
> >>>>>>
> >>>>>>> certainly worth it.
> >>>>>>>
> >>>>>>>
> >>>>>>> In conclusion:
> >>>>>>> It might actually be a good idea for us to clarify the scope of
> >>>>>>>
> >>>>>> KIP-253.
> >>>>>
> >>>>>> If
> >>>>>>
> >>>>>>> we're all agreed that it's a good algorithm for allowing in-order
> >>>>>>>
> >>>>>> message
> >>>>>
> >>>>>> delivery during partition expansion, then we can continue this
> >>>>>>>
> >>>>>> discussion
> >>>>>
> >>>>>> as a new KIP, something like "backfill with partition expansion".
> >>>>>>>
> >>>>>> This
> >>>>
> >>>>> would let Dong proceed with KIP-253. On the other hand, if it seems
> >>>>>>>
> >>>>>> like
> >>>>>
> >>>>>> this conversation may alter the design of KIP-253, then maybe we
> >>>>>>>
> >>>>>> *should*
> >>>>>
> >>>>>> just finish working it out.
> >>>>>>>
> >>>>>>> For my part, my only concern about KIP-253 is the one I raised
> >>>>>>>
> >>>>>> earlier.
> >>>>
> >>>>> Thanks again, all, for considering these points,
> >>>>>>> -John
> >>>>>>>
> >>>>>>>
> >>>>>>> On Tue, Mar 27, 2018 at 2:10 AM, Dong Lin <li...@gmail.com>
> >>>>>>>
> >>>>>> wrote:
> >>>>
> >>>>> On Tue, Mar 27, 2018 at 12:04 AM, Dong Lin <li...@gmail.com>
> >>>>>>>>
> >>>>>>> wrote:
> >>>>>>
> >>>>>>> Hey Jan,
> >>>>>>>>>
> >>>>>>>>> Thanks for the enthusiasm in improving Kafka's design. Now
> >>>>>>>>>
> >>>>>>>> that I
> >>>
> >>>> have
> >>>>>>
> >>>>>>> read through your discussion with Jun, here are my thoughts:
> >>>>>>>>>
> >>>>>>>>> - The latest proposal should with log compacted topics by
> >>>>>>>>>
> >>>>>>>> properly
> >>>>
> >>>>> deleting old messages after a new message with the same key is
> >>>>>>>>>
> >>>>>>>> produced.
> >>>>>>>
> >>>>>>>> So
> >>>>>>>>
> >>>>>>>>> it is probably not a concern anymore. Could you comment if
> >>>>>>>>>
> >>>>>>>> there
> >>>
> >>>> is
> >>>>
> >>>>> still
> >>>>>>>
> >>>>>>>> issue?
> >>>>>>>>>
> >>>>>>>>> - I wrote the SEP-5 and I am pretty familiar with the
> >>>>>>>>>
> >>>>>>>> motivation
> >>
> >>
>

Re: [DISCUSS] KIP-253: Support in-order message delivery with partition expansion

Posted by Dong Lin <li...@gmail.com>.
Thanks for the notes by Jun and Ray. I have read through the notes. It
seems that there are a few questions for the alternative solution by Jan
and maybe Jan will answer these questions later?

I have summarized the solution, which I previously provided in this thread,
in KIP-287, to hopefully show that we may have a promising direction to
solve the partition and processor expansion problem for stateful processing
jobs. Maybe we can continue the discussion related to stateful processing
in that discussion thread. If that looks good, maybe we can conclude the
discussion for KIP-253.

Not sure if I missed some ideas or questions in the notes. Is there
specific concern for the latest KIP-253?


On Mon, Apr 9, 2018 at 11:18 AM, Ray Chiang <rc...@apache.org> wrote:

> My notes from today's meeting.  Sorry if I got anyone's name wrong. Plus I
> missed a few moments with noise at home and/or dropped video.
>
> -Ray
>
> =====
>
> KIP-253 Discussion
>
> - Currently, adding partitions can cause keys to be read out-of-order.
>   This KIP is trying to preserve the key ordering when adding partitions.
>
> - State management in applications (i.e. Kafka Streams) can maintain
>   local state via caching.  If the number of partitions changes, how
>   would those applications update their local state.  This is the current
>   point of discussion/disagreement.
>
> - Jan Filipiak is mostly worried about log compacted topics.  Not as
>   concerned about producer swapping.  Worried about the consumer design is
>   a bit contradictory compared to the architecture.
>
>   Current design is to start up a new consumer in parallel with old
>   topic/consumer.  Run until consumer finishes "copying" to the new topic.
>   Once the consumer is caught up, point the producer at the new topic.
>
>   Would like to have this technique as a "core primitive" to Kafka.
>   - Is this a useful primitive?
>   - What's the best way to support it?
>
>   - Topic expansion as it currently exists just "adds partitions". But
>     how does this affect bootstrapping applications?  How to deal with
>     "moved" (from "old partition" to "new expanded partition") keys?
>
>   - Dong's proposal example.  10 partitions growing to 15.  5 of the
>     first 10 partitions are split into 2 each.  Say Kafka remembers
>     parent->child relationship.  Then for each parent partition, there
>     are two child partitions.  Initially, there were 10 states to
>     manage.  Then bootstrapping new application would have 15 states.
>     Need to know which "generation" of partition you are consuming
>     from.  Until you get to "newer" generation of data, then the keys
>     will be find (i.e. reading from old partition).
>
>   - Scheme works well for transient events.  Any stateful processor will
>     likely break.
>
>   - Tracking can become extremely complicated, since each split requires
>     potentially more and more offset/partition combos.
>
>   - Need to support continuation for consumers to read the new partitions.
>
>   - With linear hashing, integral multiple increase (2x, 3x, 4x, etc).
>     Easier mapping from old partition sets to new partition sets.
>     Keys end up with a clean hierarchy instead of a major reshuffling.
>
>   - Dong's approach piggyback on existing leader epoch.  Log segment
>     could be tagged with version in linear hashing case.
>
>   - In Jan's case, existing consumers bootstrap from the beginning.
>
>   - James' use case.  Using Kafka as a long term persistent data store.
>     Putting "source of truth" information into Kafka.  Bootstrap case
>     is very important.  New applications could be bootstrapping as they
>     come up.
>
>     - Increasing partitions will help with load from prodcuer and
>       increasing consumer parallelism.
>     - How does Kinesis handling partition splits?  They don't have
>       compacted logs, so no issue with bootstrapping.  Kinesis uses
>       MD5 and splits results based on md5sum into bucket ranges.
>     - Is it useful for the server to know the partitioning function?
>       Consumer has some implicit assumptions about keyed partitions,
>       but not strongly enforced on server side.
>
>     - KIP-213 (one to many joins in Kafka Streams)
>
>       - MySQL case.  Primary key forced to be used as Kafka key.
>
>         (Sorry had some audio and video drop at this point)
>
>       - Mirror Maker.  Source cluster has custom partitioning function.
>         Producer won't duplicate to same partitioning setup as source.
>         Need to provide same partitioning function to producer.
>         Would need to determine partitioning function based on topic.
>
>         - Should server validate partitioning?
>         - Who does actual determination of which key goes to which
> partition.
>
>       - How to implement backfill?
>
>         - Who will do it?  In producer?  Hard to do.  Every client would
>           need to add this functionality.  Better to do on server side.
>         - Add a type of "copy consumer"?  Add backoff to producer?
>           Benefit of doing in consumer vs. producer?
>
>   - Still TBD
>     - How to dedupe control messages?
>     - How to deal with subtle cases during transition?
>     - Is it useful for the server to have the option to validate the key
>       distribution?
>     - Jan concerned about how a consumer application would look with the
>       new "split partition" design.
>     - KIP introduced callback.  Jan doesn't think is useful. Callback
>       for switching "between Partition 1 and can start on Partition 11".
>       Rely on marker in Partition 1 instead.  Intent for callback is
>       for possibility that delivery of messages for given key is moved
>       to a different consumer instance.
>
>
>
> On 4/6/18 9:44 AM, Dong Lin wrote:
>
>> Hey John,
>>
>> Thanks much for your super-detailed explanation. This is very helpful.
>>
>> Now that I have finished reading through your email, I think the proposed
>> solution in my previous email probably meets the requirement #6 without
>> requiring additional coordination (w.r.t. partition function) among
>> clients. My understanding of requirement #6 is that, after partition
>> expansion, messages with the given key will go to the same consumer before
>> and after the partition expansion such that stream processing jobs won't
>> be
>> affected. Thus this approach seems to be better than backfilling since it
>> does not require data copy for input topics.
>>
>> In order for the proposed solution to meet requirements #6, we need two
>> extra requirements in addition to what has been described in the previous
>> email: 1) stream processing job starts with the same number of processors
>> as the initial number of partitions of the input topics; and 2) at any
>> given time the number of partitions of the input topic >= the number of
>> processors of the given stream processing job.
>>
>> Could you take a look at the proposed solution and see if any of the
>> claims
>> above is false?
>>
>>
>> Hey Jan,
>>
>> Maybe it is more efficient for us to discuss your concern in the KIP
>> Meeting.
>>
>>
>> Thanks,
>> Dong
>>
>>
>> On Thu, Mar 29, 2018 at 2:05 PM, John Roesler <jo...@confluent.io> wrote:
>>
>> Hi Jun,
>>>
>>> Thanks for the response. I'm very new to this project, but I will share
>>> my
>>> perspective. I'm going to say a bunch of stuff that I know you know
>>> already, but just so we're on the same page...
>>>
>>> This may also be a good time to get feedback from the other KStreams
>>> folks.
>>>
>>> Using KStreams as a reference implementation for how stream processing
>>> frameworks may interact with Kafka, I think it's important to eschew
>>> knowledge about how KStreams currently handles internal communication,
>>> making state durable, etc. Both because these details may change, and
>>> because they won't be shared with other stream processors.
>>>
>>> =================================
>>> Background
>>>
>>> We are looking at a picture like this:
>>>
>>>       input input input
>>>           \   |   /
>>>        +-------------+
>>> +-----+ Consumer(s) +-------+
>>> |     +-------------+       |
>>> |                           |
>>> |    KStreams Application   |
>>> |                           |
>>> |     +-------------+       |
>>> +-----+ Producer(s) +-------+
>>>        +-------------+
>>>             /    \
>>>          output output
>>>
>>> The inputs and outputs are Kafka topics (and therefore have 1 or more
>>> partitions). We'd have at least 1 input and 0 or more outputs. The
>>> Consumers and Producers are both the official KafkaConsumer and
>>> KafkaProducer.
>>>
>>> In general, we'll assume that the input topics are provided by actors
>>> over
>>> which we have no control, although we may as well assume they are
>>> friendly
>>> and amenable to requests, and also that their promises are trustworthy.
>>> This is important because we must depend on them to uphold some promises:
>>> * That they tell us the schema of the data they publish, and abide by
>>> that
>>> schema. Without this, the inputs are essentially garbage.
>>> * That they tell us some defining characteristics of the topics (more on
>>> this in a sec.) and again strictly abide by that promise.
>>>
>>> What are the topic characteristics we care about?
>>> 1. The name (or name pattern)
>>> 2. How the messages are keyed (if at all)
>>> 3. Whether the message timestamps are meaningful, and if so, what their
>>> meaning is
>>> 4. Assuming the records have identity, whether the partitions partition
>>> the
>>> records' identity space
>>> 5. Whether the topic completely contains the data set
>>> 6. Whether the messages in the topic are ordered
>>>
>>> #1 is obvious: without this information, we cannot access the data at
>>> all.
>>>
>>> For #2, #3, #4, and #6, we may or may not need this information,
>>> depending
>>> on the logic of the application. For example, a trivial application that
>>> simply counts all events it sees doesn't care about #2, #3, #4, or #6.
>>> But
>>> an application that groups by some attribute can take advantage of #2 and
>>> #4 if the topic data is already keyed and partitioned over that
>>> attribute.
>>> Likewise, if the application includes some temporal semantics on a
>>> temporal
>>> dimension that is already captured in #3, it may take advantage of that
>>> fact.
>>>
>>> Note that #2, #3, #4, and #6 are all optional. If they are not promised,
>>> we
>>> can do extra work inside the application to accomplish what we need.
>>> However, if they are promised (and if we depend on that promise), it is
>>> essential that the topic providers uphold those promises, as we may not
>>> be
>>> in a position to verify them.
>>>
>>> Note also that if they make a promise, but it doesn't happen to line up
>>> with our needs (data is keyed by attr1, but we need it by attr2, or
>>> timestamp is produce-time, but we need it by event-time, etc.), then we
>>> will have to go ahead and do that extra work internally anyway. This also
>>> captures the situation in which two inputs are produced by different
>>> providers, one of which meets our needs, and the other does not. The fact
>>> that we can cope with this situation is the basis for my statement that
>>> we
>>> do not require coordination among producers.
>>>
>>> (Key Point A): In terms of optimization, #4 and #6 are the most valuable.
>>> If these characteristics happen to line up with our needs, then KStreams
>>> can be incredibly efficient in both time and computational resources.
>>>
>>>   #5 is similar to knowing the schema in that it tells us whether the
>>> computation we want to do is possible or not. For example, suppose we
>>> have
>>> a topic of "users", and we want to construct a table for querying. If the
>>> user topic doesn't completely contain the dataset, we cannot construct
>>> the
>>> table. Note that it doesn't matter whether the topic is compacted or not.
>>> If the topic is complete, I can consume it starting at "earliest" and
>>> build
>>> my table. If it is not complete, I can do other computations on it. In
>>> both
>>> cases, it may or may not be compacted; it just doesn't matter.
>>>
>>> On the output side, the roles are reversed. We provide (or not) exactly
>>> the
>>> same set of guarantees to consumers of our outputs, and we likewise must
>>> abide by the promises we make.
>>>
>>>
>>> =================================
>>> Partition Expansion
>>>
>>> With this formation in place, let's talk about partition expansion.
>>>
>>> Why do we have partitions in the first place? (let me know if I miss
>>> something here)
>>> * For logical data streams that are themselves partitionable, it allows
>>> producers to operate concurrently without coordination. For example,
>>> streaming data from a sensor in a particle accelerator, the sensor can be
>>> subdivided into a grid and each grid square can produce independently to
>>> a
>>> different topic. This may be valuable because the total rate of data
>>> exceeds the throughput to a single broker node or just because it allows
>>> for failure of a single producer to cause the loss of only part of the
>>> data.
>>> * The brokers can offer linearly scaling throughput on the number of
>>> partitions by hosting each partition on a separate broker node
>>> * The brokers can host topics that are too large to fit on a single
>>> broker's storage by hosting some partitions on separate broker nodes
>>> * In cases where the use case permits handling partitions independently,
>>> consumers can have algorithmic simplicity by processing the data for
>>> separate partitions in separate threads, avoiding costly and error-prone
>>> concurrent coordination code
>>> * In cases where the use case permits handling partitions independently,
>>> consumers can exceed the total throughput of a single broker-consumer
>>> pair
>>> * Just to throw this in as well, in cases where some network links are
>>> less
>>> costly than others (or lower latency or more reliable), such as when
>>> brokers, producers, and consumers are running in racks: producer and
>>> consumers can both benefit (independently) by locating work on each
>>> partition in the same rack as the broker hosting that partition.
>>>
>>> In other words, we have three actors in this system: producers, brokers,
>>> and consumers, and they all benefit from partitioning for different (but
>>> sometimes related) reasons.
>>>
>>> This leads naturally to the conclusion that any of these actors may find
>>> themselves in a sub-optimal or even dangerous situation in which
>>> partition
>>> expansion would be the solution. For example, the producer may find that
>>> the existing throughput to the brokers is insufficient to match the data
>>> rate, forcing them to drop data. Or a broker hosting a single partition
>>> may
>>> be running out of disk space. Or a consumer node handling a single
>>> partition cannot match the rate of production for that partition, causing
>>> it to fall behind.
>>>
>>> I think it's reasonable to assume that all the actors in the system can't
>>> just arbitrarily expand a topic's partition. I think it's reasonable to
>>> align this responsibility with the provider of the data, namely the
>>> producer (the logical producer, not the KafkaProducer class). Therefore,
>>> the producer who finds themselves in trouble can unilaterally expand
>>> partitions to solve their problem.
>>>
>>> For the broker or a consumer in trouble, they have only one resort: to
>>> request the producer to expand partitions. This is where it's helpful to
>>> assume the producer is friendly.
>>>
>>>
>>> Now, let's look at how a KStreams application fits into this scenario.
>>>
>>> (Key Point B1): As a consumer, we may find that the producer expands the
>>> partitions of a topic, either for their own benefit or for the brokers.
>>> In
>>> this situation, the expand operation MUST NOT violate any promises that
>>> have previously been made to us. This is the essence of KIP-253, to
>>> ensure
>>> the maintenance of promises #6 and #4. It would be great if the mechanics
>>> of the expansion required no major disruption to processing or human
>>> intervention.
>>>
>>> Specifically, let's say that input partition X splits into X1 and X2. #6
>>> requires that the same old ordering guarantees of Kafka continue to hold.
>>> Obviously, this is what KIP-253's title is about. #4 requires that we
>>> either ensure that X1 and X2 are assigned to the same thread that was
>>> previously assigned X OR that we immediately pause processing and split
>>> any
>>> state such that it appears X1 and X2 were *always* separate partitions.
>>>
>>> In other words, Option 1 is we treat X1 and X2 as still logically one
>>> partition, equal to X. This is ideal, since in this scenario, partitions
>>> are expanding for external reasons. We don't need to expand our
>>> processing
>>> to match. Option 2 requires a major disruption, since we'd have to pause
>>> processing while we split our state. Clearly, KStreams or any other
>>> stateful consumer would advocate for Option 1.
>>>
>>>
>>> (Corollary to Key Point A): Still on the consumer side, we may find that
>>> we
>>> ourselves can benefit from partition expansion of an input. Since we can
>>> cope with the absence of promise #4, partition expansion is not a hard
>>> requirement for us, but assuming we were already benefiting from the
>>> major
>>> performance optimizations afforded by #4, it would be nice to be able to
>>> request the producer satisfy our request for partition expansion **and to
>>> be able to benefit from it**.
>>>
>>> What does it mean to be able to benefit from partition expansion?
>>> Assuming
>>> input topic partition X splits into X1 and X2, in this scenario, we
>>> *would*
>>> wish to be able to split our state such that it appears X1 and X2 were
>>> *always* separate partitions. Of course, the conclusion of Key Point B1
>>> still applies: we should be able to continue operating on (X1+X2 = X) as
>>> one partition while asynchronously building the state of X1 and X2
>>> separately.
>>>
>>> When it comes to the mechanics of building the state of X1 and X2
>>> separately, we have really just two high-level options. Either this
>>> problem
>>> is solved by Kafka itself, giving me a view in which X1 and X2 were
>>> always
>>> separate partitions, or I have to do it myself. The latter means that I
>>> have to take on substantially more complexity than I do today:
>>> Bummer 1: My state has to be splittable to begin with, implying at the
>>> least that I need to be able to scan every record in my state, a
>>> requirement that otherwise does not exist.
>>> Bummer 2: After splitting the state  of X1 and X2, I need to be able to
>>> send at least one of those tasks, state included, to another application
>>> node (in order to realize the benefit of the split). This is also a
>>> requirement that does not currently exist.
>>> Bummer 3: In order to actually perform the split, I must know and be able
>>> to execute the exact same partition function the producer of my topic
>>> uses.
>>> This introduces a brand-new a priori commitment from my input producers:
>>> (would-be #7: convey the partition function and abide by it). This is a
>>> big
>>> restriction over #4, which only requires them to guarantee *that there
>>> is a
>>> partition function*. Now they actually have to share the function with
>>> me.
>>> And I have to be able to implement and execute it myself. And if the
>>> producer wishes to refine the partition function for an existing topic,
>>> we
>>> have another round of coordination, as they have to be sure that I, and
>>> all
>>> other consumers, begin using the new function *before* they do. This is
>>> similar to the schema problem, with a similar set of solutions. We would
>>> likely need a partition function registry and another magic byte on every
>>> record to be sure we do this right. Not to mention some way to express
>>> arbitrary partitioning logic over arbitrary data in a way that is
>>> portable
>>> across programming languages.
>>>
>>> Alternatively, if Kafka gives me a view in which X1 and X2 were always
>>> separate, then I can create tasks for X1 and X2 and allow them to
>>> bootstrap
>>> while I continue to process X. Once they are ready, I can coordinate a
>>> transition to stop X's task and switch to X1 and X2. None of those
>>> bummers
>>> are present, so this is a significantly better option for me.
>>>
>>> (Key Point B2): As a (friendly) producer, we may once again want on our
>>> own
>>> to expand partitions, or we may want to satisfy a request from the broker
>>> or our consumers to do so. Again, we MUST NOT violate any promises we
>>> have
>>> previously given, and it would be great if the expansion required no
>>> major
>>> disruption to processing or human intervention. Additionally, since we
>>> are
>>> actually driving the expansion, it would also be great if we could avoid
>>> Bummer 3's coordination problems from the producer's perspective.
>>>
>>>
>>> ======================================
>>> Briefly: KStreams internals
>>>
>>> I'm pretty sure you were asking me to comment on the implementation
>>> details
>>> of KStreams, so I'll say a few words about it. The most important thing
>>> is
>>> that KStreams is still very early in its development. Maybe "early-middle
>>> maturity" is a good way to put it. We are actively discussing
>>> more-or-less
>>> major implementation changes to improve performance, footprint,
>>> scalability, and ergonomics. So it may actually be misleading to discuss
>>> deeply how KStreams internally uses Kafka topics.
>>>
>>> Nevertheless, it is currently true that KStreams uses Kafka topics for
>>> communication between some internal computation nodes. We partition these
>>> topics as the base unit of concurrency granularity, so it would
>>> potentially
>>> be beneficial to be able to expand partitions for some of these internal
>>> topics at some point. However, we can alternatively just overpartition
>>> these internal topics, creating in the low 100s of partitions instead of
>>> the low 10s, for example. (Side note: if Kafka were someday to support
>>> higher numbers of partitions, we could expand this scheme to
>>> overpartition
>>> in the 1000s of partitions.) With the option to overpartition, we don't
>>> have a strong need for partition expansion internally.
>>>
>>> It is also currently true that KStreams uses Kafka to store a durable
>>> changelog for some of our internal state stores. But we *only* read from
>>> this topic *if* we need to restore a state store after node loss (or to
>>> maintain a hot mirror of the state store), so I think it's unlikely that
>>> we
>>> would ever make use of partition expansion on the changelog topics.
>>>
>>> But once again, I'd like to emphasize that we may choose an alternative
>>> implementation for either interprocess communication or state durability.
>>>
>>>
>>> ======================================
>>> Concluding thoughts
>>>
>>> I know this is a very long email, and I really appreciate you sticking
>>> with
>>> me this long. I hope it was useful for syncing our mental picture of this
>>> system. Also, you're far more knowledgeable than I am about this system
>>> and
>>> this domain, so please correct me if I've said anything wrong.
>>>
>>> To me the key takeaways are that:
>>> - KIP-253 satisfies all we need for correctness, since it contains
>>> solutions to guarantee producers can abide by their promises w.r.t. #4
>>> and
>>> #6.
>>> - From Key Point A: #4 is actually optional for KIP-253, but without it,
>>> we
>>> lose a potentially valuable optimization in KStreams (and all other
>>> consumer applications)
>>> - From Corollary to Point A: Without low-level support for partition
>>> expansion with backfill, we cannot employ requesting partition expansion
>>> as
>>> a consumer to improve application performance. In that case, to ensure
>>> performance scalability, we would have to discard for all KStreams
>>> applications the performance optimization afforded by #4.
>>> - From Key Point B1: After a partition split, we really need to be able
>>> to
>>> seamlessly continue operating as if it had not split.
>>> - From Key Point B2: Since KIP-253 allows us to maintain all our
>>> promises,
>>> we have the option of expanding partitions in the topics we produce.
>>> Without a backfill operation, though, our consumers may not be able to
>>> realize the benefits of that split, if they were hoping to.
>>>
>>> In general, faced with the possibility of having to coordinate the
>>> partition function with our inputs' producers or with our outputs'
>>> consumers, I would personally lean toward overprovisioning and completely
>>> avoiding resize for our use case. This doesn't mean that it's not useful
>>> in
>>> the ecosystem at large without backfill, just that it loses its luster
>>> for
>>> me. It also means that we can no longer take advantage of some of our
>>> current optimizations, and in fact that we must introduce an extra hop of
>>> repartitioning on every single input.
>>>
>>> I think this is actually a pretty good picture of the opportunities and
>>> challenges that other consumers and producers in the Kafka ecosystem will
>>> face.
>>>
>>> I hope this helps!
>>>
>>> Thanks,
>>> -John
>>>
>>> On Wed, Mar 28, 2018 at 11:51 AM, Jun Rao <ju...@confluent.io> wrote:
>>>
>>> Hi, John,
>>>>
>>>> I actually think it's important to think through how KStreams handles
>>>> partition expansion in this KIP. If we do decide that we truly need
>>>> backfilling, it's much better to think through how to add it now,
>>>> instead
>>>> of retrofitting it later. It would be useful to outline how both
>>>> existing
>>>> KStreams jobs and new KStreams jobs work to see if backfilling is really
>>>> needed.
>>>>
>>>> If we can figure out how KStreams works, at least we have one reference
>>>> implementation for other stream processing frameworks that face the same
>>>> issue.
>>>>
>>>> Thanks,
>>>>
>>>> Jun
>>>>
>>>>
>>>> On Tue, Mar 27, 2018 at 4:56 PM, John Roesler <jo...@confluent.io>
>>>> wrote:
>>>>
>>>> Hi Jun,
>>>>>
>>>>> That's a good point.
>>>>>
>>>>> Yeah, I don't think it would work too well for existing consumers in
>>>>>
>>>> the
>>>
>>>> middle of gen 0 to try and switch to a newly backfilled prefix of gen
>>>>>
>>>> 1.
>>>
>>>> They probably just need to finish up until they get to the end of gen 0
>>>>>
>>>> and
>>>>
>>>>> transition just as if there were no backfill available yet.
>>>>>
>>>>> This isn't terrible, since consumer applications that care about
>>>>>
>>>> scaling
>>>
>>>> up
>>>>
>>>>> to match a freshly split partition would wait until after the backfill
>>>>>
>>>> is
>>>
>>>> available to scale up. The consumer that starts out in gen=0, part=0 is
>>>>> going to be stuck with part=0 and part=3 in gen=1 in my example
>>>>>
>>>> regardless
>>>>
>>>>> of whether they finish scanning gen=0 before or after the backfill is
>>>>> available.
>>>>>
>>>>> The broker knowing when it's ok to delete gen 0, including its offset
>>>>> mappings, is a big issue, though. I don't have any immediate ideas for
>>>>> solving it, but it doesn't feel impossible. Hopefully, you agree this
>>>>>
>>>> is
>>>
>>>> outside of KIP-253's scope, so maybe we don't need to worry about it
>>>>>
>>>> right
>>>>
>>>>> now.
>>>>>
>>>>> I do agree that reshuffling in KStreams effectively solves the
>>>>>
>>>> scalability
>>>>
>>>>> problem as well, as it decouples the partition count (and the partition
>>>>> scheme) upstream from the parallelism of the streams application.
>>>>>
>>>> Likely,
>>>
>>>> we will do this in any case. I'm predominantly advocating for follow-on
>>>>> work to enable backfill for the *other* Kafka users that are not
>>>>>
>>>> KStreams.
>>>>
>>>>> Thanks for your consideration,
>>>>> -John
>>>>>
>>>>> On Tue, Mar 27, 2018 at 6:19 PM, Jun Rao <ju...@confluent.io> wrote:
>>>>>
>>>>> Hi, John,
>>>>>>
>>>>>> Thanks for the reply. I agree that the backfill approach works
>>>>>>
>>>>> cleaner
>>>
>>>> for
>>>>>
>>>>>> newly started consumers. I am just not sure if it's a good primitive
>>>>>>
>>>>> to
>>>
>>>> support for existing consumers. One of the challenges that I see is
>>>>>>
>>>>> the
>>>
>>>> remapping of the offsets. In your approach, we need to copy the
>>>>>>
>>>>> existing
>>>>
>>>>> records from the partitions in generation 0 to generation 1. Those
>>>>>>
>>>>> records
>>>>>
>>>>>> will get different offsets in the new generation. The broker will
>>>>>>
>>>>> have
>>>
>>>> to
>>>>
>>>>> store those offset mappings somewhere. When the backfill completes,
>>>>>>
>>>>> you
>>>
>>>> can
>>>>>
>>>>>> delete generation 0's data. However, the broker can't throw away the
>>>>>>
>>>>> offset
>>>>>
>>>>>> mappings immediately since it doesn't know if there is any existing
>>>>>> consumer still consuming generation 0's records. In a compacted
>>>>>>
>>>>> topic,
>>>
>>>> the
>>>>>
>>>>>> broker probably can only safely remove the offset mappings when all
>>>>>>
>>>>> records
>>>>>
>>>>>> in generation 0 are removed by the cleaner. This may never happen
>>>>>>
>>>>> though.
>>>>
>>>>> If we reshuffle the input inside a KStreams job, it obviates the need
>>>>>>
>>>>> for
>>>>
>>>>> offset remapping on the broker.
>>>>>>
>>>>>> Jun
>>>>>>
>>>>>> On Tue, Mar 27, 2018 at 11:34 AM, John Roesler <jo...@confluent.io>
>>>>>>
>>>>> wrote:
>>>>>
>>>>>> Hey Dong and Jun,
>>>>>>>
>>>>>>> Thanks for the thoughtful responses. If you don't mind, I'll mix my
>>>>>>>
>>>>>> replies
>>>>>>
>>>>>>> together to try for a coherent response. I'm not too familiar with
>>>>>>> mailing-list etiquette, though.
>>>>>>>
>>>>>>> I'm going to keep numbering my points because it makes it easy for
>>>>>>>
>>>>>> you
>>>>
>>>>> all
>>>>>>
>>>>>>> to respond.
>>>>>>>
>>>>>>> Point 1:
>>>>>>> As I read it, KIP-253 is *just* about properly fencing the
>>>>>>>
>>>>>> producers
>>>
>>>> and
>>>>>
>>>>>> consumers so that you preserve the correct ordering of records
>>>>>>>
>>>>>> during
>>>
>>>> partition expansion. This is clearly necessary regardless of
>>>>>>>
>>>>>> anything
>>>
>>>> else
>>>>>>
>>>>>>> we discuss. I think this whole discussion about backfill,
>>>>>>>
>>>>>> consumers,
>>>
>>>> streams, etc., is beyond the scope of KIP-253. But it would be
>>>>>>>
>>>>>> cumbersome
>>>>>
>>>>>> to start a new thread at this point.
>>>>>>>
>>>>>>> I had missed KIP-253's Proposed Change #9 among all the details...
>>>>>>>
>>>>>> I
>>>
>>>> think
>>>>>>
>>>>>>> this is a nice addition to the proposal. One thought is that it's
>>>>>>>
>>>>>> actually
>>>>>>
>>>>>>> irrelevant whether the hash function is linear. This is simply an
>>>>>>>
>>>>>> algorithm
>>>>>>
>>>>>>> for moving a key from one partition to another, so the type of hash
>>>>>>> function need not be a precondition. In fact, it also doesn't
>>>>>>>
>>>>>> matter
>>>
>>>> whether the topic is compacted or not, the algorithm works
>>>>>>>
>>>>>> regardless.
>>>>
>>>>> I think this is a good algorithm to keep in mind, as it might
>>>>>>>
>>>>>> solve a
>>>
>>>> variety of problems, but it does have a downside: that the producer
>>>>>>>
>>>>>> won't
>>>>>
>>>>>> know whether or not K1 was actually in P1, it just knows that K1
>>>>>>>
>>>>>> was
>>>
>>>> in
>>>>
>>>>> P1's keyspace before the new epoch. Therefore, it will have to
>>>>>>> pessimistically send (K1,null) to P1 just in case. But the next
>>>>>>>
>>>>>> time
>>>
>>>> K1
>>>>
>>>>> comes along, the producer *also* won't remember that it already
>>>>>>>
>>>>>> retracted
>>>>>
>>>>>> K1 from P1, so it will have to send (K1,null) *again*. By
>>>>>>>
>>>>>> extension,
>>>
>>>> every
>>>>>>
>>>>>>> time the producer sends to P2, it will also have to send a
>>>>>>>
>>>>>> tombstone
>>>
>>>> to
>>>>
>>>>> P1,
>>>>>>
>>>>>>> which is a pretty big burden. To make the situation worse, if there
>>>>>>>
>>>>>> is
>>>>
>>>>> a
>>>>>
>>>>>> second split, say P2 becomes P2 and P3, then any key Kx belonging
>>>>>>>
>>>>>> to
>>>
>>>> P3
>>>>
>>>>> will also have to be retracted from P2 *and* P1, since the producer
>>>>>>>
>>>>>> can't
>>>>>
>>>>>> know whether Kx had been last written to P2 or P1. Over a long
>>>>>>>
>>>>>> period
>>>
>>>> of
>>>>>
>>>>>> time, this clearly becomes a issue, as the producer must send an
>>>>>>>
>>>>>> arbitrary
>>>>>>
>>>>>>> number of retractions along with every update.
>>>>>>>
>>>>>>> In contrast, the proposed backfill operation has an end, and after
>>>>>>>
>>>>>> it
>>>
>>>> ends,
>>>>>>
>>>>>>> everyone can afford to forget that there ever was a different
>>>>>>>
>>>>>> partition
>>>>
>>>>> layout.
>>>>>>>
>>>>>>> Really, though, figuring out how to split compacted topics is
>>>>>>>
>>>>>> beyond
>>>
>>>> the
>>>>>
>>>>>> scope of KIP-253, so I'm not sure #9 really even needs to be in
>>>>>>>
>>>>>> this
>>>
>>>> KIP...
>>>>>>
>>>>>>> We do need in-order delivery during partition expansion. It would
>>>>>>>
>>>>>> be
>>>
>>>> fine
>>>>>
>>>>>> by me to say that you *cannot* expand partitions of a log-compacted
>>>>>>>
>>>>>> topic
>>>>>
>>>>>> and call it a day. I think it would be better to tackle that in
>>>>>>>
>>>>>> another
>>>>
>>>>> KIP.
>>>>>>>
>>>>>>>
>>>>>>> Point 2:
>>>>>>> Regarding whether the consumer re-shuffles its inputs, this is
>>>>>>>
>>>>>> always
>>>
>>>> on
>>>>>
>>>>>> the table; any consumer who wants to re-shuffle its input is free
>>>>>>>
>>>>>> to
>>>
>>>> do
>>>>
>>>>> so.
>>>>>>
>>>>>>> But this is currently not required. It's just that the current
>>>>>>>
>>>>>> high-level
>>>>>
>>>>>> story with Kafka encourages the use of partitions as a unit of
>>>>>>>
>>>>>> concurrency.
>>>>>>
>>>>>>> As long as consumers are single-threaded, they can happily consume
>>>>>>>
>>>>>> a
>>>
>>>> single
>>>>>>
>>>>>>> partition without concurrency control of any kind. This is a key
>>>>>>>
>>>>>> aspect
>>>>
>>>>> to
>>>>>>
>>>>>>> this system that lets folks design high-throughput systems on top
>>>>>>>
>>>>>> of
>>>
>>>> it
>>>>
>>>>> surprisingly easily. If all consumers were instead
>>>>>>>
>>>>>> encouraged/required
>>>>
>>>>> to
>>>>>
>>>>>> implement a repartition of their own, then the consumer becomes
>>>>>>> significantly more complex, requiring either the consumer to first
>>>>>>>
>>>>>> produce
>>>>>>
>>>>>>> to its own intermediate repartition topic or to ensure that
>>>>>>>
>>>>>> consumer
>>>
>>>> threads have a reliable, high-bandwith channel of communication
>>>>>>>
>>>>>> with
>>>
>>>> every
>>>>>>
>>>>>>> other consumer thread.
>>>>>>>
>>>>>>> Either of those tradeoffs may be reasonable for a particular user
>>>>>>>
>>>>>> of
>>>
>>>> Kafka,
>>>>>>
>>>>>>> but I don't know if we're in a position to say that they are
>>>>>>>
>>>>>> reasonable
>>>>
>>>>> for
>>>>>>
>>>>>>> *every* user of Kafka.
>>>>>>>
>>>>>>>
>>>>>>> Point 3:
>>>>>>> Regarding Jun's point about this use case, "(3) stateful and
>>>>>>>
>>>>>> maintaining
>>>>>
>>>>>> the
>>>>>>> states in a local store", I agree that they may use a framework
>>>>>>>
>>>>>> *like*
>>>>
>>>>> Kafka Streams, but that is not the same as using Kafka Streams.
>>>>>>>
>>>>>> This
>>>
>>>> is
>>>>
>>>>> why
>>>>>>
>>>>>>> I think it's better to solve it in Core: because it is then solved
>>>>>>>
>>>>>> for
>>>>
>>>>> KStreams and also for everything else that facilitates local state
>>>>>>> maintenance. To me, Streams is a member of the category of "stream
>>>>>>> processing frameworks", which is itself a subcategory of "things
>>>>>>>
>>>>>> requiring
>>>>>>
>>>>>>> local state maintenence". I'm not sure if it makes sense to assert
>>>>>>>
>>>>>> that
>>>>
>>>>> Streams is a sufficient and practical replacement for everything in
>>>>>>>
>>>>>> "things
>>>>>>
>>>>>>> requiring local state maintenence".
>>>>>>>
>>>>>>> But, yes, I do agree that per-key ordering is an absolute
>>>>>>>
>>>>>> requirement,
>>>>
>>>>> therefore I think that KIP-253 itself is a necessary step.
>>>>>>>
>>>>>> Regarding
>>>
>>>> the
>>>>>
>>>>>> coupling of the state store partitioning to the topic partitioning,
>>>>>>>
>>>>>> yes,
>>>>>
>>>>>> this is an issue we are discussing solutions to right now. We may
>>>>>>>
>>>>>> go
>>>
>>>> ahead
>>>>>>
>>>>>>> and introduce an overpartition layer on our inputs to solve it, but
>>>>>>>
>>>>>> then
>>>>>
>>>>>> again, if we get the ability to split partitions with backfill, we
>>>>>>>
>>>>>> may
>>>>
>>>>> not
>>>>>>
>>>>>>> need to!
>>>>>>>
>>>>>>>
>>>>>>> Point 4:
>>>>>>> On this:
>>>>>>>
>>>>>>> Regarding thought 2: If we don't care about the stream use-case,
>>>>>>>>
>>>>>>> then
>>>>
>>>>> the
>>>>>>
>>>>>>> current KIP probably has already addressed problem without
>>>>>>>>
>>>>>>> requiring
>>>>
>>>>> consumer to know the partition function. If we care about the
>>>>>>>>
>>>>>>> stream
>>>>
>>>>> use-case, we already need coordination across producers of
>>>>>>>>
>>>>>>> different
>>>>
>>>>> topics, i.e. the same partition function needs to be used by
>>>>>>>>
>>>>>>> producers
>>>>>
>>>>>> of
>>>>>>
>>>>>>> topics A and B in order to join topics A and B. Thus, it might be
>>>>>>>> reasonable to extend coordination a bit and say we need
>>>>>>>>
>>>>>>> coordination
>>>>
>>>>> across
>>>>>>>
>>>>>>>> clients (i.e. producer and consumer), such that consumer knows
>>>>>>>>
>>>>>>> the
>>>
>>>> partition function used by producer. If we do so, then we can let
>>>>>>>>
>>>>>>> consumer
>>>>>>>
>>>>>>>> re-copy data for the change log topic using the same partition
>>>>>>>>
>>>>>>> function
>>>>>
>>>>>> as
>>>>>>>
>>>>>>>> producer. This approach has lower overhead as compared to having
>>>>>>>>
>>>>>>> producer
>>>>>>
>>>>>>> re-copy data of the input topic.
>>>>>>>> Also, producer currently does not need to know the data already
>>>>>>>>
>>>>>>> produced
>>>>>>
>>>>>>> to
>>>>>>>
>>>>>>>> the topic. If we let producer split/merge partition, it would
>>>>>>>>
>>>>>>> require
>>>>
>>>>> producer to consume the existing data, which intuitively is the
>>>>>>>>
>>>>>>> task
>>>>
>>>>> of
>>>>>
>>>>>> consumer.
>>>>>>>>
>>>>>>>
>>>>>>> I think we do care about use cases *like* Streams, I just don't
>>>>>>>
>>>>>> think
>>>
>>>> we
>>>>>
>>>>>> should rely on Streams to implement a feature of Core like
>>>>>>>
>>>>>> partition
>>>
>>>> expansion.
>>>>>>>
>>>>>>> Note, though, that we (Streams) do not require coordination across
>>>>>>> producers. If two topics are certified to be co-partitioned, then
>>>>>>>
>>>>>> Streams
>>>>>
>>>>>> apps can make use of that knowledge to optimize their topology
>>>>>>>
>>>>>> (skipping
>>>>>
>>>>>> a
>>>>>>
>>>>>>> repartition). But if they don't know whether they are
>>>>>>>
>>>>>> co-partitioned,
>>>
>>>> then
>>>>>>
>>>>>>> they'd better go ahead and repartition within the topology. This is
>>>>>>>
>>>>>> the
>>>>
>>>>> current state.
>>>>>>>
>>>>>>> A huge selling point of Kafka is enabling different parts of
>>>>>>>
>>>>>> loosely
>>>
>>>> coupled organizations to produce and consume data independently.
>>>>>>>
>>>>>> Some
>>>
>>>> coordination between producers and consumers is necessary, like
>>>>>>> coordinating on the names of topics and their schemas. But Kafka's
>>>>>>>
>>>>>> value
>>>>>
>>>>>> proposition w.r.t. ESBs, etc. is inversely proportional to the
>>>>>>>
>>>>>> amount
>>>
>>>> of
>>>>>
>>>>>> coordination required. I think it behooves us to be extremely
>>>>>>>
>>>>>> skeptical
>>>>
>>>>> about introducing any coordination beyond correctness protocols.
>>>>>>>
>>>>>>> Asking producers and consumers, or even two different producers, to
>>>>>>>
>>>>>> share
>>>>>
>>>>>> code like the partition function is a pretty huge ask. What if they
>>>>>>>
>>>>>> are
>>>>
>>>>> using different languages?
>>>>>>>
>>>>>>> Comparing organizational overhead vs computational overhead, there
>>>>>>>
>>>>>> are
>>>>
>>>>> maybe two orders of magnitude difference between them. In other
>>>>>>>
>>>>>> words,
>>>>
>>>>> I
>>>>>
>>>>>> would happily take on the (linear) overhead of having the producer
>>>>>>>
>>>>>> re-copy
>>>>>>
>>>>>>> the data once during a re-partition in order to save the
>>>>>>>
>>>>>> organizational
>>>>
>>>>> overhead of tying all the producers and consumers together across
>>>>>>>
>>>>>> multiple
>>>>>>
>>>>>>> boundaries.
>>>>>>>
>>>>>>> On that last paragraph: note that the producer *did* know the data
>>>>>>>
>>>>>> it
>>>
>>>> already produced. It handled it the first time around. Asking it to
>>>>>>> re-produce it into a new partition layout is squarely within its
>>>>>>>
>>>>>> scope
>>>>
>>>>> of
>>>>>
>>>>>> capabilities. Contrast this with the alternative, asking the
>>>>>>>
>>>>>> consumer
>>>
>>>> to
>>>>>
>>>>>> re-partition the data. I think this is even less intuitive, when
>>>>>>>
>>>>>> the
>>>
>>>> partition function belongs to the producer.
>>>>>>>
>>>>>>>
>>>>>>> Point 5:
>>>>>>> Dong asked this:
>>>>>>>
>>>>>>> For stream use-case that needs to increase consumer number, the
>>>>>>>> existing consumer can backfill the existing data in the change
>>>>>>>>
>>>>>>> log
>>>
>>>> topic
>>>>>>
>>>>>>> to
>>>>>>>
>>>>>>>> the same change log topic with the new partition number, before
>>>>>>>>
>>>>>>> the
>>>
>>>> new
>>>>>
>>>>>> set
>>>>>>>
>>>>>>>> of consumers bootstrap state from the new partitions of the
>>>>>>>>
>>>>>>> change
>>>
>>>> log
>>>>>
>>>>>> topic, right?
>>>>>>>>
>>>>>>>
>>>>>>> In this sense, the "consumer" is actually the producer of the
>>>>>>>
>>>>>> changelog
>>>>
>>>>> topic, so if we support partition expansion + backfill as a
>>>>>>>
>>>>>> producer/broker
>>>>>>
>>>>>>> operation, then it would be very straightforward for Streams to
>>>>>>>
>>>>>> split a
>>>>
>>>>> state store. As you say, they would simply instruct the broker to
>>>>>>>
>>>>>> split
>>>>
>>>>> the
>>>>>>
>>>>>>> changelog topic's partitions, then backfill. Once the backfill is
>>>>>>>
>>>>>> ready,
>>>>>
>>>>>> they can create a new crop of StandbyTasks to bootstrap the more
>>>>>>>
>>>>>> granular
>>>>>
>>>>>> state stores and finally switch over to them when they are ready.
>>>>>>>
>>>>>>> But this actually seems to be an argument in favor of
>>>>>>>
>>>>>> split+backfill,
>>>
>>>> so
>>>>>
>>>>>> maybe I missed the point.
>>>>>>>
>>>>>>> You also asked me to explain why copying the "input" topic is
>>>>>>>
>>>>>> better
>>>
>>>> than
>>>>>
>>>>>> copying the "changelog" topic. I think they are totally
>>>>>>>
>>>>>> independent,
>>>
>>>> actually. For one thing, you can't depend on the existence of a
>>>>>>>
>>>>>> "changelog"
>>>>>>
>>>>>>> topic in general, only within Streams, but Kafka's user base
>>>>>>>
>>>>>> clearly
>>>
>>>> exceeds Streams's user base. Plus, you actually also can't depend
>>>>>>>
>>>>>> on
>>>
>>>> the
>>>>>
>>>>>> existence of a changelog topic within Streams, since that is an
>>>>>>>
>>>>>> optional
>>>>>
>>>>>> feature of *some* state store implementations. Even in the
>>>>>>>
>>>>>> situation
>>>
>>>> where
>>>>>>
>>>>>>> you do have a changelog topic in Streams, there may be use cases
>>>>>>>
>>>>>> where
>>>>
>>>>> it
>>>>>
>>>>>> makes sense to expand the partitions of just the input, or just the
>>>>>>> changelog.
>>>>>>>
>>>>>>> The ask for a Core feature of split+backfill is really about
>>>>>>>
>>>>>> supporting
>>>>
>>>>> the
>>>>>>
>>>>>>> use case of splitting partitions in log-compacted topics,
>>>>>>>
>>>>>> regardless
>>>
>>>> of
>>>>
>>>>> whether that topic is an "input" or a "changelog" or anything else
>>>>>>>
>>>>>> for
>>>>
>>>>> that
>>>>>>
>>>>>>> matter.
>>>>>>>
>>>>>>>
>>>>>>> Point 6:
>>>>>>> On the concern about the performance overhead of copying data
>>>>>>>
>>>>>> between
>>>
>>>> the
>>>>>
>>>>>> brokers, I think it's actually a bit overestimated. Splitting a
>>>>>>>
>>>>>> topic's
>>>>
>>>>> partition is probably rare, certainly rarer in general than
>>>>>>>
>>>>>> bootstrapping
>>>>>
>>>>>> new consumers on that topic. If "bootstrapping new consumers" means
>>>>>>>
>>>>>> that
>>>>>
>>>>>> they have to re-shuffle the data before they consume it, then you
>>>>>>>
>>>>>> wind
>>>>
>>>>> up
>>>>>
>>>>>> copying the same record multiple times:
>>>>>>>
>>>>>>> (broker: input topic) -> (initial consumer) -> (broker: repartition
>>>>>>>
>>>>>> topic)
>>>>>>
>>>>>>> -> (real consumer)
>>>>>>>
>>>>>>> That's 3x, and it's also 3x for every new record after the split as
>>>>>>>
>>>>>> well,
>>>>>
>>>>>> since you don't get to stop repartitioning/reshuffling once you
>>>>>>>
>>>>>> start.
>>>>
>>>>> Whereas if you do a backfill in something like the procedure I
>>>>>>>
>>>>>> outlined,
>>>>>
>>>>>> you only copy the prefix of the partition before the split, and you
>>>>>>>
>>>>>> send
>>>>>
>>>>>> it
>>>>>>
>>>>>>> once to the producer and then once to the new generation partition.
>>>>>>>
>>>>>> Plus,
>>>>>
>>>>>> assuming we're splitting the partition for the benefit of
>>>>>>>
>>>>>> consumers,
>>>
>>>> there's no reason we can't co-locate the post-split partitions on
>>>>>>>
>>>>>> the
>>>
>>>> same
>>>>>>
>>>>>>> host as the pre-split partition, making the second copy a local
>>>>>>>
>>>>>> filesystem
>>>>>>
>>>>>>> operation.
>>>>>>>
>>>>>>> Even if you follow these two copies up with bootstrapping a new
>>>>>>>
>>>>>> consumer,
>>>>>
>>>>>> it's still rare for this to occur, so you get to amortize these
>>>>>>>
>>>>>> copies
>>>>
>>>>> over
>>>>>>
>>>>>>> the lifetime of the topic, whereas a reshuffle just keeps making
>>>>>>>
>>>>>> copies
>>>>
>>>>> for
>>>>>>
>>>>>>> every new event.
>>>>>>>
>>>>>>> And finally, I really do think that regardless of any performance
>>>>>>>
>>>>>> concerns
>>>>>>
>>>>>>> about this operation, if it preserves loose organizational
>>>>>>>
>>>>>> coupling,
>>>
>>>> it
>>>>
>>>>> is
>>>>>>
>>>>>>> certainly worth it.
>>>>>>>
>>>>>>>
>>>>>>> In conclusion:
>>>>>>> It might actually be a good idea for us to clarify the scope of
>>>>>>>
>>>>>> KIP-253.
>>>>>
>>>>>> If
>>>>>>
>>>>>>> we're all agreed that it's a good algorithm for allowing in-order
>>>>>>>
>>>>>> message
>>>>>
>>>>>> delivery during partition expansion, then we can continue this
>>>>>>>
>>>>>> discussion
>>>>>
>>>>>> as a new KIP, something like "backfill with partition expansion".
>>>>>>>
>>>>>> This
>>>>
>>>>> would let Dong proceed with KIP-253. On the other hand, if it seems
>>>>>>>
>>>>>> like
>>>>>
>>>>>> this conversation may alter the design of KIP-253, then maybe we
>>>>>>>
>>>>>> *should*
>>>>>
>>>>>> just finish working it out.
>>>>>>>
>>>>>>> For my part, my only concern about KIP-253 is the one I raised
>>>>>>>
>>>>>> earlier.
>>>>
>>>>> Thanks again, all, for considering these points,
>>>>>>> -John
>>>>>>>
>>>>>>>
>>>>>>> On Tue, Mar 27, 2018 at 2:10 AM, Dong Lin <li...@gmail.com>
>>>>>>>
>>>>>> wrote:
>>>>
>>>>> On Tue, Mar 27, 2018 at 12:04 AM, Dong Lin <li...@gmail.com>
>>>>>>>>
>>>>>>> wrote:
>>>>>>
>>>>>>> Hey Jan,
>>>>>>>>>
>>>>>>>>> Thanks for the enthusiasm in improving Kafka's design. Now
>>>>>>>>>
>>>>>>>> that I
>>>
>>>> have
>>>>>>
>>>>>>> read through your discussion with Jun, here are my thoughts:
>>>>>>>>>
>>>>>>>>> - The latest proposal should with log compacted topics by
>>>>>>>>>
>>>>>>>> properly
>>>>
>>>>> deleting old messages after a new message with the same key is
>>>>>>>>>
>>>>>>>> produced.
>>>>>>>
>>>>>>>> So
>>>>>>>>
>>>>>>>>> it is probably not a concern anymore. Could you comment if
>>>>>>>>>
>>>>>>>> there
>>>
>>>> is
>>>>
>>>>> still
>>>>>>>
>>>>>>>> issue?
>>>>>>>>>
>>>>>>>>> - I wrote the SEP-5 and I am pretty familiar with the
>>>>>>>>>
>>>>>>>> motivation
>>
>>

Re: [DISCUSS] KIP-253: Support in-order message delivery with partition expansion

Posted by Ray Chiang <rc...@apache.org>.
My notes from today's meeting.  Sorry if I got anyone's name wrong. Plus 
I missed a few moments with noise at home and/or dropped video.

-Ray

=====

KIP-253 Discussion

- Currently, adding partitions can cause keys to be read out-of-order.
   This KIP is trying to preserve the key ordering when adding partitions.

- State management in applications (i.e. Kafka Streams) can maintain
   local state via caching.  If the number of partitions changes, how
   would those applications update their local state.  This is the current
   point of discussion/disagreement.

- Jan Filipiak is mostly worried about log compacted topics.  Not as
   concerned about producer swapping.  Worried about the consumer design is
   a bit contradictory compared to the architecture.

   Current design is to start up a new consumer in parallel with old
   topic/consumer.  Run until consumer finishes "copying" to the new topic.
   Once the consumer is caught up, point the producer at the new topic.

   Would like to have this technique as a "core primitive" to Kafka.
   - Is this a useful primitive?
   - What's the best way to support it?

   - Topic expansion as it currently exists just "adds partitions". But
     how does this affect bootstrapping applications?  How to deal with
     "moved" (from "old partition" to "new expanded partition") keys?

   - Dong's proposal example.  10 partitions growing to 15.  5 of the
     first 10 partitions are split into 2 each.  Say Kafka remembers
     parent->child relationship.  Then for each parent partition, there
     are two child partitions.  Initially, there were 10 states to
     manage.  Then bootstrapping new application would have 15 states.
     Need to know which "generation" of partition you are consuming
     from.  Until you get to "newer" generation of data, then the keys
     will be find (i.e. reading from old partition).

   - Scheme works well for transient events.  Any stateful processor will
     likely break.

   - Tracking can become extremely complicated, since each split requires
     potentially more and more offset/partition combos.

   - Need to support continuation for consumers to read the new partitions.

   - With linear hashing, integral multiple increase (2x, 3x, 4x, etc).
     Easier mapping from old partition sets to new partition sets.
     Keys end up with a clean hierarchy instead of a major reshuffling.

   - Dong's approach piggyback on existing leader epoch.  Log segment
     could be tagged with version in linear hashing case.

   - In Jan's case, existing consumers bootstrap from the beginning.

   - James' use case.  Using Kafka as a long term persistent data store.
     Putting "source of truth" information into Kafka.  Bootstrap case
     is very important.  New applications could be bootstrapping as they
     come up.

     - Increasing partitions will help with load from prodcuer and
       increasing consumer parallelism.
     - How does Kinesis handling partition splits?  They don't have
       compacted logs, so no issue with bootstrapping.  Kinesis uses
       MD5 and splits results based on md5sum into bucket ranges.
     - Is it useful for the server to know the partitioning function?
       Consumer has some implicit assumptions about keyed partitions,
       but not strongly enforced on server side.

     - KIP-213 (one to many joins in Kafka Streams)

       - MySQL case.  Primary key forced to be used as Kafka key.

         (Sorry had some audio and video drop at this point)

       - Mirror Maker.  Source cluster has custom partitioning function.
         Producer won't duplicate to same partitioning setup as source.
         Need to provide same partitioning function to producer.
         Would need to determine partitioning function based on topic.

         - Should server validate partitioning?
         - Who does actual determination of which key goes to which 
partition.

       - How to implement backfill?

         - Who will do it?  In producer?  Hard to do.  Every client would
           need to add this functionality.  Better to do on server side.
         - Add a type of "copy consumer"?  Add backoff to producer?
           Benefit of doing in consumer vs. producer?

   - Still TBD
     - How to dedupe control messages?
     - How to deal with subtle cases during transition?
     - Is it useful for the server to have the option to validate the key
       distribution?
     - Jan concerned about how a consumer application would look with the
       new "split partition" design.
     - KIP introduced callback.  Jan doesn't think is useful. Callback
       for switching "between Partition 1 and can start on Partition 11".
       Rely on marker in Partition 1 instead.  Intent for callback is
       for possibility that delivery of messages for given key is moved
       to a different consumer instance.



On 4/6/18 9:44 AM, Dong Lin wrote:
> Hey John,
>
> Thanks much for your super-detailed explanation. This is very helpful.
>
> Now that I have finished reading through your email, I think the proposed
> solution in my previous email probably meets the requirement #6 without
> requiring additional coordination (w.r.t. partition function) among
> clients. My understanding of requirement #6 is that, after partition
> expansion, messages with the given key will go to the same consumer before
> and after the partition expansion such that stream processing jobs won't be
> affected. Thus this approach seems to be better than backfilling since it
> does not require data copy for input topics.
>
> In order for the proposed solution to meet requirements #6, we need two
> extra requirements in addition to what has been described in the previous
> email: 1) stream processing job starts with the same number of processors
> as the initial number of partitions of the input topics; and 2) at any
> given time the number of partitions of the input topic >= the number of
> processors of the given stream processing job.
>
> Could you take a look at the proposed solution and see if any of the claims
> above is false?
>
>
> Hey Jan,
>
> Maybe it is more efficient for us to discuss your concern in the KIP
> Meeting.
>
>
> Thanks,
> Dong
>
>
> On Thu, Mar 29, 2018 at 2:05 PM, John Roesler <jo...@confluent.io> wrote:
>
>> Hi Jun,
>>
>> Thanks for the response. I'm very new to this project, but I will share my
>> perspective. I'm going to say a bunch of stuff that I know you know
>> already, but just so we're on the same page...
>>
>> This may also be a good time to get feedback from the other KStreams folks.
>>
>> Using KStreams as a reference implementation for how stream processing
>> frameworks may interact with Kafka, I think it's important to eschew
>> knowledge about how KStreams currently handles internal communication,
>> making state durable, etc. Both because these details may change, and
>> because they won't be shared with other stream processors.
>>
>> =================================
>> Background
>>
>> We are looking at a picture like this:
>>
>>       input input input
>>           \   |   /
>>        +-------------+
>> +-----+ Consumer(s) +-------+
>> |     +-------------+       |
>> |                           |
>> |    KStreams Application   |
>> |                           |
>> |     +-------------+       |
>> +-----+ Producer(s) +-------+
>>        +-------------+
>>             /    \
>>          output output
>>
>> The inputs and outputs are Kafka topics (and therefore have 1 or more
>> partitions). We'd have at least 1 input and 0 or more outputs. The
>> Consumers and Producers are both the official KafkaConsumer and
>> KafkaProducer.
>>
>> In general, we'll assume that the input topics are provided by actors over
>> which we have no control, although we may as well assume they are friendly
>> and amenable to requests, and also that their promises are trustworthy.
>> This is important because we must depend on them to uphold some promises:
>> * That they tell us the schema of the data they publish, and abide by that
>> schema. Without this, the inputs are essentially garbage.
>> * That they tell us some defining characteristics of the topics (more on
>> this in a sec.) and again strictly abide by that promise.
>>
>> What are the topic characteristics we care about?
>> 1. The name (or name pattern)
>> 2. How the messages are keyed (if at all)
>> 3. Whether the message timestamps are meaningful, and if so, what their
>> meaning is
>> 4. Assuming the records have identity, whether the partitions partition the
>> records' identity space
>> 5. Whether the topic completely contains the data set
>> 6. Whether the messages in the topic are ordered
>>
>> #1 is obvious: without this information, we cannot access the data at all.
>>
>> For #2, #3, #4, and #6, we may or may not need this information, depending
>> on the logic of the application. For example, a trivial application that
>> simply counts all events it sees doesn't care about #2, #3, #4, or #6. But
>> an application that groups by some attribute can take advantage of #2 and
>> #4 if the topic data is already keyed and partitioned over that attribute.
>> Likewise, if the application includes some temporal semantics on a temporal
>> dimension that is already captured in #3, it may take advantage of that
>> fact.
>>
>> Note that #2, #3, #4, and #6 are all optional. If they are not promised, we
>> can do extra work inside the application to accomplish what we need.
>> However, if they are promised (and if we depend on that promise), it is
>> essential that the topic providers uphold those promises, as we may not be
>> in a position to verify them.
>>
>> Note also that if they make a promise, but it doesn't happen to line up
>> with our needs (data is keyed by attr1, but we need it by attr2, or
>> timestamp is produce-time, but we need it by event-time, etc.), then we
>> will have to go ahead and do that extra work internally anyway. This also
>> captures the situation in which two inputs are produced by different
>> providers, one of which meets our needs, and the other does not. The fact
>> that we can cope with this situation is the basis for my statement that we
>> do not require coordination among producers.
>>
>> (Key Point A): In terms of optimization, #4 and #6 are the most valuable.
>> If these characteristics happen to line up with our needs, then KStreams
>> can be incredibly efficient in both time and computational resources.
>>
>>   #5 is similar to knowing the schema in that it tells us whether the
>> computation we want to do is possible or not. For example, suppose we have
>> a topic of "users", and we want to construct a table for querying. If the
>> user topic doesn't completely contain the dataset, we cannot construct the
>> table. Note that it doesn't matter whether the topic is compacted or not.
>> If the topic is complete, I can consume it starting at "earliest" and build
>> my table. If it is not complete, I can do other computations on it. In both
>> cases, it may or may not be compacted; it just doesn't matter.
>>
>> On the output side, the roles are reversed. We provide (or not) exactly the
>> same set of guarantees to consumers of our outputs, and we likewise must
>> abide by the promises we make.
>>
>>
>> =================================
>> Partition Expansion
>>
>> With this formation in place, let's talk about partition expansion.
>>
>> Why do we have partitions in the first place? (let me know if I miss
>> something here)
>> * For logical data streams that are themselves partitionable, it allows
>> producers to operate concurrently without coordination. For example,
>> streaming data from a sensor in a particle accelerator, the sensor can be
>> subdivided into a grid and each grid square can produce independently to a
>> different topic. This may be valuable because the total rate of data
>> exceeds the throughput to a single broker node or just because it allows
>> for failure of a single producer to cause the loss of only part of the
>> data.
>> * The brokers can offer linearly scaling throughput on the number of
>> partitions by hosting each partition on a separate broker node
>> * The brokers can host topics that are too large to fit on a single
>> broker's storage by hosting some partitions on separate broker nodes
>> * In cases where the use case permits handling partitions independently,
>> consumers can have algorithmic simplicity by processing the data for
>> separate partitions in separate threads, avoiding costly and error-prone
>> concurrent coordination code
>> * In cases where the use case permits handling partitions independently,
>> consumers can exceed the total throughput of a single broker-consumer pair
>> * Just to throw this in as well, in cases where some network links are less
>> costly than others (or lower latency or more reliable), such as when
>> brokers, producers, and consumers are running in racks: producer and
>> consumers can both benefit (independently) by locating work on each
>> partition in the same rack as the broker hosting that partition.
>>
>> In other words, we have three actors in this system: producers, brokers,
>> and consumers, and they all benefit from partitioning for different (but
>> sometimes related) reasons.
>>
>> This leads naturally to the conclusion that any of these actors may find
>> themselves in a sub-optimal or even dangerous situation in which partition
>> expansion would be the solution. For example, the producer may find that
>> the existing throughput to the brokers is insufficient to match the data
>> rate, forcing them to drop data. Or a broker hosting a single partition may
>> be running out of disk space. Or a consumer node handling a single
>> partition cannot match the rate of production for that partition, causing
>> it to fall behind.
>>
>> I think it's reasonable to assume that all the actors in the system can't
>> just arbitrarily expand a topic's partition. I think it's reasonable to
>> align this responsibility with the provider of the data, namely the
>> producer (the logical producer, not the KafkaProducer class). Therefore,
>> the producer who finds themselves in trouble can unilaterally expand
>> partitions to solve their problem.
>>
>> For the broker or a consumer in trouble, they have only one resort: to
>> request the producer to expand partitions. This is where it's helpful to
>> assume the producer is friendly.
>>
>>
>> Now, let's look at how a KStreams application fits into this scenario.
>>
>> (Key Point B1): As a consumer, we may find that the producer expands the
>> partitions of a topic, either for their own benefit or for the brokers. In
>> this situation, the expand operation MUST NOT violate any promises that
>> have previously been made to us. This is the essence of KIP-253, to ensure
>> the maintenance of promises #6 and #4. It would be great if the mechanics
>> of the expansion required no major disruption to processing or human
>> intervention.
>>
>> Specifically, let's say that input partition X splits into X1 and X2. #6
>> requires that the same old ordering guarantees of Kafka continue to hold.
>> Obviously, this is what KIP-253's title is about. #4 requires that we
>> either ensure that X1 and X2 are assigned to the same thread that was
>> previously assigned X OR that we immediately pause processing and split any
>> state such that it appears X1 and X2 were *always* separate partitions.
>>
>> In other words, Option 1 is we treat X1 and X2 as still logically one
>> partition, equal to X. This is ideal, since in this scenario, partitions
>> are expanding for external reasons. We don't need to expand our processing
>> to match. Option 2 requires a major disruption, since we'd have to pause
>> processing while we split our state. Clearly, KStreams or any other
>> stateful consumer would advocate for Option 1.
>>
>>
>> (Corollary to Key Point A): Still on the consumer side, we may find that we
>> ourselves can benefit from partition expansion of an input. Since we can
>> cope with the absence of promise #4, partition expansion is not a hard
>> requirement for us, but assuming we were already benefiting from the major
>> performance optimizations afforded by #4, it would be nice to be able to
>> request the producer satisfy our request for partition expansion **and to
>> be able to benefit from it**.
>>
>> What does it mean to be able to benefit from partition expansion? Assuming
>> input topic partition X splits into X1 and X2, in this scenario, we *would*
>> wish to be able to split our state such that it appears X1 and X2 were
>> *always* separate partitions. Of course, the conclusion of Key Point B1
>> still applies: we should be able to continue operating on (X1+X2 = X) as
>> one partition while asynchronously building the state of X1 and X2
>> separately.
>>
>> When it comes to the mechanics of building the state of X1 and X2
>> separately, we have really just two high-level options. Either this problem
>> is solved by Kafka itself, giving me a view in which X1 and X2 were always
>> separate partitions, or I have to do it myself. The latter means that I
>> have to take on substantially more complexity than I do today:
>> Bummer 1: My state has to be splittable to begin with, implying at the
>> least that I need to be able to scan every record in my state, a
>> requirement that otherwise does not exist.
>> Bummer 2: After splitting the state  of X1 and X2, I need to be able to
>> send at least one of those tasks, state included, to another application
>> node (in order to realize the benefit of the split). This is also a
>> requirement that does not currently exist.
>> Bummer 3: In order to actually perform the split, I must know and be able
>> to execute the exact same partition function the producer of my topic uses.
>> This introduces a brand-new a priori commitment from my input producers:
>> (would-be #7: convey the partition function and abide by it). This is a big
>> restriction over #4, which only requires them to guarantee *that there is a
>> partition function*. Now they actually have to share the function with me.
>> And I have to be able to implement and execute it myself. And if the
>> producer wishes to refine the partition function for an existing topic, we
>> have another round of coordination, as they have to be sure that I, and all
>> other consumers, begin using the new function *before* they do. This is
>> similar to the schema problem, with a similar set of solutions. We would
>> likely need a partition function registry and another magic byte on every
>> record to be sure we do this right. Not to mention some way to express
>> arbitrary partitioning logic over arbitrary data in a way that is portable
>> across programming languages.
>>
>> Alternatively, if Kafka gives me a view in which X1 and X2 were always
>> separate, then I can create tasks for X1 and X2 and allow them to bootstrap
>> while I continue to process X. Once they are ready, I can coordinate a
>> transition to stop X's task and switch to X1 and X2. None of those bummers
>> are present, so this is a significantly better option for me.
>>
>> (Key Point B2): As a (friendly) producer, we may once again want on our own
>> to expand partitions, or we may want to satisfy a request from the broker
>> or our consumers to do so. Again, we MUST NOT violate any promises we have
>> previously given, and it would be great if the expansion required no major
>> disruption to processing or human intervention. Additionally, since we are
>> actually driving the expansion, it would also be great if we could avoid
>> Bummer 3's coordination problems from the producer's perspective.
>>
>>
>> ======================================
>> Briefly: KStreams internals
>>
>> I'm pretty sure you were asking me to comment on the implementation details
>> of KStreams, so I'll say a few words about it. The most important thing is
>> that KStreams is still very early in its development. Maybe "early-middle
>> maturity" is a good way to put it. We are actively discussing more-or-less
>> major implementation changes to improve performance, footprint,
>> scalability, and ergonomics. So it may actually be misleading to discuss
>> deeply how KStreams internally uses Kafka topics.
>>
>> Nevertheless, it is currently true that KStreams uses Kafka topics for
>> communication between some internal computation nodes. We partition these
>> topics as the base unit of concurrency granularity, so it would potentially
>> be beneficial to be able to expand partitions for some of these internal
>> topics at some point. However, we can alternatively just overpartition
>> these internal topics, creating in the low 100s of partitions instead of
>> the low 10s, for example. (Side note: if Kafka were someday to support
>> higher numbers of partitions, we could expand this scheme to overpartition
>> in the 1000s of partitions.) With the option to overpartition, we don't
>> have a strong need for partition expansion internally.
>>
>> It is also currently true that KStreams uses Kafka to store a durable
>> changelog for some of our internal state stores. But we *only* read from
>> this topic *if* we need to restore a state store after node loss (or to
>> maintain a hot mirror of the state store), so I think it's unlikely that we
>> would ever make use of partition expansion on the changelog topics.
>>
>> But once again, I'd like to emphasize that we may choose an alternative
>> implementation for either interprocess communication or state durability.
>>
>>
>> ======================================
>> Concluding thoughts
>>
>> I know this is a very long email, and I really appreciate you sticking with
>> me this long. I hope it was useful for syncing our mental picture of this
>> system. Also, you're far more knowledgeable than I am about this system and
>> this domain, so please correct me if I've said anything wrong.
>>
>> To me the key takeaways are that:
>> - KIP-253 satisfies all we need for correctness, since it contains
>> solutions to guarantee producers can abide by their promises w.r.t. #4 and
>> #6.
>> - From Key Point A: #4 is actually optional for KIP-253, but without it, we
>> lose a potentially valuable optimization in KStreams (and all other
>> consumer applications)
>> - From Corollary to Point A: Without low-level support for partition
>> expansion with backfill, we cannot employ requesting partition expansion as
>> a consumer to improve application performance. In that case, to ensure
>> performance scalability, we would have to discard for all KStreams
>> applications the performance optimization afforded by #4.
>> - From Key Point B1: After a partition split, we really need to be able to
>> seamlessly continue operating as if it had not split.
>> - From Key Point B2: Since KIP-253 allows us to maintain all our promises,
>> we have the option of expanding partitions in the topics we produce.
>> Without a backfill operation, though, our consumers may not be able to
>> realize the benefits of that split, if they were hoping to.
>>
>> In general, faced with the possibility of having to coordinate the
>> partition function with our inputs' producers or with our outputs'
>> consumers, I would personally lean toward overprovisioning and completely
>> avoiding resize for our use case. This doesn't mean that it's not useful in
>> the ecosystem at large without backfill, just that it loses its luster for
>> me. It also means that we can no longer take advantage of some of our
>> current optimizations, and in fact that we must introduce an extra hop of
>> repartitioning on every single input.
>>
>> I think this is actually a pretty good picture of the opportunities and
>> challenges that other consumers and producers in the Kafka ecosystem will
>> face.
>>
>> I hope this helps!
>>
>> Thanks,
>> -John
>>
>> On Wed, Mar 28, 2018 at 11:51 AM, Jun Rao <ju...@confluent.io> wrote:
>>
>>> Hi, John,
>>>
>>> I actually think it's important to think through how KStreams handles
>>> partition expansion in this KIP. If we do decide that we truly need
>>> backfilling, it's much better to think through how to add it now, instead
>>> of retrofitting it later. It would be useful to outline how both existing
>>> KStreams jobs and new KStreams jobs work to see if backfilling is really
>>> needed.
>>>
>>> If we can figure out how KStreams works, at least we have one reference
>>> implementation for other stream processing frameworks that face the same
>>> issue.
>>>
>>> Thanks,
>>>
>>> Jun
>>>
>>>
>>> On Tue, Mar 27, 2018 at 4:56 PM, John Roesler <jo...@confluent.io> wrote:
>>>
>>>> Hi Jun,
>>>>
>>>> That's a good point.
>>>>
>>>> Yeah, I don't think it would work too well for existing consumers in
>> the
>>>> middle of gen 0 to try and switch to a newly backfilled prefix of gen
>> 1.
>>>> They probably just need to finish up until they get to the end of gen 0
>>> and
>>>> transition just as if there were no backfill available yet.
>>>>
>>>> This isn't terrible, since consumer applications that care about
>> scaling
>>> up
>>>> to match a freshly split partition would wait until after the backfill
>> is
>>>> available to scale up. The consumer that starts out in gen=0, part=0 is
>>>> going to be stuck with part=0 and part=3 in gen=1 in my example
>>> regardless
>>>> of whether they finish scanning gen=0 before or after the backfill is
>>>> available.
>>>>
>>>> The broker knowing when it's ok to delete gen 0, including its offset
>>>> mappings, is a big issue, though. I don't have any immediate ideas for
>>>> solving it, but it doesn't feel impossible. Hopefully, you agree this
>> is
>>>> outside of KIP-253's scope, so maybe we don't need to worry about it
>>> right
>>>> now.
>>>>
>>>> I do agree that reshuffling in KStreams effectively solves the
>>> scalability
>>>> problem as well, as it decouples the partition count (and the partition
>>>> scheme) upstream from the parallelism of the streams application.
>> Likely,
>>>> we will do this in any case. I'm predominantly advocating for follow-on
>>>> work to enable backfill for the *other* Kafka users that are not
>>> KStreams.
>>>> Thanks for your consideration,
>>>> -John
>>>>
>>>> On Tue, Mar 27, 2018 at 6:19 PM, Jun Rao <ju...@confluent.io> wrote:
>>>>
>>>>> Hi, John,
>>>>>
>>>>> Thanks for the reply. I agree that the backfill approach works
>> cleaner
>>>> for
>>>>> newly started consumers. I am just not sure if it's a good primitive
>> to
>>>>> support for existing consumers. One of the challenges that I see is
>> the
>>>>> remapping of the offsets. In your approach, we need to copy the
>>> existing
>>>>> records from the partitions in generation 0 to generation 1. Those
>>>> records
>>>>> will get different offsets in the new generation. The broker will
>> have
>>> to
>>>>> store those offset mappings somewhere. When the backfill completes,
>> you
>>>> can
>>>>> delete generation 0's data. However, the broker can't throw away the
>>>> offset
>>>>> mappings immediately since it doesn't know if there is any existing
>>>>> consumer still consuming generation 0's records. In a compacted
>> topic,
>>>> the
>>>>> broker probably can only safely remove the offset mappings when all
>>>> records
>>>>> in generation 0 are removed by the cleaner. This may never happen
>>> though.
>>>>> If we reshuffle the input inside a KStreams job, it obviates the need
>>> for
>>>>> offset remapping on the broker.
>>>>>
>>>>> Jun
>>>>>
>>>>> On Tue, Mar 27, 2018 at 11:34 AM, John Roesler <jo...@confluent.io>
>>>> wrote:
>>>>>> Hey Dong and Jun,
>>>>>>
>>>>>> Thanks for the thoughtful responses. If you don't mind, I'll mix my
>>>>> replies
>>>>>> together to try for a coherent response. I'm not too familiar with
>>>>>> mailing-list etiquette, though.
>>>>>>
>>>>>> I'm going to keep numbering my points because it makes it easy for
>>> you
>>>>> all
>>>>>> to respond.
>>>>>>
>>>>>> Point 1:
>>>>>> As I read it, KIP-253 is *just* about properly fencing the
>> producers
>>>> and
>>>>>> consumers so that you preserve the correct ordering of records
>> during
>>>>>> partition expansion. This is clearly necessary regardless of
>> anything
>>>>> else
>>>>>> we discuss. I think this whole discussion about backfill,
>> consumers,
>>>>>> streams, etc., is beyond the scope of KIP-253. But it would be
>>>> cumbersome
>>>>>> to start a new thread at this point.
>>>>>>
>>>>>> I had missed KIP-253's Proposed Change #9 among all the details...
>> I
>>>>> think
>>>>>> this is a nice addition to the proposal. One thought is that it's
>>>>> actually
>>>>>> irrelevant whether the hash function is linear. This is simply an
>>>>> algorithm
>>>>>> for moving a key from one partition to another, so the type of hash
>>>>>> function need not be a precondition. In fact, it also doesn't
>> matter
>>>>>> whether the topic is compacted or not, the algorithm works
>>> regardless.
>>>>>> I think this is a good algorithm to keep in mind, as it might
>> solve a
>>>>>> variety of problems, but it does have a downside: that the producer
>>>> won't
>>>>>> know whether or not K1 was actually in P1, it just knows that K1
>> was
>>> in
>>>>>> P1's keyspace before the new epoch. Therefore, it will have to
>>>>>> pessimistically send (K1,null) to P1 just in case. But the next
>> time
>>> K1
>>>>>> comes along, the producer *also* won't remember that it already
>>>> retracted
>>>>>> K1 from P1, so it will have to send (K1,null) *again*. By
>> extension,
>>>>> every
>>>>>> time the producer sends to P2, it will also have to send a
>> tombstone
>>> to
>>>>> P1,
>>>>>> which is a pretty big burden. To make the situation worse, if there
>>> is
>>>> a
>>>>>> second split, say P2 becomes P2 and P3, then any key Kx belonging
>> to
>>> P3
>>>>>> will also have to be retracted from P2 *and* P1, since the producer
>>>> can't
>>>>>> know whether Kx had been last written to P2 or P1. Over a long
>> period
>>>> of
>>>>>> time, this clearly becomes a issue, as the producer must send an
>>>>> arbitrary
>>>>>> number of retractions along with every update.
>>>>>>
>>>>>> In contrast, the proposed backfill operation has an end, and after
>> it
>>>>> ends,
>>>>>> everyone can afford to forget that there ever was a different
>>> partition
>>>>>> layout.
>>>>>>
>>>>>> Really, though, figuring out how to split compacted topics is
>> beyond
>>>> the
>>>>>> scope of KIP-253, so I'm not sure #9 really even needs to be in
>> this
>>>>> KIP...
>>>>>> We do need in-order delivery during partition expansion. It would
>> be
>>>> fine
>>>>>> by me to say that you *cannot* expand partitions of a log-compacted
>>>> topic
>>>>>> and call it a day. I think it would be better to tackle that in
>>> another
>>>>>> KIP.
>>>>>>
>>>>>>
>>>>>> Point 2:
>>>>>> Regarding whether the consumer re-shuffles its inputs, this is
>> always
>>>> on
>>>>>> the table; any consumer who wants to re-shuffle its input is free
>> to
>>> do
>>>>> so.
>>>>>> But this is currently not required. It's just that the current
>>>> high-level
>>>>>> story with Kafka encourages the use of partitions as a unit of
>>>>> concurrency.
>>>>>> As long as consumers are single-threaded, they can happily consume
>> a
>>>>> single
>>>>>> partition without concurrency control of any kind. This is a key
>>> aspect
>>>>> to
>>>>>> this system that lets folks design high-throughput systems on top
>> of
>>> it
>>>>>> surprisingly easily. If all consumers were instead
>>> encouraged/required
>>>> to
>>>>>> implement a repartition of their own, then the consumer becomes
>>>>>> significantly more complex, requiring either the consumer to first
>>>>> produce
>>>>>> to its own intermediate repartition topic or to ensure that
>> consumer
>>>>>> threads have a reliable, high-bandwith channel of communication
>> with
>>>>> every
>>>>>> other consumer thread.
>>>>>>
>>>>>> Either of those tradeoffs may be reasonable for a particular user
>> of
>>>>> Kafka,
>>>>>> but I don't know if we're in a position to say that they are
>>> reasonable
>>>>> for
>>>>>> *every* user of Kafka.
>>>>>>
>>>>>>
>>>>>> Point 3:
>>>>>> Regarding Jun's point about this use case, "(3) stateful and
>>>> maintaining
>>>>>> the
>>>>>> states in a local store", I agree that they may use a framework
>>> *like*
>>>>>> Kafka Streams, but that is not the same as using Kafka Streams.
>> This
>>> is
>>>>> why
>>>>>> I think it's better to solve it in Core: because it is then solved
>>> for
>>>>>> KStreams and also for everything else that facilitates local state
>>>>>> maintenance. To me, Streams is a member of the category of "stream
>>>>>> processing frameworks", which is itself a subcategory of "things
>>>>> requiring
>>>>>> local state maintenence". I'm not sure if it makes sense to assert
>>> that
>>>>>> Streams is a sufficient and practical replacement for everything in
>>>>> "things
>>>>>> requiring local state maintenence".
>>>>>>
>>>>>> But, yes, I do agree that per-key ordering is an absolute
>>> requirement,
>>>>>> therefore I think that KIP-253 itself is a necessary step.
>> Regarding
>>>> the
>>>>>> coupling of the state store partitioning to the topic partitioning,
>>>> yes,
>>>>>> this is an issue we are discussing solutions to right now. We may
>> go
>>>>> ahead
>>>>>> and introduce an overpartition layer on our inputs to solve it, but
>>>> then
>>>>>> again, if we get the ability to split partitions with backfill, we
>>> may
>>>>> not
>>>>>> need to!
>>>>>>
>>>>>>
>>>>>> Point 4:
>>>>>> On this:
>>>>>>
>>>>>>> Regarding thought 2: If we don't care about the stream use-case,
>>> then
>>>>> the
>>>>>>> current KIP probably has already addressed problem without
>>> requiring
>>>>>>> consumer to know the partition function. If we care about the
>>> stream
>>>>>>> use-case, we already need coordination across producers of
>>> different
>>>>>>> topics, i.e. the same partition function needs to be used by
>>>> producers
>>>>> of
>>>>>>> topics A and B in order to join topics A and B. Thus, it might be
>>>>>>> reasonable to extend coordination a bit and say we need
>>> coordination
>>>>>> across
>>>>>>> clients (i.e. producer and consumer), such that consumer knows
>> the
>>>>>>> partition function used by producer. If we do so, then we can let
>>>>>> consumer
>>>>>>> re-copy data for the change log topic using the same partition
>>>> function
>>>>>> as
>>>>>>> producer. This approach has lower overhead as compared to having
>>>>> producer
>>>>>>> re-copy data of the input topic.
>>>>>>> Also, producer currently does not need to know the data already
>>>>> produced
>>>>>> to
>>>>>>> the topic. If we let producer split/merge partition, it would
>>> require
>>>>>>> producer to consume the existing data, which intuitively is the
>>> task
>>>> of
>>>>>>> consumer.
>>>>>>
>>>>>> I think we do care about use cases *like* Streams, I just don't
>> think
>>>> we
>>>>>> should rely on Streams to implement a feature of Core like
>> partition
>>>>>> expansion.
>>>>>>
>>>>>> Note, though, that we (Streams) do not require coordination across
>>>>>> producers. If two topics are certified to be co-partitioned, then
>>>> Streams
>>>>>> apps can make use of that knowledge to optimize their topology
>>>> (skipping
>>>>> a
>>>>>> repartition). But if they don't know whether they are
>> co-partitioned,
>>>>> then
>>>>>> they'd better go ahead and repartition within the topology. This is
>>> the
>>>>>> current state.
>>>>>>
>>>>>> A huge selling point of Kafka is enabling different parts of
>> loosely
>>>>>> coupled organizations to produce and consume data independently.
>> Some
>>>>>> coordination between producers and consumers is necessary, like
>>>>>> coordinating on the names of topics and their schemas. But Kafka's
>>>> value
>>>>>> proposition w.r.t. ESBs, etc. is inversely proportional to the
>> amount
>>>> of
>>>>>> coordination required. I think it behooves us to be extremely
>>> skeptical
>>>>>> about introducing any coordination beyond correctness protocols.
>>>>>>
>>>>>> Asking producers and consumers, or even two different producers, to
>>>> share
>>>>>> code like the partition function is a pretty huge ask. What if they
>>> are
>>>>>> using different languages?
>>>>>>
>>>>>> Comparing organizational overhead vs computational overhead, there
>>> are
>>>>>> maybe two orders of magnitude difference between them. In other
>>> words,
>>>> I
>>>>>> would happily take on the (linear) overhead of having the producer
>>>>> re-copy
>>>>>> the data once during a re-partition in order to save the
>>> organizational
>>>>>> overhead of tying all the producers and consumers together across
>>>>> multiple
>>>>>> boundaries.
>>>>>>
>>>>>> On that last paragraph: note that the producer *did* know the data
>> it
>>>>>> already produced. It handled it the first time around. Asking it to
>>>>>> re-produce it into a new partition layout is squarely within its
>>> scope
>>>> of
>>>>>> capabilities. Contrast this with the alternative, asking the
>> consumer
>>>> to
>>>>>> re-partition the data. I think this is even less intuitive, when
>> the
>>>>>> partition function belongs to the producer.
>>>>>>
>>>>>>
>>>>>> Point 5:
>>>>>> Dong asked this:
>>>>>>
>>>>>>> For stream use-case that needs to increase consumer number, the
>>>>>>> existing consumer can backfill the existing data in the change
>> log
>>>>> topic
>>>>>> to
>>>>>>> the same change log topic with the new partition number, before
>> the
>>>> new
>>>>>> set
>>>>>>> of consumers bootstrap state from the new partitions of the
>> change
>>>> log
>>>>>>> topic, right?
>>>>>>
>>>>>> In this sense, the "consumer" is actually the producer of the
>>> changelog
>>>>>> topic, so if we support partition expansion + backfill as a
>>>>> producer/broker
>>>>>> operation, then it would be very straightforward for Streams to
>>> split a
>>>>>> state store. As you say, they would simply instruct the broker to
>>> split
>>>>> the
>>>>>> changelog topic's partitions, then backfill. Once the backfill is
>>>> ready,
>>>>>> they can create a new crop of StandbyTasks to bootstrap the more
>>>> granular
>>>>>> state stores and finally switch over to them when they are ready.
>>>>>>
>>>>>> But this actually seems to be an argument in favor of
>> split+backfill,
>>>> so
>>>>>> maybe I missed the point.
>>>>>>
>>>>>> You also asked me to explain why copying the "input" topic is
>> better
>>>> than
>>>>>> copying the "changelog" topic. I think they are totally
>> independent,
>>>>>> actually. For one thing, you can't depend on the existence of a
>>>>> "changelog"
>>>>>> topic in general, only within Streams, but Kafka's user base
>> clearly
>>>>>> exceeds Streams's user base. Plus, you actually also can't depend
>> on
>>>> the
>>>>>> existence of a changelog topic within Streams, since that is an
>>>> optional
>>>>>> feature of *some* state store implementations. Even in the
>> situation
>>>>> where
>>>>>> you do have a changelog topic in Streams, there may be use cases
>>> where
>>>> it
>>>>>> makes sense to expand the partitions of just the input, or just the
>>>>>> changelog.
>>>>>>
>>>>>> The ask for a Core feature of split+backfill is really about
>>> supporting
>>>>> the
>>>>>> use case of splitting partitions in log-compacted topics,
>> regardless
>>> of
>>>>>> whether that topic is an "input" or a "changelog" or anything else
>>> for
>>>>> that
>>>>>> matter.
>>>>>>
>>>>>>
>>>>>> Point 6:
>>>>>> On the concern about the performance overhead of copying data
>> between
>>>> the
>>>>>> brokers, I think it's actually a bit overestimated. Splitting a
>>> topic's
>>>>>> partition is probably rare, certainly rarer in general than
>>>> bootstrapping
>>>>>> new consumers on that topic. If "bootstrapping new consumers" means
>>>> that
>>>>>> they have to re-shuffle the data before they consume it, then you
>>> wind
>>>> up
>>>>>> copying the same record multiple times:
>>>>>>
>>>>>> (broker: input topic) -> (initial consumer) -> (broker: repartition
>>>>> topic)
>>>>>> -> (real consumer)
>>>>>>
>>>>>> That's 3x, and it's also 3x for every new record after the split as
>>>> well,
>>>>>> since you don't get to stop repartitioning/reshuffling once you
>>> start.
>>>>>> Whereas if you do a backfill in something like the procedure I
>>>> outlined,
>>>>>> you only copy the prefix of the partition before the split, and you
>>>> send
>>>>> it
>>>>>> once to the producer and then once to the new generation partition.
>>>> Plus,
>>>>>> assuming we're splitting the partition for the benefit of
>> consumers,
>>>>>> there's no reason we can't co-locate the post-split partitions on
>> the
>>>>> same
>>>>>> host as the pre-split partition, making the second copy a local
>>>>> filesystem
>>>>>> operation.
>>>>>>
>>>>>> Even if you follow these two copies up with bootstrapping a new
>>>> consumer,
>>>>>> it's still rare for this to occur, so you get to amortize these
>>> copies
>>>>> over
>>>>>> the lifetime of the topic, whereas a reshuffle just keeps making
>>> copies
>>>>> for
>>>>>> every new event.
>>>>>>
>>>>>> And finally, I really do think that regardless of any performance
>>>>> concerns
>>>>>> about this operation, if it preserves loose organizational
>> coupling,
>>> it
>>>>> is
>>>>>> certainly worth it.
>>>>>>
>>>>>>
>>>>>> In conclusion:
>>>>>> It might actually be a good idea for us to clarify the scope of
>>>> KIP-253.
>>>>> If
>>>>>> we're all agreed that it's a good algorithm for allowing in-order
>>>> message
>>>>>> delivery during partition expansion, then we can continue this
>>>> discussion
>>>>>> as a new KIP, something like "backfill with partition expansion".
>>> This
>>>>>> would let Dong proceed with KIP-253. On the other hand, if it seems
>>>> like
>>>>>> this conversation may alter the design of KIP-253, then maybe we
>>>> *should*
>>>>>> just finish working it out.
>>>>>>
>>>>>> For my part, my only concern about KIP-253 is the one I raised
>>> earlier.
>>>>>> Thanks again, all, for considering these points,
>>>>>> -John
>>>>>>
>>>>>>
>>>>>> On Tue, Mar 27, 2018 at 2:10 AM, Dong Lin <li...@gmail.com>
>>> wrote:
>>>>>>> On Tue, Mar 27, 2018 at 12:04 AM, Dong Lin <li...@gmail.com>
>>>>> wrote:
>>>>>>>> Hey Jan,
>>>>>>>>
>>>>>>>> Thanks for the enthusiasm in improving Kafka's design. Now
>> that I
>>>>> have
>>>>>>>> read through your discussion with Jun, here are my thoughts:
>>>>>>>>
>>>>>>>> - The latest proposal should with log compacted topics by
>>> properly
>>>>>>>> deleting old messages after a new message with the same key is
>>>>>> produced.
>>>>>>> So
>>>>>>>> it is probably not a concern anymore. Could you comment if
>> there
>>> is
>>>>>> still
>>>>>>>> issue?
>>>>>>>>
>>>>>>>> - I wrote the SEP-5 and I am pretty familiar with the
>> motivation
>>>> and
>>>>>> the
>>>>>>>> design of SEP-5. SEP-5 is probably orthornal to the motivation
>> of
>>>>> this
>>>>>>> KIP.
>>>>>>>> The goal of SEP-5 is to allow user to increase task number of
>> an
>>>>>> existing
>>>>>>>> Samza job. But if we increase the partition number of input
>>> topics,
>>>>>>>> messages may still be consumed out-of-order by tasks in Samza
>>> which
>>>>>> cause
>>>>>>>> incorrect result. Similarly, the approach you proposed does not
>>>> seem
>>>>> to
>>>>>>>> ensure that the messages can be delivered in order, even if we
>>> can
>>>>> make
>>>>>>>> sure that each consumer instance is assigned the set of new
>>>>> partitions
>>>>>>>> covering the same set of keys.
>>>>>>>>
>>>>>>> Let me correct this comment. The approach of copying data to a
>> new
>>>>> topic
>>>>>>> can ensure in-order message delivery suppose we properly migrate
>>>>> offsets
>>>>>>> from old topic to new topic.
>>>>>>>
>>>>>>>
>>>>>>>> - I am trying to understand why it is better to copy the data
>>>> instead
>>>>>> of
>>>>>>>> copying the change log topic for streaming use-case. For core
>>> Kafka
>>>>>>>> use-case, and for the stream use-case that does not need to
>>>> increase
>>>>>>>> consumers, the current KIP already supports in-order delivery
>>>> without
>>>>>> the
>>>>>>>> overhead of copying the data. For stream use-case that needs to
>>>>>> increase
>>>>>>>> consumer number, the existing consumer can backfill the
>> existing
>>>> data
>>>>>> in
>>>>>>>> the change log topic to the same change log topic with the new
>>>>>> partition
>>>>>>>> number, before the new set of consumers bootstrap state from
>> the
>>>> new
>>>>>>>> partitions of the change log topic. If this solution works,
>> then
>>>>> could
>>>>>>> you
>>>>>>>> summarize the advantage of copying the data of input topic as
>>>>> compared
>>>>>> to
>>>>>>>> copying the change log topic? For example, does it enable more
>>>>>> use-case,
>>>>>>>> simplify the implementation of Kafka library, or reduce the
>>>> operation
>>>>>>>> overhead etc?
>>>>>>>>
>>>>>>>> Thanks,
>>>>>>>> Dong
>>>>>>>>
>>>>>>>>
>>>>>>>> On Wed, Mar 21, 2018 at 6:57 AM, Jan Filipiak <
>>>>>> Jan.Filipiak@trivago.com>
>>>>>>>> wrote:
>>>>>>>>
>>>>>>>>> Hi Jun,
>>>>>>>>>
>>>>>>>>> I was really seeing progress in our conversation but your
>> latest
>>>>> reply
>>>>>>> is
>>>>>>>>> just devastating.
>>>>>>>>> I though we were getting close being on the same page now it
>>> feels
>>>>>> like
>>>>>>>>> we are in different libraries.
>>>>>>>>>
>>>>>>>>> I just quickly slam my answers in here. If they are to brief I
>>> am
>>>>>> sorry
>>>>>>>>> give me a ping and try to go into details more.
>>>>>>>>> Just want to show that your pro/cons listing is broken.
>>>>>>>>>
>>>>>>>>> Best Jan
>>>>>>>>>
>>>>>>>>> and want to get rid of this horrible compromise
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> On 19.03.2018 05:48, Jun Rao wrote:
>>>>>>>>>
>>>>>>>>>> Hi, Jan,
>>>>>>>>>>
>>>>>>>>>> Thanks for the discussion. Great points.
>>>>>>>>>>
>>>>>>>>>> Let me try to summarize the approach that you are proposing.
>> On
>>>> the
>>>>>>>>>> broker
>>>>>>>>>> side, we reshuffle the existing data in a topic from current
>>>>>> partitions
>>>>>>>>>> to
>>>>>>>>>> the new partitions. Once the reshuffle fully catches up,
>> switch
>>>> the
>>>>>>>>>> consumers to start consuming from the new partitions. If a
>>>> consumer
>>>>>>> needs
>>>>>>>>>> to rebuild its local state (due to partition changes), let
>> the
>>>>>> consumer
>>>>>>>>>> rebuild its state by reading all existing data from the new
>>>>>> partitions.
>>>>>>>>>> Once all consumers have switches over, cut over the producer
>> to
>>>> the
>>>>>> new
>>>>>>>>>> partitions.
>>>>>>>>>>
>>>>>>>>>> The pros for this approach are that :
>>>>>>>>>> 1. There is just one way to rebuild the local state, which is
>>>>>> simpler.
>>>>>>>>> true thanks
>>>>>>>>>
>>>>>>>>>> The cons for this approach are:
>>>>>>>>>> 1. Need to copy existing data.
>>>>>>>>>>
>>>>>>>>> Very unfair and not correct. It does not require you to copy
>>> over
>>>>>>>>> existing data. It _allows_ you to copy all existing data.
>>>>>>>>>
>>>>>>>>> 2. The cutover of the producer is a bit complicated since it
>>> needs
>>>>> to
>>>>>>>>>> coordinate with all consumer groups.
>>>>>>>>>>
>>>>>>>>> Also not true. I explicitly tried to make clear that there is
>>> only
>>>>> one
>>>>>>>>> special consumer (in the case of actually copying data)
>>>> coordination
>>>>>> is
>>>>>>>>> required.
>>>>>>>>>
>>>>>>>>>> 3. The rebuilding of the state in the consumer is from the
>>> input
>>>>>> topic,
>>>>>>>>>> which can be more expensive than rebuilding from the existing
>>>>> state.
>>>>>>>>> true, but rebuilding state is only required if you want to
>>>> increase
>>>>>>>>> processing power, so we assume this is at hand.
>>>>>>>>>
>>>>>>>>>> 4. The broker potentially has to know the partitioning
>>> function.
>>>> If
>>>>>>> this
>>>>>>>>>> needs to be customized at the topic level, it can be a bit
>>> messy.
>>>>>>>>> I would argue against having the operation being performed by
>>> the
>>>>>>> broker.
>>>>>>>>> This was not discussed yet but if you see my original email i
>>>>>> suggested
>>>>>>>>> otherwise from the beginning.
>>>>>>>>>
>>>>>>>>>> Here is an alternative approach by applying your idea not in
>>> the
>>>>>>> broker,
>>>>>>>>>> but in the consumer. When new partitions are added, we don't
>>> move
>>>>>>>>>> existing
>>>>>>>>>> data. In KStreams, we first reshuffle the new input data to a
>>> new
>>>>>> topic
>>>>>>>>>> T1
>>>>>>>>>> with the old number of partitions and feed T1's data to the
>>> rest
>>>> of
>>>>>> the
>>>>>>>>>> pipeline. In the meantime, KStreams reshuffles all existing
>>> data
>>>> of
>>>>>> the
>>>>>>>>>> change capture topic to another topic C1 with the new number
>> of
>>>>>>>>>> partitions.
>>>>>>>>>> We can then build the state of the new tasks from C1. Once
>> the
>>>> new
>>>>>>> states
>>>>>>>>>> have been fully built, we can cut over the consumption to the
>>>> input
>>>>>>> topic
>>>>>>>>>> and delete T1. This approach works with compacted topic too.
>> If
>>>> an
>>>>>>>>>> application reads from the beginning of a compacted topic,
>> the
>>>>>> consumer
>>>>>>>>>> will reshuffle the portion of the input when the number of
>>>>> partitions
>>>>>>>>>> doesn't match the number of tasks.
>>>>>>>>>>
>>>>>>>>> We all wipe this idea from our heads instantly. Mixing Ideas
>>> from
>>>> an
>>>>>>>>> argument is not a resolution strategy
>>>>>>>>> just leads to horrible horrible software.
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>> The pros of this approach are:
>>>>>>>>>> 1. No need to copy existing data.
>>>>>>>>>> 2. Each consumer group can cut over to the new partitions
>>>>>>> independently.
>>>>>>>>>> 3. The state is rebuilt from the change capture topic, which
>> is
>>>>>> cheaper
>>>>>>>>>> than rebuilding from the input topic.
>>>>>>>>>> 4. Only the KStreams job needs to know the partitioning
>>> function.
>>>>>>>>>> The cons of this approach are:
>>>>>>>>>> 1. Potentially the same input topic needs to be reshuffled
>> more
>>>>> than
>>>>>>> once
>>>>>>>>>> in different consumer groups during the transition phase.
>>>>>>>>>>
>>>>>>>>>> What do you think?
>>>>>>>>>>
>>>>>>>>>> Thanks,
>>>>>>>>>>
>>>>>>>>>> Jun
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> On Thu, Mar 15, 2018 at 1:04 AM, Jan Filipiak <
>>>>>>> Jan.Filipiak@trivago.com>
>>>>>>>>>> wrote:
>>>>>>>>>>
>>>>>>>>>> Hi Jun,
>>>>>>>>>>> thank you for following me on these thoughts. It was
>> important
>>>> to
>>>>> me
>>>>>>> to
>>>>>>>>>>> feel that kind of understanding for my arguments.
>>>>>>>>>>>
>>>>>>>>>>> What I was hoping for (I mentioned this earlier) is that we
>>> can
>>>>>> model
>>>>>>>>>>> the
>>>>>>>>>>> case where we do not want to copy the data the exact same
>> way
>>> as
>>>>> the
>>>>>>>>>>> case
>>>>>>>>>>> when we do copy the data. Maybe you can peek into the mails
>>>> before
>>>>>> to
>>>>>>>>>>> see
>>>>>>>>>>> more details for this.
>>>>>>>>>>>
>>>>>>>>>>> This means we have the same mechanism to transfer consumer
>>>> groups
>>>>> to
>>>>>>>>>>> switch topic. The offset mapping that would be generated
>> would
>>>>> even
>>>>>> be
>>>>>>>>>>> simpler End Offset of the Old topic => offset 0 off all the
>>>>>> partitions
>>>>>>>>>>> of
>>>>>>>>>>> the new topic. Then we could model the transition of a
>>> non-copy
>>>>>>>>>>> expansion
>>>>>>>>>>> the exact same way as a copy-expansion.
>>>>>>>>>>>
>>>>>>>>>>> I know this only works when topic growth by a factor. But
>> the
>>>>>> benefits
>>>>>>>>>>> of
>>>>>>>>>>> only growing by a factor are to strong anyways. See
>> Clemens's
>>>> hint
>>>>>> and
>>>>>>>>>>> remember that state reshuffling is entirely not needed if
>> one
>>>>>> doesn't
>>>>>>>>>>> want
>>>>>>>>>>> to grow processing power.
>>>>>>>>>>>
>>>>>>>>>>> I think these benefits should be clear, and that there is
>>>>> basically
>>>>>> no
>>>>>>>>>>> downside to what is currently at hand but just makes
>>> everything
>>>>>> easy.
>>>>>>>>>>> One thing you need to know is. that if you do not offer
>>>>> rebuilding a
>>>>>>> log
>>>>>>>>>>> compacted topic like i suggest that even if you have
>> consumer
>>>>> state
>>>>>>>>>>> reshuffling. The topic is broken and can not be used to
>>>> bootstrap
>>>>>> new
>>>>>>>>>>> consumers. They don't know if they need to apply a key from
>>> and
>>>>> old
>>>>>>>>>>> partition or not. This is a horrible downside I haven't
>> seen a
>>>>>>> solution
>>>>>>>>>>> for
>>>>>>>>>>> in the email conversation.
>>>>>>>>>>>
>>>>>>>>>>> I argue to:
>>>>>>>>>>>
>>>>>>>>>>> Only grow topic by a factor always.
>>>>>>>>>>> Have the "no copy consumer" transition as the trivial case
>> of
>>>> the
>>>>>>> "copy
>>>>>>>>>>> consumer transition".
>>>>>>>>>>> If processors needs to be scaled, let them rebuild from the
>>> new
>>>>>> topic
>>>>>>>>>>> and
>>>>>>>>>>> leave the old running in the mean time.
>>>>>>>>>>> Do not implement key shuffling in streams.
>>>>>>>>>>>
>>>>>>>>>>> I hope I can convince you especially with the fact how I
>> want
>>> to
>>>>>>> handle
>>>>>>>>>>> consumer transition. I think
>>>>>>>>>>> you didn't quite understood me there before. I think the
>> term
>>>> "new
>>>>>>>>>>> topic"
>>>>>>>>>>> intimidated you a little.
>>>>>>>>>>> How we solve this on disc doesn't really matter, If the data
>>>> goes
>>>>>> into
>>>>>>>>>>> the
>>>>>>>>>>> same Dir or a different Dir or anything. I do think that it
>>>> needs
>>>>> to
>>>>>>>>>>> involve at least rolling a new segment for the existing
>>>>> partitions.
>>>>>>>>>>> But most of the transitions should work without restarting
>>>>>> consumers.
>>>>>>>>>>> (newer consumers with support for this). But with new topic
>> i
>>>> just
>>>>>>> meant
>>>>>>>>>>> the topic that now has a different partition count. Plenty
>> of
>>>> ways
>>>>>> to
>>>>>>>>>>> handle that (versions, aliases)
>>>>>>>>>>>
>>>>>>>>>>> Hope I can further get my idea across.
>>>>>>>>>>>
>>>>>>>>>>> Best Jan
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> On 14.03.2018 02:45, Jun Rao wrote:
>>>>>>>>>>>
>>>>>>>>>>> Hi, Jan,
>>>>>>>>>>>> Thanks for sharing your view.
>>>>>>>>>>>>
>>>>>>>>>>>> I agree with you that recopying the data potentially makes
>>> the
>>>>>> state
>>>>>>>>>>>> management easier since the consumer can just rebuild its
>>> state
>>>>>> from
>>>>>>>>>>>> scratch (i.e., no need for state reshuffling).
>>>>>>>>>>>>
>>>>>>>>>>>> On the flip slide, I saw a few disadvantages of the
>> approach
>>>> that
>>>>>> you
>>>>>>>>>>>> suggested. (1) Building the state from the input topic from
>>>>> scratch
>>>>>>> is
>>>>>>>>>>>> in
>>>>>>>>>>>> general less efficient than state reshuffling. Let's say
>> one
>>>>>>> computes a
>>>>>>>>>>>> count per key from an input topic. The former requires
>>> reading
>>>>> all
>>>>>>>>>>>> existing
>>>>>>>>>>>> records in the input topic whereas the latter only requires
>>>>> reading
>>>>>>>>>>>> data
>>>>>>>>>>>> proportional to the number of unique keys. (2) The
>> switching
>>> of
>>>>> the
>>>>>>>>>>>> topic
>>>>>>>>>>>> needs modification to the application. If there are many
>>>>>> applications
>>>>>>>>>>>> on a
>>>>>>>>>>>> topic, coordinating such an effort may not be easy. Also,
>>> it's
>>>>> not
>>>>>>>>>>>> clear
>>>>>>>>>>>> how to enforce exactly-once semantic during the switch. (3)
>>> If
>>>> a
>>>>>>> topic
>>>>>>>>>>>> doesn't need any state management, recopying the data seems
>>>>>> wasteful.
>>>>>>>>>>>> In
>>>>>>>>>>>> that case, in place partition expansion seems more
>> desirable.
>>>>>>>>>>>> I understand your concern about adding complexity in
>>> KStreams.
>>>>> But,
>>>>>>>>>>>> perhaps
>>>>>>>>>>>> we could iterate on that a bit more to see if it can be
>>>>> simplified.
>>>>>>>>>>>> Jun
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>> On Mon, Mar 12, 2018 at 11:21 PM, Jan Filipiak <
>>>>>>>>>>>> Jan.Filipiak@trivago.com>
>>>>>>>>>>>> wrote:
>>>>>>>>>>>>
>>>>>>>>>>>> Hi Jun,
>>>>>>>>>>>>
>>>>>>>>>>>>> I will focus on point 61 as I think its _the_ fundamental
>>> part
>>>>>> that
>>>>>>> I
>>>>>>>>>>>>> cant
>>>>>>>>>>>>> get across at the moment.
>>>>>>>>>>>>>
>>>>>>>>>>>>> Kafka is the platform to have state materialized multiple
>>>> times
>>>>>> from
>>>>>>>>>>>>> one
>>>>>>>>>>>>> input. I emphasize this: It is the building block in
>>>>> architectures
>>>>>>>>>>>>> that
>>>>>>>>>>>>> allow you to
>>>>>>>>>>>>> have your state maintained multiple times. You put a
>> message
>>>> in
>>>>>>> once,
>>>>>>>>>>>>> and
>>>>>>>>>>>>> you have it pop out as often as you like. I believe you
>>>>> understand
>>>>>>>>>>>>> this.
>>>>>>>>>>>>>
>>>>>>>>>>>>> Now! The path of thinking goes the following: I am using
>>>> apache
>>>>>>> kafka
>>>>>>>>>>>>> and
>>>>>>>>>>>>> I _want_ my state multiple times. What am I going todo?
>>>>>>>>>>>>>
>>>>>>>>>>>>> A) Am I going to take my state that I build up, plunge
>> some
>>>> sort
>>>>>> of
>>>>>>>>>>>>> RPC
>>>>>>>>>>>>> layer ontop of it, use that RPC layer to throw my records
>>>> across
>>>>>>>>>>>>> instances?
>>>>>>>>>>>>> B) Am I just going to read the damn message twice?
>>>>>>>>>>>>>
>>>>>>>>>>>>> Approach A is fundamentally flawed and a violation of all
>>> that
>>>>> is
>>>>>>> good
>>>>>>>>>>>>> and
>>>>>>>>>>>>> holy in kafka deployments. I can not understand how this
>>> Idea
>>>>> can
>>>>>>>>>>>>> come in
>>>>>>>>>>>>> the first place.
>>>>>>>>>>>>> (I do understand: IQ in streams, they polluted the kafka
>>>> streams
>>>>>>>>>>>>> codebase
>>>>>>>>>>>>> really bad already. It is not funny! I think they are
>>> equally
>>>>>> flawed
>>>>>>>>>>>>> as
>>>>>>>>>>>>> A)
>>>>>>>>>>>>>
>>>>>>>>>>>>> I say, we do what Kafka is good at. We repartition the
>> topic
>>>>> once.
>>>>>>> We
>>>>>>>>>>>>> switch the consumers.
>>>>>>>>>>>>> (Those that need more partitions are going to rebuild
>> their
>>>>> state
>>>>>> in
>>>>>>>>>>>>> multiple partitions by reading the new topic, those that
>>> don't
>>>>>> just
>>>>>>>>>>>>> assign
>>>>>>>>>>>>> the new partitions properly)
>>>>>>>>>>>>> We switch producers. Done!
>>>>>>>>>>>>>
>>>>>>>>>>>>> The best thing! It is trivial, hipster stream processor
>> will
>>>>> have
>>>>>> an
>>>>>>>>>>>>> easy
>>>>>>>>>>>>> time with that aswell. Its so super simple. And simple IS
>>>> good!
>>>>>>>>>>>>> It is what kafka was build todo. It is how we do it today.
>>>> All I
>>>>>> am
>>>>>>>>>>>>> saying
>>>>>>>>>>>>> is that a little broker help doing the producer swap is
>>> super
>>>>>>> useful.
>>>>>>>>>>>>> For everyone interested in why kafka is so powerful with
>>>>> approach
>>>>>> B,
>>>>>>>>>>>>> please watch https://youtu.be/bEbeZPVo98c?t=1633
>>>>>>>>>>>>> I already looked up a good point in time, I think after 5
>>>>> minutes
>>>>>>> the
>>>>>>>>>>>>> "state" topic is handled and you should be able to
>>> understand
>>>> me
>>>>>>>>>>>>> and inch better.
>>>>>>>>>>>>>
>>>>>>>>>>>>> Please do not do A to the project, it deserves better!
>>>>>>>>>>>>>
>>>>>>>>>>>>> Best Jan
>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>> On 13.03.2018 02:40, Jun Rao wrote:
>>>>>>>>>>>>>
>>>>>>>>>>>>> Hi, Jan,
>>>>>>>>>>>>>
>>>>>>>>>>>>>> Thanks for the reply. A few more comments below.
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> 50. Ok, we can think a bit harder for supporting
>> compacted
>>>>>> topics.
>>>>>>>>>>>>>> 51. This is a fundamental design question. In the more
>>> common
>>>>>> case,
>>>>>>>>>>>>>> the
>>>>>>>>>>>>>> reason why someone wants to increase the number of
>>> partitions
>>>>> is
>>>>>>> that
>>>>>>>>>>>>>> the
>>>>>>>>>>>>>> consumer application is slow and one wants to run more
>>>> consumer
>>>>>>>>>>>>>> instances
>>>>>>>>>>>>>> to increase the degree of parallelism. So, fixing the
>>> number
>>>> of
>>>>>>>>>>>>>> running
>>>>>>>>>>>>>> consumer instances when expanding the partitions won't
>> help
>>>>> this
>>>>>>>>>>>>>> case.
>>>>>>>>>>>>>> If
>>>>>>>>>>>>>> we do need to increase the number of consumer instances,
>> we
>>>>> need
>>>>>> to
>>>>>>>>>>>>>> somehow
>>>>>>>>>>>>>> reshuffle the state of the consumer across instances.
>> What
>>> we
>>>>>> have
>>>>>>>>>>>>>> been
>>>>>>>>>>>>>> discussing in this KIP is whether we can do this more
>>>>> effectively
>>>>>>>>>>>>>> through
>>>>>>>>>>>>>> the KStream library (e.g. through a 2-phase partition
>>>>> expansion).
>>>>>>>>>>>>>> This
>>>>>>>>>>>>>> will
>>>>>>>>>>>>>> add some complexity, but it's probably better than
>> everyone
>>>>> doing
>>>>>>>>>>>>>> this
>>>>>>>>>>>>>> in
>>>>>>>>>>>>>> the application space. The recopying approach that you
>>>>> mentioned
>>>>>>>>>>>>>> doesn't
>>>>>>>>>>>>>> seem to address the consumer state management issue when
>>> the
>>>>>>> consumer
>>>>>>>>>>>>>> switches from an old to a new topic.
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> 52. As for your example, it depends on whether the join
>> key
>>>> is
>>>>>> the
>>>>>>>>>>>>>> same
>>>>>>>>>>>>>> between (A,B) and (B,C). If the join key is the same, we
>>> can
>>>>> do a
>>>>>>>>>>>>>> 2-phase
>>>>>>>>>>>>>> partition expansion of A, B, and C together. If the join
>>> keys
>>>>> are
>>>>>>>>>>>>>> different, one would need to repartition the data on a
>>>>> different
>>>>>>> key
>>>>>>>>>>>>>> for
>>>>>>>>>>>>>> the second join, then the partition expansion can be done
>>>>>>>>>>>>>> independently
>>>>>>>>>>>>>> between (A,B) and (B,C).
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> 53. If you always fix the number of consumer instances,
>> we
>>>> you
>>>>>>>>>>>>>> described
>>>>>>>>>>>>>> works. However, as I mentioned in #51, I am not sure how
>>> your
>>>>>>>>>>>>>> proposal
>>>>>>>>>>>>>> deals with consumer states when the number of consumer
>>>>> instances
>>>>>>>>>>>>>> grows.
>>>>>>>>>>>>>> Also, it just seems that it's better to avoid re-copying
>>> the
>>>>>>> existing
>>>>>>>>>>>>>> data.
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> 60. "just want to throw in my question from the longer
>>> email
>>>> in
>>>>>> the
>>>>>>>>>>>>>> other
>>>>>>>>>>>>>> Thread here. How will the bloom filter help a new
>> consumer
>>> to
>>>>>>> decide
>>>>>>>>>>>>>> to
>>>>>>>>>>>>>> apply the key or not?" Not sure that I fully understood
>>> your
>>>>>>>>>>>>>> question.
>>>>>>>>>>>>>> The
>>>>>>>>>>>>>> consumer just reads whatever key is in the log. The bloom
>>>>> filter
>>>>>>> just
>>>>>>>>>>>>>> helps
>>>>>>>>>>>>>> clean up the old keys.
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> 61. "Why can we afford having a topic where its
>> apparently
>>>> not
>>>>>>>>>>>>>> possible
>>>>>>>>>>>>>> to
>>>>>>>>>>>>>> start a new application on? I think this is an overall
>> flaw
>>>> of
>>>>>> the
>>>>>>>>>>>>>> discussed idea here. Not playing attention to the overall
>>>>>>>>>>>>>> architecture."
>>>>>>>>>>>>>> Could you explain a bit more when one can't start a new
>>>>>>> application?
>>>>>>>>>>>>>> Jun
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> On Sat, Mar 10, 2018 at 1:40 AM, Jan Filipiak <
>>>>>>>>>>>>>> Jan.Filipiak@trivago.com
>>>>>>>>>>>>>> wrote:
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> Hi Jun, thanks for your mail.
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> Thank you for your questions!
>>>>>>>>>>>>>>> I think they are really good and tackle the core of the
>>>>> problem
>>>>>> I
>>>>>>>>>>>>>>> see.
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> I will answer inline, mostly but still want to set the
>>> tone
>>>>>> here.
>>>>>>>>>>>>>>> The core strength of kafka is what Martin once called
>> the
>>>>>>>>>>>>>>> kappa-Architecture. How does this work?
>>>>>>>>>>>>>>> You have everything as a log as in kafka. When you need
>> to
>>>>>> change
>>>>>>>>>>>>>>> something.
>>>>>>>>>>>>>>> You create the new version of your application and leave
>>> it
>>>>>>> running
>>>>>>>>>>>>>>> in
>>>>>>>>>>>>>>> parallel.
>>>>>>>>>>>>>>> Once the new version is good you switch your users to
>> use
>>>> the
>>>>>> new
>>>>>>>>>>>>>>> application.
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> The online reshuffling effectively breaks this
>>> architecture
>>>>> and
>>>>>> I
>>>>>>>>>>>>>>> think
>>>>>>>>>>>>>>> the switch in thinking here is more harmful
>>>>>>>>>>>>>>> than any details about the partitioning function to
>> allow
>>>>> such a
>>>>>>>>>>>>>>> change.
>>>>>>>>>>>>>>> I
>>>>>>>>>>>>>>> feel with my suggestion we are the closest to
>>>>>>>>>>>>>>> the original and battle proven architecture and I can
>> only
>>>>> warn
>>>>>> to
>>>>>>>>>>>>>>> move
>>>>>>>>>>>>>>> away from it.
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> I might have forgotten something, sometimes its hard for
>>> me
>>>> to
>>>>>>>>>>>>>>> getting
>>>>>>>>>>>>>>> all
>>>>>>>>>>>>>>> the thoughts captured in a mail, but I hope the comments
>>>>> inline
>>>>>>> will
>>>>>>>>>>>>>>> further make my concern clear, and put some emphasis on
>>> why
>>>> I
>>>>>>>>>>>>>>> prefer my
>>>>>>>>>>>>>>> solution ;)
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> One thing we should all be aware of when discussing
>> this,
>>>> and
>>>>> I
>>>>>>>>>>>>>>> think
>>>>>>>>>>>>>>> Dong
>>>>>>>>>>>>>>> should have mentioned it (maybe he did).
>>>>>>>>>>>>>>> We are not discussing all of this out of thin air but
>>> there
>>>> is
>>>>>> an
>>>>>>>>>>>>>>> effort
>>>>>>>>>>>>>>> in the Samza project.
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> https://cwiki.apache.org/confluence/display/SAMZA/SEP-
>>> 5%3A+
>>>>>>>>>>>>>>> Enable+partition+expansion+of+input+streams
>>>>>>>>>>>>>>> https://issues.apache.org/jira/browse/SAMZA-1293
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> To be clear. I think SEP-5 (state of last week, dont
>> know
>>> if
>>>>> it
>>>>>>>>>>>>>>> adapted
>>>>>>>>>>>>>>> to
>>>>>>>>>>>>>>> this discussion) is on a way better path than KIP-253,
>>> and I
>>>>>> can't
>>>>>>>>>>>>>>> really
>>>>>>>>>>>>>>> explain why.
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> Best Jan,
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> nice weekend everyone
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> On 09.03.2018 03:36, Jun Rao wrote:
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> Hi, Jan,
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> Thanks for the feedback. Just some comments on the
>> earlier
>>>>>> points
>>>>>>>>>>>>>>>> that
>>>>>>>>>>>>>>>> you
>>>>>>>>>>>>>>>> mentioned.
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> 50. You brought up the question of whether existing
>> data
>>>>> needs
>>>>>> to
>>>>>>>>>>>>>>>> be
>>>>>>>>>>>>>>>> copied
>>>>>>>>>>>>>>>> during partition expansion. My understand of your view
>> is
>>>>> that
>>>>>>>>>>>>>>>> avoid
>>>>>>>>>>>>>>>> copying existing data will be more efficient, but it
>>>> doesn't
>>>>>> work
>>>>>>>>>>>>>>>> well
>>>>>>>>>>>>>>>> with
>>>>>>>>>>>>>>>> compacted topics since some keys in the original
>>> partitions
>>>>>> will
>>>>>>>>>>>>>>>> never
>>>>>>>>>>>>>>>> be
>>>>>>>>>>>>>>>> cleaned. It would be useful to understand your use case
>>> of
>>>>>>>>>>>>>>>> compacted
>>>>>>>>>>>>>>>> topics
>>>>>>>>>>>>>>>> a bit more. In the common use case, the data volume in
>> a
>>>>>>> compacted
>>>>>>>>>>>>>>>> topic
>>>>>>>>>>>>>>>> may not be large. So, I am not sure if there is a
>> strong
>>>> need
>>>>>> to
>>>>>>>>>>>>>>>> expand
>>>>>>>>>>>>>>>> partitions in a compacted topic, at least initially.
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> I do agree. State is usually smaller. Update rates
>> might
>>> be
>>>>>> also
>>>>>>>>>>>>>>>> competitively high.
>>>>>>>>>>>>>>> Doing Log-compaction (even beeing very efficient and
>>>>>> configurable)
>>>>>>>>>>>>>>> is
>>>>>>>>>>>>>>> also
>>>>>>>>>>>>>>> a more expensive operation than
>>>>>>>>>>>>>>> just discarding old segments. Further if you want to use
>>>> more
>>>>>>>>>>>>>>> consumers
>>>>>>>>>>>>>>> processing the events
>>>>>>>>>>>>>>> you also have to grow the number of partitions.
>> Especially
>>>> for
>>>>>>>>>>>>>>> use-cases
>>>>>>>>>>>>>>> we do (KIP-213) a tiny state full
>>>>>>>>>>>>>>> table might be very expensive to process if it joins
>>>> against a
>>>>>>> huge
>>>>>>>>>>>>>>> table.
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> I can just say we have been in the spot of needing to
>> grow
>>>> log
>>>>>>>>>>>>>>> compacted
>>>>>>>>>>>>>>> topics. Mainly for processing power we can bring to the
>>>> table.
>>>>>>>>>>>>>>> Further i am not at all concerned about the extra spaced
>>>> used
>>>>> by
>>>>>>>>>>>>>>> "garbage
>>>>>>>>>>>>>>> keys". I am more concerned about the correctness of
>>> innocent
>>>>>>>>>>>>>>> consumers.
>>>>>>>>>>>>>>> The
>>>>>>>>>>>>>>> logic becomes complicated. Say for streams one would
>> need
>>> to
>>>>>> load
>>>>>>>>>>>>>>> the
>>>>>>>>>>>>>>> record into state but not forward it the topology ( to
>>> have
>>>> it
>>>>>>>>>>>>>>> available
>>>>>>>>>>>>>>> for shuffeling). I rather have it simple and a topic
>> clean
>>>>>>>>>>>>>>> regardless
>>>>>>>>>>>>>>> if
>>>>>>>>>>>>>>> it
>>>>>>>>>>>>>>> still has its old partition count. Especially with
>>> multiple
>>>>>>>>>>>>>>> partitions
>>>>>>>>>>>>>>> growth's I think it becomes insanely hard to to this
>>> shuffle
>>>>>>>>>>>>>>> correct.
>>>>>>>>>>>>>>> Maybe
>>>>>>>>>>>>>>> Streams and Samza can do it. Especially if you do
>> "hipster
>>>>>> stream
>>>>>>>>>>>>>>> processing" <https://www.confluent.io/blog
>>>>>>>>>>>>>>> /introducing-kafka-streams-
>>>>>>>>>>>>>>> stream-processing-made-simple/>. This makes kafka way
>> to
>>>>>>>>>>>>>>> complicated.
>>>>>>>>>>>>>>> With my approach I think its way simpler because the
>> topic
>>>> has
>>>>>> no
>>>>>>>>>>>>>>> "history"
>>>>>>>>>>>>>>> in terms of partitioning but is always clean.
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> 51. "Growing the topic by an integer factor does not
>>> require
>>>>> any
>>>>>>>>>>>>>>> state
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> redistribution at all." Could you clarify this a bit
>> more?
>>>>> Let's
>>>>>>> say
>>>>>>>>>>>>>>>> you
>>>>>>>>>>>>>>>> have a consumer app that computes the windowed count
>> per
>>>> key.
>>>>>> If
>>>>>>>>>>>>>>>> you
>>>>>>>>>>>>>>>> double
>>>>>>>>>>>>>>>> the number of partitions from 1 to 2 and grow the
>>> consumer
>>>>>>>>>>>>>>>> instances
>>>>>>>>>>>>>>>> from
>>>>>>>>>>>>>>>> 1
>>>>>>>>>>>>>>>> to 2, we would need to redistribute some of the counts
>> to
>>>> the
>>>>>> new
>>>>>>>>>>>>>>>> consumer
>>>>>>>>>>>>>>>> instance. Regarding to linear hashing, it's true that
>> it
>>>>> won't
>>>>>>>>>>>>>>>> solve
>>>>>>>>>>>>>>>> the
>>>>>>>>>>>>>>>> problem with compacted topics. The main benefit is that
>>> it
>>>>>>>>>>>>>>>> redistributes
>>>>>>>>>>>>>>>> the keys in one partition to no more than two
>> partitions,
>>>>> which
>>>>>>>>>>>>>>>> could
>>>>>>>>>>>>>>>> help
>>>>>>>>>>>>>>>> redistribute the state.
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> You don't need to spin up a new consumer in this case.
>>>> every
>>>>>>>>>>>>>>>> consumer
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> would just read every partition with the (partition %
>>>>> num_task)
>>>>>>>>>>>>>>> task.
>>>>>>>>>>>>>>> it
>>>>>>>>>>>>>>> will still have the previous data right there and can go
>>> on.
>>>>>>>>>>>>>>> This sounds contradictory to what I said before, but
>>> please
>>>>> bear
>>>>>>>>>>>>>>> with
>>>>>>>>>>>>>>> me.
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> 52. Good point on coordinating the expansion of 2 topics
>>>> that
>>>>>> need
>>>>>>>>>>>>>>> to
>>>>>>>>>>>>>>> be
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> joined together. This is where the 2-phase partition
>>>> expansion
>>>>>>> could
>>>>>>>>>>>>>>>> potentially help. In the first phase, we could add new
>>>>>> partitions
>>>>>>>>>>>>>>>> to
>>>>>>>>>>>>>>>> the 2
>>>>>>>>>>>>>>>> topics one at a time but without publishing to the new
>>>>>> patitions.
>>>>>>>>>>>>>>>> Then,
>>>>>>>>>>>>>>>> we
>>>>>>>>>>>>>>>> can add new consumer instances to pick up the new
>>>> partitions.
>>>>>> In
>>>>>>>>>>>>>>>> this
>>>>>>>>>>>>>>>> transition phase, no reshuffling is needed since no
>> data
>>> is
>>>>>>> coming
>>>>>>>>>>>>>>>> from
>>>>>>>>>>>>>>>> the
>>>>>>>>>>>>>>>> new partitions. Finally, we can enable the publishing
>> to
>>>> the
>>>>>> new
>>>>>>>>>>>>>>>> partitions.
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> I think its even worse than you think. I would like to
>>>>>> introduce
>>>>>>>>>>>>>>>> the
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> Term
>>>>>>>>>>>>>>> transitive copartitioning. Imagine
>>>>>>>>>>>>>>> 2 streams application. One joins (A,B) the other (B,C)
>>> then
>>>>>> there
>>>>>>>>>>>>>>> is a
>>>>>>>>>>>>>>> transitive copartition requirement for
>>>>>>>>>>>>>>> (A,C) to be copartitioned aswell. This can spread
>>>>> significantly
>>>>>>> and
>>>>>>>>>>>>>>> require many consumers to adapt at the same time.
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> It is also not entirely clear to me how you not need
>>>>> reshuffling
>>>>>>> in
>>>>>>>>>>>>>>> this
>>>>>>>>>>>>>>> case. If A has a record that never gets updated after
>> the
>>>>>>> expansion
>>>>>>>>>>>>>>> and
>>>>>>>>>>>>>>> the
>>>>>>>>>>>>>>> coresponding B record moves to a new partition. How
>> shall
>>>> they
>>>>>>> meet
>>>>>>>>>>>>>>> w/o
>>>>>>>>>>>>>>> shuffle?
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> 53. "Migrating consumer is a step that might be made
>>>> completly
>>>>>>>>>>>>>>> unnecessary
>>>>>>>>>>>>>>>> if - for example streams - takes the gcd as
>> partitioning
>>>>> scheme
>>>>>>>>>>>>>>>> instead
>>>>>>>>>>>>>>>> of
>>>>>>>>>>>>>>>> enforcing 1 to 1." Not sure that I fully understand
>>> this. I
>>>>>> think
>>>>>>>>>>>>>>>> you
>>>>>>>>>>>>>>>> mean
>>>>>>>>>>>>>>>> that a consumer application can run more instances than
>>> the
>>>>>>> number
>>>>>>>>>>>>>>>> of
>>>>>>>>>>>>>>>> partitions. In that case, the consumer can just
>>>>> repartitioning
>>>>>>> the
>>>>>>>>>>>>>>>> input
>>>>>>>>>>>>>>>> data according to the number of instances. This is
>>>> possible,
>>>>>> but
>>>>>>>>>>>>>>>> just
>>>>>>>>>>>>>>>> has
>>>>>>>>>>>>>>>> the overhead of reshuffling the data.
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> No what I meant is ( that is also your question i think
>>>>>> Mathias)
>>>>>>>>>>>>>>>> that
>>>>>>>>>>>>>>>> if
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> you grow a topic by a factor.
>>>>>>>>>>>>>>> Even if your processor is statefull you can can just
>>> assign
>>>>> all
>>>>>>> the
>>>>>>>>>>>>>>> multiples of the previous partition to
>>>>>>>>>>>>>>> this consumer and the state to keep processing correctly
>>>> will
>>>>> be
>>>>>>>>>>>>>>> present
>>>>>>>>>>>>>>> w/o any shuffling.
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> Say you have an assignment
>>>>>>>>>>>>>>> Statefull consumer => partition
>>>>>>>>>>>>>>> 0 => 0
>>>>>>>>>>>>>>> 1 => 1
>>>>>>>>>>>>>>> 2 => 2
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> and you grow you topic by 4 you get,
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> 0 => 0,3,6,9
>>>>>>>>>>>>>>> 1 => 1,4,7,10
>>>>>>>>>>>>>>> 2 => 2,5,8,11
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> Say your hashcode is 8. 8%3 => 2  before so consumer for
>>>>>>> partition 2
>>>>>>>>>>>>>>> has
>>>>>>>>>>>>>>> it.
>>>>>>>>>>>>>>> Now you you have 12 partitions so 8%12 => 8, so it goes
>>> into
>>>>>>>>>>>>>>> partition
>>>>>>>>>>>>>>> 8
>>>>>>>>>>>>>>> which is assigned to the same consumer
>>>>>>>>>>>>>>> who had 2 before and therefore knows the key.
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> Userland reshuffeling is there as an options. And it
>> does
>>>>>> exactly
>>>>>>>>>>>>>>> what
>>>>>>>>>>>>>>> I
>>>>>>>>>>>>>>> suggest. And I think its the perfect strategie. All I am
>>>>>>> suggestion
>>>>>>>>>>>>>>> is
>>>>>>>>>>>>>>> broker side support to switch the producers to the newly
>>>>>>> partitioned
>>>>>>>>>>>>>>> topic.
>>>>>>>>>>>>>>> Then the old (to few partition topic) can go away.
>>> Remember
>>>>> the
>>>>>>>>>>>>>>> list
>>>>>>>>>>>>>>> of
>>>>>>>>>>>>>>> steps in the beginning of this thread. If one has broker
>>>>> support
>>>>>>> for
>>>>>>>>>>>>>>> all
>>>>>>>>>>>>>>> where its required and streams support for those that
>>> aren’t
>>>>>>>>>>>>>>> necessarily.
>>>>>>>>>>>>>>> Then one has solved the problem.
>>>>>>>>>>>>>>> I repeat it because I think its important. I am really
>>> happy
>>>>>> that
>>>>>>>>>>>>>>> you
>>>>>>>>>>>>>>> brought that up! because its 100% what I want just with
>>> the
>>>>>>>>>>>>>>> differences
>>>>>>>>>>>>>>> to
>>>>>>>>>>>>>>> have an option to discard the to small topic later
>> (after
>>>> all
>>>>>>>>>>>>>>> consumers
>>>>>>>>>>>>>>> adapted). And to have order correct there. I need broker
>>>>> support
>>>>>>>>>>>>>>> managing
>>>>>>>>>>>>>>> the copy process + the produces and fence them against
>>> each
>>>>>>> other. I
>>>>>>>>>>>>>>> also
>>>>>>>>>>>>>>> repeat. the copy process can run for weeks in the worst
>>>> case.
>>>>>>>>>>>>>>> Copying
>>>>>>>>>>>>>>> the
>>>>>>>>>>>>>>> data is not the longest task migrating consumers might
>>> very
>>>>> well
>>>>>>> be.
>>>>>>>>>>>>>>> Once all consumers switched and copying is really up to
>>> date
>>>>>>> (think
>>>>>>>>>>>>>>> ISR
>>>>>>>>>>>>>>> like up to date) only then we stop the producer, wait
>> for
>>>> the
>>>>>> copy
>>>>>>>>>>>>>>> to
>>>>>>>>>>>>>>> finish and use the new topic for producing.
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> After this the topic is perfect in shape. and no one
>> needs
>>>> to
>>>>>>> worry
>>>>>>>>>>>>>>> about
>>>>>>>>>>>>>>> complicated stuff. (old keys hanging around might arrive
>>> in
>>>>> some
>>>>>>>>>>>>>>> other
>>>>>>>>>>>>>>> topic later.....). can only imagine how many tricky bugs
>>>> gonna
>>>>>>>>>>>>>>> arrive
>>>>>>>>>>>>>>> after
>>>>>>>>>>>>>>> someone had grown and shrunken is topic 10 times.
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> 54. "The other thing I wanted to mention is that I
>> believe
>>>> the
>>>>>>>>>>>>>>> current
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> suggestion (without copying data over) can be
>> implemented
>>> in
>>>>>> pure
>>>>>>>>>>>>>>>> userland
>>>>>>>>>>>>>>>> with a custom partitioner and a small feedbackloop from
>>>>>>>>>>>>>>>> ProduceResponse
>>>>>>>>>>>>>>>> =>
>>>>>>>>>>>>>>>> Partitionier in coorporation with a change management
>>>>> system."
>>>>>> I
>>>>>>> am
>>>>>>>>>>>>>>>> not
>>>>>>>>>>>>>>>> sure a customized partitioner itself solves the
>> problem.
>>> We
>>>>>>>>>>>>>>>> probably
>>>>>>>>>>>>>>>> need
>>>>>>>>>>>>>>>> some broker side support to enforce when the new
>>> partitions
>>>>> can
>>>>>>> be
>>>>>>>>>>>>>>>> used.
>>>>>>>>>>>>>>>> We
>>>>>>>>>>>>>>>> also need some support on the consumer/kstream side to
>>>>> preserve
>>>>>>> the
>>>>>>>>>>>>>>>> per
>>>>>>>>>>>>>>>> key
>>>>>>>>>>>>>>>> ordering and potentially migrate the processing state.
>>> This
>>>>> is
>>>>>>> not
>>>>>>>>>>>>>>>> trivial
>>>>>>>>>>>>>>>> and I am not sure if it's ideal to fully push to the
>>>>>> application
>>>>>>>>>>>>>>>> space.
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> Broker support is defenitly the preferred way here. I
>>> have
>>>>>>> nothing
>>>>>>>>>>>>>>>> against
>>>>>>>>>>>>>>> broker support.
>>>>>>>>>>>>>>> I tried to say that for what I would preffer - copying
>> the
>>>>> data
>>>>>>>>>>>>>>> over,
>>>>>>>>>>>>>>> at
>>>>>>>>>>>>>>> least for log compacted topics -
>>>>>>>>>>>>>>> I would require more broker support than the KIP
>> currently
>>>>>> offers.
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> Jun
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> On Tue, Mar 6, 2018 at 10:33 PM, Jan Filipiak <
>>>>>>>>>>>>>>>> Jan.Filipiak@trivago.com
>>>>>>>>>>>>>>>> wrote:
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> Hi Dong,
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> are you actually reading my emails, or are you just
>> using
>>>> the
>>>>>>>>>>>>>>>> thread I
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> started for general announcements regarding the KIP?
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> I tried to argue really hard against linear hashing.
>>>> Growing
>>>>>> the
>>>>>>>>>>>>>>>>> topic
>>>>>>>>>>>>>>>>> by
>>>>>>>>>>>>>>>>> an integer factor does not require any state
>>>> redistribution
>>>>> at
>>>>>>>>>>>>>>>>> all. I
>>>>>>>>>>>>>>>>> fail
>>>>>>>>>>>>>>>>> to see completely where linear hashing helps on log
>>>>> compacted
>>>>>>>>>>>>>>>>> topics.
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> If you are not willing to explain to me what I might
>> be
>>>>>>>>>>>>>>>>> overlooking:
>>>>>>>>>>>>>>>>> that
>>>>>>>>>>>>>>>>> is fine.
>>>>>>>>>>>>>>>>> But I ask you to not reply to my emails then. Please
>>>>>> understand
>>>>>>> my
>>>>>>>>>>>>>>>>> frustration with this.
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> Best Jan
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> On 06.03.2018 19:38, Dong Lin wrote:
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> Hi everyone,
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> Thanks for all the comments! It appears that everyone
>>>>> prefers
>>>>>>>>>>>>>>>>> linear
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> hashing because it reduces the amount of state that
>>> needs
>>>>> to
>>>>>> be
>>>>>>>>>>>>>>>>>> moved
>>>>>>>>>>>>>>>>>> between consumers (for stream processing). The KIP
>> has
>>>> been
>>>>>>>>>>>>>>>>>> updated
>>>>>>>>>>>>>>>>>> to
>>>>>>>>>>>>>>>>>> use
>>>>>>>>>>>>>>>>>> linear hashing.
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> Regarding the migration endeavor: it seems that
>>> migrating
>>>>>>>>>>>>>>>>>> producer
>>>>>>>>>>>>>>>>>> library
>>>>>>>>>>>>>>>>>> to use linear hashing should be pretty
>> straightforward
>>>>>> without
>>>>>>>>>>>>>>>>>> much operational endeavor. If we don't upgrade client
>>>>> library
>>>>>>> to
>>>>>>>>>>>>>>>>>> use
>>>>>>>>>>>>>>>>>> this
>>>>>>>>>>>>>>>>>> KIP, we can not support in-order delivery after
>>> partition
>>>>> is
>>>>>>>>>>>>>>>>>> changed
>>>>>>>>>>>>>>>>>> anyway. Suppose we upgrade client library to use this
>>>> KIP,
>>>>> if
>>>>>>>>>>>>>>>>>> partition
>>>>>>>>>>>>>>>>>> number is not changed, the key -> partition mapping
>>> will
>>>> be
>>>>>>>>>>>>>>>>>> exactly
>>>>>>>>>>>>>>>>>> the
>>>>>>>>>>>>>>>>>> same as it is now because it is still determined
>> using
>>>>>>>>>>>>>>>>>> murmur_hash(key)
>>>>>>>>>>>>>>>>>> %
>>>>>>>>>>>>>>>>>> original_partition_num. In other words, this change
>> is
>>>>>> backward
>>>>>>>>>>>>>>>>>> compatible.
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> Regarding the load distribution: if we use linear
>>>> hashing,
>>>>>> the
>>>>>>>>>>>>>>>>>> load
>>>>>>>>>>>>>>>>>> may
>>>>>>>>>>>>>>>>>> be
>>>>>>>>>>>>>>>>>> unevenly distributed because those partitions which
>> are
>>>> not
>>>>>>> split
>>>>>>>>>>>>>>>>>> may
>>>>>>>>>>>>>>>>>> receive twice as much traffic as other partitions
>> that
>>>> are
>>>>>>> split.
>>>>>>>>>>>>>>>>>> This
>>>>>>>>>>>>>>>>>> issue can be mitigated by creating topic with
>>> partitions
>>>>> that
>>>>>>> are
>>>>>>>>>>>>>>>>>> several
>>>>>>>>>>>>>>>>>> times the number of consumers. And there will be no
>>>>> imbalance
>>>>>>> if
>>>>>>>>>>>>>>>>>> the
>>>>>>>>>>>>>>>>>> partition number is always doubled. So this imbalance
>>>> seems
>>>>>>>>>>>>>>>>>> acceptable.
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> Regarding storing the partition strategy as per-topic
>>>>> config:
>>>>>>> It
>>>>>>>>>>>>>>>>>> seems
>>>>>>>>>>>>>>>>>> not
>>>>>>>>>>>>>>>>>> necessary since we can still use murmur_hash as the
>>>> default
>>>>>>> hash
>>>>>>>>>>>>>>>>>> function
>>>>>>>>>>>>>>>>>> and additionally apply the linear hashing algorithm
>> if
>>>> the
>>>>>>>>>>>>>>>>>> partition
>>>>>>>>>>>>>>>>>> number
>>>>>>>>>>>>>>>>>> has increased. Not sure if there is any use-case for
>>>>> producer
>>>>>>> to
>>>>>>>>>>>>>>>>>> use a
>>>>>>>>>>>>>>>>>> different hash function. Jason, can you check if
>> there
>>> is
>>>>>> some
>>>>>>>>>>>>>>>>>> use-case
>>>>>>>>>>>>>>>>>> that I missed for using the per-topic partition
>>> strategy?
>>>>>>>>>>>>>>>>>> Regarding how to reduce latency (due to state
>>> store/load)
>>>>> in
>>>>>>>>>>>>>>>>>> stream
>>>>>>>>>>>>>>>>>> processing consumer when partition number changes: I
>>> need
>>>>> to
>>>>>>> read
>>>>>>>>>>>>>>>>>> the
>>>>>>>>>>>>>>>>>> Kafka
>>>>>>>>>>>>>>>>>> Stream code to understand how Kafka Stream currently
>>>>> migrate
>>>>>>>>>>>>>>>>>> state
>>>>>>>>>>>>>>>>>> between
>>>>>>>>>>>>>>>>>> consumers when the application is added/removed for a
>>>> given
>>>>>>> job.
>>>>>>>>>>>>>>>>>> I
>>>>>>>>>>>>>>>>>> will
>>>>>>>>>>>>>>>>>> reply after I finish reading the documentation and
>>> code.
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> Thanks,
>>>>>>>>>>>>>>>>>> Dong
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> On Mon, Mar 5, 2018 at 10:43 AM, Jason Gustafson <
>>>>>>>>>>>>>>>>>> jason@confluent.io>
>>>>>>>>>>>>>>>>>> wrote:
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> Great discussion. I think I'm wondering whether we
>> can
>>>>>> continue
>>>>>>>>>>>>>>>>>> to
>>>>>>>>>>>>>>>>>> leave
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> Kafka agnostic to the partitioning strategy. The
>>>> challenge
>>>>> is
>>>>>>>>>>>>>>>>>> communicating
>>>>>>>>>>>>>>>>>>> the partitioning logic from producers to consumers
>> so
>>>> that
>>>>>> the
>>>>>>>>>>>>>>>>>>> dependencies
>>>>>>>>>>>>>>>>>>> between each epoch can be determined. For the sake
>> of
>>>>>>>>>>>>>>>>>>> discussion,
>>>>>>>>>>>>>>>>>>> imagine
>>>>>>>>>>>>>>>>>>> you did something like the following:
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>> 1. The name (and perhaps version) of a partitioning
>>>>> strategy
>>>>>>> is
>>>>>>>>>>>>>>>>>>> stored
>>>>>>>>>>>>>>>>>>> in
>>>>>>>>>>>>>>>>>>> topic configuration when a topic is created.
>>>>>>>>>>>>>>>>>>> 2. The producer looks up the partitioning strategy
>>>> before
>>>>>>>>>>>>>>>>>>> writing
>>>>>>>>>>>>>>>>>>> to
>>>>>>>>>>>>>>>>>>> a
>>>>>>>>>>>>>>>>>>> topic and includes it in the produce request (for
>>>>> fencing).
>>>>>> If
>>>>>>>>>>>>>>>>>>> it
>>>>>>>>>>>>>>>>>>> doesn't
>>>>>>>>>>>>>>>>>>> have an implementation for the configured strategy,
>> it
>>>>>> fails.
>>>>>>>>>>>>>>>>>>> 3. The consumer also looks up the partitioning
>>> strategy
>>>>> and
>>>>>>>>>>>>>>>>>>> uses it
>>>>>>>>>>>>>>>>>>> to
>>>>>>>>>>>>>>>>>>> determine dependencies when reading a new epoch. It
>>>> could
>>>>>>> either
>>>>>>>>>>>>>>>>>>> fail
>>>>>>>>>>>>>>>>>>> or
>>>>>>>>>>>>>>>>>>> make the most conservative dependency assumptions if
>>> it
>>>>>>> doesn't
>>>>>>>>>>>>>>>>>>> know
>>>>>>>>>>>>>>>>>>> how
>>>>>>>>>>>>>>>>>>> to
>>>>>>>>>>>>>>>>>>> implement the partitioning strategy. For the
>> consumer,
>>>> the
>>>>>> new
>>>>>>>>>>>>>>>>>>> interface
>>>>>>>>>>>>>>>>>>> might look something like this:
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>> // Return the partition dependencies following an
>>> epoch
>>>>> bump
>>>>>>>>>>>>>>>>>>> Map<Integer, List<Integer>> dependencies(int
>>>>>>>>>>>>>>>>>>> numPartitionsBeforeEpochBump,
>>>>>>>>>>>>>>>>>>> int numPartitionsAfterEpochBump)
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>> The unordered case then is just a particular
>>>>> implementation
>>>>>>>>>>>>>>>>>>> which
>>>>>>>>>>>>>>>>>>> never
>>>>>>>>>>>>>>>>>>> has
>>>>>>>>>>>>>>>>>>> any epoch dependencies. To implement this, we would
>>> need
>>>>>> some
>>>>>>>>>>>>>>>>>>> way
>>>>>>>>>>>>>>>>>>> for
>>>>>>>>>>>>>>>>>>> the
>>>>>>>>>>>>>>>>>>> consumer to find out how many partitions there were
>> in
>>>>> each
>>>>>>>>>>>>>>>>>>> epoch,
>>>>>>>>>>>>>>>>>>> but
>>>>>>>>>>>>>>>>>>> maybe that's not too unreasonable.
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>> Thanks,
>>>>>>>>>>>>>>>>>>> Jason
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>> On Mon, Mar 5, 2018 at 4:51 AM, Jan Filipiak <
>>>>>>>>>>>>>>>>>>> Jan.Filipiak@trivago.com
>>>>>>>>>>>>>>>>>>> wrote:
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>> Hi Dong
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>> thank you very much for your questions.
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>> regarding the time spend copying data across:
>>>>>>>>>>>>>>>>>>>> It is correct that copying data from a topic with
>> one
>>>>>>> partition
>>>>>>>>>>>>>>>>>>>> mapping
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>> to
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>> a topic with a different partition mapping takes
>> way
>>>>> longer
>>>>>>>>>>>>>>>>>>>> than
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>> we
>>>>>>>>>>>>>>>>>>> can
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>> stop producers. Tens of minutes is a very optimistic
>>>>>> estimate
>>>>>>>>>>>>>>>>>>> here.
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>> Many
>>>>>>>>>>>>>>>>>>>> people can not afford copy full steam and therefore
>>>> will
>>>>>> have
>>>>>>>>>>>>>>>>>>>> some
>>>>>>>>>>>>>>>>>>>> rate
>>>>>>>>>>>>>>>>>>>> limiting in place, this can bump the timespan into
>>> the
>>>>>> day's.
>>>>>>>>>>>>>>>>>>>> The
>>>>>>>>>>>>>>>>>>>> good
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>> part
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>> is that the vast majority of the data can be copied
>>>> while
>>>>>> the
>>>>>>>>>>>>>>>>>>> producers
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>> are
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>> still going. One can then, piggyback the consumers
>>>> ontop
>>>>> of
>>>>>>>>>>>>>>>>>>>> this
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>> timeframe,
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>> by the method mentioned (provide them an mapping
>> from
>>>>> their
>>>>>>> old
>>>>>>>>>>>>>>>>>>> offsets
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>> to
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>> new offsets in their repartitioned topics. In that
>>> way
>>>> we
>>>>>>>>>>>>>>>>>>>> separate
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>> migration of consumers from migration of producers
>>>>>> (decoupling
>>>>>>>>>>>>>>>>>>>> these
>>>>>>>>>>>>>>>>>>>> is
>>>>>>>>>>>>>>>>>>>> what kafka is strongest at). The time to actually
>>> swap
>>>>> over
>>>>>>> the
>>>>>>>>>>>>>>>>>>>> producers
>>>>>>>>>>>>>>>>>>>> should be kept minimal by ensuring that when a swap
>>>>> attempt
>>>>>>> is
>>>>>>>>>>>>>>>>>>>> started
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>> the
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>> consumer copying over should be very close to the
>> log
>>>> end
>>>>>> and
>>>>>>>>>>>>>>>>>>>> is
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>> expected
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>> to finish within the next fetch. The operation
>> should
>>>>> have
>>>>>> a
>>>>>>>>>>>>>>>>>>>> time-out
>>>>>>>>>>>>>>>>>>>> and
>>>>>>>>>>>>>>>>>>>> should be "reattemtable".
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>> Importance of logcompaction:
>>>>>>>>>>>>>>>>>>>> If a producer produces key A, to partiton 0, its
>>>> forever
>>>>>>> gonna
>>>>>>>>>>>>>>>>>>>> be
>>>>>>>>>>>>>>>>>>>> there,
>>>>>>>>>>>>>>>>>>>> unless it gets deleted. The record might sit in
>> there
>>>> for
>>>>>>>>>>>>>>>>>>>> years. A
>>>>>>>>>>>>>>>>>>>> new
>>>>>>>>>>>>>>>>>>>> producer started with the new partitions will fail
>> to
>>>>>> delete
>>>>>>>>>>>>>>>>>>>> the
>>>>>>>>>>>>>>>>>>>> record
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>> in
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>> the correct partition. Th record will be there
>>> forever
>>>>> and
>>>>>>> one
>>>>>>>>>>>>>>>>>>>> can
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>> not
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>> reliable bootstrap new consumers. I cannot see how
>>>> linear
>>>>>>>>>>>>>>>>>>> hashing
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>> can
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>> solve
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>> this.
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>> Regarding your skipping of userland copying:
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>> 100%, copying the data across in userland is, as
>> far
>>>> as i
>>>>>> can
>>>>>>>>>>>>>>>>>>>> see,
>>>>>>>>>>>>>>>>>>>> only
>>>>>>>>>>>>>>>>>>>> a
>>>>>>>>>>>>>>>>>>>> usecase for log compacted topics. Even for
>>>> logcompaction
>>>>> +
>>>>>>>>>>>>>>>>>>>> retentions
>>>>>>>>>>>>>>>>>>>> it
>>>>>>>>>>>>>>>>>>>> should only be opt-in. Why did I bring it up? I
>> think
>>>> log
>>>>>>>>>>>>>>>>>>>> compaction
>>>>>>>>>>>>>>>>>>>> is
>>>>>>>>>>>>>>>>>>>> a
>>>>>>>>>>>>>>>>>>>> very important feature to really embrace kafka as a
>>>> "data
>>>>>>>>>>>>>>>>>>>> plattform".
>>>>>>>>>>>>>>>>>>>> The
>>>>>>>>>>>>>>>>>>>> point I also want to make is that copying data this
>>> way
>>>>> is
>>>>>>>>>>>>>>>>>>>> completely
>>>>>>>>>>>>>>>>>>>> inline with the kafka architecture. it only
>> consists
>>> of
>>>>>>> reading
>>>>>>>>>>>>>>>>>>>> and
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>> writing
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>> to topics.
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>> I hope it clarifies more why I think we should aim
>> for
>>>>> more
>>>>>>> than
>>>>>>>>>>>>>>>>>>>> the
>>>>>>>>>>>>>>>>>>>> current KIP. I fear that once the KIP is done not
>>> much
>>>>> more
>>>>>>>>>>>>>>>>>>>> effort
>>>>>>>>>>>>>>>>>>>> will
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>> be
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>> taken.
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>> On 04.03.2018 02:28, Dong Lin wrote:
>>>>>>>>>>>>>>>>>>>> Hey Jan,
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>> In the current proposal, the consumer will be
>> blocked
>>>> on
>>>>>>>>>>>>>>>>>>>> waiting
>>>>>>>>>>>>>>>>>>>> for
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>> other
>>>>>>>>>>>>>>>>>>>>> consumers of the group to consume up to a given
>>>> offset.
>>>>> In
>>>>>>>>>>>>>>>>>>>>> most
>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>> cases,
>>>>>>>>>>>>>>>>>>>> all
>>>>>>>>>>>>>>>>>>>> consumers should be close to the LEO of the
>>> partitions
>>>>> when
>>>>>>> the
>>>>>>>>>>>>>>>>>>>> partition
>>>>>>>>>>>>>>>>>>>> expansion happens. Thus the time waiting should not
>>> be
>>>>> long
>>>>>>>>>>>>>>>>>>>> e.g.
>>>>>>>>>>>>>>>>>>>> on
>>>>>>>>>>>>>>>>>>>> the
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>> order of seconds. On the other hand, it may take a
>>> long
>>>>>> time
>>>>>>> to
>>>>>>>>>>>>>>>>>>>> wait
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>> for
>>>>>>>>>>>>>>>>>>>>> the entire partition to be copied -- the amount of
>>>> time
>>>>> is
>>>>>>>>>>>>>>>>>>>>> proportional
>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>> to
>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>> the amount of existing data in the partition,
>> which
>>>> can
>>>>>> take
>>>>>>>>>>>>>>>>>>>> tens of
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>> minutes. So the amount of time that we stop
>> consumers
>>>> may
>>>>>> not
>>>>>>>>>>>>>>>>>>>> be
>>>>>>>>>>>>>>>>>>>> on
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>> the
>>>>>>>>>>>>>>>>>>>>> same order of magnitude.
>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>> If we can implement this suggestion without
>> copying
>>>> data
>>>>>>> over
>>>>>>>>>>>>>>>>>>>>> in
>>>>>>>>>>>>>>>>>>>>> purse
>>>>>>>>>>>>>>>>>>>>> userland, it will be much more valuable. Do you
>> have
>>>>> ideas
>>>>>>> on
>>>>>>>>>>>>>>>>>>>>> how
>>>>>>>>>>>>>>>>>>>>> this
>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>> can
>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>> be done?
>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>> Not sure why the current KIP not help people who
>>> depend
>>>>> on
>>>>>>> log
>>>>>>>>>>>>>>>>>>>> compaction.
>>>>>>>>>>>>>>>>>>>>> Could you elaborate more on this point?
>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>> Thanks,
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>> Dong
>>>>>>>>>>>>>>>>>>>>> On Wed, Feb 28, 2018 at 10:55 PM, Jan
>>>>>>>>>>>>>>>>>>>>> Filipiak<Jan.Filipiak@trivago.
>>>>>>>>>>>>>>>>>>>>> com
>>>>>>>>>>>>>>>>>>>>> wrote:
>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>> Hi Dong,
>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>> I tried to focus on what the steps are one can
>>>> currently
>>>>>>>>>>>>>>>>>>>>> perform
>>>>>>>>>>>>>>>>>>>>> to
>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>> expand
>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>> or shrink a keyed topic while maintaining a top
>>> notch
>>>>>>>>>>>>>>>>>>>>>> semantics.
>>>>>>>>>>>>>>>>>>>>>> I can understand that there might be confusion
>>> about
>>>>>>>>>>>>>>>>>>>>>> "stopping
>>>>>>>>>>>>>>>>>>>>>> the
>>>>>>>>>>>>>>>>>>>>>> consumer". It is exactly the same as proposed in
>>> the
>>>>> KIP.
>>>>>>>>>>>>>>>>>>>>>> there
>>>>>>>>>>>>>>>>>>>>>> needs
>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>> to
>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>> be
>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>> a time the producers agree on the new
>> partitioning.
>>>> The
>>>>>>> extra
>>>>>>>>>>>>>>>>>>>> semantics I
>>>>>>>>>>>>>>>>>>>>>> want to put in there is that we have a
>> possibility
>>> to
>>>>>> wait
>>>>>>>>>>>>>>>>>>>>>> until
>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>> all
>>>>>>>>>>>>>>>>>>>> the
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>> existing data
>>>>>>>>>>>>>>>>>>>>> is copied over into the new partitioning scheme.
>>> When
>>>> I
>>>>>> say
>>>>>>>>>>>>>>>>>>>> stopping
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>> I
>>>>>>>>>>>>>>>>>>>>>> think more of having a memory barrier that
>> ensures
>>>> the
>>>>>>>>>>>>>>>>>>>>>> ordering. I
>>>>>>>>>>>>>>>>>>>>>> am
>>>>>>>>>>>>>>>>>>>>>> still
>>>>>>>>>>>>>>>>>>>>>> aming for latencies  on the scale of leader
>>>> failovers.
>>>>>>>>>>>>>>>>>>>>>> Consumers have to explicitly adapt the new
>>>> partitioning
>>>>>>>>>>>>>>>>>>>>>> scheme
>>>>>>>>>>>>>>>>>>>>>> in
>>>>>>>>>>>>>>>>>>>>>> the
>>>>>>>>>>>>>>>>>>>>>> above scenario. The reason is that in these cases
>>>> where
>>>>>> you
>>>>>>>>>>>>>>>>>>>>>> are
>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>> dependent
>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>> on a particular partitioning scheme, you also
>> have
>>>>> other
>>>>>>>>>>>>>>>>>>>>>> topics
>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>> that
>>>>>>>>>>>>>>>>>>>> have
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>> co-partition enforcements or the kind -frequently.
>>>>>> Therefore
>>>>>>>>>>>>>>>>>>>>> all
>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>> your
>>>>>>>>>>>>>>>>>>>> other
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>> input topics might need to grow accordingly.
>>>>>>>>>>>>>>>>>>>>>> What I was suggesting was to streamline all these
>>>>>>> operations
>>>>>>>>>>>>>>>>>>>>>> as
>>>>>>>>>>>>>>>>>>>>>> best
>>>>>>>>>>>>>>>>>>>>>> as
>>>>>>>>>>>>>>>>>>>>>> possible to have "real" partition grow and
>>> shrinkage
>>>>>> going
>>>>>>>>>>>>>>>>>>>>>> on.
>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>> Migrating
>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>> the producers to a new partitioning scheme can be
>>>> much
>>>>>> more
>>>>>>>>>>>>>>>>>>>>> streamlined
>>>>>>>>>>>>>>>>>>>> with proper broker support for this. Migrating
>>> consumer
>>>>> is
>>>>>> a
>>>>>>>>>>>>>>>>>>>> step
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>> that
>>>>>>>>>>>>>>>>>>>>>> might be made completly unnecessary if - for
>>> example
>>>>>>> streams
>>>>>>>>>>>>>>>>>>>>>> -
>>>>>>>>>>>>>>>>>>>>>> takes
>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>> the
>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>> gcd as partitioning scheme instead of enforcing 1
>>> to
>>>> 1.
>>>>>>>>>>>>>>>>>>>>>> Connect
>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>> consumers
>>>>>>>>>>>>>>>>>>>> and other consumers should be fine anyways.
>>>>>>>>>>>>>>>>>>>>> I hope this makes more clear where I was aiming
>> at.
>>>> The
>>>>>> rest
>>>>>>>>>>>>>>>>>>>> needs
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>> to
>>>>>>>>>>>>>>>>>>>>> be
>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>> figured out. The only danger i see is that when
>> we
>>>> are
>>>>>>>>>>>>>>>>>>>>> introducing
>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>> this
>>>>>>>>>>>>>>>>>>>> feature as supposed in the KIP, it wont help any
>>> people
>>>>>>>>>>>>>>>>>>>> depending
>>>>>>>>>>>>>>>>>>>> on
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>> log
>>>>>>>>>>>>>>>>>>>>>> compaction.
>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>> The other thing I wanted to mention is that I
>>> believe
>>>>> the
>>>>>>>>>>>>>>>>>>>> current
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>> suggestion (without copying data over) can be
>>>> implemented
>>>>>> in
>>>>>>>>>>>>>>>>>>>>> pure
>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>> userland
>>>>>>>>>>>>>>>>>>>>>> with a custom partitioner and a small
>> feedbackloop
>>>> from
>>>>>>>>>>>>>>>>>>>>>> ProduceResponse
>>>>>>>>>>>>>>>>>>>>>> =>
>>>>>>>>>>>>>>>>>>>>>> Partitionier in coorporation with a change
>>> management
>>>>>>> system.
>>>>>>>>>>>>>>>>>>>>>> Best Jan
>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>> On 28.02.2018 07:13, Dong Lin wrote:
>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>> Hey Jan,
>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>> I am not sure if it is acceptable for producer to
>>> be
>>>>>>> stopped
>>>>>>>>>>>>>>>>>>>>>> for a
>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>> while,
>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>> particularly for online application which
>> requires
>>>> low
>>>>>>>>>>>>>>>>>>>>>>> latency. I
>>>>>>>>>>>>>>>>>>>>>>> am
>>>>>>>>>>>>>>>>>>>>>>> also
>>>>>>>>>>>>>>>>>>>>>>> not sure how consumers can switch to a new
>> topic.
>>>> Does
>>>>>>> user
>>>>>>>>>>>>>>>>>>>>>>> application
>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>> needs to explicitly specify a different topic
>> for
>>>>>>>>>>>>>>>>>>>>>> producer/consumer
>>>>>>>>>>>>>>>>>>>>> to
>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>> subscribe to? It will be helpful for discussion if
>>> you
>>>>> can
>>>>>>>>>>>>>>>>>>>> provide
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>> more
>>>>>>>>>>>>>>>>>>>>>> detail on the interface change for this solution.
>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>> Thanks,
>>>>>>>>>>>>>>>>>>>>> Dong
>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>> On Mon, Feb 26, 2018 at 12:48 AM, Jan
>>>>>>>>>>>>>>>>>>>>>>> Filipiak<Jan.Filipiak@trivago.
>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>> com
>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>> wrote:
>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>> Hi,
>>>>>>>>>>>>>>>>>>>>> just want to throw my though in. In general the
>>>>>>> functionality
>>>>>>>>>>>>>>>>>>>>> is
>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>> very
>>>>>>>>>>>>>>>>>>>>>>> usefull, we should though not try to find the
>>>>>> architecture
>>>>>>>>>>>>>>>>>>>>>>> to
>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>> hard
>>>>>>>>>>>>>>>>>>>>>>>> while
>>>>>>>>>>>>>>>>>>>>>>>> implementing.
>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>> The manual steps would be to
>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>> create a new topic
>>>>>>>>>>>>>>>>>>>>>>>> the mirrormake from the new old topic to the
>> new
>>>>> topic
>>>>>>>>>>>>>>>>>>>>>>>> wait for mirror making to catch up.
>>>>>>>>>>>>>>>>>>>>>>>> then put the consumers onto the new topic
>>>>>>>>>>>>>>>>>>>>>>>>             (having mirrormaker spit out a
>> mapping
>>>>> from
>>>>>>> old
>>>>>>>>>>>>>>>>>>>>>>>> offsets to
>>>>>>>>>>>>>>>>>>>>>>>> new
>>>>>>>>>>>>>>>>>>>>>>>> offsets:
>>>>>>>>>>>>>>>>>>>>>>>>                 if topic is increased by factor
>> X
>>>>> there
>>>>>> is
>>>>>>>>>>>>>>>>>>>>>>>> gonna
>>>>>>>>>>>>>>>>>>>>>>>> be a
>>>>>>>>>>>>>>>>>>>>>>>> clean
>>>>>>>>>>>>>>>>>>>>>>>> mapping from 1 offset in the old topic to X
>>> offsets
>>>>> in
>>>>>>> the
>>>>>>>>>>>>>>>>>>>>>>>> new
>>>>>>>>>>>>>>>>>>>>>>>> topic,
>>>>>>>>>>>>>>>>>>>>>>>>                 if there is no factor then there
>>> is
>>>> no
>>>>>>>>>>>>>>>>>>>>>>>> chance to
>>>>>>>>>>>>>>>>>>>>>>>> generate a
>>>>>>>>>>>>>>>>>>>>>>>> mapping that can be reasonable used for
>>> continuing)
>>>>>>>>>>>>>>>>>>>>>>>>             make consumers stop at appropriate
>>>> points
>>>>>> and
>>>>>>>>>>>>>>>>>>>>>>>> continue
>>>>>>>>>>>>>>>>>>>>>>>> consumption
>>>>>>>>>>>>>>>>>>>>>>>> with offsets from the mapping.
>>>>>>>>>>>>>>>>>>>>>>>> have the producers stop for a minimal time.
>>>>>>>>>>>>>>>>>>>>>>>> wait for mirrormaker to finish
>>>>>>>>>>>>>>>>>>>>>>>> let producer produce with the new metadata.
>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>> Instead of implementing the approach suggest in
>>> the
>>>>> KIP
>>>>>>>>>>>>>>>>>>>>>>>> which
>>>>>>>>>>>>>>>>>>>>>>>> will
>>>>>>>>>>>>>>>>>>>>>>>> leave
>>>>>>>>>>>>>>>>>>>>>>>> log compacted topic completely crumbled and
>>>> unusable.
>>>>>>>>>>>>>>>>>>>>>>>> I would much rather try to build infrastructure
>>> to
>>>>>>> support
>>>>>>>>>>>>>>>>>>>>>>>> the
>>>>>>>>>>>>>>>>>>>>>>>> mentioned
>>>>>>>>>>>>>>>>>>>>>>>> above operations more smoothly.
>>>>>>>>>>>>>>>>>>>>>>>> Especially having producers stop and use
>> another
>>>>> topic
>>>>>> is
>>>>>>>>>>>>>>>>>>>>>>>> difficult
>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>> and
>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>> it would be nice if one can trigger "invalid
>>>>> metadata"
>>>>>>>>>>>>>>>>>>>>>>> exceptions
>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>> for
>>>>>>>>>>>>>>>>>>>>> them
>>>>>>>>>>>>>>>>>>>> and
>>>>>>>>>>>>>>>>>>>>>> if one could give topics aliases so that their
>>>> produces
>>>>>>> with
>>>>>>>>>>>>>>>>>>>>>>>> the
>>>>>>>>>>>>>>>>>>>>>>>> old
>>>>>>>>>>>>>>>>>>>>>>>> topic
>>>>>>>>>>>>>>>>>>>>>>>> will arrive in the new topic.
>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>> The downsides are obvious I guess ( having the
>>> same
>>>>>> data
>>>>>>>>>>>>>>>>>>>>>>>> twice
>>>>>>>>>>>>>>>>>>>>>>>> for
>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>> the
>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>> transition period, but kafka tends to scale
>> well
>>>> with
>>>>>>>>>>>>>>>>>>>>>>> datasize).
>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>> So
>>>>>>>>>>>>>>>>>>>>>> its a
>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>> nicer fit into the architecture.
>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>> I further want to argument that the functionality
>>> by
>>>>> the
>>>>>>> KIP
>>>>>>>>>>>>>>>>>>>>>>>> can
>>>>>>>>>>>>>>>>>>>>>>>> completely be implementing in "userland" with a
>>>>> custom
>>>>>>>>>>>>>>>>>>>>>>>> partitioner
>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>> that
>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>> handles the transition as needed. I would
>>>> appreciate
>>>>> if
>>>>>>>>>>>>>>>>>>>>>>> someone
>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>> could
>>>>>>>>>>>>>>>>>>>>> point
>>>>>>>>>>>>>>>>>>>> out what a custom partitioner couldn't handle in
>> this
>>>>> case?
>>>>>>>>>>>>>>>>>>>>>> With the above approach, shrinking a topic
>> becomes
>>>> the
>>>>>> same
>>>>>>>>>>>>>>>>>>>>>>>> steps.
>>>>>>>>>>>>>>>>>>>>>>>> Without
>>>>>>>>>>>>>>>>>>>>>>>> loosing keys in the discontinued partitions.
>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>> Would love to hear what everyone thinks.
>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>> Best Jan
>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>> On 11.02.2018 00:35, Dong Lin wrote:
>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>> Hi all,
>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>> I have created KIP-253: Support in-order
>> message
>>>>>> delivery
>>>>>>>>>>>>>>>>>>>>>>>> with
>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>> partition
>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>> expansion. See
>>>>>>>>>>>>>>>>>>>>>>>>> https://cwiki.apache.org/confl
>>>>>>>>>>>>>>>>>>>>>>>>> uence/display/KAFKA/KIP-253%
>>>>>>>>>>>>>>>>>>>>>>>>> 3A+Support+in-order+message+de
>>>>>>>>>>>>>>>>>>>>>>>>> livery+with+partition+expansio
>>>>>>>>>>>>>>>>>>>>>>>>> n
>>>>>>>>>>>>>>>>>>>>>>>>> .
>>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>>> This KIP provides a way to allow messages of
>> the
>>>>> same
>>>>>>> key
>>>>>>>>>>>>>>>>>>>>>>>>> from
>>>>>>>>>>>>>>>>>>>>>>>>> the
>>>>>>>>>>>>>>>>>>>>>>>>> same
>>>>>>>>>>>>>>>>>>>>>>>>> producer to be consumed in the same order they
>>> are
>>>>>>>>>>>>>>>>>>>>>>>>> produced
>>>>>>>>>>>>>>>>>>>>>>>>> even
>>>>>>>>>>>>>>>>>>>>>>>>> if
>>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>>> we
>>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>>> expand partition of the topic.
>>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>> Thanks,
>>>>>>>>>>>>>>>>>>>>>> Dong
>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>


Re: [DISCUSS] KIP-253: Support in-order message delivery with partition expansion

Posted by Jan Filipiak <Ja...@trivago.com>.
Hi Dong.

I do disagree here. I think we are fooling ourselfs!

This KIP lays the foundation for the wrong path and
I am heavily against it. We should have state full producers in mind at this
very moment.

One can clearly see that you are on a wrong path when you talk about taking
away custom partitioner for this usecase!

This is soooo wrong!

Please reiterate my idea, try to understand it or ask me what is not clear
but don't continue with this assumption.

best Jan



On 28.03.2018 08:34, Dong Lin wrote:
> Hey John,
>
> Great! Thanks for all the comment. It seems that we agree that the current
> KIP is in good shape for core Kafka. IMO, what we have been discussing in
> the recent email exchanges is mostly about the second step, i.e. how to
> address problem for the stream use-case (or stateful processing in general).
>
> I will comment inline.
>
>
>
>
> On Tue, Mar 27, 2018 at 4:38 PM, John Roesler <jo...@confluent.io> wrote:
>
>> Thanks for the response, Dong.
>>
>> Here are my answers to your questions:
>>
>> - "Asking producers and consumers, or even two different producers, to
>>> share code like the partition function is a pretty huge ask. What if they
>>> are using different languages?". It seems that today we already require
>>> different producer's to use the same hash function -- otherwise messages
>>> with the same key will go to different partitions of the same topic which
>>> may cause problem for downstream consumption. So not sure if it adds any
>>> more constraint by assuming consumers know the hash function of producer.
>>> Could you explain more why user would want to use a cusmtom partition
>>> function? Maybe we can check if this is something that can be supported
>> in
>>> the default Kafka hash function. Also, can you explain more why it is
>>> difficuilt to implement the same hash function in different languages?
>>
>> Sorry, I meant two different producers as in producers to two different
>> topics. This was in response to the suggestion that we already require
>> coordination among producers to different topics in order to achieve
>> co-partitioning. I was saying that we do not (and should not).
>
> It is probably common for producers of different team to produce message to
> the same topic. In order to ensure that messages with the same key go to
> same partition, we need producers of different team to share the same
> partition algorithm, which by definition requires coordination among
> producers of different teams in an organization. Even for producers of
> different topics, it may be common to require producers to use the same
> partition algorithm in order to join two topics for stream processing. Does
> this make it reasonable to say we already require coordination across
> producers?
>
>
>> By design, consumers are currently ignorant of the partitioning scheme. It
>> suffices to trust that the producer has partitioned the topic by key, if
>> they claim to have done so. If you don't trust that, or even if you just
>> need some other partitioning scheme, then you must re-partition it
>> yourself. Nothing we're discussing can or should change that. The value of
>> backfill is that it preserves the ability for consumers to avoid
>> re-partitioning before consuming, in the case where they don't need to
>> today.
>
>> Regarding shared "hash functions", note that it's a bit inaccurate to talk
>> about the "hash function" of the producer. Properly speaking, the producer
>> has only a "partition function". We do not know that it is a hash. The
>> producer can use any method at their disposal to assign a partition to a
>> record. The partition function obviously may we written in any programming
>> language, so in general it's not something that can be shared around
>> without a formal spec or the ability to execute arbitrary executables in
>> arbitrary runtime environments.
>>
> Yeah it is probably better to say partition algorithm. I guess it should
> not be difficult to implement same partition algorithms in different
> languages, right? Yes we would need a formal specification of the default
> partition algorithm in the producer. I think that can be documented as part
> of the producer interface.
>
>
>> Why would a producer want a custom partition function? I don't know... why
>> did we design the interface so that our users can provide one? In general,
>> such systems provide custom partitioners because some data sets may be
>> unbalanced under the default or because they can provide some interesting
>> functionality built on top of the partitioning scheme, etc. Having provided
>> this ability, I don't know why we would remove it.
>>
> Yeah it is reasonable to assume that there was reason to support custom
> partition function in producer. On the other hand it may also be reasonable
> to revisit this interface and discuss whether we actually need to support
> custom partition function. If we don't have a good reason, we can choose
> not to support custom partition function in this KIP in a backward
> compatible manner, i.e. user can still use custom partition function but
> they would not get the benefit of in-order delivery when there is partition
> expansion. What do you think?
>
>
>> - Besides the assumption that consumer needs to share the hash function of
>>> producer, is there other organization overhead of the proposal in the
>>> current KIP?
>>>
>> It wasn't clear to me that KIP-253 currently required the producer and
>> consumer to share the partition function, or in fact that it had a hard
>> requirement to abandon the general partition function and use a linear hash
>> function instead.
>
>> In my reading, there is a requirement to track the metadata about what
>> partitions split into what other partitions during an expansion operation.
>> If the partition function is linear, this is easy. If not, you can always
>> just record that all old partitions split into all new partitions. This has
>> the effect of forcing all consumers to wait until the old epoch is
>> completely consumed before starting on the new epoch. But this may be a
>> reasonable tradeoff, and it doesn't otherwise alter your design.
>>
>> You only mention the consumer needing to know that the partition function
>> is linear, not what the actual function is, so I don't think your design
>> actually calls for sharing the function. Plus, really all the consumer
>> needs is the metadata about what old-epoch partitions to wait for before
>> consuming a new-epoch partition. This information is directly captured in
>> metadata, so I don't think it actually even cares whether the partition
>> function is linear or not.
>>
> You are right that the current KIP does not mention it. My comment related
> to the partition function coordination was related to support the
> stream-use case which we have been discussing so far.
>
>
>> So, no, I really think KIP-253 is in good shape. I was really more talking
>> about the part of this thread that's outside of KIP-253's scope, namely,
>> creating the possibility of backfilling partitions after expansion.
>>
> Great! Can you also confirm that the main motivation for backfilling
> partitions after expansion is to support the stream use-case?
>
>
>> - Currently producer can forget about the message that has been
>>> acknowledged by the broker. Thus the producer probably does not know most
>>> of the exiting messages in topic, including those messages produced by
>>> other producers. We can have the owner of the producer to split+backfill.
>>> In my opion it will be a new program that wraps around the existing
>>> producer and consumer classes.
>>>
>> This sounds fine by me!
>>
>> Really, I was just emphasizing that the part of the organization that
>> produces a topic shouldn't have to export their partition function to the
>> part(s) of the organization (or other organizations) that consume the
>> topic. Whether the backfill operation goes into the Producer interface is
>> secondary, I think.
>>
>> - Regarding point 5. The argument is in favor of the split+backfill but for
>>> changelog topic. And it intends to address the problem for stream
>> use-case
>>> in general. In this KIP we will provide interface (i.e.
>>> PartitionKeyRebalanceListener in the KIP) to be used by sream use-case
>> and
>>> the goal is that user can flush/re-consume the state as part of the
>>> interface implementation regardless of whether there is change log topic.
>>>
>>> Maybe you are suggesting that the main reason to do split+backfill of
>> input
>>> topic is to support log compacted topics? You mentioned in Point 1 that
>> log
>>> compacted topics is out of the scope of this KIP. Maybe I could
>> understand
>>> your position better. Regarding Jan's proposal to split partitions with
>>> backfill, do you think this should replace the proposal in the existing
>>> KIP, or do you think this is something that we should do in addition to
>> the
>>> existing KIP?
>>>
>> I think that interface is a good/necessary component of KIP-253.
>>
>> I personally (FWIW) feel that KIP-253 is appropriately scoped, but I do
>> think its utility will be limited unless there is a later KIP offering
>> backfill. But, maybe unlike Jan, I think it makes sense to try and tackle
>> the ordering problem independently of backfill, so I'm in support of the
>> current KIP.
>>
>> - Regarding point 6. I guess we can agree that it is better not to have the
>>> performance overhread of copying the input data. Before we discuss more
>> on
>>> whether the performance overhead is acceptable or not, I am trying to
>>> figure out what is the benefit of introducing this overhread. You
>> mentioned
>>> that the benefit is the loose organizational coupling. By "organizational
>>> coupling", are you referring to the requirement that consumer needs to
>> know
>>> the hash function of producer? If so, maybe we can discuss the use-case
>> of
>>> custom partiton function and see whether we can find a way to support
>> such
>>> use-case without having to copy the input data.
>>>
>> I'm not too sure about what an "input" is in this sense, since we are just
>> talking about topics. Actually the point I was making there is that AKAICT
>> the performance overhead of a backfill is less than any other option,
>> assuming you split partitions rarely.
>>
> By "input" I was referring to source Kafka topic of a stream processing job.
>
>
>> Separately, yes, "organizational coupling" increases if producers and
>> consumers have to share code, such as the partition function. This would
>> not be the case if producers could only pick from a menu of a few
>> well-known partition functions, but I think this is a poor tradeoff.
>>
> Maybe we can revisit the custom partition function and see whether we
> actually need it? Otherwise, I am concerned that every user will pay the
> overhead of data movement to support something that was not really needed
> for most users.
>
>
>> To me, this is two strong arguments in favor of backfill being less
>> expensive than no backfill, but again, I think that particular debate comes
>> after KIP-253, so I don't want to create the impression of opposition to
>> your proposal.
>>
>>
>> Finally, to respond to a new email I just noticed:
>>
>>> BTW, here is my understanding of the scope of this KIP. We want to allow
>>> consumers to always consume messages with the same key from the same
>>> producer in the order they are produced. And we need to provide a way for
>>> stream use-case to be able to flush/load state when messages with the
>> same
>>> key are migrated between consumers. In addition to ensuring that this
>> goal
>>> is correctly supported, we should do our best to keep the performance and
>>> organization overhead of this KIP as low as possible.
>>>
>> I think we're on the same page there! In fact, I would generalize a little
>> more and say that the mechanism you've designed provides *all consumers*
>> the ability "to flush/load state when messages with the same key are
>> migrated between consumers", not just Streams.
>>
> Thanks for all the comment!
>
>
>> Thanks for the discussion,
>> -John
>>
>>
>>
>> On Tue, Mar 27, 2018 at 3:14 PM, Dong Lin <li...@gmail.com> wrote:
>>
>>> Hey John,
>>>
>>> Thanks much for the detailed comments. Here are my thoughts:
>>>
>>> - The need to delete messages from log compacted topics is mainly for
>>> performance (e.g. storage space) optimization than for correctness for
>> this
>>> KIP. I agree that we probably don't need to focus on this in our
>> discussion
>>> since it is mostly for performance optimization.
>>>
>>> - "Asking producers and consumers, or even two different producers, to
>>> share code like the partition function is a pretty huge ask. What if they
>>> are using different languages?". It seems that today we already require
>>> different producer's to use the same hash function -- otherwise messages
>>> with the same key will go to different partitions of the same topic which
>>> may cause problem for downstream consumption. So not sure if it adds any
>>> more constraint by assuming consumers know the hash function of producer.
>>> Could you explain more why user would want to use a cusmtom partition
>>> function? Maybe we can check if this is something that can be supported
>> in
>>> the default Kafka hash function. Also, can you explain more why it is
>>> difficuilt to implement the same hash function in different languages?
>>>
>>> - Besides the assumption that consumer needs to share the hash function
>> of
>>> producer, is there other organization overhead of the proposal in the
>>> current KIP?
>>>
>>> - Currently producer can forget about the message that has been
>>> acknowledged by the broker. Thus the producer probably does not know most
>>> of the exiting messages in topic, including those messages produced by
>>> other producers. We can have the owner of the producer to split+backfill.
>>> In my opion it will be a new program that wraps around the existing
>>> producer and consumer classes.
>>>
>>> - Regarding point 5. The argument is in favor of the split+backfill but
>> for
>>> changelog topic. And it intends to address the problem for stream
>> use-case
>>> in general. In this KIP we will provide interface (i.e.
>>> PartitionKeyRebalanceListener in the KIP) to be used by sream use-case
>> and
>>> the goal is that user can flush/re-consume the state as part of the
>>> interface implementation regardless of whether there is change log topic.
>>>
>>> Maybe you are suggesting that the main reason to do split+backfill of
>> input
>>> topic is to support log compacted topics? You mentioned in Point 1 that
>> log
>>> compacted topics is out of the scope of this KIP. Maybe I could
>> understand
>>> your position better. Regarding Jan's proposal to split partitions with
>>> backfill, do you think this should replace the proposal in the existing
>>> KIP, or do you think this is something that we should do in addition to
>> the
>>> existing KIP?
>>>
>>> - Regarding point 6. I guess we can agree that it is better not to have
>> the
>>> performance overhread of copying the input data. Before we discuss more
>> on
>>> whether the performance overhead is acceptable or not, I am trying to
>>> figure out what is the benefit of introducing this overhread. You
>> mentioned
>>> that the benefit is the loose organizational coupling. By "organizational
>>> coupling", are you referring to the requirement that consumer needs to
>> know
>>> the hash function of producer? If so, maybe we can discuss the use-case
>> of
>>> custom partiton function and see whether we can find a way to support
>> such
>>> use-case without having to copy the input data.
>>>
>>> Thanks,
>>> Dong
>>>
>>>
>>> On Tue, Mar 27, 2018 at 11:34 AM, John Roesler <jo...@confluent.io>
>> wrote:
>>>> Hey Dong and Jun,
>>>>
>>>> Thanks for the thoughtful responses. If you don't mind, I'll mix my
>>> replies
>>>> together to try for a coherent response. I'm not too familiar with
>>>> mailing-list etiquette, though.
>>>>
>>>> I'm going to keep numbering my points because it makes it easy for you
>>> all
>>>> to respond.
>>>>
>>>> Point 1:
>>>> As I read it, KIP-253 is *just* about properly fencing the producers
>> and
>>>> consumers so that you preserve the correct ordering of records during
>>>> partition expansion. This is clearly necessary regardless of anything
>>> else
>>>> we discuss. I think this whole discussion about backfill, consumers,
>>>> streams, etc., is beyond the scope of KIP-253. But it would be
>> cumbersome
>>>> to start a new thread at this point.
>>>>
>>>> I had missed KIP-253's Proposed Change #9 among all the details... I
>>> think
>>>> this is a nice addition to the proposal. One thought is that it's
>>> actually
>>>> irrelevant whether the hash function is linear. This is simply an
>>> algorithm
>>>> for moving a key from one partition to another, so the type of hash
>>>> function need not be a precondition. In fact, it also doesn't matter
>>>> whether the topic is compacted or not, the algorithm works regardless.
>>>>
>>>> I think this is a good algorithm to keep in mind, as it might solve a
>>>> variety of problems, but it does have a downside: that the producer
>> won't
>>>> know whether or not K1 was actually in P1, it just knows that K1 was in
>>>> P1's keyspace before the new epoch. Therefore, it will have to
>>>> pessimistically send (K1,null) to P1 just in case. But the next time K1
>>>> comes along, the producer *also* won't remember that it already
>> retracted
>>>> K1 from P1, so it will have to send (K1,null) *again*. By extension,
>>> every
>>>> time the producer sends to P2, it will also have to send a tombstone to
>>> P1,
>>>> which is a pretty big burden. To make the situation worse, if there is
>> a
>>>> second split, say P2 becomes P2 and P3, then any key Kx belonging to P3
>>>> will also have to be retracted from P2 *and* P1, since the producer
>> can't
>>>> know whether Kx had been last written to P2 or P1. Over a long period
>> of
>>>> time, this clearly becomes a issue, as the producer must send an
>>> arbitrary
>>>> number of retractions along with every update.
>>>>
>>>> In contrast, the proposed backfill operation has an end, and after it
>>> ends,
>>>> everyone can afford to forget that there ever was a different partition
>>>> layout.
>>>>
>>>> Really, though, figuring out how to split compacted topics is beyond
>> the
>>>> scope of KIP-253, so I'm not sure #9 really even needs to be in this
>>> KIP...
>>>> We do need in-order delivery during partition expansion. It would be
>> fine
>>>> by me to say that you *cannot* expand partitions of a log-compacted
>> topic
>>>> and call it a day. I think it would be better to tackle that in another
>>>> KIP.
>>>>
>>>>
>>>> Point 2:
>>>> Regarding whether the consumer re-shuffles its inputs, this is always
>> on
>>>> the table; any consumer who wants to re-shuffle its input is free to do
>>> so.
>>>> But this is currently not required. It's just that the current
>> high-level
>>>> story with Kafka encourages the use of partitions as a unit of
>>> concurrency.
>>>> As long as consumers are single-threaded, they can happily consume a
>>> single
>>>> partition without concurrency control of any kind. This is a key aspect
>>> to
>>>> this system that lets folks design high-throughput systems on top of it
>>>> surprisingly easily. If all consumers were instead encouraged/required
>> to
>>>> implement a repartition of their own, then the consumer becomes
>>>> significantly more complex, requiring either the consumer to first
>>> produce
>>>> to its own intermediate repartition topic or to ensure that consumer
>>>> threads have a reliable, high-bandwith channel of communication with
>>> every
>>>> other consumer thread.
>>>>
>>>> Either of those tradeoffs may be reasonable for a particular user of
>>> Kafka,
>>>> but I don't know if we're in a position to say that they are reasonable
>>> for
>>>> *every* user of Kafka.
>>>>
>>>>
>>>> Point 3:
>>>> Regarding Jun's point about this use case, "(3) stateful and
>> maintaining
>>>> the
>>>> states in a local store", I agree that they may use a framework *like*
>>>> Kafka Streams, but that is not the same as using Kafka Streams. This is
>>> why
>>>> I think it's better to solve it in Core: because it is then solved for
>>>> KStreams and also for everything else that facilitates local state
>>>> maintenance. To me, Streams is a member of the category of "stream
>>>> processing frameworks", which is itself a subcategory of "things
>>> requiring
>>>> local state maintenence". I'm not sure if it makes sense to assert that
>>>> Streams is a sufficient and practical replacement for everything in
>>> "things
>>>> requiring local state maintenence".
>>>>
>>>> But, yes, I do agree that per-key ordering is an absolute requirement,
>>>> therefore I think that KIP-253 itself is a necessary step. Regarding
>> the
>>>> coupling of the state store partitioning to the topic partitioning,
>> yes,
>>>> this is an issue we are discussing solutions to right now. We may go
>>> ahead
>>>> and introduce an overpartition layer on our inputs to solve it, but
>> then
>>>> again, if we get the ability to split partitions with backfill, we may
>>> not
>>>> need to!
>>>>
>>>>
>>>> Point 4:
>>>> On this:
>>>>
>>>>> Regarding thought 2: If we don't care about the stream use-case, then
>>> the
>>>>> current KIP probably has already addressed problem without requiring
>>>>> consumer to know the partition function. If we care about the stream
>>>>> use-case, we already need coordination across producers of different
>>>>> topics, i.e. the same partition function needs to be used by
>> producers
>>> of
>>>>> topics A and B in order to join topics A and B. Thus, it might be
>>>>> reasonable to extend coordination a bit and say we need coordination
>>>> across
>>>>> clients (i.e. producer and consumer), such that consumer knows the
>>>>> partition function used by producer. If we do so, then we can let
>>>> consumer
>>>>> re-copy data for the change log topic using the same partition
>> function
>>>> as
>>>>> producer. This approach has lower overhead as compared to having
>>> producer
>>>>> re-copy data of the input topic.
>>>>> Also, producer currently does not need to know the data already
>>> produced
>>>> to
>>>>> the topic. If we let producer split/merge partition, it would require
>>>>> producer to consume the existing data, which intuitively is the task
>> of
>>>>> consumer.
>>>>
>>>> I think we do care about use cases *like* Streams, I just don't think
>> we
>>>> should rely on Streams to implement a feature of Core like partition
>>>> expansion.
>>>>
>>>> Note, though, that we (Streams) do not require coordination across
>>>> producers. If two topics are certified to be co-partitioned, then
>> Streams
>>>> apps can make use of that knowledge to optimize their topology
>> (skipping
>>> a
>>>> repartition). But if they don't know whether they are co-partitioned,
>>> then
>>>> they'd better go ahead and repartition within the topology. This is the
>>>> current state.
>>>>
>>>> A huge selling point of Kafka is enabling different parts of loosely
>>>> coupled organizations to produce and consume data independently. Some
>>>> coordination between producers and consumers is necessary, like
>>>> coordinating on the names of topics and their schemas. But Kafka's
>> value
>>>> proposition w.r.t. ESBs, etc. is inversely proportional to the amount
>> of
>>>> coordination required. I think it behooves us to be extremely skeptical
>>>> about introducing any coordination beyond correctness protocols.
>>>>
>>>> Asking producers and consumers, or even two different producers, to
>> share
>>>> code like the partition function is a pretty huge ask. What if they are
>>>> using different languages?
>>>>
>>>> Comparing organizational overhead vs computational overhead, there are
>>>> maybe two orders of magnitude difference between them. In other words,
>> I
>>>> would happily take on the (linear) overhead of having the producer
>>> re-copy
>>>> the data once during a re-partition in order to save the organizational
>>>> overhead of tying all the producers and consumers together across
>>> multiple
>>>> boundaries.
>>>>
>>>> On that last paragraph: note that the producer *did* know the data it
>>>> already produced. It handled it the first time around. Asking it to
>>>> re-produce it into a new partition layout is squarely within its scope
>> of
>>>> capabilities. Contrast this with the alternative, asking the consumer
>> to
>>>> re-partition the data. I think this is even less intuitive, when the
>>>> partition function belongs to the producer.
>>>>
>>>>
>>>> Point 5:
>>>> Dong asked this:
>>>>
>>>>> For stream use-case that needs to increase consumer number, the
>>>>> existing consumer can backfill the existing data in the change log
>>> topic
>>>> to
>>>>> the same change log topic with the new partition number, before the
>> new
>>>> set
>>>>> of consumers bootstrap state from the new partitions of the change
>> log
>>>>> topic, right?
>>>>
>>>> In this sense, the "consumer" is actually the producer of the changelog
>>>> topic, so if we support partition expansion + backfill as a
>>> producer/broker
>>>> operation, then it would be very straightforward for Streams to split a
>>>> state store. As you say, they would simply instruct the broker to split
>>> the
>>>> changelog topic's partitions, then backfill. Once the backfill is
>> ready,
>>>> they can create a new crop of StandbyTasks to bootstrap the more
>> granular
>>>> state stores and finally switch over to them when they are ready.
>>>>
>>>> But this actually seems to be an argument in favor of split+backfill,
>> so
>>>> maybe I missed the point.
>>>>
>>>> You also asked me to explain why copying the "input" topic is better
>> than
>>>> copying the "changelog" topic. I think they are totally independent,
>>>> actually. For one thing, you can't depend on the existence of a
>>> "changelog"
>>>> topic in general, only within Streams, but Kafka's user base clearly
>>>> exceeds Streams's user base. Plus, you actually also can't depend on
>> the
>>>> existence of a changelog topic within Streams, since that is an
>> optional
>>>> feature of *some* state store implementations. Even in the situation
>>> where
>>>> you do have a changelog topic in Streams, there may be use cases where
>> it
>>>> makes sense to expand the partitions of just the input, or just the
>>>> changelog.
>>>>
>>>> The ask for a Core feature of split+backfill is really about supporting
>>> the
>>>> use case of splitting partitions in log-compacted topics, regardless of
>>>> whether that topic is an "input" or a "changelog" or anything else for
>>> that
>>>> matter.
>>>>
>>>>
>>>> Point 6:
>>>> On the concern about the performance overhead of copying data between
>> the
>>>> brokers, I think it's actually a bit overestimated. Splitting a topic's
>>>> partition is probably rare, certainly rarer in general than
>> bootstrapping
>>>> new consumers on that topic. If "bootstrapping new consumers" means
>> that
>>>> they have to re-shuffle the data before they consume it, then you wind
>> up
>>>> copying the same record multiple times:
>>>>
>>>> (broker: input topic) -> (initial consumer) -> (broker: repartition
>>> topic)
>>>> -> (real consumer)
>>>>
>>>> That's 3x, and it's also 3x for every new record after the split as
>> well,
>>>> since you don't get to stop repartitioning/reshuffling once you start.
>>>>
>>>> Whereas if you do a backfill in something like the procedure I
>> outlined,
>>>> you only copy the prefix of the partition before the split, and you
>> send
>>> it
>>>> once to the producer and then once to the new generation partition.
>> Plus,
>>>> assuming we're splitting the partition for the benefit of consumers,
>>>> there's no reason we can't co-locate the post-split partitions on the
>>> same
>>>> host as the pre-split partition, making the second copy a local
>>> filesystem
>>>> operation.
>>>>
>>>> Even if you follow these two copies up with bootstrapping a new
>> consumer,
>>>> it's still rare for this to occur, so you get to amortize these copies
>>> over
>>>> the lifetime of the topic, whereas a reshuffle just keeps making copies
>>> for
>>>> every new event.
>>>>
>>>> And finally, I really do think that regardless of any performance
>>> concerns
>>>> about this operation, if it preserves loose organizational coupling, it
>>> is
>>>> certainly worth it.
>>>>
>>>>
>>>> In conclusion:
>>>> It might actually be a good idea for us to clarify the scope of
>> KIP-253.
>>> If
>>>> we're all agreed that it's a good algorithm for allowing in-order
>> message
>>>> delivery during partition expansion, then we can continue this
>> discussion
>>>> as a new KIP, something like "backfill with partition expansion". This
>>>> would let Dong proceed with KIP-253. On the other hand, if it seems
>> like
>>>> this conversation may alter the design of KIP-253, then maybe we
>> *should*
>>>> just finish working it out.
>>>>
>>>> For my part, my only concern about KIP-253 is the one I raised earlier.
>>>>
>>>> Thanks again, all, for considering these points,
>>>> -John
>>>>
>>>>
>>>> On Tue, Mar 27, 2018 at 2:10 AM, Dong Lin <li...@gmail.com> wrote:
>>>>
>>>>> On Tue, Mar 27, 2018 at 12:04 AM, Dong Lin <li...@gmail.com>
>>> wrote:
>>>>>> Hey Jan,
>>>>>>
>>>>>> Thanks for the enthusiasm in improving Kafka's design. Now that I
>>> have
>>>>>> read through your discussion with Jun, here are my thoughts:
>>>>>>
>>>>>> - The latest proposal should with log compacted topics by properly
>>>>>> deleting old messages after a new message with the same key is
>>>> produced.
>>>>> So
>>>>>> it is probably not a concern anymore. Could you comment if there is
>>>> still
>>>>>> issue?
>>>>>>
>>>>>> - I wrote the SEP-5 and I am pretty familiar with the motivation
>> and
>>>> the
>>>>>> design of SEP-5. SEP-5 is probably orthornal to the motivation of
>>> this
>>>>> KIP.
>>>>>> The goal of SEP-5 is to allow user to increase task number of an
>>>> existing
>>>>>> Samza job. But if we increase the partition number of input topics,
>>>>>> messages may still be consumed out-of-order by tasks in Samza which
>>>> cause
>>>>>> incorrect result. Similarly, the approach you proposed does not
>> seem
>>> to
>>>>>> ensure that the messages can be delivered in order, even if we can
>>> make
>>>>>> sure that each consumer instance is assigned the set of new
>>> partitions
>>>>>> covering the same set of keys.
>>>>>>
>>>>> Let me correct this comment. The approach of copying data to a new
>>> topic
>>>>> can ensure in-order message delivery suppose we properly migrate
>>> offsets
>>>>> from old topic to new topic.
>>>>>
>>>>>
>>>>>> - I am trying to understand why it is better to copy the data
>> instead
>>>> of
>>>>>> copying the change log topic for streaming use-case. For core Kafka
>>>>>> use-case, and for the stream use-case that does not need to
>> increase
>>>>>> consumers, the current KIP already supports in-order delivery
>> without
>>>> the
>>>>>> overhead of copying the data. For stream use-case that needs to
>>>> increase
>>>>>> consumer number, the existing consumer can backfill the existing
>> data
>>>> in
>>>>>> the change log topic to the same change log topic with the new
>>>> partition
>>>>>> number, before the new set of consumers bootstrap state from the
>> new
>>>>>> partitions of the change log topic. If this solution works, then
>>> could
>>>>> you
>>>>>> summarize the advantage of copying the data of input topic as
>>> compared
>>>> to
>>>>>> copying the change log topic? For example, does it enable more
>>>> use-case,
>>>>>> simplify the implementation of Kafka library, or reduce the
>> operation
>>>>>> overhead etc?
>>>>>>
>>>>>> Thanks,
>>>>>> Dong
>>>>>>
>>>>>>
>>>>>> On Wed, Mar 21, 2018 at 6:57 AM, Jan Filipiak <
>>>> Jan.Filipiak@trivago.com>
>>>>>> wrote:
>>>>>>
>>>>>>> Hi Jun,
>>>>>>>
>>>>>>> I was really seeing progress in our conversation but your latest
>>> reply
>>>>> is
>>>>>>> just devastating.
>>>>>>> I though we were getting close being on the same page now it feels
>>>> like
>>>>>>> we are in different libraries.
>>>>>>>
>>>>>>> I just quickly slam my answers in here. If they are to brief I am
>>>> sorry
>>>>>>> give me a ping and try to go into details more.
>>>>>>> Just want to show that your pro/cons listing is broken.
>>>>>>>
>>>>>>> Best Jan
>>>>>>>
>>>>>>> and want to get rid of this horrible compromise
>>>>>>>
>>>>>>>
>>>>>>> On 19.03.2018 05:48, Jun Rao wrote:
>>>>>>>
>>>>>>>> Hi, Jan,
>>>>>>>>
>>>>>>>> Thanks for the discussion. Great points.
>>>>>>>>
>>>>>>>> Let me try to summarize the approach that you are proposing. On
>> the
>>>>>>>> broker
>>>>>>>> side, we reshuffle the existing data in a topic from current
>>>> partitions
>>>>>>>> to
>>>>>>>> the new partitions. Once the reshuffle fully catches up, switch
>> the
>>>>>>>> consumers to start consuming from the new partitions. If a
>> consumer
>>>>> needs
>>>>>>>> to rebuild its local state (due to partition changes), let the
>>>> consumer
>>>>>>>> rebuild its state by reading all existing data from the new
>>>> partitions.
>>>>>>>> Once all consumers have switches over, cut over the producer to
>> the
>>>> new
>>>>>>>> partitions.
>>>>>>>>
>>>>>>>> The pros for this approach are that :
>>>>>>>> 1. There is just one way to rebuild the local state, which is
>>>> simpler.
>>>>>>> true thanks
>>>>>>>
>>>>>>>> The cons for this approach are:
>>>>>>>> 1. Need to copy existing data.
>>>>>>>>
>>>>>>> Very unfair and not correct. It does not require you to copy over
>>>>>>> existing data. It _allows_ you to copy all existing data.
>>>>>>>
>>>>>>> 2. The cutover of the producer is a bit complicated since it needs
>>> to
>>>>>>>> coordinate with all consumer groups.
>>>>>>>>
>>>>>>> Also not true. I explicitly tried to make clear that there is only
>>> one
>>>>>>> special consumer (in the case of actually copying data)
>> coordination
>>>> is
>>>>>>> required.
>>>>>>>
>>>>>>>> 3. The rebuilding of the state in the consumer is from the input
>>>> topic,
>>>>>>>> which can be more expensive than rebuilding from the existing
>>> state.
>>>>>>> true, but rebuilding state is only required if you want to
>> increase
>>>>>>> processing power, so we assume this is at hand.
>>>>>>>
>>>>>>>> 4. The broker potentially has to know the partitioning function.
>> If
>>>>> this
>>>>>>>> needs to be customized at the topic level, it can be a bit messy.
>>>>>>>>
>>>>>>> I would argue against having the operation being performed by the
>>>>> broker.
>>>>>>> This was not discussed yet but if you see my original email i
>>>> suggested
>>>>>>> otherwise from the beginning.
>>>>>>>
>>>>>>>> Here is an alternative approach by applying your idea not in the
>>>>> broker,
>>>>>>>> but in the consumer. When new partitions are added, we don't move
>>>>>>>> existing
>>>>>>>> data. In KStreams, we first reshuffle the new input data to a new
>>>> topic
>>>>>>>> T1
>>>>>>>> with the old number of partitions and feed T1's data to the rest
>> of
>>>> the
>>>>>>>> pipeline. In the meantime, KStreams reshuffles all existing data
>> of
>>>> the
>>>>>>>> change capture topic to another topic C1 with the new number of
>>>>>>>> partitions.
>>>>>>>> We can then build the state of the new tasks from C1. Once the
>> new
>>>>> states
>>>>>>>> have been fully built, we can cut over the consumption to the
>> input
>>>>> topic
>>>>>>>> and delete T1. This approach works with compacted topic too. If
>> an
>>>>>>>> application reads from the beginning of a compacted topic, the
>>>> consumer
>>>>>>>> will reshuffle the portion of the input when the number of
>>> partitions
>>>>>>>> doesn't match the number of tasks.
>>>>>>>>
>>>>>>> We all wipe this idea from our heads instantly. Mixing Ideas from
>> an
>>>>>>> argument is not a resolution strategy
>>>>>>> just leads to horrible horrible software.
>>>>>>>
>>>>>>>
>>>>>>>> The pros of this approach are:
>>>>>>>> 1. No need to copy existing data.
>>>>>>>> 2. Each consumer group can cut over to the new partitions
>>>>> independently.
>>>>>>>> 3. The state is rebuilt from the change capture topic, which is
>>>> cheaper
>>>>>>>> than rebuilding from the input topic.
>>>>>>>> 4. Only the KStreams job needs to know the partitioning function.
>>>>>>>>
>>>>>>>> The cons of this approach are:
>>>>>>>> 1. Potentially the same input topic needs to be reshuffled more
>>> than
>>>>> once
>>>>>>>> in different consumer groups during the transition phase.
>>>>>>>>
>>>>>>>> What do you think?
>>>>>>>>
>>>>>>>> Thanks,
>>>>>>>>
>>>>>>>> Jun
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> On Thu, Mar 15, 2018 at 1:04 AM, Jan Filipiak <
>>>>> Jan.Filipiak@trivago.com>
>>>>>>>> wrote:
>>>>>>>>
>>>>>>>> Hi Jun,
>>>>>>>>> thank you for following me on these thoughts. It was important
>> to
>>> me
>>>>> to
>>>>>>>>> feel that kind of understanding for my arguments.
>>>>>>>>>
>>>>>>>>> What I was hoping for (I mentioned this earlier) is that we can
>>>> model
>>>>>>>>> the
>>>>>>>>> case where we do not want to copy the data the exact same way as
>>> the
>>>>>>>>> case
>>>>>>>>> when we do copy the data. Maybe you can peek into the mails
>> before
>>>> to
>>>>>>>>> see
>>>>>>>>> more details for this.
>>>>>>>>>
>>>>>>>>> This means we have the same mechanism to transfer consumer
>> groups
>>> to
>>>>>>>>> switch topic. The offset mapping that would be generated would
>>> even
>>>> be
>>>>>>>>> simpler End Offset of the Old topic => offset 0 off all the
>>>> partitions
>>>>>>>>> of
>>>>>>>>> the new topic. Then we could model the transition of a non-copy
>>>>>>>>> expansion
>>>>>>>>> the exact same way as a copy-expansion.
>>>>>>>>>
>>>>>>>>> I know this only works when topic growth by a factor. But the
>>>> benefits
>>>>>>>>> of
>>>>>>>>> only growing by a factor are to strong anyways. See Clemens's
>> hint
>>>> and
>>>>>>>>> remember that state reshuffling is entirely not needed if one
>>>> doesn't
>>>>>>>>> want
>>>>>>>>> to grow processing power.
>>>>>>>>>
>>>>>>>>> I think these benefits should be clear, and that there is
>>> basically
>>>> no
>>>>>>>>> downside to what is currently at hand but just makes everything
>>>> easy.
>>>>>>>>> One thing you need to know is. that if you do not offer
>>> rebuilding a
>>>>> log
>>>>>>>>> compacted topic like i suggest that even if you have consumer
>>> state
>>>>>>>>> reshuffling. The topic is broken and can not be used to
>> bootstrap
>>>> new
>>>>>>>>> consumers. They don't know if they need to apply a key from and
>>> old
>>>>>>>>> partition or not. This is a horrible downside I haven't seen a
>>>>> solution
>>>>>>>>> for
>>>>>>>>> in the email conversation.
>>>>>>>>>
>>>>>>>>> I argue to:
>>>>>>>>>
>>>>>>>>> Only grow topic by a factor always.
>>>>>>>>> Have the "no copy consumer" transition as the trivial case of
>> the
>>>>> "copy
>>>>>>>>> consumer transition".
>>>>>>>>> If processors needs to be scaled, let them rebuild from the new
>>>> topic
>>>>>>>>> and
>>>>>>>>> leave the old running in the mean time.
>>>>>>>>> Do not implement key shuffling in streams.
>>>>>>>>>
>>>>>>>>> I hope I can convince you especially with the fact how I want to
>>>>> handle
>>>>>>>>> consumer transition. I think
>>>>>>>>> you didn't quite understood me there before. I think the term
>> "new
>>>>>>>>> topic"
>>>>>>>>> intimidated you a little.
>>>>>>>>> How we solve this on disc doesn't really matter, If the data
>> goes
>>>> into
>>>>>>>>> the
>>>>>>>>> same Dir or a different Dir or anything. I do think that it
>> needs
>>> to
>>>>>>>>> involve at least rolling a new segment for the existing
>>> partitions.
>>>>>>>>> But most of the transitions should work without restarting
>>>> consumers.
>>>>>>>>> (newer consumers with support for this). But with new topic i
>> just
>>>>> meant
>>>>>>>>> the topic that now has a different partition count. Plenty of
>> ways
>>>> to
>>>>>>>>> handle that (versions, aliases)
>>>>>>>>>
>>>>>>>>> Hope I can further get my idea across.
>>>>>>>>>
>>>>>>>>> Best Jan
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> On 14.03.2018 02:45, Jun Rao wrote:
>>>>>>>>>
>>>>>>>>> Hi, Jan,
>>>>>>>>>> Thanks for sharing your view.
>>>>>>>>>>
>>>>>>>>>> I agree with you that recopying the data potentially makes the
>>>> state
>>>>>>>>>> management easier since the consumer can just rebuild its state
>>>> from
>>>>>>>>>> scratch (i.e., no need for state reshuffling).
>>>>>>>>>>
>>>>>>>>>> On the flip slide, I saw a few disadvantages of the approach
>> that
>>>> you
>>>>>>>>>> suggested. (1) Building the state from the input topic from
>>> scratch
>>>>> is
>>>>>>>>>> in
>>>>>>>>>> general less efficient than state reshuffling. Let's say one
>>>>> computes a
>>>>>>>>>> count per key from an input topic. The former requires reading
>>> all
>>>>>>>>>> existing
>>>>>>>>>> records in the input topic whereas the latter only requires
>>> reading
>>>>>>>>>> data
>>>>>>>>>> proportional to the number of unique keys. (2) The switching of
>>> the
>>>>>>>>>> topic
>>>>>>>>>> needs modification to the application. If there are many
>>>> applications
>>>>>>>>>> on a
>>>>>>>>>> topic, coordinating such an effort may not be easy. Also, it's
>>> not
>>>>>>>>>> clear
>>>>>>>>>> how to enforce exactly-once semantic during the switch. (3) If
>> a
>>>>> topic
>>>>>>>>>> doesn't need any state management, recopying the data seems
>>>> wasteful.
>>>>>>>>>> In
>>>>>>>>>> that case, in place partition expansion seems more desirable.
>>>>>>>>>>
>>>>>>>>>> I understand your concern about adding complexity in KStreams.
>>> But,
>>>>>>>>>> perhaps
>>>>>>>>>> we could iterate on that a bit more to see if it can be
>>> simplified.
>>>>>>>>>> Jun
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> On Mon, Mar 12, 2018 at 11:21 PM, Jan Filipiak <
>>>>>>>>>> Jan.Filipiak@trivago.com>
>>>>>>>>>> wrote:
>>>>>>>>>>
>>>>>>>>>> Hi Jun,
>>>>>>>>>>
>>>>>>>>>>> I will focus on point 61 as I think its _the_ fundamental part
>>>> that
>>>>> I
>>>>>>>>>>> cant
>>>>>>>>>>> get across at the moment.
>>>>>>>>>>>
>>>>>>>>>>> Kafka is the platform to have state materialized multiple
>> times
>>>> from
>>>>>>>>>>> one
>>>>>>>>>>> input. I emphasize this: It is the building block in
>>> architectures
>>>>>>>>>>> that
>>>>>>>>>>> allow you to
>>>>>>>>>>> have your state maintained multiple times. You put a message
>> in
>>>>> once,
>>>>>>>>>>> and
>>>>>>>>>>> you have it pop out as often as you like. I believe you
>>> understand
>>>>>>>>>>> this.
>>>>>>>>>>>
>>>>>>>>>>> Now! The path of thinking goes the following: I am using
>> apache
>>>>> kafka
>>>>>>>>>>> and
>>>>>>>>>>> I _want_ my state multiple times. What am I going todo?
>>>>>>>>>>>
>>>>>>>>>>> A) Am I going to take my state that I build up, plunge some
>> sort
>>>> of
>>>>>>>>>>> RPC
>>>>>>>>>>> layer ontop of it, use that RPC layer to throw my records
>> across
>>>>>>>>>>> instances?
>>>>>>>>>>> B) Am I just going to read the damn message twice?
>>>>>>>>>>>
>>>>>>>>>>> Approach A is fundamentally flawed and a violation of all that
>>> is
>>>>> good
>>>>>>>>>>> and
>>>>>>>>>>> holy in kafka deployments. I can not understand how this Idea
>>> can
>>>>>>>>>>> come in
>>>>>>>>>>> the first place.
>>>>>>>>>>> (I do understand: IQ in streams, they polluted the kafka
>> streams
>>>>>>>>>>> codebase
>>>>>>>>>>> really bad already. It is not funny! I think they are equally
>>>> flawed
>>>>>>>>>>> as
>>>>>>>>>>> A)
>>>>>>>>>>>
>>>>>>>>>>> I say, we do what Kafka is good at. We repartition the topic
>>> once.
>>>>> We
>>>>>>>>>>> switch the consumers.
>>>>>>>>>>> (Those that need more partitions are going to rebuild their
>>> state
>>>> in
>>>>>>>>>>> multiple partitions by reading the new topic, those that don't
>>>> just
>>>>>>>>>>> assign
>>>>>>>>>>> the new partitions properly)
>>>>>>>>>>> We switch producers. Done!
>>>>>>>>>>>
>>>>>>>>>>> The best thing! It is trivial, hipster stream processor will
>>> have
>>>> an
>>>>>>>>>>> easy
>>>>>>>>>>> time with that aswell. Its so super simple. And simple IS
>> good!
>>>>>>>>>>> It is what kafka was build todo. It is how we do it today.
>> All I
>>>> am
>>>>>>>>>>> saying
>>>>>>>>>>> is that a little broker help doing the producer swap is super
>>>>> useful.
>>>>>>>>>>> For everyone interested in why kafka is so powerful with
>>> approach
>>>> B,
>>>>>>>>>>> please watch https://youtu.be/bEbeZPVo98c?t=1633
>>>>>>>>>>> I already looked up a good point in time, I think after 5
>>> minutes
>>>>> the
>>>>>>>>>>> "state" topic is handled and you should be able to understand
>> me
>>>>>>>>>>> and inch better.
>>>>>>>>>>>
>>>>>>>>>>> Please do not do A to the project, it deserves better!
>>>>>>>>>>>
>>>>>>>>>>> Best Jan
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> On 13.03.2018 02:40, Jun Rao wrote:
>>>>>>>>>>>
>>>>>>>>>>> Hi, Jan,
>>>>>>>>>>>
>>>>>>>>>>>> Thanks for the reply. A few more comments below.
>>>>>>>>>>>>
>>>>>>>>>>>> 50. Ok, we can think a bit harder for supporting compacted
>>>> topics.
>>>>>>>>>>>> 51. This is a fundamental design question. In the more common
>>>> case,
>>>>>>>>>>>> the
>>>>>>>>>>>> reason why someone wants to increase the number of partitions
>>> is
>>>>> that
>>>>>>>>>>>> the
>>>>>>>>>>>> consumer application is slow and one wants to run more
>> consumer
>>>>>>>>>>>> instances
>>>>>>>>>>>> to increase the degree of parallelism. So, fixing the number
>> of
>>>>>>>>>>>> running
>>>>>>>>>>>> consumer instances when expanding the partitions won't help
>>> this
>>>>>>>>>>>> case.
>>>>>>>>>>>> If
>>>>>>>>>>>> we do need to increase the number of consumer instances, we
>>> need
>>>> to
>>>>>>>>>>>> somehow
>>>>>>>>>>>> reshuffle the state of the consumer across instances. What we
>>>> have
>>>>>>>>>>>> been
>>>>>>>>>>>> discussing in this KIP is whether we can do this more
>>> effectively
>>>>>>>>>>>> through
>>>>>>>>>>>> the KStream library (e.g. through a 2-phase partition
>>> expansion).
>>>>>>>>>>>> This
>>>>>>>>>>>> will
>>>>>>>>>>>> add some complexity, but it's probably better than everyone
>>> doing
>>>>>>>>>>>> this
>>>>>>>>>>>> in
>>>>>>>>>>>> the application space. The recopying approach that you
>>> mentioned
>>>>>>>>>>>> doesn't
>>>>>>>>>>>> seem to address the consumer state management issue when the
>>>>> consumer
>>>>>>>>>>>> switches from an old to a new topic.
>>>>>>>>>>>>
>>>>>>>>>>>> 52. As for your example, it depends on whether the join key
>> is
>>>> the
>>>>>>>>>>>> same
>>>>>>>>>>>> between (A,B) and (B,C). If the join key is the same, we can
>>> do a
>>>>>>>>>>>> 2-phase
>>>>>>>>>>>> partition expansion of A, B, and C together. If the join keys
>>> are
>>>>>>>>>>>> different, one would need to repartition the data on a
>>> different
>>>>> key
>>>>>>>>>>>> for
>>>>>>>>>>>> the second join, then the partition expansion can be done
>>>>>>>>>>>> independently
>>>>>>>>>>>> between (A,B) and (B,C).
>>>>>>>>>>>>
>>>>>>>>>>>> 53. If you always fix the number of consumer instances, we
>> you
>>>>>>>>>>>> described
>>>>>>>>>>>> works. However, as I mentioned in #51, I am not sure how your
>>>>>>>>>>>> proposal
>>>>>>>>>>>> deals with consumer states when the number of consumer
>>> instances
>>>>>>>>>>>> grows.
>>>>>>>>>>>> Also, it just seems that it's better to avoid re-copying the
>>>>> existing
>>>>>>>>>>>> data.
>>>>>>>>>>>>
>>>>>>>>>>>> 60. "just want to throw in my question from the longer email
>> in
>>>> the
>>>>>>>>>>>> other
>>>>>>>>>>>> Thread here. How will the bloom filter help a new consumer to
>>>>> decide
>>>>>>>>>>>> to
>>>>>>>>>>>> apply the key or not?" Not sure that I fully understood your
>>>>>>>>>>>> question.
>>>>>>>>>>>> The
>>>>>>>>>>>> consumer just reads whatever key is in the log. The bloom
>>> filter
>>>>> just
>>>>>>>>>>>> helps
>>>>>>>>>>>> clean up the old keys.
>>>>>>>>>>>>
>>>>>>>>>>>> 61. "Why can we afford having a topic where its apparently
>> not
>>>>>>>>>>>> possible
>>>>>>>>>>>> to
>>>>>>>>>>>> start a new application on? I think this is an overall flaw
>> of
>>>> the
>>>>>>>>>>>> discussed idea here. Not playing attention to the overall
>>>>>>>>>>>> architecture."
>>>>>>>>>>>> Could you explain a bit more when one can't start a new
>>>>> application?
>>>>>>>>>>>> Jun
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>> On Sat, Mar 10, 2018 at 1:40 AM, Jan Filipiak <
>>>>>>>>>>>> Jan.Filipiak@trivago.com
>>>>>>>>>>>> wrote:
>>>>>>>>>>>>
>>>>>>>>>>>> Hi Jun, thanks for your mail.
>>>>>>>>>>>>
>>>>>>>>>>>> Thank you for your questions!
>>>>>>>>>>>>> I think they are really good and tackle the core of the
>>> problem
>>>> I
>>>>>>>>>>>>> see.
>>>>>>>>>>>>>
>>>>>>>>>>>>> I will answer inline, mostly but still want to set the tone
>>>> here.
>>>>>>>>>>>>> The core strength of kafka is what Martin once called the
>>>>>>>>>>>>> kappa-Architecture. How does this work?
>>>>>>>>>>>>> You have everything as a log as in kafka. When you need to
>>>> change
>>>>>>>>>>>>> something.
>>>>>>>>>>>>> You create the new version of your application and leave it
>>>>> running
>>>>>>>>>>>>> in
>>>>>>>>>>>>> parallel.
>>>>>>>>>>>>> Once the new version is good you switch your users to use
>> the
>>>> new
>>>>>>>>>>>>> application.
>>>>>>>>>>>>>
>>>>>>>>>>>>> The online reshuffling effectively breaks this architecture
>>> and
>>>> I
>>>>>>>>>>>>> think
>>>>>>>>>>>>> the switch in thinking here is more harmful
>>>>>>>>>>>>> than any details about the partitioning function to allow
>>> such a
>>>>>>>>>>>>> change.
>>>>>>>>>>>>> I
>>>>>>>>>>>>> feel with my suggestion we are the closest to
>>>>>>>>>>>>> the original and battle proven architecture and I can only
>>> warn
>>>> to
>>>>>>>>>>>>> move
>>>>>>>>>>>>> away from it.
>>>>>>>>>>>>>
>>>>>>>>>>>>> I might have forgotten something, sometimes its hard for me
>> to
>>>>>>>>>>>>> getting
>>>>>>>>>>>>> all
>>>>>>>>>>>>> the thoughts captured in a mail, but I hope the comments
>>> inline
>>>>> will
>>>>>>>>>>>>> further make my concern clear, and put some emphasis on why
>> I
>>>>>>>>>>>>> prefer my
>>>>>>>>>>>>> solution ;)
>>>>>>>>>>>>>
>>>>>>>>>>>>> One thing we should all be aware of when discussing this,
>> and
>>> I
>>>>>>>>>>>>> think
>>>>>>>>>>>>> Dong
>>>>>>>>>>>>> should have mentioned it (maybe he did).
>>>>>>>>>>>>> We are not discussing all of this out of thin air but there
>> is
>>>> an
>>>>>>>>>>>>> effort
>>>>>>>>>>>>> in the Samza project.
>>>>>>>>>>>>>
>>>>>>>>>>>>> https://cwiki.apache.org/confluence/display/SAMZA/SEP-5%3A+
>>>>>>>>>>>>> Enable+partition+expansion+of+input+streams
>>>>>>>>>>>>> https://issues.apache.org/jira/browse/SAMZA-1293
>>>>>>>>>>>>>
>>>>>>>>>>>>> To be clear. I think SEP-5 (state of last week, dont know if
>>> it
>>>>>>>>>>>>> adapted
>>>>>>>>>>>>> to
>>>>>>>>>>>>> this discussion) is on a way better path than KIP-253, and I
>>>> can't
>>>>>>>>>>>>> really
>>>>>>>>>>>>> explain why.
>>>>>>>>>>>>>
>>>>>>>>>>>>> Best Jan,
>>>>>>>>>>>>>
>>>>>>>>>>>>> nice weekend everyone
>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>> On 09.03.2018 03:36, Jun Rao wrote:
>>>>>>>>>>>>>
>>>>>>>>>>>>> Hi, Jan,
>>>>>>>>>>>>>
>>>>>>>>>>>>> Thanks for the feedback. Just some comments on the earlier
>>>> points
>>>>>>>>>>>>>> that
>>>>>>>>>>>>>> you
>>>>>>>>>>>>>> mentioned.
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> 50. You brought up the question of whether existing data
>>> needs
>>>> to
>>>>>>>>>>>>>> be
>>>>>>>>>>>>>> copied
>>>>>>>>>>>>>> during partition expansion. My understand of your view is
>>> that
>>>>>>>>>>>>>> avoid
>>>>>>>>>>>>>> copying existing data will be more efficient, but it
>> doesn't
>>>> work
>>>>>>>>>>>>>> well
>>>>>>>>>>>>>> with
>>>>>>>>>>>>>> compacted topics since some keys in the original partitions
>>>> will
>>>>>>>>>>>>>> never
>>>>>>>>>>>>>> be
>>>>>>>>>>>>>> cleaned. It would be useful to understand your use case of
>>>>>>>>>>>>>> compacted
>>>>>>>>>>>>>> topics
>>>>>>>>>>>>>> a bit more. In the common use case, the data volume in a
>>>>> compacted
>>>>>>>>>>>>>> topic
>>>>>>>>>>>>>> may not be large. So, I am not sure if there is a strong
>> need
>>>> to
>>>>>>>>>>>>>> expand
>>>>>>>>>>>>>> partitions in a compacted topic, at least initially.
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> I do agree. State is usually smaller. Update rates might be
>>>> also
>>>>>>>>>>>>>> competitively high.
>>>>>>>>>>>>> Doing Log-compaction (even beeing very efficient and
>>>> configurable)
>>>>>>>>>>>>> is
>>>>>>>>>>>>> also
>>>>>>>>>>>>> a more expensive operation than
>>>>>>>>>>>>> just discarding old segments. Further if you want to use
>> more
>>>>>>>>>>>>> consumers
>>>>>>>>>>>>> processing the events
>>>>>>>>>>>>> you also have to grow the number of partitions. Especially
>> for
>>>>>>>>>>>>> use-cases
>>>>>>>>>>>>> we do (KIP-213) a tiny state full
>>>>>>>>>>>>> table might be very expensive to process if it joins
>> against a
>>>>> huge
>>>>>>>>>>>>> table.
>>>>>>>>>>>>>
>>>>>>>>>>>>> I can just say we have been in the spot of needing to grow
>> log
>>>>>>>>>>>>> compacted
>>>>>>>>>>>>> topics. Mainly for processing power we can bring to the
>> table.
>>>>>>>>>>>>> Further i am not at all concerned about the extra spaced
>> used
>>> by
>>>>>>>>>>>>> "garbage
>>>>>>>>>>>>> keys". I am more concerned about the correctness of innocent
>>>>>>>>>>>>> consumers.
>>>>>>>>>>>>> The
>>>>>>>>>>>>> logic becomes complicated. Say for streams one would need to
>>>> load
>>>>>>>>>>>>> the
>>>>>>>>>>>>> record into state but not forward it the topology ( to have
>> it
>>>>>>>>>>>>> available
>>>>>>>>>>>>> for shuffeling). I rather have it simple and a topic clean
>>>>>>>>>>>>> regardless
>>>>>>>>>>>>> if
>>>>>>>>>>>>> it
>>>>>>>>>>>>> still has its old partition count. Especially with multiple
>>>>>>>>>>>>> partitions
>>>>>>>>>>>>> growth's I think it becomes insanely hard to to this shuffle
>>>>>>>>>>>>> correct.
>>>>>>>>>>>>> Maybe
>>>>>>>>>>>>> Streams and Samza can do it. Especially if you do "hipster
>>>> stream
>>>>>>>>>>>>> processing" <https://www.confluent.io/blog
>>>>>>>>>>>>> /introducing-kafka-streams-
>>>>>>>>>>>>> stream-processing-made-simple/>. This makes kafka way to
>>>>>>>>>>>>> complicated.
>>>>>>>>>>>>> With my approach I think its way simpler because the topic
>> has
>>>> no
>>>>>>>>>>>>> "history"
>>>>>>>>>>>>> in terms of partitioning but is always clean.
>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>> 51. "Growing the topic by an integer factor does not require
>>> any
>>>>>>>>>>>>> state
>>>>>>>>>>>>>
>>>>>>>>>>>>> redistribution at all." Could you clarify this a bit more?
>>> Let's
>>>>> say
>>>>>>>>>>>>>> you
>>>>>>>>>>>>>> have a consumer app that computes the windowed count per
>> key.
>>>> If
>>>>>>>>>>>>>> you
>>>>>>>>>>>>>> double
>>>>>>>>>>>>>> the number of partitions from 1 to 2 and grow the consumer
>>>>>>>>>>>>>> instances
>>>>>>>>>>>>>> from
>>>>>>>>>>>>>> 1
>>>>>>>>>>>>>> to 2, we would need to redistribute some of the counts to
>> the
>>>> new
>>>>>>>>>>>>>> consumer
>>>>>>>>>>>>>> instance. Regarding to linear hashing, it's true that it
>>> won't
>>>>>>>>>>>>>> solve
>>>>>>>>>>>>>> the
>>>>>>>>>>>>>> problem with compacted topics. The main benefit is that it
>>>>>>>>>>>>>> redistributes
>>>>>>>>>>>>>> the keys in one partition to no more than two partitions,
>>> which
>>>>>>>>>>>>>> could
>>>>>>>>>>>>>> help
>>>>>>>>>>>>>> redistribute the state.
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> You don't need to spin up a new consumer in this case.
>> every
>>>>>>>>>>>>>> consumer
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> would just read every partition with the (partition %
>>> num_task)
>>>>>>>>>>>>> task.
>>>>>>>>>>>>> it
>>>>>>>>>>>>> will still have the previous data right there and can go on.
>>>>>>>>>>>>>
>>>>>>>>>>>>> This sounds contradictory to what I said before, but please
>>> bear
>>>>>>>>>>>>> with
>>>>>>>>>>>>> me.
>>>>>>>>>>>>>
>>>>>>>>>>>>> 52. Good point on coordinating the expansion of 2 topics
>> that
>>>> need
>>>>>>>>>>>>> to
>>>>>>>>>>>>> be
>>>>>>>>>>>>>
>>>>>>>>>>>>> joined together. This is where the 2-phase partition
>> expansion
>>>>> could
>>>>>>>>>>>>>> potentially help. In the first phase, we could add new
>>>> partitions
>>>>>>>>>>>>>> to
>>>>>>>>>>>>>> the 2
>>>>>>>>>>>>>> topics one at a time but without publishing to the new
>>>> patitions.
>>>>>>>>>>>>>> Then,
>>>>>>>>>>>>>> we
>>>>>>>>>>>>>> can add new consumer instances to pick up the new
>> partitions.
>>>> In
>>>>>>>>>>>>>> this
>>>>>>>>>>>>>> transition phase, no reshuffling is needed since no data is
>>>>> coming
>>>>>>>>>>>>>> from
>>>>>>>>>>>>>> the
>>>>>>>>>>>>>> new partitions. Finally, we can enable the publishing to
>> the
>>>> new
>>>>>>>>>>>>>> partitions.
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> I think its even worse than you think. I would like to
>>>> introduce
>>>>>>>>>>>>>> the
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> Term
>>>>>>>>>>>>> transitive copartitioning. Imagine
>>>>>>>>>>>>> 2 streams application. One joins (A,B) the other (B,C) then
>>>> there
>>>>>>>>>>>>> is a
>>>>>>>>>>>>> transitive copartition requirement for
>>>>>>>>>>>>> (A,C) to be copartitioned aswell. This can spread
>>> significantly
>>>>> and
>>>>>>>>>>>>> require many consumers to adapt at the same time.
>>>>>>>>>>>>>
>>>>>>>>>>>>> It is also not entirely clear to me how you not need
>>> reshuffling
>>>>> in
>>>>>>>>>>>>> this
>>>>>>>>>>>>> case. If A has a record that never gets updated after the
>>>>> expansion
>>>>>>>>>>>>> and
>>>>>>>>>>>>> the
>>>>>>>>>>>>> coresponding B record moves to a new partition. How shall
>> they
>>>>> meet
>>>>>>>>>>>>> w/o
>>>>>>>>>>>>> shuffle?
>>>>>>>>>>>>>
>>>>>>>>>>>>> 53. "Migrating consumer is a step that might be made
>> completly
>>>>>>>>>>>>> unnecessary
>>>>>>>>>>>>>> if - for example streams - takes the gcd as partitioning
>>> scheme
>>>>>>>>>>>>>> instead
>>>>>>>>>>>>>> of
>>>>>>>>>>>>>> enforcing 1 to 1." Not sure that I fully understand this. I
>>>> think
>>>>>>>>>>>>>> you
>>>>>>>>>>>>>> mean
>>>>>>>>>>>>>> that a consumer application can run more instances than the
>>>>> number
>>>>>>>>>>>>>> of
>>>>>>>>>>>>>> partitions. In that case, the consumer can just
>>> repartitioning
>>>>> the
>>>>>>>>>>>>>> input
>>>>>>>>>>>>>> data according to the number of instances. This is
>> possible,
>>>> but
>>>>>>>>>>>>>> just
>>>>>>>>>>>>>> has
>>>>>>>>>>>>>> the overhead of reshuffling the data.
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> No what I meant is ( that is also your question i think
>>>> Mathias)
>>>>>>>>>>>>>> that
>>>>>>>>>>>>>> if
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> you grow a topic by a factor.
>>>>>>>>>>>>> Even if your processor is statefull you can can just assign
>>> all
>>>>> the
>>>>>>>>>>>>> multiples of the previous partition to
>>>>>>>>>>>>> this consumer and the state to keep processing correctly
>> will
>>> be
>>>>>>>>>>>>> present
>>>>>>>>>>>>> w/o any shuffling.
>>>>>>>>>>>>>
>>>>>>>>>>>>> Say you have an assignment
>>>>>>>>>>>>> Statefull consumer => partition
>>>>>>>>>>>>> 0 => 0
>>>>>>>>>>>>> 1 => 1
>>>>>>>>>>>>> 2 => 2
>>>>>>>>>>>>>
>>>>>>>>>>>>> and you grow you topic by 4 you get,
>>>>>>>>>>>>>
>>>>>>>>>>>>> 0 => 0,3,6,9
>>>>>>>>>>>>> 1 => 1,4,7,10
>>>>>>>>>>>>> 2 => 2,5,8,11
>>>>>>>>>>>>>
>>>>>>>>>>>>> Say your hashcode is 8. 8%3 => 2  before so consumer for
>>>>> partition 2
>>>>>>>>>>>>> has
>>>>>>>>>>>>> it.
>>>>>>>>>>>>> Now you you have 12 partitions so 8%12 => 8, so it goes into
>>>>>>>>>>>>> partition
>>>>>>>>>>>>> 8
>>>>>>>>>>>>> which is assigned to the same consumer
>>>>>>>>>>>>> who had 2 before and therefore knows the key.
>>>>>>>>>>>>>
>>>>>>>>>>>>> Userland reshuffeling is there as an options. And it does
>>>> exactly
>>>>>>>>>>>>> what
>>>>>>>>>>>>> I
>>>>>>>>>>>>> suggest. And I think its the perfect strategie. All I am
>>>>> suggestion
>>>>>>>>>>>>> is
>>>>>>>>>>>>> broker side support to switch the producers to the newly
>>>>> partitioned
>>>>>>>>>>>>> topic.
>>>>>>>>>>>>> Then the old (to few partition topic) can go away.  Remember
>>> the
>>>>>>>>>>>>> list
>>>>>>>>>>>>> of
>>>>>>>>>>>>> steps in the beginning of this thread. If one has broker
>>> support
>>>>> for
>>>>>>>>>>>>> all
>>>>>>>>>>>>> where its required and streams support for those that aren’t
>>>>>>>>>>>>> necessarily.
>>>>>>>>>>>>> Then one has solved the problem.
>>>>>>>>>>>>> I repeat it because I think its important. I am really happy
>>>> that
>>>>>>>>>>>>> you
>>>>>>>>>>>>> brought that up! because its 100% what I want just with the
>>>>>>>>>>>>> differences
>>>>>>>>>>>>> to
>>>>>>>>>>>>> have an option to discard the to small topic later (after
>> all
>>>>>>>>>>>>> consumers
>>>>>>>>>>>>> adapted). And to have order correct there. I need broker
>>> support
>>>>>>>>>>>>> managing
>>>>>>>>>>>>> the copy process + the produces and fence them against each
>>>>> other. I
>>>>>>>>>>>>> also
>>>>>>>>>>>>> repeat. the copy process can run for weeks in the worst
>> case.
>>>>>>>>>>>>> Copying
>>>>>>>>>>>>> the
>>>>>>>>>>>>> data is not the longest task migrating consumers might very
>>> well
>>>>> be.
>>>>>>>>>>>>> Once all consumers switched and copying is really up to date
>>>>> (think
>>>>>>>>>>>>> ISR
>>>>>>>>>>>>> like up to date) only then we stop the producer, wait for
>> the
>>>> copy
>>>>>>>>>>>>> to
>>>>>>>>>>>>> finish and use the new topic for producing.
>>>>>>>>>>>>>
>>>>>>>>>>>>> After this the topic is perfect in shape. and no one needs
>> to
>>>>> worry
>>>>>>>>>>>>> about
>>>>>>>>>>>>> complicated stuff. (old keys hanging around might arrive in
>>> some
>>>>>>>>>>>>> other
>>>>>>>>>>>>> topic later.....). can only imagine how many tricky bugs
>> gonna
>>>>>>>>>>>>> arrive
>>>>>>>>>>>>> after
>>>>>>>>>>>>> someone had grown and shrunken is topic 10 times.
>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>> 54. "The other thing I wanted to mention is that I believe
>> the
>>>>>>>>>>>>> current
>>>>>>>>>>>>>
>>>>>>>>>>>>> suggestion (without copying data over) can be implemented in
>>>> pure
>>>>>>>>>>>>>> userland
>>>>>>>>>>>>>> with a custom partitioner and a small feedbackloop from
>>>>>>>>>>>>>> ProduceResponse
>>>>>>>>>>>>>> =>
>>>>>>>>>>>>>> Partitionier in coorporation with a change management
>>> system."
>>>> I
>>>>> am
>>>>>>>>>>>>>> not
>>>>>>>>>>>>>> sure a customized partitioner itself solves the problem. We
>>>>>>>>>>>>>> probably
>>>>>>>>>>>>>> need
>>>>>>>>>>>>>> some broker side support to enforce when the new partitions
>>> can
>>>>> be
>>>>>>>>>>>>>> used.
>>>>>>>>>>>>>> We
>>>>>>>>>>>>>> also need some support on the consumer/kstream side to
>>> preserve
>>>>> the
>>>>>>>>>>>>>> per
>>>>>>>>>>>>>> key
>>>>>>>>>>>>>> ordering and potentially migrate the processing state. This
>>> is
>>>>> not
>>>>>>>>>>>>>> trivial
>>>>>>>>>>>>>> and I am not sure if it's ideal to fully push to the
>>>> application
>>>>>>>>>>>>>> space.
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> Broker support is defenitly the preferred way here. I have
>>>>> nothing
>>>>>>>>>>>>>> against
>>>>>>>>>>>>> broker support.
>>>>>>>>>>>>> I tried to say that for what I would preffer - copying the
>>> data
>>>>>>>>>>>>> over,
>>>>>>>>>>>>> at
>>>>>>>>>>>>> least for log compacted topics -
>>>>>>>>>>>>> I would require more broker support than the KIP currently
>>>> offers.
>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>> Jun
>>>>>>>>>>>>>
>>>>>>>>>>>>> On Tue, Mar 6, 2018 at 10:33 PM, Jan Filipiak <
>>>>>>>>>>>>>> Jan.Filipiak@trivago.com
>>>>>>>>>>>>>> wrote:
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> Hi Dong,
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> are you actually reading my emails, or are you just using
>> the
>>>>>>>>>>>>>> thread I
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> started for general announcements regarding the KIP?
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> I tried to argue really hard against linear hashing.
>> Growing
>>>> the
>>>>>>>>>>>>>>> topic
>>>>>>>>>>>>>>> by
>>>>>>>>>>>>>>> an integer factor does not require any state
>> redistribution
>>> at
>>>>>>>>>>>>>>> all. I
>>>>>>>>>>>>>>> fail
>>>>>>>>>>>>>>> to see completely where linear hashing helps on log
>>> compacted
>>>>>>>>>>>>>>> topics.
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> If you are not willing to explain to me what I might be
>>>>>>>>>>>>>>> overlooking:
>>>>>>>>>>>>>>> that
>>>>>>>>>>>>>>> is fine.
>>>>>>>>>>>>>>> But I ask you to not reply to my emails then. Please
>>>> understand
>>>>> my
>>>>>>>>>>>>>>> frustration with this.
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> Best Jan
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> On 06.03.2018 19:38, Dong Lin wrote:
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> Hi everyone,
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> Thanks for all the comments! It appears that everyone
>>> prefers
>>>>>>>>>>>>>>> linear
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> hashing because it reduces the amount of state that needs
>>> to
>>>> be
>>>>>>>>>>>>>>>> moved
>>>>>>>>>>>>>>>> between consumers (for stream processing). The KIP has
>> been
>>>>>>>>>>>>>>>> updated
>>>>>>>>>>>>>>>> to
>>>>>>>>>>>>>>>> use
>>>>>>>>>>>>>>>> linear hashing.
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> Regarding the migration endeavor: it seems that migrating
>>>>>>>>>>>>>>>> producer
>>>>>>>>>>>>>>>> library
>>>>>>>>>>>>>>>> to use linear hashing should be pretty straightforward
>>>> without
>>>>>>>>>>>>>>>> much operational endeavor. If we don't upgrade client
>>> library
>>>>> to
>>>>>>>>>>>>>>>> use
>>>>>>>>>>>>>>>> this
>>>>>>>>>>>>>>>> KIP, we can not support in-order delivery after partition
>>> is
>>>>>>>>>>>>>>>> changed
>>>>>>>>>>>>>>>> anyway. Suppose we upgrade client library to use this
>> KIP,
>>> if
>>>>>>>>>>>>>>>> partition
>>>>>>>>>>>>>>>> number is not changed, the key -> partition mapping will
>> be
>>>>>>>>>>>>>>>> exactly
>>>>>>>>>>>>>>>> the
>>>>>>>>>>>>>>>> same as it is now because it is still determined using
>>>>>>>>>>>>>>>> murmur_hash(key)
>>>>>>>>>>>>>>>> %
>>>>>>>>>>>>>>>> original_partition_num. In other words, this change is
>>>> backward
>>>>>>>>>>>>>>>> compatible.
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> Regarding the load distribution: if we use linear
>> hashing,
>>>> the
>>>>>>>>>>>>>>>> load
>>>>>>>>>>>>>>>> may
>>>>>>>>>>>>>>>> be
>>>>>>>>>>>>>>>> unevenly distributed because those partitions which are
>> not
>>>>> split
>>>>>>>>>>>>>>>> may
>>>>>>>>>>>>>>>> receive twice as much traffic as other partitions that
>> are
>>>>> split.
>>>>>>>>>>>>>>>> This
>>>>>>>>>>>>>>>> issue can be mitigated by creating topic with partitions
>>> that
>>>>> are
>>>>>>>>>>>>>>>> several
>>>>>>>>>>>>>>>> times the number of consumers. And there will be no
>>> imbalance
>>>>> if
>>>>>>>>>>>>>>>> the
>>>>>>>>>>>>>>>> partition number is always doubled. So this imbalance
>> seems
>>>>>>>>>>>>>>>> acceptable.
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> Regarding storing the partition strategy as per-topic
>>> config:
>>>>> It
>>>>>>>>>>>>>>>> seems
>>>>>>>>>>>>>>>> not
>>>>>>>>>>>>>>>> necessary since we can still use murmur_hash as the
>> default
>>>>> hash
>>>>>>>>>>>>>>>> function
>>>>>>>>>>>>>>>> and additionally apply the linear hashing algorithm if
>> the
>>>>>>>>>>>>>>>> partition
>>>>>>>>>>>>>>>> number
>>>>>>>>>>>>>>>> has increased. Not sure if there is any use-case for
>>> producer
>>>>> to
>>>>>>>>>>>>>>>> use a
>>>>>>>>>>>>>>>> different hash function. Jason, can you check if there is
>>>> some
>>>>>>>>>>>>>>>> use-case
>>>>>>>>>>>>>>>> that I missed for using the per-topic partition strategy?
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> Regarding how to reduce latency (due to state store/load)
>>> in
>>>>>>>>>>>>>>>> stream
>>>>>>>>>>>>>>>> processing consumer when partition number changes: I need
>>> to
>>>>> read
>>>>>>>>>>>>>>>> the
>>>>>>>>>>>>>>>> Kafka
>>>>>>>>>>>>>>>> Stream code to understand how Kafka Stream currently
>>> migrate
>>>>>>>>>>>>>>>> state
>>>>>>>>>>>>>>>> between
>>>>>>>>>>>>>>>> consumers when the application is added/removed for a
>> given
>>>>> job.
>>>>>>>>>>>>>>>> I
>>>>>>>>>>>>>>>> will
>>>>>>>>>>>>>>>> reply after I finish reading the documentation and code.
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> Thanks,
>>>>>>>>>>>>>>>> Dong
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> On Mon, Mar 5, 2018 at 10:43 AM, Jason Gustafson <
>>>>>>>>>>>>>>>> jason@confluent.io>
>>>>>>>>>>>>>>>> wrote:
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> Great discussion. I think I'm wondering whether we can
>>>> continue
>>>>>>>>>>>>>>>> to
>>>>>>>>>>>>>>>> leave
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> Kafka agnostic to the partitioning strategy. The
>> challenge
>>> is
>>>>>>>>>>>>>>>> communicating
>>>>>>>>>>>>>>>>> the partitioning logic from producers to consumers so
>> that
>>>> the
>>>>>>>>>>>>>>>>> dependencies
>>>>>>>>>>>>>>>>> between each epoch can be determined. For the sake of
>>>>>>>>>>>>>>>>> discussion,
>>>>>>>>>>>>>>>>> imagine
>>>>>>>>>>>>>>>>> you did something like the following:
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> 1. The name (and perhaps version) of a partitioning
>>> strategy
>>>>> is
>>>>>>>>>>>>>>>>> stored
>>>>>>>>>>>>>>>>> in
>>>>>>>>>>>>>>>>> topic configuration when a topic is created.
>>>>>>>>>>>>>>>>> 2. The producer looks up the partitioning strategy
>> before
>>>>>>>>>>>>>>>>> writing
>>>>>>>>>>>>>>>>> to
>>>>>>>>>>>>>>>>> a
>>>>>>>>>>>>>>>>> topic and includes it in the produce request (for
>>> fencing).
>>>> If
>>>>>>>>>>>>>>>>> it
>>>>>>>>>>>>>>>>> doesn't
>>>>>>>>>>>>>>>>> have an implementation for the configured strategy, it
>>>> fails.
>>>>>>>>>>>>>>>>> 3. The consumer also looks up the partitioning strategy
>>> and
>>>>>>>>>>>>>>>>> uses it
>>>>>>>>>>>>>>>>> to
>>>>>>>>>>>>>>>>> determine dependencies when reading a new epoch. It
>> could
>>>>> either
>>>>>>>>>>>>>>>>> fail
>>>>>>>>>>>>>>>>> or
>>>>>>>>>>>>>>>>> make the most conservative dependency assumptions if it
>>>>> doesn't
>>>>>>>>>>>>>>>>> know
>>>>>>>>>>>>>>>>> how
>>>>>>>>>>>>>>>>> to
>>>>>>>>>>>>>>>>> implement the partitioning strategy. For the consumer,
>> the
>>>> new
>>>>>>>>>>>>>>>>> interface
>>>>>>>>>>>>>>>>> might look something like this:
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> // Return the partition dependencies following an epoch
>>> bump
>>>>>>>>>>>>>>>>> Map<Integer, List<Integer>> dependencies(int
>>>>>>>>>>>>>>>>> numPartitionsBeforeEpochBump,
>>>>>>>>>>>>>>>>> int numPartitionsAfterEpochBump)
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> The unordered case then is just a particular
>>> implementation
>>>>>>>>>>>>>>>>> which
>>>>>>>>>>>>>>>>> never
>>>>>>>>>>>>>>>>> has
>>>>>>>>>>>>>>>>> any epoch dependencies. To implement this, we would need
>>>> some
>>>>>>>>>>>>>>>>> way
>>>>>>>>>>>>>>>>> for
>>>>>>>>>>>>>>>>> the
>>>>>>>>>>>>>>>>> consumer to find out how many partitions there were in
>>> each
>>>>>>>>>>>>>>>>> epoch,
>>>>>>>>>>>>>>>>> but
>>>>>>>>>>>>>>>>> maybe that's not too unreasonable.
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> Thanks,
>>>>>>>>>>>>>>>>> Jason
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> On Mon, Mar 5, 2018 at 4:51 AM, Jan Filipiak <
>>>>>>>>>>>>>>>>> Jan.Filipiak@trivago.com
>>>>>>>>>>>>>>>>> wrote:
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> Hi Dong
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> thank you very much for your questions.
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> regarding the time spend copying data across:
>>>>>>>>>>>>>>>>>> It is correct that copying data from a topic with one
>>>>> partition
>>>>>>>>>>>>>>>>>> mapping
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> to
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> a topic with a different partition mapping takes way
>>> longer
>>>>>>>>>>>>>>>>>> than
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> we
>>>>>>>>>>>>>>>>> can
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> stop producers. Tens of minutes is a very optimistic
>>>> estimate
>>>>>>>>>>>>>>>>> here.
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> Many
>>>>>>>>>>>>>>>>>> people can not afford copy full steam and therefore
>> will
>>>> have
>>>>>>>>>>>>>>>>>> some
>>>>>>>>>>>>>>>>>> rate
>>>>>>>>>>>>>>>>>> limiting in place, this can bump the timespan into the
>>>> day's.
>>>>>>>>>>>>>>>>>> The
>>>>>>>>>>>>>>>>>> good
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> part
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> is that the vast majority of the data can be copied
>> while
>>>> the
>>>>>>>>>>>>>>>>> producers
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> are
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> still going. One can then, piggyback the consumers
>> ontop
>>> of
>>>>>>>>>>>>>>>>>> this
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> timeframe,
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> by the method mentioned (provide them an mapping from
>>> their
>>>>> old
>>>>>>>>>>>>>>>>> offsets
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> to
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> new offsets in their repartitioned topics. In that way
>> we
>>>>>>>>>>>>>>>>>> separate
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> migration of consumers from migration of producers
>>>> (decoupling
>>>>>>>>>>>>>>>>>> these
>>>>>>>>>>>>>>>>>> is
>>>>>>>>>>>>>>>>>> what kafka is strongest at). The time to actually swap
>>> over
>>>>> the
>>>>>>>>>>>>>>>>>> producers
>>>>>>>>>>>>>>>>>> should be kept minimal by ensuring that when a swap
>>> attempt
>>>>> is
>>>>>>>>>>>>>>>>>> started
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> the
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> consumer copying over should be very close to the log
>> end
>>>> and
>>>>>>>>>>>>>>>>>> is
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> expected
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> to finish within the next fetch. The operation should
>>> have
>>>> a
>>>>>>>>>>>>>>>>>> time-out
>>>>>>>>>>>>>>>>>> and
>>>>>>>>>>>>>>>>>> should be "reattemtable".
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> Importance of logcompaction:
>>>>>>>>>>>>>>>>>> If a producer produces key A, to partiton 0, its
>> forever
>>>>> gonna
>>>>>>>>>>>>>>>>>> be
>>>>>>>>>>>>>>>>>> there,
>>>>>>>>>>>>>>>>>> unless it gets deleted. The record might sit in there
>> for
>>>>>>>>>>>>>>>>>> years. A
>>>>>>>>>>>>>>>>>> new
>>>>>>>>>>>>>>>>>> producer started with the new partitions will fail to
>>>> delete
>>>>>>>>>>>>>>>>>> the
>>>>>>>>>>>>>>>>>> record
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> in
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> the correct partition. Th record will be there forever
>>> and
>>>>> one
>>>>>>>>>>>>>>>>>> can
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> not
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> reliable bootstrap new consumers. I cannot see how
>> linear
>>>>>>>>>>>>>>>>> hashing
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> can
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> solve
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> this.
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> Regarding your skipping of userland copying:
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> 100%, copying the data across in userland is, as far
>> as i
>>>> can
>>>>>>>>>>>>>>>>>> see,
>>>>>>>>>>>>>>>>>> only
>>>>>>>>>>>>>>>>>> a
>>>>>>>>>>>>>>>>>> usecase for log compacted topics. Even for
>> logcompaction
>>> +
>>>>>>>>>>>>>>>>>> retentions
>>>>>>>>>>>>>>>>>> it
>>>>>>>>>>>>>>>>>> should only be opt-in. Why did I bring it up? I think
>> log
>>>>>>>>>>>>>>>>>> compaction
>>>>>>>>>>>>>>>>>> is
>>>>>>>>>>>>>>>>>> a
>>>>>>>>>>>>>>>>>> very important feature to really embrace kafka as a
>> "data
>>>>>>>>>>>>>>>>>> plattform".
>>>>>>>>>>>>>>>>>> The
>>>>>>>>>>>>>>>>>> point I also want to make is that copying data this way
>>> is
>>>>>>>>>>>>>>>>>> completely
>>>>>>>>>>>>>>>>>> inline with the kafka architecture. it only consists of
>>>>> reading
>>>>>>>>>>>>>>>>>> and
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> writing
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> to topics.
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> I hope it clarifies more why I think we should aim for
>>> more
>>>>> than
>>>>>>>>>>>>>>>>>> the
>>>>>>>>>>>>>>>>>> current KIP. I fear that once the KIP is done not much
>>> more
>>>>>>>>>>>>>>>>>> effort
>>>>>>>>>>>>>>>>>> will
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> be
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> taken.
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> On 04.03.2018 02:28, Dong Lin wrote:
>>>>>>>>>>>>>>>>>> Hey Jan,
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> In the current proposal, the consumer will be blocked
>> on
>>>>>>>>>>>>>>>>>> waiting
>>>>>>>>>>>>>>>>>> for
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> other
>>>>>>>>>>>>>>>>>>> consumers of the group to consume up to a given
>> offset.
>>> In
>>>>>>>>>>>>>>>>>>> most
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> cases,
>>>>>>>>>>>>>>>>>> all
>>>>>>>>>>>>>>>>>> consumers should be close to the LEO of the partitions
>>> when
>>>>> the
>>>>>>>>>>>>>>>>>> partition
>>>>>>>>>>>>>>>>>> expansion happens. Thus the time waiting should not be
>>> long
>>>>>>>>>>>>>>>>>> e.g.
>>>>>>>>>>>>>>>>>> on
>>>>>>>>>>>>>>>>>> the
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> order of seconds. On the other hand, it may take a long
>>>> time
>>>>> to
>>>>>>>>>>>>>>>>>> wait
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> for
>>>>>>>>>>>>>>>>>>> the entire partition to be copied -- the amount of
>> time
>>> is
>>>>>>>>>>>>>>>>>>> proportional
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>> to
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>> the amount of existing data in the partition, which
>> can
>>>> take
>>>>>>>>>>>>>>>>>> tens of
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> minutes. So the amount of time that we stop consumers
>> may
>>>> not
>>>>>>>>>>>>>>>>>> be
>>>>>>>>>>>>>>>>>> on
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> the
>>>>>>>>>>>>>>>>>>> same order of magnitude.
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>> If we can implement this suggestion without copying
>> data
>>>>> over
>>>>>>>>>>>>>>>>>>> in
>>>>>>>>>>>>>>>>>>> purse
>>>>>>>>>>>>>>>>>>> userland, it will be much more valuable. Do you have
>>> ideas
>>>>> on
>>>>>>>>>>>>>>>>>>> how
>>>>>>>>>>>>>>>>>>> this
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>> can
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>> be done?
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> Not sure why the current KIP not help people who depend
>>> on
>>>>> log
>>>>>>>>>>>>>>>>>> compaction.
>>>>>>>>>>>>>>>>>>> Could you elaborate more on this point?
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> Thanks,
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> Dong
>>>>>>>>>>>>>>>>>>> On Wed, Feb 28, 2018 at 10:55 PM, Jan
>>>>>>>>>>>>>>>>>>> Filipiak<Jan.Filipiak@trivago.
>>>>>>>>>>>>>>>>>>> com
>>>>>>>>>>>>>>>>>>> wrote:
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>> Hi Dong,
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>> I tried to focus on what the steps are one can
>> currently
>>>>>>>>>>>>>>>>>>> perform
>>>>>>>>>>>>>>>>>>> to
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>> expand
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>> or shrink a keyed topic while maintaining a top notch
>>>>>>>>>>>>>>>>>>>> semantics.
>>>>>>>>>>>>>>>>>>>> I can understand that there might be confusion about
>>>>>>>>>>>>>>>>>>>> "stopping
>>>>>>>>>>>>>>>>>>>> the
>>>>>>>>>>>>>>>>>>>> consumer". It is exactly the same as proposed in the
>>> KIP.
>>>>>>>>>>>>>>>>>>>> there
>>>>>>>>>>>>>>>>>>>> needs
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>> to
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>> be
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>> a time the producers agree on the new partitioning.
>> The
>>>>> extra
>>>>>>>>>>>>>>>>>> semantics I
>>>>>>>>>>>>>>>>>>>> want to put in there is that we have a possibility to
>>>> wait
>>>>>>>>>>>>>>>>>>>> until
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>> all
>>>>>>>>>>>>>>>>>> the
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> existing data
>>>>>>>>>>>>>>>>>>> is copied over into the new partitioning scheme. When
>> I
>>>> say
>>>>>>>>>>>>>>>>>> stopping
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> I
>>>>>>>>>>>>>>>>>>>> think more of having a memory barrier that ensures
>> the
>>>>>>>>>>>>>>>>>>>> ordering. I
>>>>>>>>>>>>>>>>>>>> am
>>>>>>>>>>>>>>>>>>>> still
>>>>>>>>>>>>>>>>>>>> aming for latencies  on the scale of leader
>> failovers.
>>>>>>>>>>>>>>>>>>>> Consumers have to explicitly adapt the new
>> partitioning
>>>>>>>>>>>>>>>>>>>> scheme
>>>>>>>>>>>>>>>>>>>> in
>>>>>>>>>>>>>>>>>>>> the
>>>>>>>>>>>>>>>>>>>> above scenario. The reason is that in these cases
>> where
>>>> you
>>>>>>>>>>>>>>>>>>>> are
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>> dependent
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>> on a particular partitioning scheme, you also have
>>> other
>>>>>>>>>>>>>>>>>>>> topics
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>> that
>>>>>>>>>>>>>>>>>> have
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> co-partition enforcements or the kind -frequently.
>>>> Therefore
>>>>>>>>>>>>>>>>>>> all
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>> your
>>>>>>>>>>>>>>>>>> other
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> input topics might need to grow accordingly.
>>>>>>>>>>>>>>>>>>>> What I was suggesting was to streamline all these
>>>>> operations
>>>>>>>>>>>>>>>>>>>> as
>>>>>>>>>>>>>>>>>>>> best
>>>>>>>>>>>>>>>>>>>> as
>>>>>>>>>>>>>>>>>>>> possible to have "real" partition grow and shrinkage
>>>> going
>>>>>>>>>>>>>>>>>>>> on.
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>> Migrating
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>> the producers to a new partitioning scheme can be
>> much
>>>> more
>>>>>>>>>>>>>>>>>>> streamlined
>>>>>>>>>>>>>>>>>> with proper broker support for this. Migrating consumer
>>> is
>>>> a
>>>>>>>>>>>>>>>>>> step
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> that
>>>>>>>>>>>>>>>>>>>> might be made completly unnecessary if - for example
>>>>> streams
>>>>>>>>>>>>>>>>>>>> -
>>>>>>>>>>>>>>>>>>>> takes
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>> the
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>> gcd as partitioning scheme instead of enforcing 1 to
>> 1.
>>>>>>>>>>>>>>>>>>>> Connect
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>> consumers
>>>>>>>>>>>>>>>>>> and other consumers should be fine anyways.
>>>>>>>>>>>>>>>>>>> I hope this makes more clear where I was aiming at.
>> The
>>>> rest
>>>>>>>>>>>>>>>>>> needs
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> to
>>>>>>>>>>>>>>>>>>> be
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>> figured out. The only danger i see is that when we
>> are
>>>>>>>>>>>>>>>>>>> introducing
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>> this
>>>>>>>>>>>>>>>>>> feature as supposed in the KIP, it wont help any people
>>>>>>>>>>>>>>>>>> depending
>>>>>>>>>>>>>>>>>> on
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> log
>>>>>>>>>>>>>>>>>>>> compaction.
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>> The other thing I wanted to mention is that I believe
>>> the
>>>>>>>>>>>>>>>>>> current
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> suggestion (without copying data over) can be
>> implemented
>>>> in
>>>>>>>>>>>>>>>>>>> pure
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>> userland
>>>>>>>>>>>>>>>>>>>> with a custom partitioner and a small feedbackloop
>> from
>>>>>>>>>>>>>>>>>>>> ProduceResponse
>>>>>>>>>>>>>>>>>>>> =>
>>>>>>>>>>>>>>>>>>>> Partitionier in coorporation with a change management
>>>>> system.
>>>>>>>>>>>>>>>>>>>> Best Jan
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>> On 28.02.2018 07:13, Dong Lin wrote:
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>> Hey Jan,
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>> I am not sure if it is acceptable for producer to be
>>>>> stopped
>>>>>>>>>>>>>>>>>>>> for a
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>> while,
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>> particularly for online application which requires
>> low
>>>>>>>>>>>>>>>>>>>>> latency. I
>>>>>>>>>>>>>>>>>>>>> am
>>>>>>>>>>>>>>>>>>>>> also
>>>>>>>>>>>>>>>>>>>>> not sure how consumers can switch to a new topic.
>> Does
>>>>> user
>>>>>>>>>>>>>>>>>>>>> application
>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>> needs to explicitly specify a different topic for
>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>> producer/consumer
>>>>>>>>>>>>>>>>>>> to
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> subscribe to? It will be helpful for discussion if you
>>> can
>>>>>>>>>>>>>>>>>> provide
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> more
>>>>>>>>>>>>>>>>>>>> detail on the interface change for this solution.
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>> Thanks,
>>>>>>>>>>>>>>>>>>> Dong
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>> On Mon, Feb 26, 2018 at 12:48 AM, Jan
>>>>>>>>>>>>>>>>>>>>> Filipiak<Jan.Filipiak@trivago.
>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>> com
>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>> wrote:
>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>> Hi,
>>>>>>>>>>>>>>>>>>> just want to throw my though in. In general the
>>>>> functionality
>>>>>>>>>>>>>>>>>>> is
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>> very
>>>>>>>>>>>>>>>>>>>>> usefull, we should though not try to find the
>>>> architecture
>>>>>>>>>>>>>>>>>>>>> to
>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>> hard
>>>>>>>>>>>>>>>>>>>>>> while
>>>>>>>>>>>>>>>>>>>>>> implementing.
>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>> The manual steps would be to
>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>> create a new topic
>>>>>>>>>>>>>>>>>>>>>> the mirrormake from the new old topic to the new
>>> topic
>>>>>>>>>>>>>>>>>>>>>> wait for mirror making to catch up.
>>>>>>>>>>>>>>>>>>>>>> then put the consumers onto the new topic
>>>>>>>>>>>>>>>>>>>>>>             (having mirrormaker spit out a mapping
>>> from
>>>>> old
>>>>>>>>>>>>>>>>>>>>>> offsets to
>>>>>>>>>>>>>>>>>>>>>> new
>>>>>>>>>>>>>>>>>>>>>> offsets:
>>>>>>>>>>>>>>>>>>>>>>                 if topic is increased by factor X
>>> there
>>>> is
>>>>>>>>>>>>>>>>>>>>>> gonna
>>>>>>>>>>>>>>>>>>>>>> be a
>>>>>>>>>>>>>>>>>>>>>> clean
>>>>>>>>>>>>>>>>>>>>>> mapping from 1 offset in the old topic to X offsets
>>> in
>>>>> the
>>>>>>>>>>>>>>>>>>>>>> new
>>>>>>>>>>>>>>>>>>>>>> topic,
>>>>>>>>>>>>>>>>>>>>>>                 if there is no factor then there is
>> no
>>>>>>>>>>>>>>>>>>>>>> chance to
>>>>>>>>>>>>>>>>>>>>>> generate a
>>>>>>>>>>>>>>>>>>>>>> mapping that can be reasonable used for continuing)
>>>>>>>>>>>>>>>>>>>>>>             make consumers stop at appropriate
>> points
>>>> and
>>>>>>>>>>>>>>>>>>>>>> continue
>>>>>>>>>>>>>>>>>>>>>> consumption
>>>>>>>>>>>>>>>>>>>>>> with offsets from the mapping.
>>>>>>>>>>>>>>>>>>>>>> have the producers stop for a minimal time.
>>>>>>>>>>>>>>>>>>>>>> wait for mirrormaker to finish
>>>>>>>>>>>>>>>>>>>>>> let producer produce with the new metadata.
>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>> Instead of implementing the approach suggest in the
>>> KIP
>>>>>>>>>>>>>>>>>>>>>> which
>>>>>>>>>>>>>>>>>>>>>> will
>>>>>>>>>>>>>>>>>>>>>> leave
>>>>>>>>>>>>>>>>>>>>>> log compacted topic completely crumbled and
>> unusable.
>>>>>>>>>>>>>>>>>>>>>> I would much rather try to build infrastructure to
>>>>> support
>>>>>>>>>>>>>>>>>>>>>> the
>>>>>>>>>>>>>>>>>>>>>> mentioned
>>>>>>>>>>>>>>>>>>>>>> above operations more smoothly.
>>>>>>>>>>>>>>>>>>>>>> Especially having producers stop and use another
>>> topic
>>>> is
>>>>>>>>>>>>>>>>>>>>>> difficult
>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>> and
>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>> it would be nice if one can trigger "invalid
>>> metadata"
>>>>>>>>>>>>>>>>>>>>> exceptions
>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>> for
>>>>>>>>>>>>>>>>>>> them
>>>>>>>>>>>>>>>>>> and
>>>>>>>>>>>>>>>>>>>> if one could give topics aliases so that their
>> produces
>>>>> with
>>>>>>>>>>>>>>>>>>>>>> the
>>>>>>>>>>>>>>>>>>>>>> old
>>>>>>>>>>>>>>>>>>>>>> topic
>>>>>>>>>>>>>>>>>>>>>> will arrive in the new topic.
>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>> The downsides are obvious I guess ( having the same
>>>> data
>>>>>>>>>>>>>>>>>>>>>> twice
>>>>>>>>>>>>>>>>>>>>>> for
>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>> the
>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>> transition period, but kafka tends to scale well
>> with
>>>>>>>>>>>>>>>>>>>>> datasize).
>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>> So
>>>>>>>>>>>>>>>>>>>> its a
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>> nicer fit into the architecture.
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>> I further want to argument that the functionality by
>>> the
>>>>> KIP
>>>>>>>>>>>>>>>>>>>>>> can
>>>>>>>>>>>>>>>>>>>>>> completely be implementing in "userland" with a
>>> custom
>>>>>>>>>>>>>>>>>>>>>> partitioner
>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>> that
>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>> handles the transition as needed. I would
>> appreciate
>>> if
>>>>>>>>>>>>>>>>>>>>> someone
>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>> could
>>>>>>>>>>>>>>>>>>> point
>>>>>>>>>>>>>>>>>> out what a custom partitioner couldn't handle in this
>>> case?
>>>>>>>>>>>>>>>>>>>> With the above approach, shrinking a topic becomes
>> the
>>>> same
>>>>>>>>>>>>>>>>>>>>>> steps.
>>>>>>>>>>>>>>>>>>>>>> Without
>>>>>>>>>>>>>>>>>>>>>> loosing keys in the discontinued partitions.
>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>> Would love to hear what everyone thinks.
>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>> Best Jan
>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>> On 11.02.2018 00:35, Dong Lin wrote:
>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>> Hi all,
>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>> I have created KIP-253: Support in-order message
>>>> delivery
>>>>>>>>>>>>>>>>>>>>>> with
>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>> partition
>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>> expansion. See
>>>>>>>>>>>>>>>>>>>>>>> https://cwiki.apache.org/confl
>>>>>>>>>>>>>>>>>>>>>>> uence/display/KAFKA/KIP-253%
>>>>>>>>>>>>>>>>>>>>>>> 3A+Support+in-order+message+de
>>>>>>>>>>>>>>>>>>>>>>> livery+with+partition+expansio
>>>>>>>>>>>>>>>>>>>>>>> n
>>>>>>>>>>>>>>>>>>>>>>> .
>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>> This KIP provides a way to allow messages of the
>>> same
>>>>> key
>>>>>>>>>>>>>>>>>>>>>>> from
>>>>>>>>>>>>>>>>>>>>>>> the
>>>>>>>>>>>>>>>>>>>>>>> same
>>>>>>>>>>>>>>>>>>>>>>> producer to be consumed in the same order they are
>>>>>>>>>>>>>>>>>>>>>>> produced
>>>>>>>>>>>>>>>>>>>>>>> even
>>>>>>>>>>>>>>>>>>>>>>> if
>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>> we
>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>> expand partition of the topic.
>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>> Thanks,
>>>>>>>>>>>>>>>>>>>> Dong
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>



Re: [DISCUSS] KIP-253: Support in-order message delivery with partition expansion

Posted by Jan Filipiak <Ja...@trivago.com>.
Thank you so much John Roesler! <3

Thank you for also seeing the core strengths of apache kafka!

We just cannot make sacrifices like this to the architecture for the 
benefits of streams.

Streams somehow got lost in the whole "Interactive Query" idea that is 
spreading
like cancer across the project and is one of the fundamental breaks in 
the architecture
already. I am so so happy to see your feedback!

The discussion can be held even simpler than it currently is. I will try 
to catch the threads that started
and point them to (maybe the first email in this thread) to outline that 
what I am asking for is not much.

The only two things in broker support I need is:
1. When a producer gets blocked in produces because his partition number 
is incorrect. (initial KIP)
I wanted to be able to stop it until the copy making process is done. 
Same pattern as waiting for ISR / min replicas.
Fully optional of course, so only for log compaction topic.

2. A way to distinguish the topics, by name versionnumber epoch 
something really. For convenience different
versions should not share a log segment so one does not need to include 
it in the format.

All the other things from my initial description on how to grow, can be 
dealt with in different JVMs.
(copy making MirrorMaker consumers)

I hope I can outline further how little this is I am asking for.

Thank you John for outlining the !!weirdness!!! that come from the 
current suggestion on producer side.
On the consumption side they are by no way fewer. Its an ugly proposal 
fighting the own architecture and
it can only show is ugly face in so many problems upfront. Noone has yet 
dared to ask about the race conditions
that occur with having the same key running across two partitions. It 
opens the whole flower of "key widening / key opening" that
is discussed in streams KIP-213 extensively! The partitionId esentially 
becomes part of the key for downstream processing and
Noone will get that! soo horribly complicated for joins already. I 
cannot think of all the bugs that will come out if we have to apply
the carefulness of 1:n join in every basic operation.

I cannot thank you more John! Your mail gave purpose to all my mailing 
list efforts. Thank you again so much

<3 Jan



On 27.03.2018 20:34, John Roesler wrote:
> Hey Dong and Jun,
>
> Thanks for the thoughtful responses. If you don't mind, I'll mix my replies
> together to try for a coherent response. I'm not too familiar with
> mailing-list etiquette, though.
>
> I'm going to keep numbering my points because it makes it easy for you all
> to respond.
>
> Point 1:
> As I read it, KIP-253 is *just* about properly fencing the producers and
> consumers so that you preserve the correct ordering of records during
> partition expansion. This is clearly necessary regardless of anything else
> we discuss. I think this whole discussion about backfill, consumers,
> streams, etc., is beyond the scope of KIP-253. But it would be cumbersome
> to start a new thread at this point.
>
> I had missed KIP-253's Proposed Change #9 among all the details... I think
> this is a nice addition to the proposal. One thought is that it's actually
> irrelevant whether the hash function is linear. This is simply an algorithm
> for moving a key from one partition to another, so the type of hash
> function need not be a precondition. In fact, it also doesn't matter
> whether the topic is compacted or not, the algorithm works regardless.
>
> I think this is a good algorithm to keep in mind, as it might solve a
> variety of problems, but it does have a downside: that the producer won't
> know whether or not K1 was actually in P1, it just knows that K1 was in
> P1's keyspace before the new epoch. Therefore, it will have to
> pessimistically send (K1,null) to P1 just in case. But the next time K1
> comes along, the producer *also* won't remember that it already retracted
> K1 from P1, so it will have to send (K1,null) *again*. By extension, every
> time the producer sends to P2, it will also have to send a tombstone to P1,
> which is a pretty big burden. To make the situation worse, if there is a
> second split, say P2 becomes P2 and P3, then any key Kx belonging to P3
> will also have to be retracted from P2 *and* P1, since the producer can't
> know whether Kx had been last written to P2 or P1. Over a long period of
> time, this clearly becomes a issue, as the producer must send an arbitrary
> number of retractions along with every update.
>
> In contrast, the proposed backfill operation has an end, and after it ends,
> everyone can afford to forget that there ever was a different partition
> layout.
>
> Really, though, figuring out how to split compacted topics is beyond the
> scope of KIP-253, so I'm not sure #9 really even needs to be in this KIP...
> We do need in-order delivery during partition expansion. It would be fine
> by me to say that you *cannot* expand partitions of a log-compacted topic
> and call it a day. I think it would be better to tackle that in another KIP.
>
>
> Point 2:
> Regarding whether the consumer re-shuffles its inputs, this is always on
> the table; any consumer who wants to re-shuffle its input is free to do so.
> But this is currently not required. It's just that the current high-level
> story with Kafka encourages the use of partitions as a unit of concurrency.
> As long as consumers are single-threaded, they can happily consume a single
> partition without concurrency control of any kind. This is a key aspect to
> this system that lets folks design high-throughput systems on top of it
> surprisingly easily. If all consumers were instead encouraged/required to
> implement a repartition of their own, then the consumer becomes
> significantly more complex, requiring either the consumer to first produce
> to its own intermediate repartition topic or to ensure that consumer
> threads have a reliable, high-bandwith channel of communication with every
> other consumer thread.
>
> Either of those tradeoffs may be reasonable for a particular user of Kafka,
> but I don't know if we're in a position to say that they are reasonable for
> *every* user of Kafka.
>
>
> Point 3:
> Regarding Jun's point about this use case, "(3) stateful and maintaining the
> states in a local store", I agree that they may use a framework *like*
> Kafka Streams, but that is not the same as using Kafka Streams. This is why
> I think it's better to solve it in Core: because it is then solved for
> KStreams and also for everything else that facilitates local state
> maintenance. To me, Streams is a member of the category of "stream
> processing frameworks", which is itself a subcategory of "things requiring
> local state maintenence". I'm not sure if it makes sense to assert that
> Streams is a sufficient and practical replacement for everything in "things
> requiring local state maintenence".
>
> But, yes, I do agree that per-key ordering is an absolute requirement,
> therefore I think that KIP-253 itself is a necessary step. Regarding the
> coupling of the state store partitioning to the topic partitioning, yes,
> this is an issue we are discussing solutions to right now. We may go ahead
> and introduce an overpartition layer on our inputs to solve it, but then
> again, if we get the ability to split partitions with backfill, we may not
> need to!
>
>
> Point 4:
> On this:
>
>> Regarding thought 2: If we don't care about the stream use-case, then the
>> current KIP probably has already addressed problem without requiring
>> consumer to know the partition function. If we care about the stream
>> use-case, we already need coordination across producers of different
>> topics, i.e. the same partition function needs to be used by producers of
>> topics A and B in order to join topics A and B. Thus, it might be
>> reasonable to extend coordination a bit and say we need coordination across
>> clients (i.e. producer and consumer), such that consumer knows the
>> partition function used by producer. If we do so, then we can let consumer
>> re-copy data for the change log topic using the same partition function as
>> producer. This approach has lower overhead as compared to having producer
>> re-copy data of the input topic.
>> Also, producer currently does not need to know the data already produced to
>> the topic. If we let producer split/merge partition, it would require
>> producer to consume the existing data, which intuitively is the task of
>> consumer.
>
> I think we do care about use cases *like* Streams, I just don't think we
> should rely on Streams to implement a feature of Core like partition
> expansion.
>
> Note, though, that we (Streams) do not require coordination across
> producers. If two topics are certified to be co-partitioned, then Streams
> apps can make use of that knowledge to optimize their topology (skipping a
> repartition). But if they don't know whether they are co-partitioned, then
> they'd better go ahead and repartition within the topology. This is the
> current state.
>
> A huge selling point of Kafka is enabling different parts of loosely
> coupled organizations to produce and consume data independently. Some
> coordination between producers and consumers is necessary, like
> coordinating on the names of topics and their schemas. But Kafka's value
> proposition w.r.t. ESBs, etc. is inversely proportional to the amount of
> coordination required. I think it behooves us to be extremely skeptical
> about introducing any coordination beyond correctness protocols.
>
> Asking producers and consumers, or even two different producers, to share
> code like the partition function is a pretty huge ask. What if they are
> using different languages?
>
> Comparing organizational overhead vs computational overhead, there are
> maybe two orders of magnitude difference between them. In other words, I
> would happily take on the (linear) overhead of having the producer re-copy
> the data once during a re-partition in order to save the organizational
> overhead of tying all the producers and consumers together across multiple
> boundaries.
>
> On that last paragraph: note that the producer *did* know the data it
> already produced. It handled it the first time around. Asking it to
> re-produce it into a new partition layout is squarely within its scope of
> capabilities. Contrast this with the alternative, asking the consumer to
> re-partition the data. I think this is even less intuitive, when the
> partition function belongs to the producer.
>
>
> Point 5:
> Dong asked this:
>
>> For stream use-case that needs to increase consumer number, the
>> existing consumer can backfill the existing data in the change log topic to
>> the same change log topic with the new partition number, before the new set
>> of consumers bootstrap state from the new partitions of the change log
>> topic, right?
>
> In this sense, the "consumer" is actually the producer of the changelog
> topic, so if we support partition expansion + backfill as a producer/broker
> operation, then it would be very straightforward for Streams to split a
> state store. As you say, they would simply instruct the broker to split the
> changelog topic's partitions, then backfill. Once the backfill is ready,
> they can create a new crop of StandbyTasks to bootstrap the more granular
> state stores and finally switch over to them when they are ready.
>
> But this actually seems to be an argument in favor of split+backfill, so
> maybe I missed the point.
>
> You also asked me to explain why copying the "input" topic is better than
> copying the "changelog" topic. I think they are totally independent,
> actually. For one thing, you can't depend on the existence of a "changelog"
> topic in general, only within Streams, but Kafka's user base clearly
> exceeds Streams's user base. Plus, you actually also can't depend on the
> existence of a changelog topic within Streams, since that is an optional
> feature of *some* state store implementations. Even in the situation where
> you do have a changelog topic in Streams, there may be use cases where it
> makes sense to expand the partitions of just the input, or just the
> changelog.
>
> The ask for a Core feature of split+backfill is really about supporting the
> use case of splitting partitions in log-compacted topics, regardless of
> whether that topic is an "input" or a "changelog" or anything else for that
> matter.
>
>
> Point 6:
> On the concern about the performance overhead of copying data between the
> brokers, I think it's actually a bit overestimated. Splitting a topic's
> partition is probably rare, certainly rarer in general than bootstrapping
> new consumers on that topic. If "bootstrapping new consumers" means that
> they have to re-shuffle the data before they consume it, then you wind up
> copying the same record multiple times:
>
> (broker: input topic) -> (initial consumer) -> (broker: repartition topic)
> -> (real consumer)
>
> That's 3x, and it's also 3x for every new record after the split as well,
> since you don't get to stop repartitioning/reshuffling once you start.
>
> Whereas if you do a backfill in something like the procedure I outlined,
> you only copy the prefix of the partition before the split, and you send it
> once to the producer and then once to the new generation partition. Plus,
> assuming we're splitting the partition for the benefit of consumers,
> there's no reason we can't co-locate the post-split partitions on the same
> host as the pre-split partition, making the second copy a local filesystem
> operation.
>
> Even if you follow these two copies up with bootstrapping a new consumer,
> it's still rare for this to occur, so you get to amortize these copies over
> the lifetime of the topic, whereas a reshuffle just keeps making copies for
> every new event.
>
> And finally, I really do think that regardless of any performance concerns
> about this operation, if it preserves loose organizational coupling, it is
> certainly worth it.
>
>
> In conclusion:
> It might actually be a good idea for us to clarify the scope of KIP-253. If
> we're all agreed that it's a good algorithm for allowing in-order message
> delivery during partition expansion, then we can continue this discussion
> as a new KIP, something like "backfill with partition expansion". This
> would let Dong proceed with KIP-253. On the other hand, if it seems like
> this conversation may alter the design of KIP-253, then maybe we *should*
> just finish working it out.
>
> For my part, my only concern about KIP-253 is the one I raised earlier.
>
> Thanks again, all, for considering these points,
> -John
>
>
> On Tue, Mar 27, 2018 at 2:10 AM, Dong Lin <li...@gmail.com> wrote:
>
>> On Tue, Mar 27, 2018 at 12:04 AM, Dong Lin <li...@gmail.com> wrote:
>>
>>> Hey Jan,
>>>
>>> Thanks for the enthusiasm in improving Kafka's design. Now that I have
>>> read through your discussion with Jun, here are my thoughts:
>>>
>>> - The latest proposal should with log compacted topics by properly
>>> deleting old messages after a new message with the same key is produced.
>> So
>>> it is probably not a concern anymore. Could you comment if there is still
>>> issue?
>>>
>>> - I wrote the SEP-5 and I am pretty familiar with the motivation and the
>>> design of SEP-5. SEP-5 is probably orthornal to the motivation of this
>> KIP.
>>> The goal of SEP-5 is to allow user to increase task number of an existing
>>> Samza job. But if we increase the partition number of input topics,
>>> messages may still be consumed out-of-order by tasks in Samza which cause
>>> incorrect result. Similarly, the approach you proposed does not seem to
>>> ensure that the messages can be delivered in order, even if we can make
>>> sure that each consumer instance is assigned the set of new partitions
>>> covering the same set of keys.
>>>
>> Let me correct this comment. The approach of copying data to a new topic
>> can ensure in-order message delivery suppose we properly migrate offsets
>> from old topic to new topic.
>>
>>
>>> - I am trying to understand why it is better to copy the data instead of
>>> copying the change log topic for streaming use-case. For core Kafka
>>> use-case, and for the stream use-case that does not need to increase
>>> consumers, the current KIP already supports in-order delivery without the
>>> overhead of copying the data. For stream use-case that needs to increase
>>> consumer number, the existing consumer can backfill the existing data in
>>> the change log topic to the same change log topic with the new partition
>>> number, before the new set of consumers bootstrap state from the new
>>> partitions of the change log topic. If this solution works, then could
>> you
>>> summarize the advantage of copying the data of input topic as compared to
>>> copying the change log topic? For example, does it enable more use-case,
>>> simplify the implementation of Kafka library, or reduce the operation
>>> overhead etc?
>>>
>>> Thanks,
>>> Dong
>>>
>>>
>>> On Wed, Mar 21, 2018 at 6:57 AM, Jan Filipiak <Ja...@trivago.com>
>>> wrote:
>>>
>>>> Hi Jun,
>>>>
>>>> I was really seeing progress in our conversation but your latest reply
>> is
>>>> just devastating.
>>>> I though we were getting close being on the same page now it feels like
>>>> we are in different libraries.
>>>>
>>>> I just quickly slam my answers in here. If they are to brief I am sorry
>>>> give me a ping and try to go into details more.
>>>> Just want to show that your pro/cons listing is broken.
>>>>
>>>> Best Jan
>>>>
>>>> and want to get rid of this horrible compromise
>>>>
>>>>
>>>> On 19.03.2018 05:48, Jun Rao wrote:
>>>>
>>>>> Hi, Jan,
>>>>>
>>>>> Thanks for the discussion. Great points.
>>>>>
>>>>> Let me try to summarize the approach that you are proposing. On the
>>>>> broker
>>>>> side, we reshuffle the existing data in a topic from current partitions
>>>>> to
>>>>> the new partitions. Once the reshuffle fully catches up, switch the
>>>>> consumers to start consuming from the new partitions. If a consumer
>> needs
>>>>> to rebuild its local state (due to partition changes), let the consumer
>>>>> rebuild its state by reading all existing data from the new partitions.
>>>>> Once all consumers have switches over, cut over the producer to the new
>>>>> partitions.
>>>>>
>>>>> The pros for this approach are that :
>>>>> 1. There is just one way to rebuild the local state, which is simpler.
>>>>>
>>>> true thanks
>>>>
>>>>> The cons for this approach are:
>>>>> 1. Need to copy existing data.
>>>>>
>>>> Very unfair and not correct. It does not require you to copy over
>>>> existing data. It _allows_ you to copy all existing data.
>>>>
>>>> 2. The cutover of the producer is a bit complicated since it needs to
>>>>> coordinate with all consumer groups.
>>>>>
>>>> Also not true. I explicitly tried to make clear that there is only one
>>>> special consumer (in the case of actually copying data) coordination is
>>>> required.
>>>>
>>>>> 3. The rebuilding of the state in the consumer is from the input topic,
>>>>> which can be more expensive than rebuilding from the existing state.
>>>>>
>>>> true, but rebuilding state is only required if you want to increase
>>>> processing power, so we assume this is at hand.
>>>>
>>>>> 4. The broker potentially has to know the partitioning function. If
>> this
>>>>> needs to be customized at the topic level, it can be a bit messy.
>>>>>
>>>> I would argue against having the operation being performed by the
>> broker.
>>>> This was not discussed yet but if you see my original email i suggested
>>>> otherwise from the beginning.
>>>>
>>>>> Here is an alternative approach by applying your idea not in the
>> broker,
>>>>> but in the consumer. When new partitions are added, we don't move
>>>>> existing
>>>>> data. In KStreams, we first reshuffle the new input data to a new topic
>>>>> T1
>>>>> with the old number of partitions and feed T1's data to the rest of the
>>>>> pipeline. In the meantime, KStreams reshuffles all existing data of the
>>>>> change capture topic to another topic C1 with the new number of
>>>>> partitions.
>>>>> We can then build the state of the new tasks from C1. Once the new
>> states
>>>>> have been fully built, we can cut over the consumption to the input
>> topic
>>>>> and delete T1. This approach works with compacted topic too. If an
>>>>> application reads from the beginning of a compacted topic, the consumer
>>>>> will reshuffle the portion of the input when the number of partitions
>>>>> doesn't match the number of tasks.
>>>>>
>>>> We all wipe this idea from our heads instantly. Mixing Ideas from an
>>>> argument is not a resolution strategy
>>>> just leads to horrible horrible software.
>>>>
>>>>
>>>>> The pros of this approach are:
>>>>> 1. No need to copy existing data.
>>>>> 2. Each consumer group can cut over to the new partitions
>> independently.
>>>>> 3. The state is rebuilt from the change capture topic, which is cheaper
>>>>> than rebuilding from the input topic.
>>>>> 4. Only the KStreams job needs to know the partitioning function.
>>>>>
>>>>> The cons of this approach are:
>>>>> 1. Potentially the same input topic needs to be reshuffled more than
>> once
>>>>> in different consumer groups during the transition phase.
>>>>>
>>>>> What do you think?
>>>>>
>>>>> Thanks,
>>>>>
>>>>> Jun
>>>>>
>>>>>
>>>>>
>>>>> On Thu, Mar 15, 2018 at 1:04 AM, Jan Filipiak <
>> Jan.Filipiak@trivago.com>
>>>>> wrote:
>>>>>
>>>>> Hi Jun,
>>>>>> thank you for following me on these thoughts. It was important to me
>> to
>>>>>> feel that kind of understanding for my arguments.
>>>>>>
>>>>>> What I was hoping for (I mentioned this earlier) is that we can model
>>>>>> the
>>>>>> case where we do not want to copy the data the exact same way as the
>>>>>> case
>>>>>> when we do copy the data. Maybe you can peek into the mails before to
>>>>>> see
>>>>>> more details for this.
>>>>>>
>>>>>> This means we have the same mechanism to transfer consumer groups to
>>>>>> switch topic. The offset mapping that would be generated would even be
>>>>>> simpler End Offset of the Old topic => offset 0 off all the partitions
>>>>>> of
>>>>>> the new topic. Then we could model the transition of a non-copy
>>>>>> expansion
>>>>>> the exact same way as a copy-expansion.
>>>>>>
>>>>>> I know this only works when topic growth by a factor. But the benefits
>>>>>> of
>>>>>> only growing by a factor are to strong anyways. See Clemens's hint and
>>>>>> remember that state reshuffling is entirely not needed if one doesn't
>>>>>> want
>>>>>> to grow processing power.
>>>>>>
>>>>>> I think these benefits should be clear, and that there is basically no
>>>>>> downside to what is currently at hand but just makes everything easy.
>>>>>>
>>>>>> One thing you need to know is. that if you do not offer rebuilding a
>> log
>>>>>> compacted topic like i suggest that even if you have consumer state
>>>>>> reshuffling. The topic is broken and can not be used to bootstrap new
>>>>>> consumers. They don't know if they need to apply a key from and old
>>>>>> partition or not. This is a horrible downside I haven't seen a
>> solution
>>>>>> for
>>>>>> in the email conversation.
>>>>>>
>>>>>> I argue to:
>>>>>>
>>>>>> Only grow topic by a factor always.
>>>>>> Have the "no copy consumer" transition as the trivial case of the
>> "copy
>>>>>> consumer transition".
>>>>>> If processors needs to be scaled, let them rebuild from the new topic
>>>>>> and
>>>>>> leave the old running in the mean time.
>>>>>> Do not implement key shuffling in streams.
>>>>>>
>>>>>> I hope I can convince you especially with the fact how I want to
>> handle
>>>>>> consumer transition. I think
>>>>>> you didn't quite understood me there before. I think the term "new
>>>>>> topic"
>>>>>> intimidated you a little.
>>>>>> How we solve this on disc doesn't really matter, If the data goes into
>>>>>> the
>>>>>> same Dir or a different Dir or anything. I do think that it needs to
>>>>>> involve at least rolling a new segment for the existing partitions.
>>>>>> But most of the transitions should work without restarting consumers.
>>>>>> (newer consumers with support for this). But with new topic i just
>> meant
>>>>>> the topic that now has a different partition count. Plenty of ways to
>>>>>> handle that (versions, aliases)
>>>>>>
>>>>>> Hope I can further get my idea across.
>>>>>>
>>>>>> Best Jan
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> On 14.03.2018 02:45, Jun Rao wrote:
>>>>>>
>>>>>> Hi, Jan,
>>>>>>> Thanks for sharing your view.
>>>>>>>
>>>>>>> I agree with you that recopying the data potentially makes the state
>>>>>>> management easier since the consumer can just rebuild its state from
>>>>>>> scratch (i.e., no need for state reshuffling).
>>>>>>>
>>>>>>> On the flip slide, I saw a few disadvantages of the approach that you
>>>>>>> suggested. (1) Building the state from the input topic from scratch
>> is
>>>>>>> in
>>>>>>> general less efficient than state reshuffling. Let's say one
>> computes a
>>>>>>> count per key from an input topic. The former requires reading all
>>>>>>> existing
>>>>>>> records in the input topic whereas the latter only requires reading
>>>>>>> data
>>>>>>> proportional to the number of unique keys. (2) The switching of the
>>>>>>> topic
>>>>>>> needs modification to the application. If there are many applications
>>>>>>> on a
>>>>>>> topic, coordinating such an effort may not be easy. Also, it's not
>>>>>>> clear
>>>>>>> how to enforce exactly-once semantic during the switch. (3) If a
>> topic
>>>>>>> doesn't need any state management, recopying the data seems wasteful.
>>>>>>> In
>>>>>>> that case, in place partition expansion seems more desirable.
>>>>>>>
>>>>>>> I understand your concern about adding complexity in KStreams. But,
>>>>>>> perhaps
>>>>>>> we could iterate on that a bit more to see if it can be simplified.
>>>>>>>
>>>>>>> Jun
>>>>>>>
>>>>>>>
>>>>>>> On Mon, Mar 12, 2018 at 11:21 PM, Jan Filipiak <
>>>>>>> Jan.Filipiak@trivago.com>
>>>>>>> wrote:
>>>>>>>
>>>>>>> Hi Jun,
>>>>>>>
>>>>>>>> I will focus on point 61 as I think its _the_ fundamental part that
>> I
>>>>>>>> cant
>>>>>>>> get across at the moment.
>>>>>>>>
>>>>>>>> Kafka is the platform to have state materialized multiple times from
>>>>>>>> one
>>>>>>>> input. I emphasize this: It is the building block in architectures
>>>>>>>> that
>>>>>>>> allow you to
>>>>>>>> have your state maintained multiple times. You put a message in
>> once,
>>>>>>>> and
>>>>>>>> you have it pop out as often as you like. I believe you understand
>>>>>>>> this.
>>>>>>>>
>>>>>>>> Now! The path of thinking goes the following: I am using apache
>> kafka
>>>>>>>> and
>>>>>>>> I _want_ my state multiple times. What am I going todo?
>>>>>>>>
>>>>>>>> A) Am I going to take my state that I build up, plunge some sort of
>>>>>>>> RPC
>>>>>>>> layer ontop of it, use that RPC layer to throw my records across
>>>>>>>> instances?
>>>>>>>> B) Am I just going to read the damn message twice?
>>>>>>>>
>>>>>>>> Approach A is fundamentally flawed and a violation of all that is
>> good
>>>>>>>> and
>>>>>>>> holy in kafka deployments. I can not understand how this Idea can
>>>>>>>> come in
>>>>>>>> the first place.
>>>>>>>> (I do understand: IQ in streams, they polluted the kafka streams
>>>>>>>> codebase
>>>>>>>> really bad already. It is not funny! I think they are equally flawed
>>>>>>>> as
>>>>>>>> A)
>>>>>>>>
>>>>>>>> I say, we do what Kafka is good at. We repartition the topic once.
>> We
>>>>>>>> switch the consumers.
>>>>>>>> (Those that need more partitions are going to rebuild their state in
>>>>>>>> multiple partitions by reading the new topic, those that don't just
>>>>>>>> assign
>>>>>>>> the new partitions properly)
>>>>>>>> We switch producers. Done!
>>>>>>>>
>>>>>>>> The best thing! It is trivial, hipster stream processor will have an
>>>>>>>> easy
>>>>>>>> time with that aswell. Its so super simple. And simple IS good!
>>>>>>>> It is what kafka was build todo. It is how we do it today. All I am
>>>>>>>> saying
>>>>>>>> is that a little broker help doing the producer swap is super
>> useful.
>>>>>>>> For everyone interested in why kafka is so powerful with approach B,
>>>>>>>> please watch https://youtu.be/bEbeZPVo98c?t=1633
>>>>>>>> I already looked up a good point in time, I think after 5 minutes
>> the
>>>>>>>> "state" topic is handled and you should be able to understand me
>>>>>>>> and inch better.
>>>>>>>>
>>>>>>>> Please do not do A to the project, it deserves better!
>>>>>>>>
>>>>>>>> Best Jan
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> On 13.03.2018 02:40, Jun Rao wrote:
>>>>>>>>
>>>>>>>> Hi, Jan,
>>>>>>>>
>>>>>>>>> Thanks for the reply. A few more comments below.
>>>>>>>>>
>>>>>>>>> 50. Ok, we can think a bit harder for supporting compacted topics.
>>>>>>>>>
>>>>>>>>> 51. This is a fundamental design question. In the more common case,
>>>>>>>>> the
>>>>>>>>> reason why someone wants to increase the number of partitions is
>> that
>>>>>>>>> the
>>>>>>>>> consumer application is slow and one wants to run more consumer
>>>>>>>>> instances
>>>>>>>>> to increase the degree of parallelism. So, fixing the number of
>>>>>>>>> running
>>>>>>>>> consumer instances when expanding the partitions won't help this
>>>>>>>>> case.
>>>>>>>>> If
>>>>>>>>> we do need to increase the number of consumer instances, we need to
>>>>>>>>> somehow
>>>>>>>>> reshuffle the state of the consumer across instances. What we have
>>>>>>>>> been
>>>>>>>>> discussing in this KIP is whether we can do this more effectively
>>>>>>>>> through
>>>>>>>>> the KStream library (e.g. through a 2-phase partition expansion).
>>>>>>>>> This
>>>>>>>>> will
>>>>>>>>> add some complexity, but it's probably better than everyone doing
>>>>>>>>> this
>>>>>>>>> in
>>>>>>>>> the application space. The recopying approach that you mentioned
>>>>>>>>> doesn't
>>>>>>>>> seem to address the consumer state management issue when the
>> consumer
>>>>>>>>> switches from an old to a new topic.
>>>>>>>>>
>>>>>>>>> 52. As for your example, it depends on whether the join key is the
>>>>>>>>> same
>>>>>>>>> between (A,B) and (B,C). If the join key is the same, we can do a
>>>>>>>>> 2-phase
>>>>>>>>> partition expansion of A, B, and C together. If the join keys are
>>>>>>>>> different, one would need to repartition the data on a different
>> key
>>>>>>>>> for
>>>>>>>>> the second join, then the partition expansion can be done
>>>>>>>>> independently
>>>>>>>>> between (A,B) and (B,C).
>>>>>>>>>
>>>>>>>>> 53. If you always fix the number of consumer instances, we you
>>>>>>>>> described
>>>>>>>>> works. However, as I mentioned in #51, I am not sure how your
>>>>>>>>> proposal
>>>>>>>>> deals with consumer states when the number of consumer instances
>>>>>>>>> grows.
>>>>>>>>> Also, it just seems that it's better to avoid re-copying the
>> existing
>>>>>>>>> data.
>>>>>>>>>
>>>>>>>>> 60. "just want to throw in my question from the longer email in the
>>>>>>>>> other
>>>>>>>>> Thread here. How will the bloom filter help a new consumer to
>> decide
>>>>>>>>> to
>>>>>>>>> apply the key or not?" Not sure that I fully understood your
>>>>>>>>> question.
>>>>>>>>> The
>>>>>>>>> consumer just reads whatever key is in the log. The bloom filter
>> just
>>>>>>>>> helps
>>>>>>>>> clean up the old keys.
>>>>>>>>>
>>>>>>>>> 61. "Why can we afford having a topic where its apparently not
>>>>>>>>> possible
>>>>>>>>> to
>>>>>>>>> start a new application on? I think this is an overall flaw of the
>>>>>>>>> discussed idea here. Not playing attention to the overall
>>>>>>>>> architecture."
>>>>>>>>> Could you explain a bit more when one can't start a new
>> application?
>>>>>>>>> Jun
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> On Sat, Mar 10, 2018 at 1:40 AM, Jan Filipiak <
>>>>>>>>> Jan.Filipiak@trivago.com
>>>>>>>>> wrote:
>>>>>>>>>
>>>>>>>>> Hi Jun, thanks for your mail.
>>>>>>>>>
>>>>>>>>> Thank you for your questions!
>>>>>>>>>> I think they are really good and tackle the core of the problem I
>>>>>>>>>> see.
>>>>>>>>>>
>>>>>>>>>> I will answer inline, mostly but still want to set the tone here.
>>>>>>>>>>
>>>>>>>>>> The core strength of kafka is what Martin once called the
>>>>>>>>>> kappa-Architecture. How does this work?
>>>>>>>>>> You have everything as a log as in kafka. When you need to change
>>>>>>>>>> something.
>>>>>>>>>> You create the new version of your application and leave it
>> running
>>>>>>>>>> in
>>>>>>>>>> parallel.
>>>>>>>>>> Once the new version is good you switch your users to use the new
>>>>>>>>>> application.
>>>>>>>>>>
>>>>>>>>>> The online reshuffling effectively breaks this architecture and I
>>>>>>>>>> think
>>>>>>>>>> the switch in thinking here is more harmful
>>>>>>>>>> than any details about the partitioning function to allow such a
>>>>>>>>>> change.
>>>>>>>>>> I
>>>>>>>>>> feel with my suggestion we are the closest to
>>>>>>>>>> the original and battle proven architecture and I can only warn to
>>>>>>>>>> move
>>>>>>>>>> away from it.
>>>>>>>>>>
>>>>>>>>>> I might have forgotten something, sometimes its hard for me to
>>>>>>>>>> getting
>>>>>>>>>> all
>>>>>>>>>> the thoughts captured in a mail, but I hope the comments inline
>> will
>>>>>>>>>> further make my concern clear, and put some emphasis on why I
>>>>>>>>>> prefer my
>>>>>>>>>> solution ;)
>>>>>>>>>>
>>>>>>>>>> One thing we should all be aware of when discussing this, and I
>>>>>>>>>> think
>>>>>>>>>> Dong
>>>>>>>>>> should have mentioned it (maybe he did).
>>>>>>>>>> We are not discussing all of this out of thin air but there is an
>>>>>>>>>> effort
>>>>>>>>>> in the Samza project.
>>>>>>>>>>
>>>>>>>>>> https://cwiki.apache.org/confluence/display/SAMZA/SEP-5%3A+
>>>>>>>>>> Enable+partition+expansion+of+input+streams
>>>>>>>>>> https://issues.apache.org/jira/browse/SAMZA-1293
>>>>>>>>>>
>>>>>>>>>> To be clear. I think SEP-5 (state of last week, dont know if it
>>>>>>>>>> adapted
>>>>>>>>>> to
>>>>>>>>>> this discussion) is on a way better path than KIP-253, and I can't
>>>>>>>>>> really
>>>>>>>>>> explain why.
>>>>>>>>>>
>>>>>>>>>> Best Jan,
>>>>>>>>>>
>>>>>>>>>> nice weekend everyone
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> On 09.03.2018 03:36, Jun Rao wrote:
>>>>>>>>>>
>>>>>>>>>> Hi, Jan,
>>>>>>>>>>
>>>>>>>>>> Thanks for the feedback. Just some comments on the earlier points
>>>>>>>>>>> that
>>>>>>>>>>> you
>>>>>>>>>>> mentioned.
>>>>>>>>>>>
>>>>>>>>>>> 50. You brought up the question of whether existing data needs to
>>>>>>>>>>> be
>>>>>>>>>>> copied
>>>>>>>>>>> during partition expansion. My understand of your view is that
>>>>>>>>>>> avoid
>>>>>>>>>>> copying existing data will be more efficient, but it doesn't work
>>>>>>>>>>> well
>>>>>>>>>>> with
>>>>>>>>>>> compacted topics since some keys in the original partitions will
>>>>>>>>>>> never
>>>>>>>>>>> be
>>>>>>>>>>> cleaned. It would be useful to understand your use case of
>>>>>>>>>>> compacted
>>>>>>>>>>> topics
>>>>>>>>>>> a bit more. In the common use case, the data volume in a
>> compacted
>>>>>>>>>>> topic
>>>>>>>>>>> may not be large. So, I am not sure if there is a strong need to
>>>>>>>>>>> expand
>>>>>>>>>>> partitions in a compacted topic, at least initially.
>>>>>>>>>>>
>>>>>>>>>>> I do agree. State is usually smaller. Update rates might be also
>>>>>>>>>>>
>>>>>>>>>>> competitively high.
>>>>>>>>>> Doing Log-compaction (even beeing very efficient and configurable)
>>>>>>>>>> is
>>>>>>>>>> also
>>>>>>>>>> a more expensive operation than
>>>>>>>>>> just discarding old segments. Further if you want to use more
>>>>>>>>>> consumers
>>>>>>>>>> processing the events
>>>>>>>>>> you also have to grow the number of partitions. Especially for
>>>>>>>>>> use-cases
>>>>>>>>>> we do (KIP-213) a tiny state full
>>>>>>>>>> table might be very expensive to process if it joins against a
>> huge
>>>>>>>>>> table.
>>>>>>>>>>
>>>>>>>>>> I can just say we have been in the spot of needing to grow log
>>>>>>>>>> compacted
>>>>>>>>>> topics. Mainly for processing power we can bring to the table.
>>>>>>>>>>
>>>>>>>>>> Further i am not at all concerned about the extra spaced used by
>>>>>>>>>> "garbage
>>>>>>>>>> keys". I am more concerned about the correctness of innocent
>>>>>>>>>> consumers.
>>>>>>>>>> The
>>>>>>>>>> logic becomes complicated. Say for streams one would need to load
>>>>>>>>>> the
>>>>>>>>>> record into state but not forward it the topology ( to have it
>>>>>>>>>> available
>>>>>>>>>> for shuffeling). I rather have it simple and a topic clean
>>>>>>>>>> regardless
>>>>>>>>>> if
>>>>>>>>>> it
>>>>>>>>>> still has its old partition count. Especially with multiple
>>>>>>>>>> partitions
>>>>>>>>>> growth's I think it becomes insanely hard to to this shuffle
>>>>>>>>>> correct.
>>>>>>>>>> Maybe
>>>>>>>>>> Streams and Samza can do it. Especially if you do "hipster stream
>>>>>>>>>> processing" <https://www.confluent.io/blog
>>>>>>>>>> /introducing-kafka-streams-
>>>>>>>>>> stream-processing-made-simple/>. This makes kafka way to
>>>>>>>>>> complicated.
>>>>>>>>>> With my approach I think its way simpler because the topic has no
>>>>>>>>>> "history"
>>>>>>>>>> in terms of partitioning but is always clean.
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> 51. "Growing the topic by an integer factor does not require any
>>>>>>>>>> state
>>>>>>>>>>
>>>>>>>>>> redistribution at all." Could you clarify this a bit more? Let's
>> say
>>>>>>>>>>> you
>>>>>>>>>>> have a consumer app that computes the windowed count per key. If
>>>>>>>>>>> you
>>>>>>>>>>> double
>>>>>>>>>>> the number of partitions from 1 to 2 and grow the consumer
>>>>>>>>>>> instances
>>>>>>>>>>> from
>>>>>>>>>>> 1
>>>>>>>>>>> to 2, we would need to redistribute some of the counts to the new
>>>>>>>>>>> consumer
>>>>>>>>>>> instance. Regarding to linear hashing, it's true that it won't
>>>>>>>>>>> solve
>>>>>>>>>>> the
>>>>>>>>>>> problem with compacted topics. The main benefit is that it
>>>>>>>>>>> redistributes
>>>>>>>>>>> the keys in one partition to no more than two partitions, which
>>>>>>>>>>> could
>>>>>>>>>>> help
>>>>>>>>>>> redistribute the state.
>>>>>>>>>>>
>>>>>>>>>>> You don't need to spin up a new consumer in this case. every
>>>>>>>>>>> consumer
>>>>>>>>>>>
>>>>>>>>>>> would just read every partition with the (partition % num_task)
>>>>>>>>>> task.
>>>>>>>>>> it
>>>>>>>>>> will still have the previous data right there and can go on.
>>>>>>>>>>
>>>>>>>>>> This sounds contradictory to what I said before, but please bear
>>>>>>>>>> with
>>>>>>>>>> me.
>>>>>>>>>>
>>>>>>>>>> 52. Good point on coordinating the expansion of 2 topics that need
>>>>>>>>>> to
>>>>>>>>>> be
>>>>>>>>>>
>>>>>>>>>> joined together. This is where the 2-phase partition expansion
>> could
>>>>>>>>>>> potentially help. In the first phase, we could add new partitions
>>>>>>>>>>> to
>>>>>>>>>>> the 2
>>>>>>>>>>> topics one at a time but without publishing to the new patitions.
>>>>>>>>>>> Then,
>>>>>>>>>>> we
>>>>>>>>>>> can add new consumer instances to pick up the new partitions. In
>>>>>>>>>>> this
>>>>>>>>>>> transition phase, no reshuffling is needed since no data is
>> coming
>>>>>>>>>>> from
>>>>>>>>>>> the
>>>>>>>>>>> new partitions. Finally, we can enable the publishing to the new
>>>>>>>>>>> partitions.
>>>>>>>>>>>
>>>>>>>>>>> I think its even worse than you think. I would like to introduce
>>>>>>>>>>> the
>>>>>>>>>>>
>>>>>>>>>>> Term
>>>>>>>>>> transitive copartitioning. Imagine
>>>>>>>>>> 2 streams application. One joins (A,B) the other (B,C) then there
>>>>>>>>>> is a
>>>>>>>>>> transitive copartition requirement for
>>>>>>>>>> (A,C) to be copartitioned aswell. This can spread significantly
>> and
>>>>>>>>>> require many consumers to adapt at the same time.
>>>>>>>>>>
>>>>>>>>>> It is also not entirely clear to me how you not need reshuffling
>> in
>>>>>>>>>> this
>>>>>>>>>> case. If A has a record that never gets updated after the
>> expansion
>>>>>>>>>> and
>>>>>>>>>> the
>>>>>>>>>> coresponding B record moves to a new partition. How shall they
>> meet
>>>>>>>>>> w/o
>>>>>>>>>> shuffle?
>>>>>>>>>>
>>>>>>>>>> 53. "Migrating consumer is a step that might be made completly
>>>>>>>>>>
>>>>>>>>>> unnecessary
>>>>>>>>>>> if - for example streams - takes the gcd as partitioning scheme
>>>>>>>>>>> instead
>>>>>>>>>>> of
>>>>>>>>>>> enforcing 1 to 1." Not sure that I fully understand this. I think
>>>>>>>>>>> you
>>>>>>>>>>> mean
>>>>>>>>>>> that a consumer application can run more instances than the
>> number
>>>>>>>>>>> of
>>>>>>>>>>> partitions. In that case, the consumer can just repartitioning
>> the
>>>>>>>>>>> input
>>>>>>>>>>> data according to the number of instances. This is possible, but
>>>>>>>>>>> just
>>>>>>>>>>> has
>>>>>>>>>>> the overhead of reshuffling the data.
>>>>>>>>>>>
>>>>>>>>>>> No what I meant is ( that is also your question i think Mathias)
>>>>>>>>>>> that
>>>>>>>>>>> if
>>>>>>>>>>>
>>>>>>>>>>> you grow a topic by a factor.
>>>>>>>>>> Even if your processor is statefull you can can just assign all
>> the
>>>>>>>>>> multiples of the previous partition to
>>>>>>>>>> this consumer and the state to keep processing correctly will be
>>>>>>>>>> present
>>>>>>>>>> w/o any shuffling.
>>>>>>>>>>
>>>>>>>>>> Say you have an assignment
>>>>>>>>>> Statefull consumer => partition
>>>>>>>>>> 0 => 0
>>>>>>>>>> 1 => 1
>>>>>>>>>> 2 => 2
>>>>>>>>>>
>>>>>>>>>> and you grow you topic by 4 you get,
>>>>>>>>>>
>>>>>>>>>> 0 => 0,3,6,9
>>>>>>>>>> 1 => 1,4,7,10
>>>>>>>>>> 2 => 2,5,8,11
>>>>>>>>>>
>>>>>>>>>> Say your hashcode is 8. 8%3 => 2  before so consumer for
>> partition 2
>>>>>>>>>> has
>>>>>>>>>> it.
>>>>>>>>>> Now you you have 12 partitions so 8%12 => 8, so it goes into
>>>>>>>>>> partition
>>>>>>>>>> 8
>>>>>>>>>> which is assigned to the same consumer
>>>>>>>>>> who had 2 before and therefore knows the key.
>>>>>>>>>>
>>>>>>>>>> Userland reshuffeling is there as an options. And it does exactly
>>>>>>>>>> what
>>>>>>>>>> I
>>>>>>>>>> suggest. And I think its the perfect strategie. All I am
>> suggestion
>>>>>>>>>> is
>>>>>>>>>> broker side support to switch the producers to the newly
>> partitioned
>>>>>>>>>> topic.
>>>>>>>>>> Then the old (to few partition topic) can go away.  Remember the
>>>>>>>>>> list
>>>>>>>>>> of
>>>>>>>>>> steps in the beginning of this thread. If one has broker support
>> for
>>>>>>>>>> all
>>>>>>>>>> where its required and streams support for those that aren’t
>>>>>>>>>> necessarily.
>>>>>>>>>> Then one has solved the problem.
>>>>>>>>>> I repeat it because I think its important. I am really happy that
>>>>>>>>>> you
>>>>>>>>>> brought that up! because its 100% what I want just with the
>>>>>>>>>> differences
>>>>>>>>>> to
>>>>>>>>>> have an option to discard the to small topic later (after all
>>>>>>>>>> consumers
>>>>>>>>>> adapted). And to have order correct there. I need broker support
>>>>>>>>>> managing
>>>>>>>>>> the copy process + the produces and fence them against each
>> other. I
>>>>>>>>>> also
>>>>>>>>>> repeat. the copy process can run for weeks in the worst case.
>>>>>>>>>> Copying
>>>>>>>>>> the
>>>>>>>>>> data is not the longest task migrating consumers might very well
>> be.
>>>>>>>>>> Once all consumers switched and copying is really up to date
>> (think
>>>>>>>>>> ISR
>>>>>>>>>> like up to date) only then we stop the producer, wait for the copy
>>>>>>>>>> to
>>>>>>>>>> finish and use the new topic for producing.
>>>>>>>>>>
>>>>>>>>>> After this the topic is perfect in shape. and no one needs to
>> worry
>>>>>>>>>> about
>>>>>>>>>> complicated stuff. (old keys hanging around might arrive in some
>>>>>>>>>> other
>>>>>>>>>> topic later.....). can only imagine how many tricky bugs gonna
>>>>>>>>>> arrive
>>>>>>>>>> after
>>>>>>>>>> someone had grown and shrunken is topic 10 times.
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> 54. "The other thing I wanted to mention is that I believe the
>>>>>>>>>> current
>>>>>>>>>>
>>>>>>>>>> suggestion (without copying data over) can be implemented in pure
>>>>>>>>>>> userland
>>>>>>>>>>> with a custom partitioner and a small feedbackloop from
>>>>>>>>>>> ProduceResponse
>>>>>>>>>>> =>
>>>>>>>>>>> Partitionier in coorporation with a change management system." I
>> am
>>>>>>>>>>> not
>>>>>>>>>>> sure a customized partitioner itself solves the problem. We
>>>>>>>>>>> probably
>>>>>>>>>>> need
>>>>>>>>>>> some broker side support to enforce when the new partitions can
>> be
>>>>>>>>>>> used.
>>>>>>>>>>> We
>>>>>>>>>>> also need some support on the consumer/kstream side to preserve
>> the
>>>>>>>>>>> per
>>>>>>>>>>> key
>>>>>>>>>>> ordering and potentially migrate the processing state. This is
>> not
>>>>>>>>>>> trivial
>>>>>>>>>>> and I am not sure if it's ideal to fully push to the application
>>>>>>>>>>> space.
>>>>>>>>>>>
>>>>>>>>>>> Broker support is defenitly the preferred way here. I have
>> nothing
>>>>>>>>>>> against
>>>>>>>>>> broker support.
>>>>>>>>>> I tried to say that for what I would preffer - copying the data
>>>>>>>>>> over,
>>>>>>>>>> at
>>>>>>>>>> least for log compacted topics -
>>>>>>>>>> I would require more broker support than the KIP currently offers.
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> Jun
>>>>>>>>>>
>>>>>>>>>> On Tue, Mar 6, 2018 at 10:33 PM, Jan Filipiak <
>>>>>>>>>>> Jan.Filipiak@trivago.com
>>>>>>>>>>> wrote:
>>>>>>>>>>>
>>>>>>>>>>> Hi Dong,
>>>>>>>>>>>
>>>>>>>>>>> are you actually reading my emails, or are you just using the
>>>>>>>>>>> thread I
>>>>>>>>>>>
>>>>>>>>>>>> started for general announcements regarding the KIP?
>>>>>>>>>>>>
>>>>>>>>>>>> I tried to argue really hard against linear hashing. Growing the
>>>>>>>>>>>> topic
>>>>>>>>>>>> by
>>>>>>>>>>>> an integer factor does not require any state redistribution at
>>>>>>>>>>>> all. I
>>>>>>>>>>>> fail
>>>>>>>>>>>> to see completely where linear hashing helps on log compacted
>>>>>>>>>>>> topics.
>>>>>>>>>>>>
>>>>>>>>>>>> If you are not willing to explain to me what I might be
>>>>>>>>>>>> overlooking:
>>>>>>>>>>>> that
>>>>>>>>>>>> is fine.
>>>>>>>>>>>> But I ask you to not reply to my emails then. Please understand
>> my
>>>>>>>>>>>> frustration with this.
>>>>>>>>>>>>
>>>>>>>>>>>> Best Jan
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>> On 06.03.2018 19:38, Dong Lin wrote:
>>>>>>>>>>>>
>>>>>>>>>>>> Hi everyone,
>>>>>>>>>>>>
>>>>>>>>>>>> Thanks for all the comments! It appears that everyone prefers
>>>>>>>>>>>> linear
>>>>>>>>>>>>
>>>>>>>>>>>>> hashing because it reduces the amount of state that needs to be
>>>>>>>>>>>>> moved
>>>>>>>>>>>>> between consumers (for stream processing). The KIP has been
>>>>>>>>>>>>> updated
>>>>>>>>>>>>> to
>>>>>>>>>>>>> use
>>>>>>>>>>>>> linear hashing.
>>>>>>>>>>>>>
>>>>>>>>>>>>> Regarding the migration endeavor: it seems that migrating
>>>>>>>>>>>>> producer
>>>>>>>>>>>>> library
>>>>>>>>>>>>> to use linear hashing should be pretty straightforward without
>>>>>>>>>>>>> much operational endeavor. If we don't upgrade client library
>> to
>>>>>>>>>>>>> use
>>>>>>>>>>>>> this
>>>>>>>>>>>>> KIP, we can not support in-order delivery after partition is
>>>>>>>>>>>>> changed
>>>>>>>>>>>>> anyway. Suppose we upgrade client library to use this KIP, if
>>>>>>>>>>>>> partition
>>>>>>>>>>>>> number is not changed, the key -> partition mapping will be
>>>>>>>>>>>>> exactly
>>>>>>>>>>>>> the
>>>>>>>>>>>>> same as it is now because it is still determined using
>>>>>>>>>>>>> murmur_hash(key)
>>>>>>>>>>>>> %
>>>>>>>>>>>>> original_partition_num. In other words, this change is backward
>>>>>>>>>>>>> compatible.
>>>>>>>>>>>>>
>>>>>>>>>>>>> Regarding the load distribution: if we use linear hashing, the
>>>>>>>>>>>>> load
>>>>>>>>>>>>> may
>>>>>>>>>>>>> be
>>>>>>>>>>>>> unevenly distributed because those partitions which are not
>> split
>>>>>>>>>>>>> may
>>>>>>>>>>>>> receive twice as much traffic as other partitions that are
>> split.
>>>>>>>>>>>>> This
>>>>>>>>>>>>> issue can be mitigated by creating topic with partitions that
>> are
>>>>>>>>>>>>> several
>>>>>>>>>>>>> times the number of consumers. And there will be no imbalance
>> if
>>>>>>>>>>>>> the
>>>>>>>>>>>>> partition number is always doubled. So this imbalance seems
>>>>>>>>>>>>> acceptable.
>>>>>>>>>>>>>
>>>>>>>>>>>>> Regarding storing the partition strategy as per-topic config:
>> It
>>>>>>>>>>>>> seems
>>>>>>>>>>>>> not
>>>>>>>>>>>>> necessary since we can still use murmur_hash as the default
>> hash
>>>>>>>>>>>>> function
>>>>>>>>>>>>> and additionally apply the linear hashing algorithm if the
>>>>>>>>>>>>> partition
>>>>>>>>>>>>> number
>>>>>>>>>>>>> has increased. Not sure if there is any use-case for producer
>> to
>>>>>>>>>>>>> use a
>>>>>>>>>>>>> different hash function. Jason, can you check if there is some
>>>>>>>>>>>>> use-case
>>>>>>>>>>>>> that I missed for using the per-topic partition strategy?
>>>>>>>>>>>>>
>>>>>>>>>>>>> Regarding how to reduce latency (due to state store/load) in
>>>>>>>>>>>>> stream
>>>>>>>>>>>>> processing consumer when partition number changes: I need to
>> read
>>>>>>>>>>>>> the
>>>>>>>>>>>>> Kafka
>>>>>>>>>>>>> Stream code to understand how Kafka Stream currently migrate
>>>>>>>>>>>>> state
>>>>>>>>>>>>> between
>>>>>>>>>>>>> consumers when the application is added/removed for a given
>> job.
>>>>>>>>>>>>> I
>>>>>>>>>>>>> will
>>>>>>>>>>>>> reply after I finish reading the documentation and code.
>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>> Thanks,
>>>>>>>>>>>>> Dong
>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>> On Mon, Mar 5, 2018 at 10:43 AM, Jason Gustafson <
>>>>>>>>>>>>> jason@confluent.io>
>>>>>>>>>>>>> wrote:
>>>>>>>>>>>>>
>>>>>>>>>>>>> Great discussion. I think I'm wondering whether we can continue
>>>>>>>>>>>>> to
>>>>>>>>>>>>> leave
>>>>>>>>>>>>>
>>>>>>>>>>>>> Kafka agnostic to the partitioning strategy. The challenge is
>>>>>>>>>>>>>
>>>>>>>>>>>>> communicating
>>>>>>>>>>>>>> the partitioning logic from producers to consumers so that the
>>>>>>>>>>>>>> dependencies
>>>>>>>>>>>>>> between each epoch can be determined. For the sake of
>>>>>>>>>>>>>> discussion,
>>>>>>>>>>>>>> imagine
>>>>>>>>>>>>>> you did something like the following:
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> 1. The name (and perhaps version) of a partitioning strategy
>> is
>>>>>>>>>>>>>> stored
>>>>>>>>>>>>>> in
>>>>>>>>>>>>>> topic configuration when a topic is created.
>>>>>>>>>>>>>> 2. The producer looks up the partitioning strategy before
>>>>>>>>>>>>>> writing
>>>>>>>>>>>>>> to
>>>>>>>>>>>>>> a
>>>>>>>>>>>>>> topic and includes it in the produce request (for fencing). If
>>>>>>>>>>>>>> it
>>>>>>>>>>>>>> doesn't
>>>>>>>>>>>>>> have an implementation for the configured strategy, it fails.
>>>>>>>>>>>>>> 3. The consumer also looks up the partitioning strategy and
>>>>>>>>>>>>>> uses it
>>>>>>>>>>>>>> to
>>>>>>>>>>>>>> determine dependencies when reading a new epoch. It could
>> either
>>>>>>>>>>>>>> fail
>>>>>>>>>>>>>> or
>>>>>>>>>>>>>> make the most conservative dependency assumptions if it
>> doesn't
>>>>>>>>>>>>>> know
>>>>>>>>>>>>>> how
>>>>>>>>>>>>>> to
>>>>>>>>>>>>>> implement the partitioning strategy. For the consumer, the new
>>>>>>>>>>>>>> interface
>>>>>>>>>>>>>> might look something like this:
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> // Return the partition dependencies following an epoch bump
>>>>>>>>>>>>>> Map<Integer, List<Integer>> dependencies(int
>>>>>>>>>>>>>> numPartitionsBeforeEpochBump,
>>>>>>>>>>>>>> int numPartitionsAfterEpochBump)
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> The unordered case then is just a particular implementation
>>>>>>>>>>>>>> which
>>>>>>>>>>>>>> never
>>>>>>>>>>>>>> has
>>>>>>>>>>>>>> any epoch dependencies. To implement this, we would need some
>>>>>>>>>>>>>> way
>>>>>>>>>>>>>> for
>>>>>>>>>>>>>> the
>>>>>>>>>>>>>> consumer to find out how many partitions there were in each
>>>>>>>>>>>>>> epoch,
>>>>>>>>>>>>>> but
>>>>>>>>>>>>>> maybe that's not too unreasonable.
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> Thanks,
>>>>>>>>>>>>>> Jason
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> On Mon, Mar 5, 2018 at 4:51 AM, Jan Filipiak <
>>>>>>>>>>>>>> Jan.Filipiak@trivago.com
>>>>>>>>>>>>>> wrote:
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> Hi Dong
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> thank you very much for your questions.
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> regarding the time spend copying data across:
>>>>>>>>>>>>>>> It is correct that copying data from a topic with one
>> partition
>>>>>>>>>>>>>>> mapping
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> to
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> a topic with a different partition mapping takes way longer
>>>>>>>>>>>>>>> than
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>> we
>>>>>>>>>>>>>> can
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> stop producers. Tens of minutes is a very optimistic estimate
>>>>>>>>>>>>>> here.
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> Many
>>>>>>>>>>>>>>> people can not afford copy full steam and therefore will have
>>>>>>>>>>>>>>> some
>>>>>>>>>>>>>>> rate
>>>>>>>>>>>>>>> limiting in place, this can bump the timespan into the day's.
>>>>>>>>>>>>>>> The
>>>>>>>>>>>>>>> good
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> part
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> is that the vast majority of the data can be copied while the
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>> producers
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> are
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> still going. One can then, piggyback the consumers ontop of
>>>>>>>>>>>>>>> this
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>> timeframe,
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> by the method mentioned (provide them an mapping from their
>> old
>>>>>>>>>>>>>> offsets
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> to
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> new offsets in their repartitioned topics. In that way we
>>>>>>>>>>>>>>> separate
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>> migration of consumers from migration of producers (decoupling
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> these
>>>>>>>>>>>>>>> is
>>>>>>>>>>>>>>> what kafka is strongest at). The time to actually swap over
>> the
>>>>>>>>>>>>>>> producers
>>>>>>>>>>>>>>> should be kept minimal by ensuring that when a swap attempt
>> is
>>>>>>>>>>>>>>> started
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> the
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> consumer copying over should be very close to the log end and
>>>>>>>>>>>>>>> is
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>> expected
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> to finish within the next fetch. The operation should have a
>>>>>>>>>>>>>>> time-out
>>>>>>>>>>>>>>> and
>>>>>>>>>>>>>>> should be "reattemtable".
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> Importance of logcompaction:
>>>>>>>>>>>>>>> If a producer produces key A, to partiton 0, its forever
>> gonna
>>>>>>>>>>>>>>> be
>>>>>>>>>>>>>>> there,
>>>>>>>>>>>>>>> unless it gets deleted. The record might sit in there for
>>>>>>>>>>>>>>> years. A
>>>>>>>>>>>>>>> new
>>>>>>>>>>>>>>> producer started with the new partitions will fail to delete
>>>>>>>>>>>>>>> the
>>>>>>>>>>>>>>> record
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> in
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> the correct partition. Th record will be there forever and
>> one
>>>>>>>>>>>>>>> can
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>> not
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> reliable bootstrap new consumers. I cannot see how linear
>>>>>>>>>>>>>> hashing
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> can
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> solve
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> this.
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>> Regarding your skipping of userland copying:
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> 100%, copying the data across in userland is, as far as i can
>>>>>>>>>>>>>>> see,
>>>>>>>>>>>>>>> only
>>>>>>>>>>>>>>> a
>>>>>>>>>>>>>>> usecase for log compacted topics. Even for logcompaction +
>>>>>>>>>>>>>>> retentions
>>>>>>>>>>>>>>> it
>>>>>>>>>>>>>>> should only be opt-in. Why did I bring it up? I think log
>>>>>>>>>>>>>>> compaction
>>>>>>>>>>>>>>> is
>>>>>>>>>>>>>>> a
>>>>>>>>>>>>>>> very important feature to really embrace kafka as a "data
>>>>>>>>>>>>>>> plattform".
>>>>>>>>>>>>>>> The
>>>>>>>>>>>>>>> point I also want to make is that copying data this way is
>>>>>>>>>>>>>>> completely
>>>>>>>>>>>>>>> inline with the kafka architecture. it only consists of
>> reading
>>>>>>>>>>>>>>> and
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> writing
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> to topics.
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>> I hope it clarifies more why I think we should aim for more
>> than
>>>>>>>>>>>>>>> the
>>>>>>>>>>>>>>> current KIP. I fear that once the KIP is done not much more
>>>>>>>>>>>>>>> effort
>>>>>>>>>>>>>>> will
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> be
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> taken.
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>> On 04.03.2018 02:28, Dong Lin wrote:
>>>>>>>>>>>>>>> Hey Jan,
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> In the current proposal, the consumer will be blocked on
>>>>>>>>>>>>>>> waiting
>>>>>>>>>>>>>>> for
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> other
>>>>>>>>>>>>>>>> consumers of the group to consume up to a given offset. In
>>>>>>>>>>>>>>>> most
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> cases,
>>>>>>>>>>>>>>> all
>>>>>>>>>>>>>>> consumers should be close to the LEO of the partitions when
>> the
>>>>>>>>>>>>>>> partition
>>>>>>>>>>>>>>> expansion happens. Thus the time waiting should not be long
>>>>>>>>>>>>>>> e.g.
>>>>>>>>>>>>>>> on
>>>>>>>>>>>>>>> the
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> order of seconds. On the other hand, it may take a long time
>> to
>>>>>>>>>>>>>>> wait
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> for
>>>>>>>>>>>>>>>> the entire partition to be copied -- the amount of time is
>>>>>>>>>>>>>>>> proportional
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> to
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> the amount of existing data in the partition, which can take
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> tens of
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> minutes. So the amount of time that we stop consumers may not
>>>>>>>>>>>>>>> be
>>>>>>>>>>>>>>> on
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> the
>>>>>>>>>>>>>>>> same order of magnitude.
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> If we can implement this suggestion without copying data
>> over
>>>>>>>>>>>>>>>> in
>>>>>>>>>>>>>>>> purse
>>>>>>>>>>>>>>>> userland, it will be much more valuable. Do you have ideas
>> on
>>>>>>>>>>>>>>>> how
>>>>>>>>>>>>>>>> this
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> can
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> be done?
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> Not sure why the current KIP not help people who depend on
>> log
>>>>>>>>>>>>>>> compaction.
>>>>>>>>>>>>>>>> Could you elaborate more on this point?
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> Thanks,
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> Dong
>>>>>>>>>>>>>>>> On Wed, Feb 28, 2018 at 10:55 PM, Jan
>>>>>>>>>>>>>>>> Filipiak<Jan.Filipiak@trivago.
>>>>>>>>>>>>>>>> com
>>>>>>>>>>>>>>>> wrote:
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> Hi Dong,
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> I tried to focus on what the steps are one can currently
>>>>>>>>>>>>>>>> perform
>>>>>>>>>>>>>>>> to
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> expand
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> or shrink a keyed topic while maintaining a top notch
>>>>>>>>>>>>>>>>> semantics.
>>>>>>>>>>>>>>>>> I can understand that there might be confusion about
>>>>>>>>>>>>>>>>> "stopping
>>>>>>>>>>>>>>>>> the
>>>>>>>>>>>>>>>>> consumer". It is exactly the same as proposed in the KIP.
>>>>>>>>>>>>>>>>> there
>>>>>>>>>>>>>>>>> needs
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> to
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> be
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> a time the producers agree on the new partitioning. The
>> extra
>>>>>>>>>>>>>>> semantics I
>>>>>>>>>>>>>>>>> want to put in there is that we have a possibility to wait
>>>>>>>>>>>>>>>>> until
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> all
>>>>>>>>>>>>>>> the
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> existing data
>>>>>>>>>>>>>>>> is copied over into the new partitioning scheme. When I say
>>>>>>>>>>>>>>> stopping
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> I
>>>>>>>>>>>>>>>>> think more of having a memory barrier that ensures the
>>>>>>>>>>>>>>>>> ordering. I
>>>>>>>>>>>>>>>>> am
>>>>>>>>>>>>>>>>> still
>>>>>>>>>>>>>>>>> aming for latencies  on the scale of leader failovers.
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> Consumers have to explicitly adapt the new partitioning
>>>>>>>>>>>>>>>>> scheme
>>>>>>>>>>>>>>>>> in
>>>>>>>>>>>>>>>>> the
>>>>>>>>>>>>>>>>> above scenario. The reason is that in these cases where you
>>>>>>>>>>>>>>>>> are
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> dependent
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> on a particular partitioning scheme, you also have other
>>>>>>>>>>>>>>>>> topics
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> that
>>>>>>>>>>>>>>> have
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> co-partition enforcements or the kind -frequently. Therefore
>>>>>>>>>>>>>>>> all
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> your
>>>>>>>>>>>>>>> other
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> input topics might need to grow accordingly.
>>>>>>>>>>>>>>>>> What I was suggesting was to streamline all these
>> operations
>>>>>>>>>>>>>>>>> as
>>>>>>>>>>>>>>>>> best
>>>>>>>>>>>>>>>>> as
>>>>>>>>>>>>>>>>> possible to have "real" partition grow and shrinkage going
>>>>>>>>>>>>>>>>> on.
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> Migrating
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> the producers to a new partitioning scheme can be much more
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> streamlined
>>>>>>>>>>>>>>> with proper broker support for this. Migrating consumer is a
>>>>>>>>>>>>>>> step
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> that
>>>>>>>>>>>>>>>>> might be made completly unnecessary if - for example
>> streams
>>>>>>>>>>>>>>>>> -
>>>>>>>>>>>>>>>>> takes
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> the
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> gcd as partitioning scheme instead of enforcing 1 to 1.
>>>>>>>>>>>>>>>>> Connect
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> consumers
>>>>>>>>>>>>>>> and other consumers should be fine anyways.
>>>>>>>>>>>>>>>> I hope this makes more clear where I was aiming at. The rest
>>>>>>>>>>>>>>> needs
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> to
>>>>>>>>>>>>>>>> be
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> figured out. The only danger i see is that when we are
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> introducing
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> this
>>>>>>>>>>>>>>> feature as supposed in the KIP, it wont help any people
>>>>>>>>>>>>>>> depending
>>>>>>>>>>>>>>> on
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> log
>>>>>>>>>>>>>>>>> compaction.
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> The other thing I wanted to mention is that I believe the
>>>>>>>>>>>>>>> current
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> suggestion (without copying data over) can be implemented in
>>>>>>>>>>>>>>>> pure
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> userland
>>>>>>>>>>>>>>>>> with a custom partitioner and a small feedbackloop from
>>>>>>>>>>>>>>>>> ProduceResponse
>>>>>>>>>>>>>>>>> =>
>>>>>>>>>>>>>>>>> Partitionier in coorporation with a change management
>> system.
>>>>>>>>>>>>>>>>> Best Jan
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> On 28.02.2018 07:13, Dong Lin wrote:
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> Hey Jan,
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> I am not sure if it is acceptable for producer to be
>> stopped
>>>>>>>>>>>>>>>>> for a
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> while,
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> particularly for online application which requires low
>>>>>>>>>>>>>>>>>> latency. I
>>>>>>>>>>>>>>>>>> am
>>>>>>>>>>>>>>>>>> also
>>>>>>>>>>>>>>>>>> not sure how consumers can switch to a new topic. Does
>> user
>>>>>>>>>>>>>>>>>> application
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> needs to explicitly specify a different topic for
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> producer/consumer
>>>>>>>>>>>>>>>> to
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> subscribe to? It will be helpful for discussion if you can
>>>>>>>>>>>>>>> provide
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> more
>>>>>>>>>>>>>>>>> detail on the interface change for this solution.
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> Thanks,
>>>>>>>>>>>>>>>> Dong
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> On Mon, Feb 26, 2018 at 12:48 AM, Jan
>>>>>>>>>>>>>>>>>> Filipiak<Jan.Filipiak@trivago.
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> com
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> wrote:
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> Hi,
>>>>>>>>>>>>>>>> just want to throw my though in. In general the
>> functionality
>>>>>>>>>>>>>>>> is
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> very
>>>>>>>>>>>>>>>>>> usefull, we should though not try to find the architecture
>>>>>>>>>>>>>>>>>> to
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> hard
>>>>>>>>>>>>>>>>>>> while
>>>>>>>>>>>>>>>>>>> implementing.
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>> The manual steps would be to
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>> create a new topic
>>>>>>>>>>>>>>>>>>> the mirrormake from the new old topic to the new topic
>>>>>>>>>>>>>>>>>>> wait for mirror making to catch up.
>>>>>>>>>>>>>>>>>>> then put the consumers onto the new topic
>>>>>>>>>>>>>>>>>>>             (having mirrormaker spit out a mapping from
>> old
>>>>>>>>>>>>>>>>>>> offsets to
>>>>>>>>>>>>>>>>>>> new
>>>>>>>>>>>>>>>>>>> offsets:
>>>>>>>>>>>>>>>>>>>                 if topic is increased by factor X there is
>>>>>>>>>>>>>>>>>>> gonna
>>>>>>>>>>>>>>>>>>> be a
>>>>>>>>>>>>>>>>>>> clean
>>>>>>>>>>>>>>>>>>> mapping from 1 offset in the old topic to X offsets in
>> the
>>>>>>>>>>>>>>>>>>> new
>>>>>>>>>>>>>>>>>>> topic,
>>>>>>>>>>>>>>>>>>>                 if there is no factor then there is no
>>>>>>>>>>>>>>>>>>> chance to
>>>>>>>>>>>>>>>>>>> generate a
>>>>>>>>>>>>>>>>>>> mapping that can be reasonable used for continuing)
>>>>>>>>>>>>>>>>>>>             make consumers stop at appropriate points and
>>>>>>>>>>>>>>>>>>> continue
>>>>>>>>>>>>>>>>>>> consumption
>>>>>>>>>>>>>>>>>>> with offsets from the mapping.
>>>>>>>>>>>>>>>>>>> have the producers stop for a minimal time.
>>>>>>>>>>>>>>>>>>> wait for mirrormaker to finish
>>>>>>>>>>>>>>>>>>> let producer produce with the new metadata.
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>> Instead of implementing the approach suggest in the KIP
>>>>>>>>>>>>>>>>>>> which
>>>>>>>>>>>>>>>>>>> will
>>>>>>>>>>>>>>>>>>> leave
>>>>>>>>>>>>>>>>>>> log compacted topic completely crumbled and unusable.
>>>>>>>>>>>>>>>>>>> I would much rather try to build infrastructure to
>> support
>>>>>>>>>>>>>>>>>>> the
>>>>>>>>>>>>>>>>>>> mentioned
>>>>>>>>>>>>>>>>>>> above operations more smoothly.
>>>>>>>>>>>>>>>>>>> Especially having producers stop and use another topic is
>>>>>>>>>>>>>>>>>>> difficult
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>> and
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>> it would be nice if one can trigger "invalid metadata"
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> exceptions
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> for
>>>>>>>>>>>>>>>> them
>>>>>>>>>>>>>>> and
>>>>>>>>>>>>>>>>> if one could give topics aliases so that their produces
>> with
>>>>>>>>>>>>>>>>>>> the
>>>>>>>>>>>>>>>>>>> old
>>>>>>>>>>>>>>>>>>> topic
>>>>>>>>>>>>>>>>>>> will arrive in the new topic.
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>> The downsides are obvious I guess ( having the same data
>>>>>>>>>>>>>>>>>>> twice
>>>>>>>>>>>>>>>>>>> for
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>> the
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>> transition period, but kafka tends to scale well with
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> datasize).
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> So
>>>>>>>>>>>>>>>>> its a
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> nicer fit into the architecture.
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> I further want to argument that the functionality by the
>> KIP
>>>>>>>>>>>>>>>>>>> can
>>>>>>>>>>>>>>>>>>> completely be implementing in "userland" with a custom
>>>>>>>>>>>>>>>>>>> partitioner
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>> that
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>> handles the transition as needed. I would appreciate if
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> someone
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> could
>>>>>>>>>>>>>>>> point
>>>>>>>>>>>>>>> out what a custom partitioner couldn't handle in this case?
>>>>>>>>>>>>>>>>> With the above approach, shrinking a topic becomes the same
>>>>>>>>>>>>>>>>>>> steps.
>>>>>>>>>>>>>>>>>>> Without
>>>>>>>>>>>>>>>>>>> loosing keys in the discontinued partitions.
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>> Would love to hear what everyone thinks.
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>> Best Jan
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>> On 11.02.2018 00:35, Dong Lin wrote:
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>> Hi all,
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>> I have created KIP-253: Support in-order message delivery
>>>>>>>>>>>>>>>>>>> with
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>> partition
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>> expansion. See
>>>>>>>>>>>>>>>>>>>> https://cwiki.apache.org/confl
>>>>>>>>>>>>>>>>>>>> uence/display/KAFKA/KIP-253%
>>>>>>>>>>>>>>>>>>>> 3A+Support+in-order+message+de
>>>>>>>>>>>>>>>>>>>> livery+with+partition+expansio
>>>>>>>>>>>>>>>>>>>> n
>>>>>>>>>>>>>>>>>>>> .
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>> This KIP provides a way to allow messages of the same
>> key
>>>>>>>>>>>>>>>>>>>> from
>>>>>>>>>>>>>>>>>>>> the
>>>>>>>>>>>>>>>>>>>> same
>>>>>>>>>>>>>>>>>>>> producer to be consumed in the same order they are
>>>>>>>>>>>>>>>>>>>> produced
>>>>>>>>>>>>>>>>>>>> even
>>>>>>>>>>>>>>>>>>>> if
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>> we
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>> expand partition of the topic.
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>> Thanks,
>>>>>>>>>>>>>>>>> Dong
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>
>>>>


Re: [DISCUSS] KIP-253: Support in-order message delivery with partition expansion

Posted by Jun Rao <ju...@confluent.io>.
Hi, John,

Thanks for the reply. It summarizes the tradeoffs well. At the high level,
there are two general approaches for KStreams. (a) KStreams completely
decouples from the input partitions by over-partitioning. Inside KStreams,
partition expansion is never needed. (b) Over-partitioning is not enough,
KStreams still needs to handle partition expansion at some point.

For (b), I can see that supporting backfills on a compacted topic during
partition expansion could be a useful primitive. The reason is that this
allows KStreams to rebuild the local state more conveniently. The local
state is typically backed by a compacted topic, which can either be the
input topic (e.g., for KTable during a KStream to KTable join) or a change
log topic.

We still need to figure out some of the details of the backfilling.
(1) It seems that this has to be done on the brokers. Clients come and go.
We don't want the backfilling process to stop if a client goes away. This
does mean that the broker needs to know the partitioning function. However,
to your other point, currently the partitioning semantic only happens on
the producer and is not strongly enforced. Knowing the partitioning
function, the broker can potentially enforce the partitioning semantic in a
stronger way.
(2) Your suggestion is to split a partition immediately and backfill later.
Jan's suggestion is to start the backfilling first and split the partition
when backfilling is done. There are tradeoffs between the two, but Jan's
suggestion seems a bit better since it removes an extra step for notifying
the clients when the backfilling is done.
(3) We probably don't want to maintain the offset mapping at the individual
message level between the old and the new version of partitions. Instead,
we can probably just delete the old version of the partition after a
certain amount of time has passed after the partition split. The existing
clients are expected to move the consumption to the new version of the
partition within that window.
(4) We have to figure out how this works when EOS is enabled. In EOS,
transactional managers can add the end marker to a partition. We need to
somehow make sure that those markers are transferred properly.

Since adding backfilling requires some more work, it would be helpful to
figure out how KStreams or other similar places will use it if present.

Jun

On Thu, Mar 29, 2018 at 2:05 PM, John Roesler <jo...@confluent.io> wrote:

> Hi Jun,
>
> Thanks for the response. I'm very new to this project, but I will share my
> perspective. I'm going to say a bunch of stuff that I know you know
> already, but just so we're on the same page...
>
> This may also be a good time to get feedback from the other KStreams folks.
>
> Using KStreams as a reference implementation for how stream processing
> frameworks may interact with Kafka, I think it's important to eschew
> knowledge about how KStreams currently handles internal communication,
> making state durable, etc. Both because these details may change, and
> because they won't be shared with other stream processors.
>
> =================================
> Background
>
> We are looking at a picture like this:
>
>      input input input
>          \   |   /
>       +-------------+
> +-----+ Consumer(s) +-------+
> |     +-------------+       |
> |                           |
> |    KStreams Application   |
> |                           |
> |     +-------------+       |
> +-----+ Producer(s) +-------+
>       +-------------+
>            /    \
>         output output
>
> The inputs and outputs are Kafka topics (and therefore have 1 or more
> partitions). We'd have at least 1 input and 0 or more outputs. The
> Consumers and Producers are both the official KafkaConsumer and
> KafkaProducer.
>
> In general, we'll assume that the input topics are provided by actors over
> which we have no control, although we may as well assume they are friendly
> and amenable to requests, and also that their promises are trustworthy.
> This is important because we must depend on them to uphold some promises:
> * That they tell us the schema of the data they publish, and abide by that
> schema. Without this, the inputs are essentially garbage.
> * That they tell us some defining characteristics of the topics (more on
> this in a sec.) and again strictly abide by that promise.
>
> What are the topic characteristics we care about?
> 1. The name (or name pattern)
> 2. How the messages are keyed (if at all)
> 3. Whether the message timestamps are meaningful, and if so, what their
> meaning is
> 4. Assuming the records have identity, whether the partitions partition the
> records' identity space
> 5. Whether the topic completely contains the data set
> 6. Whether the messages in the topic are ordered
>
> #1 is obvious: without this information, we cannot access the data at all.
>
> For #2, #3, #4, and #6, we may or may not need this information, depending
> on the logic of the application. For example, a trivial application that
> simply counts all events it sees doesn't care about #2, #3, #4, or #6. But
> an application that groups by some attribute can take advantage of #2 and
> #4 if the topic data is already keyed and partitioned over that attribute.
> Likewise, if the application includes some temporal semantics on a temporal
> dimension that is already captured in #3, it may take advantage of that
> fact.
>
> Note that #2, #3, #4, and #6 are all optional. If they are not promised, we
> can do extra work inside the application to accomplish what we need.
> However, if they are promised (and if we depend on that promise), it is
> essential that the topic providers uphold those promises, as we may not be
> in a position to verify them.
>
> Note also that if they make a promise, but it doesn't happen to line up
> with our needs (data is keyed by attr1, but we need it by attr2, or
> timestamp is produce-time, but we need it by event-time, etc.), then we
> will have to go ahead and do that extra work internally anyway. This also
> captures the situation in which two inputs are produced by different
> providers, one of which meets our needs, and the other does not. The fact
> that we can cope with this situation is the basis for my statement that we
> do not require coordination among producers.
>
> (Key Point A): In terms of optimization, #4 and #6 are the most valuable.
> If these characteristics happen to line up with our needs, then KStreams
> can be incredibly efficient in both time and computational resources.
>
>  #5 is similar to knowing the schema in that it tells us whether the
> computation we want to do is possible or not. For example, suppose we have
> a topic of "users", and we want to construct a table for querying. If the
> user topic doesn't completely contain the dataset, we cannot construct the
> table. Note that it doesn't matter whether the topic is compacted or not.
> If the topic is complete, I can consume it starting at "earliest" and build
> my table. If it is not complete, I can do other computations on it. In both
> cases, it may or may not be compacted; it just doesn't matter.
>
> On the output side, the roles are reversed. We provide (or not) exactly the
> same set of guarantees to consumers of our outputs, and we likewise must
> abide by the promises we make.
>
>
> =================================
> Partition Expansion
>
> With this formation in place, let's talk about partition expansion.
>
> Why do we have partitions in the first place? (let me know if I miss
> something here)
> * For logical data streams that are themselves partitionable, it allows
> producers to operate concurrently without coordination. For example,
> streaming data from a sensor in a particle accelerator, the sensor can be
> subdivided into a grid and each grid square can produce independently to a
> different topic. This may be valuable because the total rate of data
> exceeds the throughput to a single broker node or just because it allows
> for failure of a single producer to cause the loss of only part of the
> data.
> * The brokers can offer linearly scaling throughput on the number of
> partitions by hosting each partition on a separate broker node
> * The brokers can host topics that are too large to fit on a single
> broker's storage by hosting some partitions on separate broker nodes
> * In cases where the use case permits handling partitions independently,
> consumers can have algorithmic simplicity by processing the data for
> separate partitions in separate threads, avoiding costly and error-prone
> concurrent coordination code
> * In cases where the use case permits handling partitions independently,
> consumers can exceed the total throughput of a single broker-consumer pair
> * Just to throw this in as well, in cases where some network links are less
> costly than others (or lower latency or more reliable), such as when
> brokers, producers, and consumers are running in racks: producer and
> consumers can both benefit (independently) by locating work on each
> partition in the same rack as the broker hosting that partition.
>
> In other words, we have three actors in this system: producers, brokers,
> and consumers, and they all benefit from partitioning for different (but
> sometimes related) reasons.
>
> This leads naturally to the conclusion that any of these actors may find
> themselves in a sub-optimal or even dangerous situation in which partition
> expansion would be the solution. For example, the producer may find that
> the existing throughput to the brokers is insufficient to match the data
> rate, forcing them to drop data. Or a broker hosting a single partition may
> be running out of disk space. Or a consumer node handling a single
> partition cannot match the rate of production for that partition, causing
> it to fall behind.
>
> I think it's reasonable to assume that all the actors in the system can't
> just arbitrarily expand a topic's partition. I think it's reasonable to
> align this responsibility with the provider of the data, namely the
> producer (the logical producer, not the KafkaProducer class). Therefore,
> the producer who finds themselves in trouble can unilaterally expand
> partitions to solve their problem.
>
> For the broker or a consumer in trouble, they have only one resort: to
> request the producer to expand partitions. This is where it's helpful to
> assume the producer is friendly.
>
>
> Now, let's look at how a KStreams application fits into this scenario.
>
> (Key Point B1): As a consumer, we may find that the producer expands the
> partitions of a topic, either for their own benefit or for the brokers. In
> this situation, the expand operation MUST NOT violate any promises that
> have previously been made to us. This is the essence of KIP-253, to ensure
> the maintenance of promises #6 and #4. It would be great if the mechanics
> of the expansion required no major disruption to processing or human
> intervention.
>
> Specifically, let's say that input partition X splits into X1 and X2. #6
> requires that the same old ordering guarantees of Kafka continue to hold.
> Obviously, this is what KIP-253's title is about. #4 requires that we
> either ensure that X1 and X2 are assigned to the same thread that was
> previously assigned X OR that we immediately pause processing and split any
> state such that it appears X1 and X2 were *always* separate partitions.
>
> In other words, Option 1 is we treat X1 and X2 as still logically one
> partition, equal to X. This is ideal, since in this scenario, partitions
> are expanding for external reasons. We don't need to expand our processing
> to match. Option 2 requires a major disruption, since we'd have to pause
> processing while we split our state. Clearly, KStreams or any other
> stateful consumer would advocate for Option 1.
>
>
> (Corollary to Key Point A): Still on the consumer side, we may find that we
> ourselves can benefit from partition expansion of an input. Since we can
> cope with the absence of promise #4, partition expansion is not a hard
> requirement for us, but assuming we were already benefiting from the major
> performance optimizations afforded by #4, it would be nice to be able to
> request the producer satisfy our request for partition expansion **and to
> be able to benefit from it**.
>
> What does it mean to be able to benefit from partition expansion? Assuming
> input topic partition X splits into X1 and X2, in this scenario, we *would*
> wish to be able to split our state such that it appears X1 and X2 were
> *always* separate partitions. Of course, the conclusion of Key Point B1
> still applies: we should be able to continue operating on (X1+X2 = X) as
> one partition while asynchronously building the state of X1 and X2
> separately.
>
> When it comes to the mechanics of building the state of X1 and X2
> separately, we have really just two high-level options. Either this problem
> is solved by Kafka itself, giving me a view in which X1 and X2 were always
> separate partitions, or I have to do it myself. The latter means that I
> have to take on substantially more complexity than I do today:
> Bummer 1: My state has to be splittable to begin with, implying at the
> least that I need to be able to scan every record in my state, a
> requirement that otherwise does not exist.
> Bummer 2: After splitting the state  of X1 and X2, I need to be able to
> send at least one of those tasks, state included, to another application
> node (in order to realize the benefit of the split). This is also a
> requirement that does not currently exist.
> Bummer 3: In order to actually perform the split, I must know and be able
> to execute the exact same partition function the producer of my topic uses.
> This introduces a brand-new a priori commitment from my input producers:
> (would-be #7: convey the partition function and abide by it). This is a big
> restriction over #4, which only requires them to guarantee *that there is a
> partition function*. Now they actually have to share the function with me.
> And I have to be able to implement and execute it myself. And if the
> producer wishes to refine the partition function for an existing topic, we
> have another round of coordination, as they have to be sure that I, and all
> other consumers, begin using the new function *before* they do. This is
> similar to the schema problem, with a similar set of solutions. We would
> likely need a partition function registry and another magic byte on every
> record to be sure we do this right. Not to mention some way to express
> arbitrary partitioning logic over arbitrary data in a way that is portable
> across programming languages.
>
> Alternatively, if Kafka gives me a view in which X1 and X2 were always
> separate, then I can create tasks for X1 and X2 and allow them to bootstrap
> while I continue to process X. Once they are ready, I can coordinate a
> transition to stop X's task and switch to X1 and X2. None of those bummers
> are present, so this is a significantly better option for me.
>
> (Key Point B2): As a (friendly) producer, we may once again want on our own
> to expand partitions, or we may want to satisfy a request from the broker
> or our consumers to do so. Again, we MUST NOT violate any promises we have
> previously given, and it would be great if the expansion required no major
> disruption to processing or human intervention. Additionally, since we are
> actually driving the expansion, it would also be great if we could avoid
> Bummer 3's coordination problems from the producer's perspective.
>
>
> ======================================
> Briefly: KStreams internals
>
> I'm pretty sure you were asking me to comment on the implementation details
> of KStreams, so I'll say a few words about it. The most important thing is
> that KStreams is still very early in its development. Maybe "early-middle
> maturity" is a good way to put it. We are actively discussing more-or-less
> major implementation changes to improve performance, footprint,
> scalability, and ergonomics. So it may actually be misleading to discuss
> deeply how KStreams internally uses Kafka topics.
>
> Nevertheless, it is currently true that KStreams uses Kafka topics for
> communication between some internal computation nodes. We partition these
> topics as the base unit of concurrency granularity, so it would potentially
> be beneficial to be able to expand partitions for some of these internal
> topics at some point. However, we can alternatively just overpartition
> these internal topics, creating in the low 100s of partitions instead of
> the low 10s, for example. (Side note: if Kafka were someday to support
> higher numbers of partitions, we could expand this scheme to overpartition
> in the 1000s of partitions.) With the option to overpartition, we don't
> have a strong need for partition expansion internally.
>
> It is also currently true that KStreams uses Kafka to store a durable
> changelog for some of our internal state stores. But we *only* read from
> this topic *if* we need to restore a state store after node loss (or to
> maintain a hot mirror of the state store), so I think it's unlikely that we
> would ever make use of partition expansion on the changelog topics.
>
> But once again, I'd like to emphasize that we may choose an alternative
> implementation for either interprocess communication or state durability.
>
>
> ======================================
> Concluding thoughts
>
> I know this is a very long email, and I really appreciate you sticking with
> me this long. I hope it was useful for syncing our mental picture of this
> system. Also, you're far more knowledgeable than I am about this system and
> this domain, so please correct me if I've said anything wrong.
>
> To me the key takeaways are that:
> - KIP-253 satisfies all we need for correctness, since it contains
> solutions to guarantee producers can abide by their promises w.r.t. #4 and
> #6.
> - From Key Point A: #4 is actually optional for KIP-253, but without it, we
> lose a potentially valuable optimization in KStreams (and all other
> consumer applications)
> - From Corollary to Point A: Without low-level support for partition
> expansion with backfill, we cannot employ requesting partition expansion as
> a consumer to improve application performance. In that case, to ensure
> performance scalability, we would have to discard for all KStreams
> applications the performance optimization afforded by #4.
> - From Key Point B1: After a partition split, we really need to be able to
> seamlessly continue operating as if it had not split.
> - From Key Point B2: Since KIP-253 allows us to maintain all our promises,
> we have the option of expanding partitions in the topics we produce.
> Without a backfill operation, though, our consumers may not be able to
> realize the benefits of that split, if they were hoping to.
>
> In general, faced with the possibility of having to coordinate the
> partition function with our inputs' producers or with our outputs'
> consumers, I would personally lean toward overprovisioning and completely
> avoiding resize for our use case. This doesn't mean that it's not useful in
> the ecosystem at large without backfill, just that it loses its luster for
> me. It also means that we can no longer take advantage of some of our
> current optimizations, and in fact that we must introduce an extra hop of
> repartitioning on every single input.
>
> I think this is actually a pretty good picture of the opportunities and
> challenges that other consumers and producers in the Kafka ecosystem will
> face.
>
> I hope this helps!
>
> Thanks,
> -John
>
> On Wed, Mar 28, 2018 at 11:51 AM, Jun Rao <ju...@confluent.io> wrote:
>
> > Hi, John,
> >
> > I actually think it's important to think through how KStreams handles
> > partition expansion in this KIP. If we do decide that we truly need
> > backfilling, it's much better to think through how to add it now, instead
> > of retrofitting it later. It would be useful to outline how both existing
> > KStreams jobs and new KStreams jobs work to see if backfilling is really
> > needed.
> >
> > If we can figure out how KStreams works, at least we have one reference
> > implementation for other stream processing frameworks that face the same
> > issue.
> >
> > Thanks,
> >
> > Jun
> >
> >
> > On Tue, Mar 27, 2018 at 4:56 PM, John Roesler <jo...@confluent.io> wrote:
> >
> > > Hi Jun,
> > >
> > > That's a good point.
> > >
> > > Yeah, I don't think it would work too well for existing consumers in
> the
> > > middle of gen 0 to try and switch to a newly backfilled prefix of gen
> 1.
> > > They probably just need to finish up until they get to the end of gen 0
> > and
> > > transition just as if there were no backfill available yet.
> > >
> > > This isn't terrible, since consumer applications that care about
> scaling
> > up
> > > to match a freshly split partition would wait until after the backfill
> is
> > > available to scale up. The consumer that starts out in gen=0, part=0 is
> > > going to be stuck with part=0 and part=3 in gen=1 in my example
> > regardless
> > > of whether they finish scanning gen=0 before or after the backfill is
> > > available.
> > >
> > > The broker knowing when it's ok to delete gen 0, including its offset
> > > mappings, is a big issue, though. I don't have any immediate ideas for
> > > solving it, but it doesn't feel impossible. Hopefully, you agree this
> is
> > > outside of KIP-253's scope, so maybe we don't need to worry about it
> > right
> > > now.
> > >
> > > I do agree that reshuffling in KStreams effectively solves the
> > scalability
> > > problem as well, as it decouples the partition count (and the partition
> > > scheme) upstream from the parallelism of the streams application.
> Likely,
> > > we will do this in any case. I'm predominantly advocating for follow-on
> > > work to enable backfill for the *other* Kafka users that are not
> > KStreams.
> > >
> > > Thanks for your consideration,
> > > -John
> > >
> > > On Tue, Mar 27, 2018 at 6:19 PM, Jun Rao <ju...@confluent.io> wrote:
> > >
> > > > Hi, John,
> > > >
> > > > Thanks for the reply. I agree that the backfill approach works
> cleaner
> > > for
> > > > newly started consumers. I am just not sure if it's a good primitive
> to
> > > > support for existing consumers. One of the challenges that I see is
> the
> > > > remapping of the offsets. In your approach, we need to copy the
> > existing
> > > > records from the partitions in generation 0 to generation 1. Those
> > > records
> > > > will get different offsets in the new generation. The broker will
> have
> > to
> > > > store those offset mappings somewhere. When the backfill completes,
> you
> > > can
> > > > delete generation 0's data. However, the broker can't throw away the
> > > offset
> > > > mappings immediately since it doesn't know if there is any existing
> > > > consumer still consuming generation 0's records. In a compacted
> topic,
> > > the
> > > > broker probably can only safely remove the offset mappings when all
> > > records
> > > > in generation 0 are removed by the cleaner. This may never happen
> > though.
> > > >
> > > > If we reshuffle the input inside a KStreams job, it obviates the need
> > for
> > > > offset remapping on the broker.
> > > >
> > > > Jun
> > > >
> > > > On Tue, Mar 27, 2018 at 11:34 AM, John Roesler <jo...@confluent.io>
> > > wrote:
> > > >
> > > > > Hey Dong and Jun,
> > > > >
> > > > > Thanks for the thoughtful responses. If you don't mind, I'll mix my
> > > > replies
> > > > > together to try for a coherent response. I'm not too familiar with
> > > > > mailing-list etiquette, though.
> > > > >
> > > > > I'm going to keep numbering my points because it makes it easy for
> > you
> > > > all
> > > > > to respond.
> > > > >
> > > > > Point 1:
> > > > > As I read it, KIP-253 is *just* about properly fencing the
> producers
> > > and
> > > > > consumers so that you preserve the correct ordering of records
> during
> > > > > partition expansion. This is clearly necessary regardless of
> anything
> > > > else
> > > > > we discuss. I think this whole discussion about backfill,
> consumers,
> > > > > streams, etc., is beyond the scope of KIP-253. But it would be
> > > cumbersome
> > > > > to start a new thread at this point.
> > > > >
> > > > > I had missed KIP-253's Proposed Change #9 among all the details...
> I
> > > > think
> > > > > this is a nice addition to the proposal. One thought is that it's
> > > > actually
> > > > > irrelevant whether the hash function is linear. This is simply an
> > > > algorithm
> > > > > for moving a key from one partition to another, so the type of hash
> > > > > function need not be a precondition. In fact, it also doesn't
> matter
> > > > > whether the topic is compacted or not, the algorithm works
> > regardless.
> > > > >
> > > > > I think this is a good algorithm to keep in mind, as it might
> solve a
> > > > > variety of problems, but it does have a downside: that the producer
> > > won't
> > > > > know whether or not K1 was actually in P1, it just knows that K1
> was
> > in
> > > > > P1's keyspace before the new epoch. Therefore, it will have to
> > > > > pessimistically send (K1,null) to P1 just in case. But the next
> time
> > K1
> > > > > comes along, the producer *also* won't remember that it already
> > > retracted
> > > > > K1 from P1, so it will have to send (K1,null) *again*. By
> extension,
> > > > every
> > > > > time the producer sends to P2, it will also have to send a
> tombstone
> > to
> > > > P1,
> > > > > which is a pretty big burden. To make the situation worse, if there
> > is
> > > a
> > > > > second split, say P2 becomes P2 and P3, then any key Kx belonging
> to
> > P3
> > > > > will also have to be retracted from P2 *and* P1, since the producer
> > > can't
> > > > > know whether Kx had been last written to P2 or P1. Over a long
> period
> > > of
> > > > > time, this clearly becomes a issue, as the producer must send an
> > > > arbitrary
> > > > > number of retractions along with every update.
> > > > >
> > > > > In contrast, the proposed backfill operation has an end, and after
> it
> > > > ends,
> > > > > everyone can afford to forget that there ever was a different
> > partition
> > > > > layout.
> > > > >
> > > > > Really, though, figuring out how to split compacted topics is
> beyond
> > > the
> > > > > scope of KIP-253, so I'm not sure #9 really even needs to be in
> this
> > > > KIP...
> > > > > We do need in-order delivery during partition expansion. It would
> be
> > > fine
> > > > > by me to say that you *cannot* expand partitions of a log-compacted
> > > topic
> > > > > and call it a day. I think it would be better to tackle that in
> > another
> > > > > KIP.
> > > > >
> > > > >
> > > > > Point 2:
> > > > > Regarding whether the consumer re-shuffles its inputs, this is
> always
> > > on
> > > > > the table; any consumer who wants to re-shuffle its input is free
> to
> > do
> > > > so.
> > > > > But this is currently not required. It's just that the current
> > > high-level
> > > > > story with Kafka encourages the use of partitions as a unit of
> > > > concurrency.
> > > > > As long as consumers are single-threaded, they can happily consume
> a
> > > > single
> > > > > partition without concurrency control of any kind. This is a key
> > aspect
> > > > to
> > > > > this system that lets folks design high-throughput systems on top
> of
> > it
> > > > > surprisingly easily. If all consumers were instead
> > encouraged/required
> > > to
> > > > > implement a repartition of their own, then the consumer becomes
> > > > > significantly more complex, requiring either the consumer to first
> > > > produce
> > > > > to its own intermediate repartition topic or to ensure that
> consumer
> > > > > threads have a reliable, high-bandwith channel of communication
> with
> > > > every
> > > > > other consumer thread.
> > > > >
> > > > > Either of those tradeoffs may be reasonable for a particular user
> of
> > > > Kafka,
> > > > > but I don't know if we're in a position to say that they are
> > reasonable
> > > > for
> > > > > *every* user of Kafka.
> > > > >
> > > > >
> > > > > Point 3:
> > > > > Regarding Jun's point about this use case, "(3) stateful and
> > > maintaining
> > > > > the
> > > > > states in a local store", I agree that they may use a framework
> > *like*
> > > > > Kafka Streams, but that is not the same as using Kafka Streams.
> This
> > is
> > > > why
> > > > > I think it's better to solve it in Core: because it is then solved
> > for
> > > > > KStreams and also for everything else that facilitates local state
> > > > > maintenance. To me, Streams is a member of the category of "stream
> > > > > processing frameworks", which is itself a subcategory of "things
> > > > requiring
> > > > > local state maintenence". I'm not sure if it makes sense to assert
> > that
> > > > > Streams is a sufficient and practical replacement for everything in
> > > > "things
> > > > > requiring local state maintenence".
> > > > >
> > > > > But, yes, I do agree that per-key ordering is an absolute
> > requirement,
> > > > > therefore I think that KIP-253 itself is a necessary step.
> Regarding
> > > the
> > > > > coupling of the state store partitioning to the topic partitioning,
> > > yes,
> > > > > this is an issue we are discussing solutions to right now. We may
> go
> > > > ahead
> > > > > and introduce an overpartition layer on our inputs to solve it, but
> > > then
> > > > > again, if we get the ability to split partitions with backfill, we
> > may
> > > > not
> > > > > need to!
> > > > >
> > > > >
> > > > > Point 4:
> > > > > On this:
> > > > >
> > > > > > Regarding thought 2: If we don't care about the stream use-case,
> > then
> > > > the
> > > > > > current KIP probably has already addressed problem without
> > requiring
> > > > > > consumer to know the partition function. If we care about the
> > stream
> > > > > > use-case, we already need coordination across producers of
> > different
> > > > > > topics, i.e. the same partition function needs to be used by
> > > producers
> > > > of
> > > > > > topics A and B in order to join topics A and B. Thus, it might be
> > > > > > reasonable to extend coordination a bit and say we need
> > coordination
> > > > > across
> > > > > > clients (i.e. producer and consumer), such that consumer knows
> the
> > > > > > partition function used by producer. If we do so, then we can let
> > > > > consumer
> > > > > > re-copy data for the change log topic using the same partition
> > > function
> > > > > as
> > > > > > producer. This approach has lower overhead as compared to having
> > > > producer
> > > > > > re-copy data of the input topic.
> > > > > > Also, producer currently does not need to know the data already
> > > > produced
> > > > > to
> > > > > > the topic. If we let producer split/merge partition, it would
> > require
> > > > > > producer to consume the existing data, which intuitively is the
> > task
> > > of
> > > > > > consumer.
> > > > >
> > > > >
> > > > > I think we do care about use cases *like* Streams, I just don't
> think
> > > we
> > > > > should rely on Streams to implement a feature of Core like
> partition
> > > > > expansion.
> > > > >
> > > > > Note, though, that we (Streams) do not require coordination across
> > > > > producers. If two topics are certified to be co-partitioned, then
> > > Streams
> > > > > apps can make use of that knowledge to optimize their topology
> > > (skipping
> > > > a
> > > > > repartition). But if they don't know whether they are
> co-partitioned,
> > > > then
> > > > > they'd better go ahead and repartition within the topology. This is
> > the
> > > > > current state.
> > > > >
> > > > > A huge selling point of Kafka is enabling different parts of
> loosely
> > > > > coupled organizations to produce and consume data independently.
> Some
> > > > > coordination between producers and consumers is necessary, like
> > > > > coordinating on the names of topics and their schemas. But Kafka's
> > > value
> > > > > proposition w.r.t. ESBs, etc. is inversely proportional to the
> amount
> > > of
> > > > > coordination required. I think it behooves us to be extremely
> > skeptical
> > > > > about introducing any coordination beyond correctness protocols.
> > > > >
> > > > > Asking producers and consumers, or even two different producers, to
> > > share
> > > > > code like the partition function is a pretty huge ask. What if they
> > are
> > > > > using different languages?
> > > > >
> > > > > Comparing organizational overhead vs computational overhead, there
> > are
> > > > > maybe two orders of magnitude difference between them. In other
> > words,
> > > I
> > > > > would happily take on the (linear) overhead of having the producer
> > > > re-copy
> > > > > the data once during a re-partition in order to save the
> > organizational
> > > > > overhead of tying all the producers and consumers together across
> > > > multiple
> > > > > boundaries.
> > > > >
> > > > > On that last paragraph: note that the producer *did* know the data
> it
> > > > > already produced. It handled it the first time around. Asking it to
> > > > > re-produce it into a new partition layout is squarely within its
> > scope
> > > of
> > > > > capabilities. Contrast this with the alternative, asking the
> consumer
> > > to
> > > > > re-partition the data. I think this is even less intuitive, when
> the
> > > > > partition function belongs to the producer.
> > > > >
> > > > >
> > > > > Point 5:
> > > > > Dong asked this:
> > > > >
> > > > > > For stream use-case that needs to increase consumer number, the
> > > > > > existing consumer can backfill the existing data in the change
> log
> > > > topic
> > > > > to
> > > > > > the same change log topic with the new partition number, before
> the
> > > new
> > > > > set
> > > > > > of consumers bootstrap state from the new partitions of the
> change
> > > log
> > > > > > topic, right?
> > > > >
> > > > >
> > > > > In this sense, the "consumer" is actually the producer of the
> > changelog
> > > > > topic, so if we support partition expansion + backfill as a
> > > > producer/broker
> > > > > operation, then it would be very straightforward for Streams to
> > split a
> > > > > state store. As you say, they would simply instruct the broker to
> > split
> > > > the
> > > > > changelog topic's partitions, then backfill. Once the backfill is
> > > ready,
> > > > > they can create a new crop of StandbyTasks to bootstrap the more
> > > granular
> > > > > state stores and finally switch over to them when they are ready.
> > > > >
> > > > > But this actually seems to be an argument in favor of
> split+backfill,
> > > so
> > > > > maybe I missed the point.
> > > > >
> > > > > You also asked me to explain why copying the "input" topic is
> better
> > > than
> > > > > copying the "changelog" topic. I think they are totally
> independent,
> > > > > actually. For one thing, you can't depend on the existence of a
> > > > "changelog"
> > > > > topic in general, only within Streams, but Kafka's user base
> clearly
> > > > > exceeds Streams's user base. Plus, you actually also can't depend
> on
> > > the
> > > > > existence of a changelog topic within Streams, since that is an
> > > optional
> > > > > feature of *some* state store implementations. Even in the
> situation
> > > > where
> > > > > you do have a changelog topic in Streams, there may be use cases
> > where
> > > it
> > > > > makes sense to expand the partitions of just the input, or just the
> > > > > changelog.
> > > > >
> > > > > The ask for a Core feature of split+backfill is really about
> > supporting
> > > > the
> > > > > use case of splitting partitions in log-compacted topics,
> regardless
> > of
> > > > > whether that topic is an "input" or a "changelog" or anything else
> > for
> > > > that
> > > > > matter.
> > > > >
> > > > >
> > > > > Point 6:
> > > > > On the concern about the performance overhead of copying data
> between
> > > the
> > > > > brokers, I think it's actually a bit overestimated. Splitting a
> > topic's
> > > > > partition is probably rare, certainly rarer in general than
> > > bootstrapping
> > > > > new consumers on that topic. If "bootstrapping new consumers" means
> > > that
> > > > > they have to re-shuffle the data before they consume it, then you
> > wind
> > > up
> > > > > copying the same record multiple times:
> > > > >
> > > > > (broker: input topic) -> (initial consumer) -> (broker: repartition
> > > > topic)
> > > > > -> (real consumer)
> > > > >
> > > > > That's 3x, and it's also 3x for every new record after the split as
> > > well,
> > > > > since you don't get to stop repartitioning/reshuffling once you
> > start.
> > > > >
> > > > > Whereas if you do a backfill in something like the procedure I
> > > outlined,
> > > > > you only copy the prefix of the partition before the split, and you
> > > send
> > > > it
> > > > > once to the producer and then once to the new generation partition.
> > > Plus,
> > > > > assuming we're splitting the partition for the benefit of
> consumers,
> > > > > there's no reason we can't co-locate the post-split partitions on
> the
> > > > same
> > > > > host as the pre-split partition, making the second copy a local
> > > > filesystem
> > > > > operation.
> > > > >
> > > > > Even if you follow these two copies up with bootstrapping a new
> > > consumer,
> > > > > it's still rare for this to occur, so you get to amortize these
> > copies
> > > > over
> > > > > the lifetime of the topic, whereas a reshuffle just keeps making
> > copies
> > > > for
> > > > > every new event.
> > > > >
> > > > > And finally, I really do think that regardless of any performance
> > > > concerns
> > > > > about this operation, if it preserves loose organizational
> coupling,
> > it
> > > > is
> > > > > certainly worth it.
> > > > >
> > > > >
> > > > > In conclusion:
> > > > > It might actually be a good idea for us to clarify the scope of
> > > KIP-253.
> > > > If
> > > > > we're all agreed that it's a good algorithm for allowing in-order
> > > message
> > > > > delivery during partition expansion, then we can continue this
> > > discussion
> > > > > as a new KIP, something like "backfill with partition expansion".
> > This
> > > > > would let Dong proceed with KIP-253. On the other hand, if it seems
> > > like
> > > > > this conversation may alter the design of KIP-253, then maybe we
> > > *should*
> > > > > just finish working it out.
> > > > >
> > > > > For my part, my only concern about KIP-253 is the one I raised
> > earlier.
> > > > >
> > > > > Thanks again, all, for considering these points,
> > > > > -John
> > > > >
> > > > >
> > > > > On Tue, Mar 27, 2018 at 2:10 AM, Dong Lin <li...@gmail.com>
> > wrote:
> > > > >
> > > > > > On Tue, Mar 27, 2018 at 12:04 AM, Dong Lin <li...@gmail.com>
> > > > wrote:
> > > > > >
> > > > > > > Hey Jan,
> > > > > > >
> > > > > > > Thanks for the enthusiasm in improving Kafka's design. Now
> that I
> > > > have
> > > > > > > read through your discussion with Jun, here are my thoughts:
> > > > > > >
> > > > > > > - The latest proposal should with log compacted topics by
> > properly
> > > > > > > deleting old messages after a new message with the same key is
> > > > > produced.
> > > > > > So
> > > > > > > it is probably not a concern anymore. Could you comment if
> there
> > is
> > > > > still
> > > > > > > issue?
> > > > > > >
> > > > > > > - I wrote the SEP-5 and I am pretty familiar with the
> motivation
> > > and
> > > > > the
> > > > > > > design of SEP-5. SEP-5 is probably orthornal to the motivation
> of
> > > > this
> > > > > > KIP.
> > > > > > > The goal of SEP-5 is to allow user to increase task number of
> an
> > > > > existing
> > > > > > > Samza job. But if we increase the partition number of input
> > topics,
> > > > > > > messages may still be consumed out-of-order by tasks in Samza
> > which
> > > > > cause
> > > > > > > incorrect result. Similarly, the approach you proposed does not
> > > seem
> > > > to
> > > > > > > ensure that the messages can be delivered in order, even if we
> > can
> > > > make
> > > > > > > sure that each consumer instance is assigned the set of new
> > > > partitions
> > > > > > > covering the same set of keys.
> > > > > > >
> > > > > >
> > > > > > Let me correct this comment. The approach of copying data to a
> new
> > > > topic
> > > > > > can ensure in-order message delivery suppose we properly migrate
> > > > offsets
> > > > > > from old topic to new topic.
> > > > > >
> > > > > >
> > > > > > > - I am trying to understand why it is better to copy the data
> > > instead
> > > > > of
> > > > > > > copying the change log topic for streaming use-case. For core
> > Kafka
> > > > > > > use-case, and for the stream use-case that does not need to
> > > increase
> > > > > > > consumers, the current KIP already supports in-order delivery
> > > without
> > > > > the
> > > > > > > overhead of copying the data. For stream use-case that needs to
> > > > > increase
> > > > > > > consumer number, the existing consumer can backfill the
> existing
> > > data
> > > > > in
> > > > > > > the change log topic to the same change log topic with the new
> > > > > partition
> > > > > > > number, before the new set of consumers bootstrap state from
> the
> > > new
> > > > > > > partitions of the change log topic. If this solution works,
> then
> > > > could
> > > > > > you
> > > > > > > summarize the advantage of copying the data of input topic as
> > > > compared
> > > > > to
> > > > > > > copying the change log topic? For example, does it enable more
> > > > > use-case,
> > > > > > > simplify the implementation of Kafka library, or reduce the
> > > operation
> > > > > > > overhead etc?
> > > > > > >
> > > > > > > Thanks,
> > > > > > > Dong
> > > > > > >
> > > > > > >
> > > > > > > On Wed, Mar 21, 2018 at 6:57 AM, Jan Filipiak <
> > > > > Jan.Filipiak@trivago.com>
> > > > > > > wrote:
> > > > > > >
> > > > > > >> Hi Jun,
> > > > > > >>
> > > > > > >> I was really seeing progress in our conversation but your
> latest
> > > > reply
> > > > > > is
> > > > > > >> just devastating.
> > > > > > >> I though we were getting close being on the same page now it
> > feels
> > > > > like
> > > > > > >> we are in different libraries.
> > > > > > >>
> > > > > > >> I just quickly slam my answers in here. If they are to brief I
> > am
> > > > > sorry
> > > > > > >> give me a ping and try to go into details more.
> > > > > > >> Just want to show that your pro/cons listing is broken.
> > > > > > >>
> > > > > > >> Best Jan
> > > > > > >>
> > > > > > >> and want to get rid of this horrible compromise
> > > > > > >>
> > > > > > >>
> > > > > > >> On 19.03.2018 05:48, Jun Rao wrote:
> > > > > > >>
> > > > > > >>> Hi, Jan,
> > > > > > >>>
> > > > > > >>> Thanks for the discussion. Great points.
> > > > > > >>>
> > > > > > >>> Let me try to summarize the approach that you are proposing.
> On
> > > the
> > > > > > >>> broker
> > > > > > >>> side, we reshuffle the existing data in a topic from current
> > > > > partitions
> > > > > > >>> to
> > > > > > >>> the new partitions. Once the reshuffle fully catches up,
> switch
> > > the
> > > > > > >>> consumers to start consuming from the new partitions. If a
> > > consumer
> > > > > > needs
> > > > > > >>> to rebuild its local state (due to partition changes), let
> the
> > > > > consumer
> > > > > > >>> rebuild its state by reading all existing data from the new
> > > > > partitions.
> > > > > > >>> Once all consumers have switches over, cut over the producer
> to
> > > the
> > > > > new
> > > > > > >>> partitions.
> > > > > > >>>
> > > > > > >>> The pros for this approach are that :
> > > > > > >>> 1. There is just one way to rebuild the local state, which is
> > > > > simpler.
> > > > > > >>>
> > > > > > >> true thanks
> > > > > > >>
> > > > > > >>>
> > > > > > >>> The cons for this approach are:
> > > > > > >>> 1. Need to copy existing data.
> > > > > > >>>
> > > > > > >> Very unfair and not correct. It does not require you to copy
> > over
> > > > > > >> existing data. It _allows_ you to copy all existing data.
> > > > > > >>
> > > > > > >> 2. The cutover of the producer is a bit complicated since it
> > needs
> > > > to
> > > > > > >>> coordinate with all consumer groups.
> > > > > > >>>
> > > > > > >> Also not true. I explicitly tried to make clear that there is
> > only
> > > > one
> > > > > > >> special consumer (in the case of actually copying data)
> > > coordination
> > > > > is
> > > > > > >> required.
> > > > > > >>
> > > > > > >>> 3. The rebuilding of the state in the consumer is from the
> > input
> > > > > topic,
> > > > > > >>> which can be more expensive than rebuilding from the existing
> > > > state.
> > > > > > >>>
> > > > > > >> true, but rebuilding state is only required if you want to
> > > increase
> > > > > > >> processing power, so we assume this is at hand.
> > > > > > >>
> > > > > > >>> 4. The broker potentially has to know the partitioning
> > function.
> > > If
> > > > > > this
> > > > > > >>> needs to be customized at the topic level, it can be a bit
> > messy.
> > > > > > >>>
> > > > > > >> I would argue against having the operation being performed by
> > the
> > > > > > broker.
> > > > > > >> This was not discussed yet but if you see my original email i
> > > > > suggested
> > > > > > >> otherwise from the beginning.
> > > > > > >>
> > > > > > >>>
> > > > > > >>> Here is an alternative approach by applying your idea not in
> > the
> > > > > > broker,
> > > > > > >>> but in the consumer. When new partitions are added, we don't
> > move
> > > > > > >>> existing
> > > > > > >>> data. In KStreams, we first reshuffle the new input data to a
> > new
> > > > > topic
> > > > > > >>> T1
> > > > > > >>> with the old number of partitions and feed T1's data to the
> > rest
> > > of
> > > > > the
> > > > > > >>> pipeline. In the meantime, KStreams reshuffles all existing
> > data
> > > of
> > > > > the
> > > > > > >>> change capture topic to another topic C1 with the new number
> of
> > > > > > >>> partitions.
> > > > > > >>> We can then build the state of the new tasks from C1. Once
> the
> > > new
> > > > > > states
> > > > > > >>> have been fully built, we can cut over the consumption to the
> > > input
> > > > > > topic
> > > > > > >>> and delete T1. This approach works with compacted topic too.
> If
> > > an
> > > > > > >>> application reads from the beginning of a compacted topic,
> the
> > > > > consumer
> > > > > > >>> will reshuffle the portion of the input when the number of
> > > > partitions
> > > > > > >>> doesn't match the number of tasks.
> > > > > > >>>
> > > > > > >> We all wipe this idea from our heads instantly. Mixing Ideas
> > from
> > > an
> > > > > > >> argument is not a resolution strategy
> > > > > > >> just leads to horrible horrible software.
> > > > > > >>
> > > > > > >>
> > > > > > >>> The pros of this approach are:
> > > > > > >>> 1. No need to copy existing data.
> > > > > > >>> 2. Each consumer group can cut over to the new partitions
> > > > > > independently.
> > > > > > >>> 3. The state is rebuilt from the change capture topic, which
> is
> > > > > cheaper
> > > > > > >>> than rebuilding from the input topic.
> > > > > > >>> 4. Only the KStreams job needs to know the partitioning
> > function.
> > > > > > >>>
> > > > > > >>> The cons of this approach are:
> > > > > > >>> 1. Potentially the same input topic needs to be reshuffled
> more
> > > > than
> > > > > > once
> > > > > > >>> in different consumer groups during the transition phase.
> > > > > > >>>
> > > > > > >>> What do you think?
> > > > > > >>>
> > > > > > >>> Thanks,
> > > > > > >>>
> > > > > > >>> Jun
> > > > > > >>>
> > > > > > >>>
> > > > > > >>>
> > > > > > >>> On Thu, Mar 15, 2018 at 1:04 AM, Jan Filipiak <
> > > > > > Jan.Filipiak@trivago.com>
> > > > > > >>> wrote:
> > > > > > >>>
> > > > > > >>> Hi Jun,
> > > > > > >>>>
> > > > > > >>>> thank you for following me on these thoughts. It was
> important
> > > to
> > > > me
> > > > > > to
> > > > > > >>>> feel that kind of understanding for my arguments.
> > > > > > >>>>
> > > > > > >>>> What I was hoping for (I mentioned this earlier) is that we
> > can
> > > > > model
> > > > > > >>>> the
> > > > > > >>>> case where we do not want to copy the data the exact same
> way
> > as
> > > > the
> > > > > > >>>> case
> > > > > > >>>> when we do copy the data. Maybe you can peek into the mails
> > > before
> > > > > to
> > > > > > >>>> see
> > > > > > >>>> more details for this.
> > > > > > >>>>
> > > > > > >>>> This means we have the same mechanism to transfer consumer
> > > groups
> > > > to
> > > > > > >>>> switch topic. The offset mapping that would be generated
> would
> > > > even
> > > > > be
> > > > > > >>>> simpler End Offset of the Old topic => offset 0 off all the
> > > > > partitions
> > > > > > >>>> of
> > > > > > >>>> the new topic. Then we could model the transition of a
> > non-copy
> > > > > > >>>> expansion
> > > > > > >>>> the exact same way as a copy-expansion.
> > > > > > >>>>
> > > > > > >>>> I know this only works when topic growth by a factor. But
> the
> > > > > benefits
> > > > > > >>>> of
> > > > > > >>>> only growing by a factor are to strong anyways. See
> Clemens's
> > > hint
> > > > > and
> > > > > > >>>> remember that state reshuffling is entirely not needed if
> one
> > > > > doesn't
> > > > > > >>>> want
> > > > > > >>>> to grow processing power.
> > > > > > >>>>
> > > > > > >>>> I think these benefits should be clear, and that there is
> > > > basically
> > > > > no
> > > > > > >>>> downside to what is currently at hand but just makes
> > everything
> > > > > easy.
> > > > > > >>>>
> > > > > > >>>> One thing you need to know is. that if you do not offer
> > > > rebuilding a
> > > > > > log
> > > > > > >>>> compacted topic like i suggest that even if you have
> consumer
> > > > state
> > > > > > >>>> reshuffling. The topic is broken and can not be used to
> > > bootstrap
> > > > > new
> > > > > > >>>> consumers. They don't know if they need to apply a key from
> > and
> > > > old
> > > > > > >>>> partition or not. This is a horrible downside I haven't
> seen a
> > > > > > solution
> > > > > > >>>> for
> > > > > > >>>> in the email conversation.
> > > > > > >>>>
> > > > > > >>>> I argue to:
> > > > > > >>>>
> > > > > > >>>> Only grow topic by a factor always.
> > > > > > >>>> Have the "no copy consumer" transition as the trivial case
> of
> > > the
> > > > > > "copy
> > > > > > >>>> consumer transition".
> > > > > > >>>> If processors needs to be scaled, let them rebuild from the
> > new
> > > > > topic
> > > > > > >>>> and
> > > > > > >>>> leave the old running in the mean time.
> > > > > > >>>> Do not implement key shuffling in streams.
> > > > > > >>>>
> > > > > > >>>> I hope I can convince you especially with the fact how I
> want
> > to
> > > > > > handle
> > > > > > >>>> consumer transition. I think
> > > > > > >>>> you didn't quite understood me there before. I think the
> term
> > > "new
> > > > > > >>>> topic"
> > > > > > >>>> intimidated you a little.
> > > > > > >>>> How we solve this on disc doesn't really matter, If the data
> > > goes
> > > > > into
> > > > > > >>>> the
> > > > > > >>>> same Dir or a different Dir or anything. I do think that it
> > > needs
> > > > to
> > > > > > >>>> involve at least rolling a new segment for the existing
> > > > partitions.
> > > > > > >>>> But most of the transitions should work without restarting
> > > > > consumers.
> > > > > > >>>> (newer consumers with support for this). But with new topic
> i
> > > just
> > > > > > meant
> > > > > > >>>> the topic that now has a different partition count. Plenty
> of
> > > ways
> > > > > to
> > > > > > >>>> handle that (versions, aliases)
> > > > > > >>>>
> > > > > > >>>> Hope I can further get my idea across.
> > > > > > >>>>
> > > > > > >>>> Best Jan
> > > > > > >>>>
> > > > > > >>>>
> > > > > > >>>>
> > > > > > >>>>
> > > > > > >>>>
> > > > > > >>>>
> > > > > > >>>> On 14.03.2018 02:45, Jun Rao wrote:
> > > > > > >>>>
> > > > > > >>>> Hi, Jan,
> > > > > > >>>>>
> > > > > > >>>>> Thanks for sharing your view.
> > > > > > >>>>>
> > > > > > >>>>> I agree with you that recopying the data potentially makes
> > the
> > > > > state
> > > > > > >>>>> management easier since the consumer can just rebuild its
> > state
> > > > > from
> > > > > > >>>>> scratch (i.e., no need for state reshuffling).
> > > > > > >>>>>
> > > > > > >>>>> On the flip slide, I saw a few disadvantages of the
> approach
> > > that
> > > > > you
> > > > > > >>>>> suggested. (1) Building the state from the input topic from
> > > > scratch
> > > > > > is
> > > > > > >>>>> in
> > > > > > >>>>> general less efficient than state reshuffling. Let's say
> one
> > > > > > computes a
> > > > > > >>>>> count per key from an input topic. The former requires
> > reading
> > > > all
> > > > > > >>>>> existing
> > > > > > >>>>> records in the input topic whereas the latter only requires
> > > > reading
> > > > > > >>>>> data
> > > > > > >>>>> proportional to the number of unique keys. (2) The
> switching
> > of
> > > > the
> > > > > > >>>>> topic
> > > > > > >>>>> needs modification to the application. If there are many
> > > > > applications
> > > > > > >>>>> on a
> > > > > > >>>>> topic, coordinating such an effort may not be easy. Also,
> > it's
> > > > not
> > > > > > >>>>> clear
> > > > > > >>>>> how to enforce exactly-once semantic during the switch. (3)
> > If
> > > a
> > > > > > topic
> > > > > > >>>>> doesn't need any state management, recopying the data seems
> > > > > wasteful.
> > > > > > >>>>> In
> > > > > > >>>>> that case, in place partition expansion seems more
> desirable.
> > > > > > >>>>>
> > > > > > >>>>> I understand your concern about adding complexity in
> > KStreams.
> > > > But,
> > > > > > >>>>> perhaps
> > > > > > >>>>> we could iterate on that a bit more to see if it can be
> > > > simplified.
> > > > > > >>>>>
> > > > > > >>>>> Jun
> > > > > > >>>>>
> > > > > > >>>>>
> > > > > > >>>>> On Mon, Mar 12, 2018 at 11:21 PM, Jan Filipiak <
> > > > > > >>>>> Jan.Filipiak@trivago.com>
> > > > > > >>>>> wrote:
> > > > > > >>>>>
> > > > > > >>>>> Hi Jun,
> > > > > > >>>>>
> > > > > > >>>>>> I will focus on point 61 as I think its _the_ fundamental
> > part
> > > > > that
> > > > > > I
> > > > > > >>>>>> cant
> > > > > > >>>>>> get across at the moment.
> > > > > > >>>>>>
> > > > > > >>>>>> Kafka is the platform to have state materialized multiple
> > > times
> > > > > from
> > > > > > >>>>>> one
> > > > > > >>>>>> input. I emphasize this: It is the building block in
> > > > architectures
> > > > > > >>>>>> that
> > > > > > >>>>>> allow you to
> > > > > > >>>>>> have your state maintained multiple times. You put a
> message
> > > in
> > > > > > once,
> > > > > > >>>>>> and
> > > > > > >>>>>> you have it pop out as often as you like. I believe you
> > > > understand
> > > > > > >>>>>> this.
> > > > > > >>>>>>
> > > > > > >>>>>> Now! The path of thinking goes the following: I am using
> > > apache
> > > > > > kafka
> > > > > > >>>>>> and
> > > > > > >>>>>> I _want_ my state multiple times. What am I going todo?
> > > > > > >>>>>>
> > > > > > >>>>>> A) Am I going to take my state that I build up, plunge
> some
> > > sort
> > > > > of
> > > > > > >>>>>> RPC
> > > > > > >>>>>> layer ontop of it, use that RPC layer to throw my records
> > > across
> > > > > > >>>>>> instances?
> > > > > > >>>>>> B) Am I just going to read the damn message twice?
> > > > > > >>>>>>
> > > > > > >>>>>> Approach A is fundamentally flawed and a violation of all
> > that
> > > > is
> > > > > > good
> > > > > > >>>>>> and
> > > > > > >>>>>> holy in kafka deployments. I can not understand how this
> > Idea
> > > > can
> > > > > > >>>>>> come in
> > > > > > >>>>>> the first place.
> > > > > > >>>>>> (I do understand: IQ in streams, they polluted the kafka
> > > streams
> > > > > > >>>>>> codebase
> > > > > > >>>>>> really bad already. It is not funny! I think they are
> > equally
> > > > > flawed
> > > > > > >>>>>> as
> > > > > > >>>>>> A)
> > > > > > >>>>>>
> > > > > > >>>>>> I say, we do what Kafka is good at. We repartition the
> topic
> > > > once.
> > > > > > We
> > > > > > >>>>>> switch the consumers.
> > > > > > >>>>>> (Those that need more partitions are going to rebuild
> their
> > > > state
> > > > > in
> > > > > > >>>>>> multiple partitions by reading the new topic, those that
> > don't
> > > > > just
> > > > > > >>>>>> assign
> > > > > > >>>>>> the new partitions properly)
> > > > > > >>>>>> We switch producers. Done!
> > > > > > >>>>>>
> > > > > > >>>>>> The best thing! It is trivial, hipster stream processor
> will
> > > > have
> > > > > an
> > > > > > >>>>>> easy
> > > > > > >>>>>> time with that aswell. Its so super simple. And simple IS
> > > good!
> > > > > > >>>>>> It is what kafka was build todo. It is how we do it today.
> > > All I
> > > > > am
> > > > > > >>>>>> saying
> > > > > > >>>>>> is that a little broker help doing the producer swap is
> > super
> > > > > > useful.
> > > > > > >>>>>>
> > > > > > >>>>>> For everyone interested in why kafka is so powerful with
> > > > approach
> > > > > B,
> > > > > > >>>>>> please watch https://youtu.be/bEbeZPVo98c?t=1633
> > > > > > >>>>>> I already looked up a good point in time, I think after 5
> > > > minutes
> > > > > > the
> > > > > > >>>>>> "state" topic is handled and you should be able to
> > understand
> > > me
> > > > > > >>>>>> and inch better.
> > > > > > >>>>>>
> > > > > > >>>>>> Please do not do A to the project, it deserves better!
> > > > > > >>>>>>
> > > > > > >>>>>> Best Jan
> > > > > > >>>>>>
> > > > > > >>>>>>
> > > > > > >>>>>>
> > > > > > >>>>>> On 13.03.2018 02:40, Jun Rao wrote:
> > > > > > >>>>>>
> > > > > > >>>>>> Hi, Jan,
> > > > > > >>>>>>
> > > > > > >>>>>>> Thanks for the reply. A few more comments below.
> > > > > > >>>>>>>
> > > > > > >>>>>>> 50. Ok, we can think a bit harder for supporting
> compacted
> > > > > topics.
> > > > > > >>>>>>>
> > > > > > >>>>>>> 51. This is a fundamental design question. In the more
> > common
> > > > > case,
> > > > > > >>>>>>> the
> > > > > > >>>>>>> reason why someone wants to increase the number of
> > partitions
> > > > is
> > > > > > that
> > > > > > >>>>>>> the
> > > > > > >>>>>>> consumer application is slow and one wants to run more
> > > consumer
> > > > > > >>>>>>> instances
> > > > > > >>>>>>> to increase the degree of parallelism. So, fixing the
> > number
> > > of
> > > > > > >>>>>>> running
> > > > > > >>>>>>> consumer instances when expanding the partitions won't
> help
> > > > this
> > > > > > >>>>>>> case.
> > > > > > >>>>>>> If
> > > > > > >>>>>>> we do need to increase the number of consumer instances,
> we
> > > > need
> > > > > to
> > > > > > >>>>>>> somehow
> > > > > > >>>>>>> reshuffle the state of the consumer across instances.
> What
> > we
> > > > > have
> > > > > > >>>>>>> been
> > > > > > >>>>>>> discussing in this KIP is whether we can do this more
> > > > effectively
> > > > > > >>>>>>> through
> > > > > > >>>>>>> the KStream library (e.g. through a 2-phase partition
> > > > expansion).
> > > > > > >>>>>>> This
> > > > > > >>>>>>> will
> > > > > > >>>>>>> add some complexity, but it's probably better than
> everyone
> > > > doing
> > > > > > >>>>>>> this
> > > > > > >>>>>>> in
> > > > > > >>>>>>> the application space. The recopying approach that you
> > > > mentioned
> > > > > > >>>>>>> doesn't
> > > > > > >>>>>>> seem to address the consumer state management issue when
> > the
> > > > > > consumer
> > > > > > >>>>>>> switches from an old to a new topic.
> > > > > > >>>>>>>
> > > > > > >>>>>>> 52. As for your example, it depends on whether the join
> key
> > > is
> > > > > the
> > > > > > >>>>>>> same
> > > > > > >>>>>>> between (A,B) and (B,C). If the join key is the same, we
> > can
> > > > do a
> > > > > > >>>>>>> 2-phase
> > > > > > >>>>>>> partition expansion of A, B, and C together. If the join
> > keys
> > > > are
> > > > > > >>>>>>> different, one would need to repartition the data on a
> > > > different
> > > > > > key
> > > > > > >>>>>>> for
> > > > > > >>>>>>> the second join, then the partition expansion can be done
> > > > > > >>>>>>> independently
> > > > > > >>>>>>> between (A,B) and (B,C).
> > > > > > >>>>>>>
> > > > > > >>>>>>> 53. If you always fix the number of consumer instances,
> we
> > > you
> > > > > > >>>>>>> described
> > > > > > >>>>>>> works. However, as I mentioned in #51, I am not sure how
> > your
> > > > > > >>>>>>> proposal
> > > > > > >>>>>>> deals with consumer states when the number of consumer
> > > > instances
> > > > > > >>>>>>> grows.
> > > > > > >>>>>>> Also, it just seems that it's better to avoid re-copying
> > the
> > > > > > existing
> > > > > > >>>>>>> data.
> > > > > > >>>>>>>
> > > > > > >>>>>>> 60. "just want to throw in my question from the longer
> > email
> > > in
> > > > > the
> > > > > > >>>>>>> other
> > > > > > >>>>>>> Thread here. How will the bloom filter help a new
> consumer
> > to
> > > > > > decide
> > > > > > >>>>>>> to
> > > > > > >>>>>>> apply the key or not?" Not sure that I fully understood
> > your
> > > > > > >>>>>>> question.
> > > > > > >>>>>>> The
> > > > > > >>>>>>> consumer just reads whatever key is in the log. The bloom
> > > > filter
> > > > > > just
> > > > > > >>>>>>> helps
> > > > > > >>>>>>> clean up the old keys.
> > > > > > >>>>>>>
> > > > > > >>>>>>> 61. "Why can we afford having a topic where its
> apparently
> > > not
> > > > > > >>>>>>> possible
> > > > > > >>>>>>> to
> > > > > > >>>>>>> start a new application on? I think this is an overall
> flaw
> > > of
> > > > > the
> > > > > > >>>>>>> discussed idea here. Not playing attention to the overall
> > > > > > >>>>>>> architecture."
> > > > > > >>>>>>> Could you explain a bit more when one can't start a new
> > > > > > application?
> > > > > > >>>>>>>
> > > > > > >>>>>>> Jun
> > > > > > >>>>>>>
> > > > > > >>>>>>>
> > > > > > >>>>>>>
> > > > > > >>>>>>> On Sat, Mar 10, 2018 at 1:40 AM, Jan Filipiak <
> > > > > > >>>>>>> Jan.Filipiak@trivago.com
> > > > > > >>>>>>> wrote:
> > > > > > >>>>>>>
> > > > > > >>>>>>> Hi Jun, thanks for your mail.
> > > > > > >>>>>>>
> > > > > > >>>>>>> Thank you for your questions!
> > > > > > >>>>>>>> I think they are really good and tackle the core of the
> > > > problem
> > > > > I
> > > > > > >>>>>>>> see.
> > > > > > >>>>>>>>
> > > > > > >>>>>>>> I will answer inline, mostly but still want to set the
> > tone
> > > > > here.
> > > > > > >>>>>>>>
> > > > > > >>>>>>>> The core strength of kafka is what Martin once called
> the
> > > > > > >>>>>>>> kappa-Architecture. How does this work?
> > > > > > >>>>>>>> You have everything as a log as in kafka. When you need
> to
> > > > > change
> > > > > > >>>>>>>> something.
> > > > > > >>>>>>>> You create the new version of your application and leave
> > it
> > > > > > running
> > > > > > >>>>>>>> in
> > > > > > >>>>>>>> parallel.
> > > > > > >>>>>>>> Once the new version is good you switch your users to
> use
> > > the
> > > > > new
> > > > > > >>>>>>>> application.
> > > > > > >>>>>>>>
> > > > > > >>>>>>>> The online reshuffling effectively breaks this
> > architecture
> > > > and
> > > > > I
> > > > > > >>>>>>>> think
> > > > > > >>>>>>>> the switch in thinking here is more harmful
> > > > > > >>>>>>>> than any details about the partitioning function to
> allow
> > > > such a
> > > > > > >>>>>>>> change.
> > > > > > >>>>>>>> I
> > > > > > >>>>>>>> feel with my suggestion we are the closest to
> > > > > > >>>>>>>> the original and battle proven architecture and I can
> only
> > > > warn
> > > > > to
> > > > > > >>>>>>>> move
> > > > > > >>>>>>>> away from it.
> > > > > > >>>>>>>>
> > > > > > >>>>>>>> I might have forgotten something, sometimes its hard for
> > me
> > > to
> > > > > > >>>>>>>> getting
> > > > > > >>>>>>>> all
> > > > > > >>>>>>>> the thoughts captured in a mail, but I hope the comments
> > > > inline
> > > > > > will
> > > > > > >>>>>>>> further make my concern clear, and put some emphasis on
> > why
> > > I
> > > > > > >>>>>>>> prefer my
> > > > > > >>>>>>>> solution ;)
> > > > > > >>>>>>>>
> > > > > > >>>>>>>> One thing we should all be aware of when discussing
> this,
> > > and
> > > > I
> > > > > > >>>>>>>> think
> > > > > > >>>>>>>> Dong
> > > > > > >>>>>>>> should have mentioned it (maybe he did).
> > > > > > >>>>>>>> We are not discussing all of this out of thin air but
> > there
> > > is
> > > > > an
> > > > > > >>>>>>>> effort
> > > > > > >>>>>>>> in the Samza project.
> > > > > > >>>>>>>>
> > > > > > >>>>>>>> https://cwiki.apache.org/confluence/display/SAMZA/SEP-
> > 5%3A+
> > > > > > >>>>>>>> Enable+partition+expansion+of+input+streams
> > > > > > >>>>>>>> https://issues.apache.org/jira/browse/SAMZA-1293
> > > > > > >>>>>>>>
> > > > > > >>>>>>>> To be clear. I think SEP-5 (state of last week, dont
> know
> > if
> > > > it
> > > > > > >>>>>>>> adapted
> > > > > > >>>>>>>> to
> > > > > > >>>>>>>> this discussion) is on a way better path than KIP-253,
> > and I
> > > > > can't
> > > > > > >>>>>>>> really
> > > > > > >>>>>>>> explain why.
> > > > > > >>>>>>>>
> > > > > > >>>>>>>> Best Jan,
> > > > > > >>>>>>>>
> > > > > > >>>>>>>> nice weekend everyone
> > > > > > >>>>>>>>
> > > > > > >>>>>>>>
> > > > > > >>>>>>>> On 09.03.2018 03:36, Jun Rao wrote:
> > > > > > >>>>>>>>
> > > > > > >>>>>>>> Hi, Jan,
> > > > > > >>>>>>>>
> > > > > > >>>>>>>> Thanks for the feedback. Just some comments on the
> earlier
> > > > > points
> > > > > > >>>>>>>>> that
> > > > > > >>>>>>>>> you
> > > > > > >>>>>>>>> mentioned.
> > > > > > >>>>>>>>>
> > > > > > >>>>>>>>> 50. You brought up the question of whether existing
> data
> > > > needs
> > > > > to
> > > > > > >>>>>>>>> be
> > > > > > >>>>>>>>> copied
> > > > > > >>>>>>>>> during partition expansion. My understand of your view
> is
> > > > that
> > > > > > >>>>>>>>> avoid
> > > > > > >>>>>>>>> copying existing data will be more efficient, but it
> > > doesn't
> > > > > work
> > > > > > >>>>>>>>> well
> > > > > > >>>>>>>>> with
> > > > > > >>>>>>>>> compacted topics since some keys in the original
> > partitions
> > > > > will
> > > > > > >>>>>>>>> never
> > > > > > >>>>>>>>> be
> > > > > > >>>>>>>>> cleaned. It would be useful to understand your use case
> > of
> > > > > > >>>>>>>>> compacted
> > > > > > >>>>>>>>> topics
> > > > > > >>>>>>>>> a bit more. In the common use case, the data volume in
> a
> > > > > > compacted
> > > > > > >>>>>>>>> topic
> > > > > > >>>>>>>>> may not be large. So, I am not sure if there is a
> strong
> > > need
> > > > > to
> > > > > > >>>>>>>>> expand
> > > > > > >>>>>>>>> partitions in a compacted topic, at least initially.
> > > > > > >>>>>>>>>
> > > > > > >>>>>>>>> I do agree. State is usually smaller. Update rates
> might
> > be
> > > > > also
> > > > > > >>>>>>>>>
> > > > > > >>>>>>>>> competitively high.
> > > > > > >>>>>>>> Doing Log-compaction (even beeing very efficient and
> > > > > configurable)
> > > > > > >>>>>>>> is
> > > > > > >>>>>>>> also
> > > > > > >>>>>>>> a more expensive operation than
> > > > > > >>>>>>>> just discarding old segments. Further if you want to use
> > > more
> > > > > > >>>>>>>> consumers
> > > > > > >>>>>>>> processing the events
> > > > > > >>>>>>>> you also have to grow the number of partitions.
> Especially
> > > for
> > > > > > >>>>>>>> use-cases
> > > > > > >>>>>>>> we do (KIP-213) a tiny state full
> > > > > > >>>>>>>> table might be very expensive to process if it joins
> > > against a
> > > > > > huge
> > > > > > >>>>>>>> table.
> > > > > > >>>>>>>>
> > > > > > >>>>>>>> I can just say we have been in the spot of needing to
> grow
> > > log
> > > > > > >>>>>>>> compacted
> > > > > > >>>>>>>> topics. Mainly for processing power we can bring to the
> > > table.
> > > > > > >>>>>>>>
> > > > > > >>>>>>>> Further i am not at all concerned about the extra spaced
> > > used
> > > > by
> > > > > > >>>>>>>> "garbage
> > > > > > >>>>>>>> keys". I am more concerned about the correctness of
> > innocent
> > > > > > >>>>>>>> consumers.
> > > > > > >>>>>>>> The
> > > > > > >>>>>>>> logic becomes complicated. Say for streams one would
> need
> > to
> > > > > load
> > > > > > >>>>>>>> the
> > > > > > >>>>>>>> record into state but not forward it the topology ( to
> > have
> > > it
> > > > > > >>>>>>>> available
> > > > > > >>>>>>>> for shuffeling). I rather have it simple and a topic
> clean
> > > > > > >>>>>>>> regardless
> > > > > > >>>>>>>> if
> > > > > > >>>>>>>> it
> > > > > > >>>>>>>> still has its old partition count. Especially with
> > multiple
> > > > > > >>>>>>>> partitions
> > > > > > >>>>>>>> growth's I think it becomes insanely hard to to this
> > shuffle
> > > > > > >>>>>>>> correct.
> > > > > > >>>>>>>> Maybe
> > > > > > >>>>>>>> Streams and Samza can do it. Especially if you do
> "hipster
> > > > > stream
> > > > > > >>>>>>>> processing" <https://www.confluent.io/blog
> > > > > > >>>>>>>> /introducing-kafka-streams-
> > > > > > >>>>>>>> stream-processing-made-simple/>. This makes kafka way
> to
> > > > > > >>>>>>>> complicated.
> > > > > > >>>>>>>> With my approach I think its way simpler because the
> topic
> > > has
> > > > > no
> > > > > > >>>>>>>> "history"
> > > > > > >>>>>>>> in terms of partitioning but is always clean.
> > > > > > >>>>>>>>
> > > > > > >>>>>>>>
> > > > > > >>>>>>>> 51. "Growing the topic by an integer factor does not
> > require
> > > > any
> > > > > > >>>>>>>> state
> > > > > > >>>>>>>>
> > > > > > >>>>>>>> redistribution at all." Could you clarify this a bit
> more?
> > > > Let's
> > > > > > say
> > > > > > >>>>>>>>> you
> > > > > > >>>>>>>>> have a consumer app that computes the windowed count
> per
> > > key.
> > > > > If
> > > > > > >>>>>>>>> you
> > > > > > >>>>>>>>> double
> > > > > > >>>>>>>>> the number of partitions from 1 to 2 and grow the
> > consumer
> > > > > > >>>>>>>>> instances
> > > > > > >>>>>>>>> from
> > > > > > >>>>>>>>> 1
> > > > > > >>>>>>>>> to 2, we would need to redistribute some of the counts
> to
> > > the
> > > > > new
> > > > > > >>>>>>>>> consumer
> > > > > > >>>>>>>>> instance. Regarding to linear hashing, it's true that
> it
> > > > won't
> > > > > > >>>>>>>>> solve
> > > > > > >>>>>>>>> the
> > > > > > >>>>>>>>> problem with compacted topics. The main benefit is that
> > it
> > > > > > >>>>>>>>> redistributes
> > > > > > >>>>>>>>> the keys in one partition to no more than two
> partitions,
> > > > which
> > > > > > >>>>>>>>> could
> > > > > > >>>>>>>>> help
> > > > > > >>>>>>>>> redistribute the state.
> > > > > > >>>>>>>>>
> > > > > > >>>>>>>>> You don't need to spin up a new consumer in this case.
> > > every
> > > > > > >>>>>>>>> consumer
> > > > > > >>>>>>>>>
> > > > > > >>>>>>>>> would just read every partition with the (partition %
> > > > num_task)
> > > > > > >>>>>>>> task.
> > > > > > >>>>>>>> it
> > > > > > >>>>>>>> will still have the previous data right there and can go
> > on.
> > > > > > >>>>>>>>
> > > > > > >>>>>>>> This sounds contradictory to what I said before, but
> > please
> > > > bear
> > > > > > >>>>>>>> with
> > > > > > >>>>>>>> me.
> > > > > > >>>>>>>>
> > > > > > >>>>>>>> 52. Good point on coordinating the expansion of 2 topics
> > > that
> > > > > need
> > > > > > >>>>>>>> to
> > > > > > >>>>>>>> be
> > > > > > >>>>>>>>
> > > > > > >>>>>>>> joined together. This is where the 2-phase partition
> > > expansion
> > > > > > could
> > > > > > >>>>>>>>> potentially help. In the first phase, we could add new
> > > > > partitions
> > > > > > >>>>>>>>> to
> > > > > > >>>>>>>>> the 2
> > > > > > >>>>>>>>> topics one at a time but without publishing to the new
> > > > > patitions.
> > > > > > >>>>>>>>> Then,
> > > > > > >>>>>>>>> we
> > > > > > >>>>>>>>> can add new consumer instances to pick up the new
> > > partitions.
> > > > > In
> > > > > > >>>>>>>>> this
> > > > > > >>>>>>>>> transition phase, no reshuffling is needed since no
> data
> > is
> > > > > > coming
> > > > > > >>>>>>>>> from
> > > > > > >>>>>>>>> the
> > > > > > >>>>>>>>> new partitions. Finally, we can enable the publishing
> to
> > > the
> > > > > new
> > > > > > >>>>>>>>> partitions.
> > > > > > >>>>>>>>>
> > > > > > >>>>>>>>> I think its even worse than you think. I would like to
> > > > > introduce
> > > > > > >>>>>>>>> the
> > > > > > >>>>>>>>>
> > > > > > >>>>>>>>> Term
> > > > > > >>>>>>>> transitive copartitioning. Imagine
> > > > > > >>>>>>>> 2 streams application. One joins (A,B) the other (B,C)
> > then
> > > > > there
> > > > > > >>>>>>>> is a
> > > > > > >>>>>>>> transitive copartition requirement for
> > > > > > >>>>>>>> (A,C) to be copartitioned aswell. This can spread
> > > > significantly
> > > > > > and
> > > > > > >>>>>>>> require many consumers to adapt at the same time.
> > > > > > >>>>>>>>
> > > > > > >>>>>>>> It is also not entirely clear to me how you not need
> > > > reshuffling
> > > > > > in
> > > > > > >>>>>>>> this
> > > > > > >>>>>>>> case. If A has a record that never gets updated after
> the
> > > > > > expansion
> > > > > > >>>>>>>> and
> > > > > > >>>>>>>> the
> > > > > > >>>>>>>> coresponding B record moves to a new partition. How
> shall
> > > they
> > > > > > meet
> > > > > > >>>>>>>> w/o
> > > > > > >>>>>>>> shuffle?
> > > > > > >>>>>>>>
> > > > > > >>>>>>>> 53. "Migrating consumer is a step that might be made
> > > completly
> > > > > > >>>>>>>>
> > > > > > >>>>>>>> unnecessary
> > > > > > >>>>>>>>> if - for example streams - takes the gcd as
> partitioning
> > > > scheme
> > > > > > >>>>>>>>> instead
> > > > > > >>>>>>>>> of
> > > > > > >>>>>>>>> enforcing 1 to 1." Not sure that I fully understand
> > this. I
> > > > > think
> > > > > > >>>>>>>>> you
> > > > > > >>>>>>>>> mean
> > > > > > >>>>>>>>> that a consumer application can run more instances than
> > the
> > > > > > number
> > > > > > >>>>>>>>> of
> > > > > > >>>>>>>>> partitions. In that case, the consumer can just
> > > > repartitioning
> > > > > > the
> > > > > > >>>>>>>>> input
> > > > > > >>>>>>>>> data according to the number of instances. This is
> > > possible,
> > > > > but
> > > > > > >>>>>>>>> just
> > > > > > >>>>>>>>> has
> > > > > > >>>>>>>>> the overhead of reshuffling the data.
> > > > > > >>>>>>>>>
> > > > > > >>>>>>>>> No what I meant is ( that is also your question i think
> > > > > Mathias)
> > > > > > >>>>>>>>> that
> > > > > > >>>>>>>>> if
> > > > > > >>>>>>>>>
> > > > > > >>>>>>>>> you grow a topic by a factor.
> > > > > > >>>>>>>> Even if your processor is statefull you can can just
> > assign
> > > > all
> > > > > > the
> > > > > > >>>>>>>> multiples of the previous partition to
> > > > > > >>>>>>>> this consumer and the state to keep processing correctly
> > > will
> > > > be
> > > > > > >>>>>>>> present
> > > > > > >>>>>>>> w/o any shuffling.
> > > > > > >>>>>>>>
> > > > > > >>>>>>>> Say you have an assignment
> > > > > > >>>>>>>> Statefull consumer => partition
> > > > > > >>>>>>>> 0 => 0
> > > > > > >>>>>>>> 1 => 1
> > > > > > >>>>>>>> 2 => 2
> > > > > > >>>>>>>>
> > > > > > >>>>>>>> and you grow you topic by 4 you get,
> > > > > > >>>>>>>>
> > > > > > >>>>>>>> 0 => 0,3,6,9
> > > > > > >>>>>>>> 1 => 1,4,7,10
> > > > > > >>>>>>>> 2 => 2,5,8,11
> > > > > > >>>>>>>>
> > > > > > >>>>>>>> Say your hashcode is 8. 8%3 => 2  before so consumer for
> > > > > > partition 2
> > > > > > >>>>>>>> has
> > > > > > >>>>>>>> it.
> > > > > > >>>>>>>> Now you you have 12 partitions so 8%12 => 8, so it goes
> > into
> > > > > > >>>>>>>> partition
> > > > > > >>>>>>>> 8
> > > > > > >>>>>>>> which is assigned to the same consumer
> > > > > > >>>>>>>> who had 2 before and therefore knows the key.
> > > > > > >>>>>>>>
> > > > > > >>>>>>>> Userland reshuffeling is there as an options. And it
> does
> > > > > exactly
> > > > > > >>>>>>>> what
> > > > > > >>>>>>>> I
> > > > > > >>>>>>>> suggest. And I think its the perfect strategie. All I am
> > > > > > suggestion
> > > > > > >>>>>>>> is
> > > > > > >>>>>>>> broker side support to switch the producers to the newly
> > > > > > partitioned
> > > > > > >>>>>>>> topic.
> > > > > > >>>>>>>> Then the old (to few partition topic) can go away.
> > Remember
> > > > the
> > > > > > >>>>>>>> list
> > > > > > >>>>>>>> of
> > > > > > >>>>>>>> steps in the beginning of this thread. If one has broker
> > > > support
> > > > > > for
> > > > > > >>>>>>>> all
> > > > > > >>>>>>>> where its required and streams support for those that
> > aren’t
> > > > > > >>>>>>>> necessarily.
> > > > > > >>>>>>>> Then one has solved the problem.
> > > > > > >>>>>>>> I repeat it because I think its important. I am really
> > happy
> > > > > that
> > > > > > >>>>>>>> you
> > > > > > >>>>>>>> brought that up! because its 100% what I want just with
> > the
> > > > > > >>>>>>>> differences
> > > > > > >>>>>>>> to
> > > > > > >>>>>>>> have an option to discard the to small topic later
> (after
> > > all
> > > > > > >>>>>>>> consumers
> > > > > > >>>>>>>> adapted). And to have order correct there. I need broker
> > > > support
> > > > > > >>>>>>>> managing
> > > > > > >>>>>>>> the copy process + the produces and fence them against
> > each
> > > > > > other. I
> > > > > > >>>>>>>> also
> > > > > > >>>>>>>> repeat. the copy process can run for weeks in the worst
> > > case.
> > > > > > >>>>>>>> Copying
> > > > > > >>>>>>>> the
> > > > > > >>>>>>>> data is not the longest task migrating consumers might
> > very
> > > > well
> > > > > > be.
> > > > > > >>>>>>>> Once all consumers switched and copying is really up to
> > date
> > > > > > (think
> > > > > > >>>>>>>> ISR
> > > > > > >>>>>>>> like up to date) only then we stop the producer, wait
> for
> > > the
> > > > > copy
> > > > > > >>>>>>>> to
> > > > > > >>>>>>>> finish and use the new topic for producing.
> > > > > > >>>>>>>>
> > > > > > >>>>>>>> After this the topic is perfect in shape. and no one
> needs
> > > to
> > > > > > worry
> > > > > > >>>>>>>> about
> > > > > > >>>>>>>> complicated stuff. (old keys hanging around might arrive
> > in
> > > > some
> > > > > > >>>>>>>> other
> > > > > > >>>>>>>> topic later.....). can only imagine how many tricky bugs
> > > gonna
> > > > > > >>>>>>>> arrive
> > > > > > >>>>>>>> after
> > > > > > >>>>>>>> someone had grown and shrunken is topic 10 times.
> > > > > > >>>>>>>>
> > > > > > >>>>>>>>
> > > > > > >>>>>>>>
> > > > > > >>>>>>>>
> > > > > > >>>>>>>>
> > > > > > >>>>>>>>
> > > > > > >>>>>>>> 54. "The other thing I wanted to mention is that I
> believe
> > > the
> > > > > > >>>>>>>> current
> > > > > > >>>>>>>>
> > > > > > >>>>>>>> suggestion (without copying data over) can be
> implemented
> > in
> > > > > pure
> > > > > > >>>>>>>>> userland
> > > > > > >>>>>>>>> with a custom partitioner and a small feedbackloop from
> > > > > > >>>>>>>>> ProduceResponse
> > > > > > >>>>>>>>> =>
> > > > > > >>>>>>>>> Partitionier in coorporation with a change management
> > > > system."
> > > > > I
> > > > > > am
> > > > > > >>>>>>>>> not
> > > > > > >>>>>>>>> sure a customized partitioner itself solves the
> problem.
> > We
> > > > > > >>>>>>>>> probably
> > > > > > >>>>>>>>> need
> > > > > > >>>>>>>>> some broker side support to enforce when the new
> > partitions
> > > > can
> > > > > > be
> > > > > > >>>>>>>>> used.
> > > > > > >>>>>>>>> We
> > > > > > >>>>>>>>> also need some support on the consumer/kstream side to
> > > > preserve
> > > > > > the
> > > > > > >>>>>>>>> per
> > > > > > >>>>>>>>> key
> > > > > > >>>>>>>>> ordering and potentially migrate the processing state.
> > This
> > > > is
> > > > > > not
> > > > > > >>>>>>>>> trivial
> > > > > > >>>>>>>>> and I am not sure if it's ideal to fully push to the
> > > > > application
> > > > > > >>>>>>>>> space.
> > > > > > >>>>>>>>>
> > > > > > >>>>>>>>> Broker support is defenitly the preferred way here. I
> > have
> > > > > > nothing
> > > > > > >>>>>>>>>
> > > > > > >>>>>>>>> against
> > > > > > >>>>>>>> broker support.
> > > > > > >>>>>>>> I tried to say that for what I would preffer - copying
> the
> > > > data
> > > > > > >>>>>>>> over,
> > > > > > >>>>>>>> at
> > > > > > >>>>>>>> least for log compacted topics -
> > > > > > >>>>>>>> I would require more broker support than the KIP
> currently
> > > > > offers.
> > > > > > >>>>>>>>
> > > > > > >>>>>>>>
> > > > > > >>>>>>>>
> > > > > > >>>>>>>> Jun
> > > > > > >>>>>>>>
> > > > > > >>>>>>>> On Tue, Mar 6, 2018 at 10:33 PM, Jan Filipiak <
> > > > > > >>>>>>>>> Jan.Filipiak@trivago.com
> > > > > > >>>>>>>>> wrote:
> > > > > > >>>>>>>>>
> > > > > > >>>>>>>>> Hi Dong,
> > > > > > >>>>>>>>>
> > > > > > >>>>>>>>> are you actually reading my emails, or are you just
> using
> > > the
> > > > > > >>>>>>>>> thread I
> > > > > > >>>>>>>>>
> > > > > > >>>>>>>>>> started for general announcements regarding the KIP?
> > > > > > >>>>>>>>>>
> > > > > > >>>>>>>>>> I tried to argue really hard against linear hashing.
> > > Growing
> > > > > the
> > > > > > >>>>>>>>>> topic
> > > > > > >>>>>>>>>> by
> > > > > > >>>>>>>>>> an integer factor does not require any state
> > > redistribution
> > > > at
> > > > > > >>>>>>>>>> all. I
> > > > > > >>>>>>>>>> fail
> > > > > > >>>>>>>>>> to see completely where linear hashing helps on log
> > > > compacted
> > > > > > >>>>>>>>>> topics.
> > > > > > >>>>>>>>>>
> > > > > > >>>>>>>>>> If you are not willing to explain to me what I might
> be
> > > > > > >>>>>>>>>> overlooking:
> > > > > > >>>>>>>>>> that
> > > > > > >>>>>>>>>> is fine.
> > > > > > >>>>>>>>>> But I ask you to not reply to my emails then. Please
> > > > > understand
> > > > > > my
> > > > > > >>>>>>>>>> frustration with this.
> > > > > > >>>>>>>>>>
> > > > > > >>>>>>>>>> Best Jan
> > > > > > >>>>>>>>>>
> > > > > > >>>>>>>>>>
> > > > > > >>>>>>>>>>
> > > > > > >>>>>>>>>> On 06.03.2018 19:38, Dong Lin wrote:
> > > > > > >>>>>>>>>>
> > > > > > >>>>>>>>>> Hi everyone,
> > > > > > >>>>>>>>>>
> > > > > > >>>>>>>>>> Thanks for all the comments! It appears that everyone
> > > > prefers
> > > > > > >>>>>>>>>> linear
> > > > > > >>>>>>>>>>
> > > > > > >>>>>>>>>>> hashing because it reduces the amount of state that
> > needs
> > > > to
> > > > > be
> > > > > > >>>>>>>>>>> moved
> > > > > > >>>>>>>>>>> between consumers (for stream processing). The KIP
> has
> > > been
> > > > > > >>>>>>>>>>> updated
> > > > > > >>>>>>>>>>> to
> > > > > > >>>>>>>>>>> use
> > > > > > >>>>>>>>>>> linear hashing.
> > > > > > >>>>>>>>>>>
> > > > > > >>>>>>>>>>> Regarding the migration endeavor: it seems that
> > migrating
> > > > > > >>>>>>>>>>> producer
> > > > > > >>>>>>>>>>> library
> > > > > > >>>>>>>>>>> to use linear hashing should be pretty
> straightforward
> > > > > without
> > > > > > >>>>>>>>>>> much operational endeavor. If we don't upgrade client
> > > > library
> > > > > > to
> > > > > > >>>>>>>>>>> use
> > > > > > >>>>>>>>>>> this
> > > > > > >>>>>>>>>>> KIP, we can not support in-order delivery after
> > partition
> > > > is
> > > > > > >>>>>>>>>>> changed
> > > > > > >>>>>>>>>>> anyway. Suppose we upgrade client library to use this
> > > KIP,
> > > > if
> > > > > > >>>>>>>>>>> partition
> > > > > > >>>>>>>>>>> number is not changed, the key -> partition mapping
> > will
> > > be
> > > > > > >>>>>>>>>>> exactly
> > > > > > >>>>>>>>>>> the
> > > > > > >>>>>>>>>>> same as it is now because it is still determined
> using
> > > > > > >>>>>>>>>>> murmur_hash(key)
> > > > > > >>>>>>>>>>> %
> > > > > > >>>>>>>>>>> original_partition_num. In other words, this change
> is
> > > > > backward
> > > > > > >>>>>>>>>>> compatible.
> > > > > > >>>>>>>>>>>
> > > > > > >>>>>>>>>>> Regarding the load distribution: if we use linear
> > > hashing,
> > > > > the
> > > > > > >>>>>>>>>>> load
> > > > > > >>>>>>>>>>> may
> > > > > > >>>>>>>>>>> be
> > > > > > >>>>>>>>>>> unevenly distributed because those partitions which
> are
> > > not
> > > > > > split
> > > > > > >>>>>>>>>>> may
> > > > > > >>>>>>>>>>> receive twice as much traffic as other partitions
> that
> > > are
> > > > > > split.
> > > > > > >>>>>>>>>>> This
> > > > > > >>>>>>>>>>> issue can be mitigated by creating topic with
> > partitions
> > > > that
> > > > > > are
> > > > > > >>>>>>>>>>> several
> > > > > > >>>>>>>>>>> times the number of consumers. And there will be no
> > > > imbalance
> > > > > > if
> > > > > > >>>>>>>>>>> the
> > > > > > >>>>>>>>>>> partition number is always doubled. So this imbalance
> > > seems
> > > > > > >>>>>>>>>>> acceptable.
> > > > > > >>>>>>>>>>>
> > > > > > >>>>>>>>>>> Regarding storing the partition strategy as per-topic
> > > > config:
> > > > > > It
> > > > > > >>>>>>>>>>> seems
> > > > > > >>>>>>>>>>> not
> > > > > > >>>>>>>>>>> necessary since we can still use murmur_hash as the
> > > default
> > > > > > hash
> > > > > > >>>>>>>>>>> function
> > > > > > >>>>>>>>>>> and additionally apply the linear hashing algorithm
> if
> > > the
> > > > > > >>>>>>>>>>> partition
> > > > > > >>>>>>>>>>> number
> > > > > > >>>>>>>>>>> has increased. Not sure if there is any use-case for
> > > > producer
> > > > > > to
> > > > > > >>>>>>>>>>> use a
> > > > > > >>>>>>>>>>> different hash function. Jason, can you check if
> there
> > is
> > > > > some
> > > > > > >>>>>>>>>>> use-case
> > > > > > >>>>>>>>>>> that I missed for using the per-topic partition
> > strategy?
> > > > > > >>>>>>>>>>>
> > > > > > >>>>>>>>>>> Regarding how to reduce latency (due to state
> > store/load)
> > > > in
> > > > > > >>>>>>>>>>> stream
> > > > > > >>>>>>>>>>> processing consumer when partition number changes: I
> > need
> > > > to
> > > > > > read
> > > > > > >>>>>>>>>>> the
> > > > > > >>>>>>>>>>> Kafka
> > > > > > >>>>>>>>>>> Stream code to understand how Kafka Stream currently
> > > > migrate
> > > > > > >>>>>>>>>>> state
> > > > > > >>>>>>>>>>> between
> > > > > > >>>>>>>>>>> consumers when the application is added/removed for a
> > > given
> > > > > > job.
> > > > > > >>>>>>>>>>> I
> > > > > > >>>>>>>>>>> will
> > > > > > >>>>>>>>>>> reply after I finish reading the documentation and
> > code.
> > > > > > >>>>>>>>>>>
> > > > > > >>>>>>>>>>>
> > > > > > >>>>>>>>>>> Thanks,
> > > > > > >>>>>>>>>>> Dong
> > > > > > >>>>>>>>>>>
> > > > > > >>>>>>>>>>>
> > > > > > >>>>>>>>>>> On Mon, Mar 5, 2018 at 10:43 AM, Jason Gustafson <
> > > > > > >>>>>>>>>>> jason@confluent.io>
> > > > > > >>>>>>>>>>> wrote:
> > > > > > >>>>>>>>>>>
> > > > > > >>>>>>>>>>> Great discussion. I think I'm wondering whether we
> can
> > > > > continue
> > > > > > >>>>>>>>>>> to
> > > > > > >>>>>>>>>>> leave
> > > > > > >>>>>>>>>>>
> > > > > > >>>>>>>>>>> Kafka agnostic to the partitioning strategy. The
> > > challenge
> > > > is
> > > > > > >>>>>>>>>>>
> > > > > > >>>>>>>>>>> communicating
> > > > > > >>>>>>>>>>>> the partitioning logic from producers to consumers
> so
> > > that
> > > > > the
> > > > > > >>>>>>>>>>>> dependencies
> > > > > > >>>>>>>>>>>> between each epoch can be determined. For the sake
> of
> > > > > > >>>>>>>>>>>> discussion,
> > > > > > >>>>>>>>>>>> imagine
> > > > > > >>>>>>>>>>>> you did something like the following:
> > > > > > >>>>>>>>>>>>
> > > > > > >>>>>>>>>>>> 1. The name (and perhaps version) of a partitioning
> > > > strategy
> > > > > > is
> > > > > > >>>>>>>>>>>> stored
> > > > > > >>>>>>>>>>>> in
> > > > > > >>>>>>>>>>>> topic configuration when a topic is created.
> > > > > > >>>>>>>>>>>> 2. The producer looks up the partitioning strategy
> > > before
> > > > > > >>>>>>>>>>>> writing
> > > > > > >>>>>>>>>>>> to
> > > > > > >>>>>>>>>>>> a
> > > > > > >>>>>>>>>>>> topic and includes it in the produce request (for
> > > > fencing).
> > > > > If
> > > > > > >>>>>>>>>>>> it
> > > > > > >>>>>>>>>>>> doesn't
> > > > > > >>>>>>>>>>>> have an implementation for the configured strategy,
> it
> > > > > fails.
> > > > > > >>>>>>>>>>>> 3. The consumer also looks up the partitioning
> > strategy
> > > > and
> > > > > > >>>>>>>>>>>> uses it
> > > > > > >>>>>>>>>>>> to
> > > > > > >>>>>>>>>>>> determine dependencies when reading a new epoch. It
> > > could
> > > > > > either
> > > > > > >>>>>>>>>>>> fail
> > > > > > >>>>>>>>>>>> or
> > > > > > >>>>>>>>>>>> make the most conservative dependency assumptions if
> > it
> > > > > > doesn't
> > > > > > >>>>>>>>>>>> know
> > > > > > >>>>>>>>>>>> how
> > > > > > >>>>>>>>>>>> to
> > > > > > >>>>>>>>>>>> implement the partitioning strategy. For the
> consumer,
> > > the
> > > > > new
> > > > > > >>>>>>>>>>>> interface
> > > > > > >>>>>>>>>>>> might look something like this:
> > > > > > >>>>>>>>>>>>
> > > > > > >>>>>>>>>>>> // Return the partition dependencies following an
> > epoch
> > > > bump
> > > > > > >>>>>>>>>>>> Map<Integer, List<Integer>> dependencies(int
> > > > > > >>>>>>>>>>>> numPartitionsBeforeEpochBump,
> > > > > > >>>>>>>>>>>> int numPartitionsAfterEpochBump)
> > > > > > >>>>>>>>>>>>
> > > > > > >>>>>>>>>>>> The unordered case then is just a particular
> > > > implementation
> > > > > > >>>>>>>>>>>> which
> > > > > > >>>>>>>>>>>> never
> > > > > > >>>>>>>>>>>> has
> > > > > > >>>>>>>>>>>> any epoch dependencies. To implement this, we would
> > need
> > > > > some
> > > > > > >>>>>>>>>>>> way
> > > > > > >>>>>>>>>>>> for
> > > > > > >>>>>>>>>>>> the
> > > > > > >>>>>>>>>>>> consumer to find out how many partitions there were
> in
> > > > each
> > > > > > >>>>>>>>>>>> epoch,
> > > > > > >>>>>>>>>>>> but
> > > > > > >>>>>>>>>>>> maybe that's not too unreasonable.
> > > > > > >>>>>>>>>>>>
> > > > > > >>>>>>>>>>>> Thanks,
> > > > > > >>>>>>>>>>>> Jason
> > > > > > >>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>
> > > > > > >>>>>>>>>>>> On Mon, Mar 5, 2018 at 4:51 AM, Jan Filipiak <
> > > > > > >>>>>>>>>>>> Jan.Filipiak@trivago.com
> > > > > > >>>>>>>>>>>> wrote:
> > > > > > >>>>>>>>>>>>
> > > > > > >>>>>>>>>>>> Hi Dong
> > > > > > >>>>>>>>>>>>
> > > > > > >>>>>>>>>>>> thank you very much for your questions.
> > > > > > >>>>>>>>>>>>
> > > > > > >>>>>>>>>>>> regarding the time spend copying data across:
> > > > > > >>>>>>>>>>>>> It is correct that copying data from a topic with
> one
> > > > > > partition
> > > > > > >>>>>>>>>>>>> mapping
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> to
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> a topic with a different partition mapping takes
> way
> > > > longer
> > > > > > >>>>>>>>>>>>> than
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>> we
> > > > > > >>>>>>>>>>>> can
> > > > > > >>>>>>>>>>>>
> > > > > > >>>>>>>>>>>> stop producers. Tens of minutes is a very optimistic
> > > > > estimate
> > > > > > >>>>>>>>>>>> here.
> > > > > > >>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> Many
> > > > > > >>>>>>>>>>>>> people can not afford copy full steam and therefore
> > > will
> > > > > have
> > > > > > >>>>>>>>>>>>> some
> > > > > > >>>>>>>>>>>>> rate
> > > > > > >>>>>>>>>>>>> limiting in place, this can bump the timespan into
> > the
> > > > > day's.
> > > > > > >>>>>>>>>>>>> The
> > > > > > >>>>>>>>>>>>> good
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> part
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> is that the vast majority of the data can be copied
> > > while
> > > > > the
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>> producers
> > > > > > >>>>>>>>>>>>
> > > > > > >>>>>>>>>>>> are
> > > > > > >>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> still going. One can then, piggyback the consumers
> > > ontop
> > > > of
> > > > > > >>>>>>>>>>>>> this
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>> timeframe,
> > > > > > >>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> by the method mentioned (provide them an mapping
> from
> > > > their
> > > > > > old
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>> offsets
> > > > > > >>>>>>>>>>>>
> > > > > > >>>>>>>>>>>> to
> > > > > > >>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> new offsets in their repartitioned topics. In that
> > way
> > > we
> > > > > > >>>>>>>>>>>>> separate
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>> migration of consumers from migration of producers
> > > > > (decoupling
> > > > > > >>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> these
> > > > > > >>>>>>>>>>>>> is
> > > > > > >>>>>>>>>>>>> what kafka is strongest at). The time to actually
> > swap
> > > > over
> > > > > > the
> > > > > > >>>>>>>>>>>>> producers
> > > > > > >>>>>>>>>>>>> should be kept minimal by ensuring that when a swap
> > > > attempt
> > > > > > is
> > > > > > >>>>>>>>>>>>> started
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> the
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> consumer copying over should be very close to the
> log
> > > end
> > > > > and
> > > > > > >>>>>>>>>>>>> is
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>> expected
> > > > > > >>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> to finish within the next fetch. The operation
> should
> > > > have
> > > > > a
> > > > > > >>>>>>>>>>>>> time-out
> > > > > > >>>>>>>>>>>>> and
> > > > > > >>>>>>>>>>>>> should be "reattemtable".
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> Importance of logcompaction:
> > > > > > >>>>>>>>>>>>> If a producer produces key A, to partiton 0, its
> > > forever
> > > > > > gonna
> > > > > > >>>>>>>>>>>>> be
> > > > > > >>>>>>>>>>>>> there,
> > > > > > >>>>>>>>>>>>> unless it gets deleted. The record might sit in
> there
> > > for
> > > > > > >>>>>>>>>>>>> years. A
> > > > > > >>>>>>>>>>>>> new
> > > > > > >>>>>>>>>>>>> producer started with the new partitions will fail
> to
> > > > > delete
> > > > > > >>>>>>>>>>>>> the
> > > > > > >>>>>>>>>>>>> record
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> in
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> the correct partition. Th record will be there
> > forever
> > > > and
> > > > > > one
> > > > > > >>>>>>>>>>>>> can
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>> not
> > > > > > >>>>>>>>>>>>
> > > > > > >>>>>>>>>>>> reliable bootstrap new consumers. I cannot see how
> > > linear
> > > > > > >>>>>>>>>>>> hashing
> > > > > > >>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> can
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> solve
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> this.
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>> Regarding your skipping of userland copying:
> > > > > > >>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> 100%, copying the data across in userland is, as
> far
> > > as i
> > > > > can
> > > > > > >>>>>>>>>>>>> see,
> > > > > > >>>>>>>>>>>>> only
> > > > > > >>>>>>>>>>>>> a
> > > > > > >>>>>>>>>>>>> usecase for log compacted topics. Even for
> > > logcompaction
> > > > +
> > > > > > >>>>>>>>>>>>> retentions
> > > > > > >>>>>>>>>>>>> it
> > > > > > >>>>>>>>>>>>> should only be opt-in. Why did I bring it up? I
> think
> > > log
> > > > > > >>>>>>>>>>>>> compaction
> > > > > > >>>>>>>>>>>>> is
> > > > > > >>>>>>>>>>>>> a
> > > > > > >>>>>>>>>>>>> very important feature to really embrace kafka as a
> > > "data
> > > > > > >>>>>>>>>>>>> plattform".
> > > > > > >>>>>>>>>>>>> The
> > > > > > >>>>>>>>>>>>> point I also want to make is that copying data this
> > way
> > > > is
> > > > > > >>>>>>>>>>>>> completely
> > > > > > >>>>>>>>>>>>> inline with the kafka architecture. it only
> consists
> > of
> > > > > > reading
> > > > > > >>>>>>>>>>>>> and
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> writing
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> to topics.
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>> I hope it clarifies more why I think we should aim
> for
> > > > more
> > > > > > than
> > > > > > >>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> the
> > > > > > >>>>>>>>>>>>> current KIP. I fear that once the KIP is done not
> > much
> > > > more
> > > > > > >>>>>>>>>>>>> effort
> > > > > > >>>>>>>>>>>>> will
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> be
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> taken.
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>
> > > > > > >>>>>>>>>>>> On 04.03.2018 02:28, Dong Lin wrote:
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> Hey Jan,
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> In the current proposal, the consumer will be
> blocked
> > > on
> > > > > > >>>>>>>>>>>>> waiting
> > > > > > >>>>>>>>>>>>> for
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> other
> > > > > > >>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>> consumers of the group to consume up to a given
> > > offset.
> > > > In
> > > > > > >>>>>>>>>>>>>> most
> > > > > > >>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> cases,
> > > > > > >>>>>>>>>>>>> all
> > > > > > >>>>>>>>>>>>> consumers should be close to the LEO of the
> > partitions
> > > > when
> > > > > > the
> > > > > > >>>>>>>>>>>>> partition
> > > > > > >>>>>>>>>>>>> expansion happens. Thus the time waiting should not
> > be
> > > > long
> > > > > > >>>>>>>>>>>>> e.g.
> > > > > > >>>>>>>>>>>>> on
> > > > > > >>>>>>>>>>>>> the
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> order of seconds. On the other hand, it may take a
> > long
> > > > > time
> > > > > > to
> > > > > > >>>>>>>>>>>>> wait
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> for
> > > > > > >>>>>>>>>>>>>> the entire partition to be copied -- the amount of
> > > time
> > > > is
> > > > > > >>>>>>>>>>>>>> proportional
> > > > > > >>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>> to
> > > > > > >>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>> the amount of existing data in the partition,
> which
> > > can
> > > > > take
> > > > > > >>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> tens of
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> minutes. So the amount of time that we stop
> consumers
> > > may
> > > > > not
> > > > > > >>>>>>>>>>>>> be
> > > > > > >>>>>>>>>>>>> on
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> the
> > > > > > >>>>>>>>>>>>>> same order of magnitude.
> > > > > > >>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>> If we can implement this suggestion without
> copying
> > > data
> > > > > > over
> > > > > > >>>>>>>>>>>>>> in
> > > > > > >>>>>>>>>>>>>> purse
> > > > > > >>>>>>>>>>>>>> userland, it will be much more valuable. Do you
> have
> > > > ideas
> > > > > > on
> > > > > > >>>>>>>>>>>>>> how
> > > > > > >>>>>>>>>>>>>> this
> > > > > > >>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>> can
> > > > > > >>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>> be done?
> > > > > > >>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> Not sure why the current KIP not help people who
> > depend
> > > > on
> > > > > > log
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> compaction.
> > > > > > >>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>> Could you elaborate more on this point?
> > > > > > >>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> Thanks,
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> Dong
> > > > > > >>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>> On Wed, Feb 28, 2018 at 10:55 PM, Jan
> > > > > > >>>>>>>>>>>>>> Filipiak<Jan.Filipiak@trivago.
> > > > > > >>>>>>>>>>>>>> com
> > > > > > >>>>>>>>>>>>>> wrote:
> > > > > > >>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>> Hi Dong,
> > > > > > >>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>> I tried to focus on what the steps are one can
> > > currently
> > > > > > >>>>>>>>>>>>>> perform
> > > > > > >>>>>>>>>>>>>> to
> > > > > > >>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>> expand
> > > > > > >>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>> or shrink a keyed topic while maintaining a top
> > notch
> > > > > > >>>>>>>>>>>>>>> semantics.
> > > > > > >>>>>>>>>>>>>>> I can understand that there might be confusion
> > about
> > > > > > >>>>>>>>>>>>>>> "stopping
> > > > > > >>>>>>>>>>>>>>> the
> > > > > > >>>>>>>>>>>>>>> consumer". It is exactly the same as proposed in
> > the
> > > > KIP.
> > > > > > >>>>>>>>>>>>>>> there
> > > > > > >>>>>>>>>>>>>>> needs
> > > > > > >>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>> to
> > > > > > >>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>> be
> > > > > > >>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>> a time the producers agree on the new
> partitioning.
> > > The
> > > > > > extra
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> semantics I
> > > > > > >>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>> want to put in there is that we have a
> possibility
> > to
> > > > > wait
> > > > > > >>>>>>>>>>>>>>> until
> > > > > > >>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>> all
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> the
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> existing data
> > > > > > >>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>> is copied over into the new partitioning scheme.
> > When
> > > I
> > > > > say
> > > > > > >>>>>>>>>>>>> stopping
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> I
> > > > > > >>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>> think more of having a memory barrier that
> ensures
> > > the
> > > > > > >>>>>>>>>>>>>>> ordering. I
> > > > > > >>>>>>>>>>>>>>> am
> > > > > > >>>>>>>>>>>>>>> still
> > > > > > >>>>>>>>>>>>>>> aming for latencies  on the scale of leader
> > > failovers.
> > > > > > >>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>> Consumers have to explicitly adapt the new
> > > partitioning
> > > > > > >>>>>>>>>>>>>>> scheme
> > > > > > >>>>>>>>>>>>>>> in
> > > > > > >>>>>>>>>>>>>>> the
> > > > > > >>>>>>>>>>>>>>> above scenario. The reason is that in these cases
> > > where
> > > > > you
> > > > > > >>>>>>>>>>>>>>> are
> > > > > > >>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>> dependent
> > > > > > >>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>> on a particular partitioning scheme, you also
> have
> > > > other
> > > > > > >>>>>>>>>>>>>>> topics
> > > > > > >>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>> that
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> have
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> co-partition enforcements or the kind -frequently.
> > > > > Therefore
> > > > > > >>>>>>>>>>>>>> all
> > > > > > >>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>> your
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> other
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> input topics might need to grow accordingly.
> > > > > > >>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>> What I was suggesting was to streamline all these
> > > > > > operations
> > > > > > >>>>>>>>>>>>>>> as
> > > > > > >>>>>>>>>>>>>>> best
> > > > > > >>>>>>>>>>>>>>> as
> > > > > > >>>>>>>>>>>>>>> possible to have "real" partition grow and
> > shrinkage
> > > > > going
> > > > > > >>>>>>>>>>>>>>> on.
> > > > > > >>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>> Migrating
> > > > > > >>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>> the producers to a new partitioning scheme can be
> > > much
> > > > > more
> > > > > > >>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>> streamlined
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> with proper broker support for this. Migrating
> > consumer
> > > > is
> > > > > a
> > > > > > >>>>>>>>>>>>> step
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> that
> > > > > > >>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>> might be made completly unnecessary if - for
> > example
> > > > > > streams
> > > > > > >>>>>>>>>>>>>>> -
> > > > > > >>>>>>>>>>>>>>> takes
> > > > > > >>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>> the
> > > > > > >>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>> gcd as partitioning scheme instead of enforcing 1
> > to
> > > 1.
> > > > > > >>>>>>>>>>>>>>> Connect
> > > > > > >>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>> consumers
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> and other consumers should be fine anyways.
> > > > > > >>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>> I hope this makes more clear where I was aiming
> at.
> > > The
> > > > > rest
> > > > > > >>>>>>>>>>>>> needs
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> to
> > > > > > >>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>> be
> > > > > > >>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>> figured out. The only danger i see is that when
> we
> > > are
> > > > > > >>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>> introducing
> > > > > > >>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>> this
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> feature as supposed in the KIP, it wont help any
> > people
> > > > > > >>>>>>>>>>>>> depending
> > > > > > >>>>>>>>>>>>> on
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> log
> > > > > > >>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>> compaction.
> > > > > > >>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>> The other thing I wanted to mention is that I
> > believe
> > > > the
> > > > > > >>>>>>>>>>>>> current
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> suggestion (without copying data over) can be
> > > implemented
> > > > > in
> > > > > > >>>>>>>>>>>>>> pure
> > > > > > >>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>> userland
> > > > > > >>>>>>>>>>>>>>> with a custom partitioner and a small
> feedbackloop
> > > from
> > > > > > >>>>>>>>>>>>>>> ProduceResponse
> > > > > > >>>>>>>>>>>>>>> =>
> > > > > > >>>>>>>>>>>>>>> Partitionier in coorporation with a change
> > management
> > > > > > system.
> > > > > > >>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>> Best Jan
> > > > > > >>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>> On 28.02.2018 07:13, Dong Lin wrote:
> > > > > > >>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>> Hey Jan,
> > > > > > >>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>> I am not sure if it is acceptable for producer to
> > be
> > > > > > stopped
> > > > > > >>>>>>>>>>>>>>> for a
> > > > > > >>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>> while,
> > > > > > >>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>> particularly for online application which
> requires
> > > low
> > > > > > >>>>>>>>>>>>>>>> latency. I
> > > > > > >>>>>>>>>>>>>>>> am
> > > > > > >>>>>>>>>>>>>>>> also
> > > > > > >>>>>>>>>>>>>>>> not sure how consumers can switch to a new
> topic.
> > > Does
> > > > > > user
> > > > > > >>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>> application
> > > > > > >>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>> needs to explicitly specify a different topic
> for
> > > > > > >>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>> producer/consumer
> > > > > > >>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>> to
> > > > > > >>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> subscribe to? It will be helpful for discussion if
> > you
> > > > can
> > > > > > >>>>>>>>>>>>> provide
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> more
> > > > > > >>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>> detail on the interface change for this solution.
> > > > > > >>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>> Thanks,
> > > > > > >>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>> Dong
> > > > > > >>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>> On Mon, Feb 26, 2018 at 12:48 AM, Jan
> > > > > > >>>>>>>>>>>>>>>> Filipiak<Jan.Filipiak@trivago.
> > > > > > >>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>> com
> > > > > > >>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>> wrote:
> > > > > > >>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>> Hi,
> > > > > > >>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>> just want to throw my though in. In general the
> > > > > > functionality
> > > > > > >>>>>>>>>>>>>> is
> > > > > > >>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>> very
> > > > > > >>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>> usefull, we should though not try to find the
> > > > > architecture
> > > > > > >>>>>>>>>>>>>>>> to
> > > > > > >>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>> hard
> > > > > > >>>>>>>>>>>>>>>>> while
> > > > > > >>>>>>>>>>>>>>>>> implementing.
> > > > > > >>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>> The manual steps would be to
> > > > > > >>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>> create a new topic
> > > > > > >>>>>>>>>>>>>>>>> the mirrormake from the new old topic to the
> new
> > > > topic
> > > > > > >>>>>>>>>>>>>>>>> wait for mirror making to catch up.
> > > > > > >>>>>>>>>>>>>>>>> then put the consumers onto the new topic
> > > > > > >>>>>>>>>>>>>>>>>            (having mirrormaker spit out a
> mapping
> > > > from
> > > > > > old
> > > > > > >>>>>>>>>>>>>>>>> offsets to
> > > > > > >>>>>>>>>>>>>>>>> new
> > > > > > >>>>>>>>>>>>>>>>> offsets:
> > > > > > >>>>>>>>>>>>>>>>>                if topic is increased by factor
> X
> > > > there
> > > > > is
> > > > > > >>>>>>>>>>>>>>>>> gonna
> > > > > > >>>>>>>>>>>>>>>>> be a
> > > > > > >>>>>>>>>>>>>>>>> clean
> > > > > > >>>>>>>>>>>>>>>>> mapping from 1 offset in the old topic to X
> > offsets
> > > > in
> > > > > > the
> > > > > > >>>>>>>>>>>>>>>>> new
> > > > > > >>>>>>>>>>>>>>>>> topic,
> > > > > > >>>>>>>>>>>>>>>>>                if there is no factor then there
> > is
> > > no
> > > > > > >>>>>>>>>>>>>>>>> chance to
> > > > > > >>>>>>>>>>>>>>>>> generate a
> > > > > > >>>>>>>>>>>>>>>>> mapping that can be reasonable used for
> > continuing)
> > > > > > >>>>>>>>>>>>>>>>>            make consumers stop at appropriate
> > > points
> > > > > and
> > > > > > >>>>>>>>>>>>>>>>> continue
> > > > > > >>>>>>>>>>>>>>>>> consumption
> > > > > > >>>>>>>>>>>>>>>>> with offsets from the mapping.
> > > > > > >>>>>>>>>>>>>>>>> have the producers stop for a minimal time.
> > > > > > >>>>>>>>>>>>>>>>> wait for mirrormaker to finish
> > > > > > >>>>>>>>>>>>>>>>> let producer produce with the new metadata.
> > > > > > >>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>> Instead of implementing the approach suggest in
> > the
> > > > KIP
> > > > > > >>>>>>>>>>>>>>>>> which
> > > > > > >>>>>>>>>>>>>>>>> will
> > > > > > >>>>>>>>>>>>>>>>> leave
> > > > > > >>>>>>>>>>>>>>>>> log compacted topic completely crumbled and
> > > unusable.
> > > > > > >>>>>>>>>>>>>>>>> I would much rather try to build infrastructure
> > to
> > > > > > support
> > > > > > >>>>>>>>>>>>>>>>> the
> > > > > > >>>>>>>>>>>>>>>>> mentioned
> > > > > > >>>>>>>>>>>>>>>>> above operations more smoothly.
> > > > > > >>>>>>>>>>>>>>>>> Especially having producers stop and use
> another
> > > > topic
> > > > > is
> > > > > > >>>>>>>>>>>>>>>>> difficult
> > > > > > >>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>> and
> > > > > > >>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>> it would be nice if one can trigger "invalid
> > > > metadata"
> > > > > > >>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>> exceptions
> > > > > > >>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>> for
> > > > > > >>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>> them
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> and
> > > > > > >>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>> if one could give topics aliases so that their
> > > produces
> > > > > > with
> > > > > > >>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>> the
> > > > > > >>>>>>>>>>>>>>>>> old
> > > > > > >>>>>>>>>>>>>>>>> topic
> > > > > > >>>>>>>>>>>>>>>>> will arrive in the new topic.
> > > > > > >>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>> The downsides are obvious I guess ( having the
> > same
> > > > > data
> > > > > > >>>>>>>>>>>>>>>>> twice
> > > > > > >>>>>>>>>>>>>>>>> for
> > > > > > >>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>> the
> > > > > > >>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>> transition period, but kafka tends to scale
> well
> > > with
> > > > > > >>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>> datasize).
> > > > > > >>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>> So
> > > > > > >>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>> its a
> > > > > > >>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>> nicer fit into the architecture.
> > > > > > >>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>> I further want to argument that the functionality
> > by
> > > > the
> > > > > > KIP
> > > > > > >>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>> can
> > > > > > >>>>>>>>>>>>>>>>> completely be implementing in "userland" with a
> > > > custom
> > > > > > >>>>>>>>>>>>>>>>> partitioner
> > > > > > >>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>> that
> > > > > > >>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>> handles the transition as needed. I would
> > > appreciate
> > > > if
> > > > > > >>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>> someone
> > > > > > >>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>> could
> > > > > > >>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>> point
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> out what a custom partitioner couldn't handle in
> this
> > > > case?
> > > > > > >>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>> With the above approach, shrinking a topic
> becomes
> > > the
> > > > > same
> > > > > > >>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>> steps.
> > > > > > >>>>>>>>>>>>>>>>> Without
> > > > > > >>>>>>>>>>>>>>>>> loosing keys in the discontinued partitions.
> > > > > > >>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>> Would love to hear what everyone thinks.
> > > > > > >>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>> Best Jan
> > > > > > >>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>> On 11.02.2018 00:35, Dong Lin wrote:
> > > > > > >>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>> Hi all,
> > > > > > >>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>> I have created KIP-253: Support in-order
> message
> > > > > delivery
> > > > > > >>>>>>>>>>>>>>>>> with
> > > > > > >>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>> partition
> > > > > > >>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>> expansion. See
> > > > > > >>>>>>>>>>>>>>>>>> https://cwiki.apache.org/confl
> > > > > > >>>>>>>>>>>>>>>>>> uence/display/KAFKA/KIP-253%
> > > > > > >>>>>>>>>>>>>>>>>> 3A+Support+in-order+message+de
> > > > > > >>>>>>>>>>>>>>>>>> livery+with+partition+expansio
> > > > > > >>>>>>>>>>>>>>>>>> n
> > > > > > >>>>>>>>>>>>>>>>>> .
> > > > > > >>>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>>> This KIP provides a way to allow messages of
> the
> > > > same
> > > > > > key
> > > > > > >>>>>>>>>>>>>>>>>> from
> > > > > > >>>>>>>>>>>>>>>>>> the
> > > > > > >>>>>>>>>>>>>>>>>> same
> > > > > > >>>>>>>>>>>>>>>>>> producer to be consumed in the same order they
> > are
> > > > > > >>>>>>>>>>>>>>>>>> produced
> > > > > > >>>>>>>>>>>>>>>>>> even
> > > > > > >>>>>>>>>>>>>>>>>> if
> > > > > > >>>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>>> we
> > > > > > >>>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>>> expand partition of the topic.
> > > > > > >>>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>> Thanks,
> > > > > > >>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>> Dong
> > > > > > >>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>>>
> > > > > > >>>>
> > > > > > >>
> > > > > > >>
> > > > > > >
> > > > > >
> > > > >
> > > >
> > >
> >
>

Re: [DISCUSS] KIP-253: Support in-order message delivery with partition expansion

Posted by Dong Lin <li...@gmail.com>.
Hey John,

Thanks much for your super-detailed explanation. This is very helpful.

Now that I have finished reading through your email, I think the proposed
solution in my previous email probably meets the requirement #6 without
requiring additional coordination (w.r.t. partition function) among
clients. My understanding of requirement #6 is that, after partition
expansion, messages with the given key will go to the same consumer before
and after the partition expansion such that stream processing jobs won't be
affected. Thus this approach seems to be better than backfilling since it
does not require data copy for input topics.

In order for the proposed solution to meet requirements #6, we need two
extra requirements in addition to what has been described in the previous
email: 1) stream processing job starts with the same number of processors
as the initial number of partitions of the input topics; and 2) at any
given time the number of partitions of the input topic >= the number of
processors of the given stream processing job.

Could you take a look at the proposed solution and see if any of the claims
above is false?


Hey Jan,

Maybe it is more efficient for us to discuss your concern in the KIP
Meeting.


Thanks,
Dong


On Thu, Mar 29, 2018 at 2:05 PM, John Roesler <jo...@confluent.io> wrote:

> Hi Jun,
>
> Thanks for the response. I'm very new to this project, but I will share my
> perspective. I'm going to say a bunch of stuff that I know you know
> already, but just so we're on the same page...
>
> This may also be a good time to get feedback from the other KStreams folks.
>
> Using KStreams as a reference implementation for how stream processing
> frameworks may interact with Kafka, I think it's important to eschew
> knowledge about how KStreams currently handles internal communication,
> making state durable, etc. Both because these details may change, and
> because they won't be shared with other stream processors.
>
> =================================
> Background
>
> We are looking at a picture like this:
>
>      input input input
>          \   |   /
>       +-------------+
> +-----+ Consumer(s) +-------+
> |     +-------------+       |
> |                           |
> |    KStreams Application   |
> |                           |
> |     +-------------+       |
> +-----+ Producer(s) +-------+
>       +-------------+
>            /    \
>         output output
>
> The inputs and outputs are Kafka topics (and therefore have 1 or more
> partitions). We'd have at least 1 input and 0 or more outputs. The
> Consumers and Producers are both the official KafkaConsumer and
> KafkaProducer.
>
> In general, we'll assume that the input topics are provided by actors over
> which we have no control, although we may as well assume they are friendly
> and amenable to requests, and also that their promises are trustworthy.
> This is important because we must depend on them to uphold some promises:
> * That they tell us the schema of the data they publish, and abide by that
> schema. Without this, the inputs are essentially garbage.
> * That they tell us some defining characteristics of the topics (more on
> this in a sec.) and again strictly abide by that promise.
>
> What are the topic characteristics we care about?
> 1. The name (or name pattern)
> 2. How the messages are keyed (if at all)
> 3. Whether the message timestamps are meaningful, and if so, what their
> meaning is
> 4. Assuming the records have identity, whether the partitions partition the
> records' identity space
> 5. Whether the topic completely contains the data set
> 6. Whether the messages in the topic are ordered
>
> #1 is obvious: without this information, we cannot access the data at all.
>
> For #2, #3, #4, and #6, we may or may not need this information, depending
> on the logic of the application. For example, a trivial application that
> simply counts all events it sees doesn't care about #2, #3, #4, or #6. But
> an application that groups by some attribute can take advantage of #2 and
> #4 if the topic data is already keyed and partitioned over that attribute.
> Likewise, if the application includes some temporal semantics on a temporal
> dimension that is already captured in #3, it may take advantage of that
> fact.
>
> Note that #2, #3, #4, and #6 are all optional. If they are not promised, we
> can do extra work inside the application to accomplish what we need.
> However, if they are promised (and if we depend on that promise), it is
> essential that the topic providers uphold those promises, as we may not be
> in a position to verify them.
>
> Note also that if they make a promise, but it doesn't happen to line up
> with our needs (data is keyed by attr1, but we need it by attr2, or
> timestamp is produce-time, but we need it by event-time, etc.), then we
> will have to go ahead and do that extra work internally anyway. This also
> captures the situation in which two inputs are produced by different
> providers, one of which meets our needs, and the other does not. The fact
> that we can cope with this situation is the basis for my statement that we
> do not require coordination among producers.
>
> (Key Point A): In terms of optimization, #4 and #6 are the most valuable.
> If these characteristics happen to line up with our needs, then KStreams
> can be incredibly efficient in both time and computational resources.
>
>  #5 is similar to knowing the schema in that it tells us whether the
> computation we want to do is possible or not. For example, suppose we have
> a topic of "users", and we want to construct a table for querying. If the
> user topic doesn't completely contain the dataset, we cannot construct the
> table. Note that it doesn't matter whether the topic is compacted or not.
> If the topic is complete, I can consume it starting at "earliest" and build
> my table. If it is not complete, I can do other computations on it. In both
> cases, it may or may not be compacted; it just doesn't matter.
>
> On the output side, the roles are reversed. We provide (or not) exactly the
> same set of guarantees to consumers of our outputs, and we likewise must
> abide by the promises we make.
>
>
> =================================
> Partition Expansion
>
> With this formation in place, let's talk about partition expansion.
>
> Why do we have partitions in the first place? (let me know if I miss
> something here)
> * For logical data streams that are themselves partitionable, it allows
> producers to operate concurrently without coordination. For example,
> streaming data from a sensor in a particle accelerator, the sensor can be
> subdivided into a grid and each grid square can produce independently to a
> different topic. This may be valuable because the total rate of data
> exceeds the throughput to a single broker node or just because it allows
> for failure of a single producer to cause the loss of only part of the
> data.
> * The brokers can offer linearly scaling throughput on the number of
> partitions by hosting each partition on a separate broker node
> * The brokers can host topics that are too large to fit on a single
> broker's storage by hosting some partitions on separate broker nodes
> * In cases where the use case permits handling partitions independently,
> consumers can have algorithmic simplicity by processing the data for
> separate partitions in separate threads, avoiding costly and error-prone
> concurrent coordination code
> * In cases where the use case permits handling partitions independently,
> consumers can exceed the total throughput of a single broker-consumer pair
> * Just to throw this in as well, in cases where some network links are less
> costly than others (or lower latency or more reliable), such as when
> brokers, producers, and consumers are running in racks: producer and
> consumers can both benefit (independently) by locating work on each
> partition in the same rack as the broker hosting that partition.
>
> In other words, we have three actors in this system: producers, brokers,
> and consumers, and they all benefit from partitioning for different (but
> sometimes related) reasons.
>
> This leads naturally to the conclusion that any of these actors may find
> themselves in a sub-optimal or even dangerous situation in which partition
> expansion would be the solution. For example, the producer may find that
> the existing throughput to the brokers is insufficient to match the data
> rate, forcing them to drop data. Or a broker hosting a single partition may
> be running out of disk space. Or a consumer node handling a single
> partition cannot match the rate of production for that partition, causing
> it to fall behind.
>
> I think it's reasonable to assume that all the actors in the system can't
> just arbitrarily expand a topic's partition. I think it's reasonable to
> align this responsibility with the provider of the data, namely the
> producer (the logical producer, not the KafkaProducer class). Therefore,
> the producer who finds themselves in trouble can unilaterally expand
> partitions to solve their problem.
>
> For the broker or a consumer in trouble, they have only one resort: to
> request the producer to expand partitions. This is where it's helpful to
> assume the producer is friendly.
>
>
> Now, let's look at how a KStreams application fits into this scenario.
>
> (Key Point B1): As a consumer, we may find that the producer expands the
> partitions of a topic, either for their own benefit or for the brokers. In
> this situation, the expand operation MUST NOT violate any promises that
> have previously been made to us. This is the essence of KIP-253, to ensure
> the maintenance of promises #6 and #4. It would be great if the mechanics
> of the expansion required no major disruption to processing or human
> intervention.
>
> Specifically, let's say that input partition X splits into X1 and X2. #6
> requires that the same old ordering guarantees of Kafka continue to hold.
> Obviously, this is what KIP-253's title is about. #4 requires that we
> either ensure that X1 and X2 are assigned to the same thread that was
> previously assigned X OR that we immediately pause processing and split any
> state such that it appears X1 and X2 were *always* separate partitions.
>
> In other words, Option 1 is we treat X1 and X2 as still logically one
> partition, equal to X. This is ideal, since in this scenario, partitions
> are expanding for external reasons. We don't need to expand our processing
> to match. Option 2 requires a major disruption, since we'd have to pause
> processing while we split our state. Clearly, KStreams or any other
> stateful consumer would advocate for Option 1.
>
>
> (Corollary to Key Point A): Still on the consumer side, we may find that we
> ourselves can benefit from partition expansion of an input. Since we can
> cope with the absence of promise #4, partition expansion is not a hard
> requirement for us, but assuming we were already benefiting from the major
> performance optimizations afforded by #4, it would be nice to be able to
> request the producer satisfy our request for partition expansion **and to
> be able to benefit from it**.
>
> What does it mean to be able to benefit from partition expansion? Assuming
> input topic partition X splits into X1 and X2, in this scenario, we *would*
> wish to be able to split our state such that it appears X1 and X2 were
> *always* separate partitions. Of course, the conclusion of Key Point B1
> still applies: we should be able to continue operating on (X1+X2 = X) as
> one partition while asynchronously building the state of X1 and X2
> separately.
>
> When it comes to the mechanics of building the state of X1 and X2
> separately, we have really just two high-level options. Either this problem
> is solved by Kafka itself, giving me a view in which X1 and X2 were always
> separate partitions, or I have to do it myself. The latter means that I
> have to take on substantially more complexity than I do today:
> Bummer 1: My state has to be splittable to begin with, implying at the
> least that I need to be able to scan every record in my state, a
> requirement that otherwise does not exist.
> Bummer 2: After splitting the state  of X1 and X2, I need to be able to
> send at least one of those tasks, state included, to another application
> node (in order to realize the benefit of the split). This is also a
> requirement that does not currently exist.
> Bummer 3: In order to actually perform the split, I must know and be able
> to execute the exact same partition function the producer of my topic uses.
> This introduces a brand-new a priori commitment from my input producers:
> (would-be #7: convey the partition function and abide by it). This is a big
> restriction over #4, which only requires them to guarantee *that there is a
> partition function*. Now they actually have to share the function with me.
> And I have to be able to implement and execute it myself. And if the
> producer wishes to refine the partition function for an existing topic, we
> have another round of coordination, as they have to be sure that I, and all
> other consumers, begin using the new function *before* they do. This is
> similar to the schema problem, with a similar set of solutions. We would
> likely need a partition function registry and another magic byte on every
> record to be sure we do this right. Not to mention some way to express
> arbitrary partitioning logic over arbitrary data in a way that is portable
> across programming languages.
>
> Alternatively, if Kafka gives me a view in which X1 and X2 were always
> separate, then I can create tasks for X1 and X2 and allow them to bootstrap
> while I continue to process X. Once they are ready, I can coordinate a
> transition to stop X's task and switch to X1 and X2. None of those bummers
> are present, so this is a significantly better option for me.
>
> (Key Point B2): As a (friendly) producer, we may once again want on our own
> to expand partitions, or we may want to satisfy a request from the broker
> or our consumers to do so. Again, we MUST NOT violate any promises we have
> previously given, and it would be great if the expansion required no major
> disruption to processing or human intervention. Additionally, since we are
> actually driving the expansion, it would also be great if we could avoid
> Bummer 3's coordination problems from the producer's perspective.
>
>
> ======================================
> Briefly: KStreams internals
>
> I'm pretty sure you were asking me to comment on the implementation details
> of KStreams, so I'll say a few words about it. The most important thing is
> that KStreams is still very early in its development. Maybe "early-middle
> maturity" is a good way to put it. We are actively discussing more-or-less
> major implementation changes to improve performance, footprint,
> scalability, and ergonomics. So it may actually be misleading to discuss
> deeply how KStreams internally uses Kafka topics.
>
> Nevertheless, it is currently true that KStreams uses Kafka topics for
> communication between some internal computation nodes. We partition these
> topics as the base unit of concurrency granularity, so it would potentially
> be beneficial to be able to expand partitions for some of these internal
> topics at some point. However, we can alternatively just overpartition
> these internal topics, creating in the low 100s of partitions instead of
> the low 10s, for example. (Side note: if Kafka were someday to support
> higher numbers of partitions, we could expand this scheme to overpartition
> in the 1000s of partitions.) With the option to overpartition, we don't
> have a strong need for partition expansion internally.
>
> It is also currently true that KStreams uses Kafka to store a durable
> changelog for some of our internal state stores. But we *only* read from
> this topic *if* we need to restore a state store after node loss (or to
> maintain a hot mirror of the state store), so I think it's unlikely that we
> would ever make use of partition expansion on the changelog topics.
>
> But once again, I'd like to emphasize that we may choose an alternative
> implementation for either interprocess communication or state durability.
>
>
> ======================================
> Concluding thoughts
>
> I know this is a very long email, and I really appreciate you sticking with
> me this long. I hope it was useful for syncing our mental picture of this
> system. Also, you're far more knowledgeable than I am about this system and
> this domain, so please correct me if I've said anything wrong.
>
> To me the key takeaways are that:
> - KIP-253 satisfies all we need for correctness, since it contains
> solutions to guarantee producers can abide by their promises w.r.t. #4 and
> #6.
> - From Key Point A: #4 is actually optional for KIP-253, but without it, we
> lose a potentially valuable optimization in KStreams (and all other
> consumer applications)
> - From Corollary to Point A: Without low-level support for partition
> expansion with backfill, we cannot employ requesting partition expansion as
> a consumer to improve application performance. In that case, to ensure
> performance scalability, we would have to discard for all KStreams
> applications the performance optimization afforded by #4.
> - From Key Point B1: After a partition split, we really need to be able to
> seamlessly continue operating as if it had not split.
> - From Key Point B2: Since KIP-253 allows us to maintain all our promises,
> we have the option of expanding partitions in the topics we produce.
> Without a backfill operation, though, our consumers may not be able to
> realize the benefits of that split, if they were hoping to.
>
> In general, faced with the possibility of having to coordinate the
> partition function with our inputs' producers or with our outputs'
> consumers, I would personally lean toward overprovisioning and completely
> avoiding resize for our use case. This doesn't mean that it's not useful in
> the ecosystem at large without backfill, just that it loses its luster for
> me. It also means that we can no longer take advantage of some of our
> current optimizations, and in fact that we must introduce an extra hop of
> repartitioning on every single input.
>
> I think this is actually a pretty good picture of the opportunities and
> challenges that other consumers and producers in the Kafka ecosystem will
> face.
>
> I hope this helps!
>
> Thanks,
> -John
>
> On Wed, Mar 28, 2018 at 11:51 AM, Jun Rao <ju...@confluent.io> wrote:
>
> > Hi, John,
> >
> > I actually think it's important to think through how KStreams handles
> > partition expansion in this KIP. If we do decide that we truly need
> > backfilling, it's much better to think through how to add it now, instead
> > of retrofitting it later. It would be useful to outline how both existing
> > KStreams jobs and new KStreams jobs work to see if backfilling is really
> > needed.
> >
> > If we can figure out how KStreams works, at least we have one reference
> > implementation for other stream processing frameworks that face the same
> > issue.
> >
> > Thanks,
> >
> > Jun
> >
> >
> > On Tue, Mar 27, 2018 at 4:56 PM, John Roesler <jo...@confluent.io> wrote:
> >
> > > Hi Jun,
> > >
> > > That's a good point.
> > >
> > > Yeah, I don't think it would work too well for existing consumers in
> the
> > > middle of gen 0 to try and switch to a newly backfilled prefix of gen
> 1.
> > > They probably just need to finish up until they get to the end of gen 0
> > and
> > > transition just as if there were no backfill available yet.
> > >
> > > This isn't terrible, since consumer applications that care about
> scaling
> > up
> > > to match a freshly split partition would wait until after the backfill
> is
> > > available to scale up. The consumer that starts out in gen=0, part=0 is
> > > going to be stuck with part=0 and part=3 in gen=1 in my example
> > regardless
> > > of whether they finish scanning gen=0 before or after the backfill is
> > > available.
> > >
> > > The broker knowing when it's ok to delete gen 0, including its offset
> > > mappings, is a big issue, though. I don't have any immediate ideas for
> > > solving it, but it doesn't feel impossible. Hopefully, you agree this
> is
> > > outside of KIP-253's scope, so maybe we don't need to worry about it
> > right
> > > now.
> > >
> > > I do agree that reshuffling in KStreams effectively solves the
> > scalability
> > > problem as well, as it decouples the partition count (and the partition
> > > scheme) upstream from the parallelism of the streams application.
> Likely,
> > > we will do this in any case. I'm predominantly advocating for follow-on
> > > work to enable backfill for the *other* Kafka users that are not
> > KStreams.
> > >
> > > Thanks for your consideration,
> > > -John
> > >
> > > On Tue, Mar 27, 2018 at 6:19 PM, Jun Rao <ju...@confluent.io> wrote:
> > >
> > > > Hi, John,
> > > >
> > > > Thanks for the reply. I agree that the backfill approach works
> cleaner
> > > for
> > > > newly started consumers. I am just not sure if it's a good primitive
> to
> > > > support for existing consumers. One of the challenges that I see is
> the
> > > > remapping of the offsets. In your approach, we need to copy the
> > existing
> > > > records from the partitions in generation 0 to generation 1. Those
> > > records
> > > > will get different offsets in the new generation. The broker will
> have
> > to
> > > > store those offset mappings somewhere. When the backfill completes,
> you
> > > can
> > > > delete generation 0's data. However, the broker can't throw away the
> > > offset
> > > > mappings immediately since it doesn't know if there is any existing
> > > > consumer still consuming generation 0's records. In a compacted
> topic,
> > > the
> > > > broker probably can only safely remove the offset mappings when all
> > > records
> > > > in generation 0 are removed by the cleaner. This may never happen
> > though.
> > > >
> > > > If we reshuffle the input inside a KStreams job, it obviates the need
> > for
> > > > offset remapping on the broker.
> > > >
> > > > Jun
> > > >
> > > > On Tue, Mar 27, 2018 at 11:34 AM, John Roesler <jo...@confluent.io>
> > > wrote:
> > > >
> > > > > Hey Dong and Jun,
> > > > >
> > > > > Thanks for the thoughtful responses. If you don't mind, I'll mix my
> > > > replies
> > > > > together to try for a coherent response. I'm not too familiar with
> > > > > mailing-list etiquette, though.
> > > > >
> > > > > I'm going to keep numbering my points because it makes it easy for
> > you
> > > > all
> > > > > to respond.
> > > > >
> > > > > Point 1:
> > > > > As I read it, KIP-253 is *just* about properly fencing the
> producers
> > > and
> > > > > consumers so that you preserve the correct ordering of records
> during
> > > > > partition expansion. This is clearly necessary regardless of
> anything
> > > > else
> > > > > we discuss. I think this whole discussion about backfill,
> consumers,
> > > > > streams, etc., is beyond the scope of KIP-253. But it would be
> > > cumbersome
> > > > > to start a new thread at this point.
> > > > >
> > > > > I had missed KIP-253's Proposed Change #9 among all the details...
> I
> > > > think
> > > > > this is a nice addition to the proposal. One thought is that it's
> > > > actually
> > > > > irrelevant whether the hash function is linear. This is simply an
> > > > algorithm
> > > > > for moving a key from one partition to another, so the type of hash
> > > > > function need not be a precondition. In fact, it also doesn't
> matter
> > > > > whether the topic is compacted or not, the algorithm works
> > regardless.
> > > > >
> > > > > I think this is a good algorithm to keep in mind, as it might
> solve a
> > > > > variety of problems, but it does have a downside: that the producer
> > > won't
> > > > > know whether or not K1 was actually in P1, it just knows that K1
> was
> > in
> > > > > P1's keyspace before the new epoch. Therefore, it will have to
> > > > > pessimistically send (K1,null) to P1 just in case. But the next
> time
> > K1
> > > > > comes along, the producer *also* won't remember that it already
> > > retracted
> > > > > K1 from P1, so it will have to send (K1,null) *again*. By
> extension,
> > > > every
> > > > > time the producer sends to P2, it will also have to send a
> tombstone
> > to
> > > > P1,
> > > > > which is a pretty big burden. To make the situation worse, if there
> > is
> > > a
> > > > > second split, say P2 becomes P2 and P3, then any key Kx belonging
> to
> > P3
> > > > > will also have to be retracted from P2 *and* P1, since the producer
> > > can't
> > > > > know whether Kx had been last written to P2 or P1. Over a long
> period
> > > of
> > > > > time, this clearly becomes a issue, as the producer must send an
> > > > arbitrary
> > > > > number of retractions along with every update.
> > > > >
> > > > > In contrast, the proposed backfill operation has an end, and after
> it
> > > > ends,
> > > > > everyone can afford to forget that there ever was a different
> > partition
> > > > > layout.
> > > > >
> > > > > Really, though, figuring out how to split compacted topics is
> beyond
> > > the
> > > > > scope of KIP-253, so I'm not sure #9 really even needs to be in
> this
> > > > KIP...
> > > > > We do need in-order delivery during partition expansion. It would
> be
> > > fine
> > > > > by me to say that you *cannot* expand partitions of a log-compacted
> > > topic
> > > > > and call it a day. I think it would be better to tackle that in
> > another
> > > > > KIP.
> > > > >
> > > > >
> > > > > Point 2:
> > > > > Regarding whether the consumer re-shuffles its inputs, this is
> always
> > > on
> > > > > the table; any consumer who wants to re-shuffle its input is free
> to
> > do
> > > > so.
> > > > > But this is currently not required. It's just that the current
> > > high-level
> > > > > story with Kafka encourages the use of partitions as a unit of
> > > > concurrency.
> > > > > As long as consumers are single-threaded, they can happily consume
> a
> > > > single
> > > > > partition without concurrency control of any kind. This is a key
> > aspect
> > > > to
> > > > > this system that lets folks design high-throughput systems on top
> of
> > it
> > > > > surprisingly easily. If all consumers were instead
> > encouraged/required
> > > to
> > > > > implement a repartition of their own, then the consumer becomes
> > > > > significantly more complex, requiring either the consumer to first
> > > > produce
> > > > > to its own intermediate repartition topic or to ensure that
> consumer
> > > > > threads have a reliable, high-bandwith channel of communication
> with
> > > > every
> > > > > other consumer thread.
> > > > >
> > > > > Either of those tradeoffs may be reasonable for a particular user
> of
> > > > Kafka,
> > > > > but I don't know if we're in a position to say that they are
> > reasonable
> > > > for
> > > > > *every* user of Kafka.
> > > > >
> > > > >
> > > > > Point 3:
> > > > > Regarding Jun's point about this use case, "(3) stateful and
> > > maintaining
> > > > > the
> > > > > states in a local store", I agree that they may use a framework
> > *like*
> > > > > Kafka Streams, but that is not the same as using Kafka Streams.
> This
> > is
> > > > why
> > > > > I think it's better to solve it in Core: because it is then solved
> > for
> > > > > KStreams and also for everything else that facilitates local state
> > > > > maintenance. To me, Streams is a member of the category of "stream
> > > > > processing frameworks", which is itself a subcategory of "things
> > > > requiring
> > > > > local state maintenence". I'm not sure if it makes sense to assert
> > that
> > > > > Streams is a sufficient and practical replacement for everything in
> > > > "things
> > > > > requiring local state maintenence".
> > > > >
> > > > > But, yes, I do agree that per-key ordering is an absolute
> > requirement,
> > > > > therefore I think that KIP-253 itself is a necessary step.
> Regarding
> > > the
> > > > > coupling of the state store partitioning to the topic partitioning,
> > > yes,
> > > > > this is an issue we are discussing solutions to right now. We may
> go
> > > > ahead
> > > > > and introduce an overpartition layer on our inputs to solve it, but
> > > then
> > > > > again, if we get the ability to split partitions with backfill, we
> > may
> > > > not
> > > > > need to!
> > > > >
> > > > >
> > > > > Point 4:
> > > > > On this:
> > > > >
> > > > > > Regarding thought 2: If we don't care about the stream use-case,
> > then
> > > > the
> > > > > > current KIP probably has already addressed problem without
> > requiring
> > > > > > consumer to know the partition function. If we care about the
> > stream
> > > > > > use-case, we already need coordination across producers of
> > different
> > > > > > topics, i.e. the same partition function needs to be used by
> > > producers
> > > > of
> > > > > > topics A and B in order to join topics A and B. Thus, it might be
> > > > > > reasonable to extend coordination a bit and say we need
> > coordination
> > > > > across
> > > > > > clients (i.e. producer and consumer), such that consumer knows
> the
> > > > > > partition function used by producer. If we do so, then we can let
> > > > > consumer
> > > > > > re-copy data for the change log topic using the same partition
> > > function
> > > > > as
> > > > > > producer. This approach has lower overhead as compared to having
> > > > producer
> > > > > > re-copy data of the input topic.
> > > > > > Also, producer currently does not need to know the data already
> > > > produced
> > > > > to
> > > > > > the topic. If we let producer split/merge partition, it would
> > require
> > > > > > producer to consume the existing data, which intuitively is the
> > task
> > > of
> > > > > > consumer.
> > > > >
> > > > >
> > > > > I think we do care about use cases *like* Streams, I just don't
> think
> > > we
> > > > > should rely on Streams to implement a feature of Core like
> partition
> > > > > expansion.
> > > > >
> > > > > Note, though, that we (Streams) do not require coordination across
> > > > > producers. If two topics are certified to be co-partitioned, then
> > > Streams
> > > > > apps can make use of that knowledge to optimize their topology
> > > (skipping
> > > > a
> > > > > repartition). But if they don't know whether they are
> co-partitioned,
> > > > then
> > > > > they'd better go ahead and repartition within the topology. This is
> > the
> > > > > current state.
> > > > >
> > > > > A huge selling point of Kafka is enabling different parts of
> loosely
> > > > > coupled organizations to produce and consume data independently.
> Some
> > > > > coordination between producers and consumers is necessary, like
> > > > > coordinating on the names of topics and their schemas. But Kafka's
> > > value
> > > > > proposition w.r.t. ESBs, etc. is inversely proportional to the
> amount
> > > of
> > > > > coordination required. I think it behooves us to be extremely
> > skeptical
> > > > > about introducing any coordination beyond correctness protocols.
> > > > >
> > > > > Asking producers and consumers, or even two different producers, to
> > > share
> > > > > code like the partition function is a pretty huge ask. What if they
> > are
> > > > > using different languages?
> > > > >
> > > > > Comparing organizational overhead vs computational overhead, there
> > are
> > > > > maybe two orders of magnitude difference between them. In other
> > words,
> > > I
> > > > > would happily take on the (linear) overhead of having the producer
> > > > re-copy
> > > > > the data once during a re-partition in order to save the
> > organizational
> > > > > overhead of tying all the producers and consumers together across
> > > > multiple
> > > > > boundaries.
> > > > >
> > > > > On that last paragraph: note that the producer *did* know the data
> it
> > > > > already produced. It handled it the first time around. Asking it to
> > > > > re-produce it into a new partition layout is squarely within its
> > scope
> > > of
> > > > > capabilities. Contrast this with the alternative, asking the
> consumer
> > > to
> > > > > re-partition the data. I think this is even less intuitive, when
> the
> > > > > partition function belongs to the producer.
> > > > >
> > > > >
> > > > > Point 5:
> > > > > Dong asked this:
> > > > >
> > > > > > For stream use-case that needs to increase consumer number, the
> > > > > > existing consumer can backfill the existing data in the change
> log
> > > > topic
> > > > > to
> > > > > > the same change log topic with the new partition number, before
> the
> > > new
> > > > > set
> > > > > > of consumers bootstrap state from the new partitions of the
> change
> > > log
> > > > > > topic, right?
> > > > >
> > > > >
> > > > > In this sense, the "consumer" is actually the producer of the
> > changelog
> > > > > topic, so if we support partition expansion + backfill as a
> > > > producer/broker
> > > > > operation, then it would be very straightforward for Streams to
> > split a
> > > > > state store. As you say, they would simply instruct the broker to
> > split
> > > > the
> > > > > changelog topic's partitions, then backfill. Once the backfill is
> > > ready,
> > > > > they can create a new crop of StandbyTasks to bootstrap the more
> > > granular
> > > > > state stores and finally switch over to them when they are ready.
> > > > >
> > > > > But this actually seems to be an argument in favor of
> split+backfill,
> > > so
> > > > > maybe I missed the point.
> > > > >
> > > > > You also asked me to explain why copying the "input" topic is
> better
> > > than
> > > > > copying the "changelog" topic. I think they are totally
> independent,
> > > > > actually. For one thing, you can't depend on the existence of a
> > > > "changelog"
> > > > > topic in general, only within Streams, but Kafka's user base
> clearly
> > > > > exceeds Streams's user base. Plus, you actually also can't depend
> on
> > > the
> > > > > existence of a changelog topic within Streams, since that is an
> > > optional
> > > > > feature of *some* state store implementations. Even in the
> situation
> > > > where
> > > > > you do have a changelog topic in Streams, there may be use cases
> > where
> > > it
> > > > > makes sense to expand the partitions of just the input, or just the
> > > > > changelog.
> > > > >
> > > > > The ask for a Core feature of split+backfill is really about
> > supporting
> > > > the
> > > > > use case of splitting partitions in log-compacted topics,
> regardless
> > of
> > > > > whether that topic is an "input" or a "changelog" or anything else
> > for
> > > > that
> > > > > matter.
> > > > >
> > > > >
> > > > > Point 6:
> > > > > On the concern about the performance overhead of copying data
> between
> > > the
> > > > > brokers, I think it's actually a bit overestimated. Splitting a
> > topic's
> > > > > partition is probably rare, certainly rarer in general than
> > > bootstrapping
> > > > > new consumers on that topic. If "bootstrapping new consumers" means
> > > that
> > > > > they have to re-shuffle the data before they consume it, then you
> > wind
> > > up
> > > > > copying the same record multiple times:
> > > > >
> > > > > (broker: input topic) -> (initial consumer) -> (broker: repartition
> > > > topic)
> > > > > -> (real consumer)
> > > > >
> > > > > That's 3x, and it's also 3x for every new record after the split as
> > > well,
> > > > > since you don't get to stop repartitioning/reshuffling once you
> > start.
> > > > >
> > > > > Whereas if you do a backfill in something like the procedure I
> > > outlined,
> > > > > you only copy the prefix of the partition before the split, and you
> > > send
> > > > it
> > > > > once to the producer and then once to the new generation partition.
> > > Plus,
> > > > > assuming we're splitting the partition for the benefit of
> consumers,
> > > > > there's no reason we can't co-locate the post-split partitions on
> the
> > > > same
> > > > > host as the pre-split partition, making the second copy a local
> > > > filesystem
> > > > > operation.
> > > > >
> > > > > Even if you follow these two copies up with bootstrapping a new
> > > consumer,
> > > > > it's still rare for this to occur, so you get to amortize these
> > copies
> > > > over
> > > > > the lifetime of the topic, whereas a reshuffle just keeps making
> > copies
> > > > for
> > > > > every new event.
> > > > >
> > > > > And finally, I really do think that regardless of any performance
> > > > concerns
> > > > > about this operation, if it preserves loose organizational
> coupling,
> > it
> > > > is
> > > > > certainly worth it.
> > > > >
> > > > >
> > > > > In conclusion:
> > > > > It might actually be a good idea for us to clarify the scope of
> > > KIP-253.
> > > > If
> > > > > we're all agreed that it's a good algorithm for allowing in-order
> > > message
> > > > > delivery during partition expansion, then we can continue this
> > > discussion
> > > > > as a new KIP, something like "backfill with partition expansion".
> > This
> > > > > would let Dong proceed with KIP-253. On the other hand, if it seems
> > > like
> > > > > this conversation may alter the design of KIP-253, then maybe we
> > > *should*
> > > > > just finish working it out.
> > > > >
> > > > > For my part, my only concern about KIP-253 is the one I raised
> > earlier.
> > > > >
> > > > > Thanks again, all, for considering these points,
> > > > > -John
> > > > >
> > > > >
> > > > > On Tue, Mar 27, 2018 at 2:10 AM, Dong Lin <li...@gmail.com>
> > wrote:
> > > > >
> > > > > > On Tue, Mar 27, 2018 at 12:04 AM, Dong Lin <li...@gmail.com>
> > > > wrote:
> > > > > >
> > > > > > > Hey Jan,
> > > > > > >
> > > > > > > Thanks for the enthusiasm in improving Kafka's design. Now
> that I
> > > > have
> > > > > > > read through your discussion with Jun, here are my thoughts:
> > > > > > >
> > > > > > > - The latest proposal should with log compacted topics by
> > properly
> > > > > > > deleting old messages after a new message with the same key is
> > > > > produced.
> > > > > > So
> > > > > > > it is probably not a concern anymore. Could you comment if
> there
> > is
> > > > > still
> > > > > > > issue?
> > > > > > >
> > > > > > > - I wrote the SEP-5 and I am pretty familiar with the
> motivation
> > > and
> > > > > the
> > > > > > > design of SEP-5. SEP-5 is probably orthornal to the motivation
> of
> > > > this
> > > > > > KIP.
> > > > > > > The goal of SEP-5 is to allow user to increase task number of
> an
> > > > > existing
> > > > > > > Samza job. But if we increase the partition number of input
> > topics,
> > > > > > > messages may still be consumed out-of-order by tasks in Samza
> > which
> > > > > cause
> > > > > > > incorrect result. Similarly, the approach you proposed does not
> > > seem
> > > > to
> > > > > > > ensure that the messages can be delivered in order, even if we
> > can
> > > > make
> > > > > > > sure that each consumer instance is assigned the set of new
> > > > partitions
> > > > > > > covering the same set of keys.
> > > > > > >
> > > > > >
> > > > > > Let me correct this comment. The approach of copying data to a
> new
> > > > topic
> > > > > > can ensure in-order message delivery suppose we properly migrate
> > > > offsets
> > > > > > from old topic to new topic.
> > > > > >
> > > > > >
> > > > > > > - I am trying to understand why it is better to copy the data
> > > instead
> > > > > of
> > > > > > > copying the change log topic for streaming use-case. For core
> > Kafka
> > > > > > > use-case, and for the stream use-case that does not need to
> > > increase
> > > > > > > consumers, the current KIP already supports in-order delivery
> > > without
> > > > > the
> > > > > > > overhead of copying the data. For stream use-case that needs to
> > > > > increase
> > > > > > > consumer number, the existing consumer can backfill the
> existing
> > > data
> > > > > in
> > > > > > > the change log topic to the same change log topic with the new
> > > > > partition
> > > > > > > number, before the new set of consumers bootstrap state from
> the
> > > new
> > > > > > > partitions of the change log topic. If this solution works,
> then
> > > > could
> > > > > > you
> > > > > > > summarize the advantage of copying the data of input topic as
> > > > compared
> > > > > to
> > > > > > > copying the change log topic? For example, does it enable more
> > > > > use-case,
> > > > > > > simplify the implementation of Kafka library, or reduce the
> > > operation
> > > > > > > overhead etc?
> > > > > > >
> > > > > > > Thanks,
> > > > > > > Dong
> > > > > > >
> > > > > > >
> > > > > > > On Wed, Mar 21, 2018 at 6:57 AM, Jan Filipiak <
> > > > > Jan.Filipiak@trivago.com>
> > > > > > > wrote:
> > > > > > >
> > > > > > >> Hi Jun,
> > > > > > >>
> > > > > > >> I was really seeing progress in our conversation but your
> latest
> > > > reply
> > > > > > is
> > > > > > >> just devastating.
> > > > > > >> I though we were getting close being on the same page now it
> > feels
> > > > > like
> > > > > > >> we are in different libraries.
> > > > > > >>
> > > > > > >> I just quickly slam my answers in here. If they are to brief I
> > am
> > > > > sorry
> > > > > > >> give me a ping and try to go into details more.
> > > > > > >> Just want to show that your pro/cons listing is broken.
> > > > > > >>
> > > > > > >> Best Jan
> > > > > > >>
> > > > > > >> and want to get rid of this horrible compromise
> > > > > > >>
> > > > > > >>
> > > > > > >> On 19.03.2018 05:48, Jun Rao wrote:
> > > > > > >>
> > > > > > >>> Hi, Jan,
> > > > > > >>>
> > > > > > >>> Thanks for the discussion. Great points.
> > > > > > >>>
> > > > > > >>> Let me try to summarize the approach that you are proposing.
> On
> > > the
> > > > > > >>> broker
> > > > > > >>> side, we reshuffle the existing data in a topic from current
> > > > > partitions
> > > > > > >>> to
> > > > > > >>> the new partitions. Once the reshuffle fully catches up,
> switch
> > > the
> > > > > > >>> consumers to start consuming from the new partitions. If a
> > > consumer
> > > > > > needs
> > > > > > >>> to rebuild its local state (due to partition changes), let
> the
> > > > > consumer
> > > > > > >>> rebuild its state by reading all existing data from the new
> > > > > partitions.
> > > > > > >>> Once all consumers have switches over, cut over the producer
> to
> > > the
> > > > > new
> > > > > > >>> partitions.
> > > > > > >>>
> > > > > > >>> The pros for this approach are that :
> > > > > > >>> 1. There is just one way to rebuild the local state, which is
> > > > > simpler.
> > > > > > >>>
> > > > > > >> true thanks
> > > > > > >>
> > > > > > >>>
> > > > > > >>> The cons for this approach are:
> > > > > > >>> 1. Need to copy existing data.
> > > > > > >>>
> > > > > > >> Very unfair and not correct. It does not require you to copy
> > over
> > > > > > >> existing data. It _allows_ you to copy all existing data.
> > > > > > >>
> > > > > > >> 2. The cutover of the producer is a bit complicated since it
> > needs
> > > > to
> > > > > > >>> coordinate with all consumer groups.
> > > > > > >>>
> > > > > > >> Also not true. I explicitly tried to make clear that there is
> > only
> > > > one
> > > > > > >> special consumer (in the case of actually copying data)
> > > coordination
> > > > > is
> > > > > > >> required.
> > > > > > >>
> > > > > > >>> 3. The rebuilding of the state in the consumer is from the
> > input
> > > > > topic,
> > > > > > >>> which can be more expensive than rebuilding from the existing
> > > > state.
> > > > > > >>>
> > > > > > >> true, but rebuilding state is only required if you want to
> > > increase
> > > > > > >> processing power, so we assume this is at hand.
> > > > > > >>
> > > > > > >>> 4. The broker potentially has to know the partitioning
> > function.
> > > If
> > > > > > this
> > > > > > >>> needs to be customized at the topic level, it can be a bit
> > messy.
> > > > > > >>>
> > > > > > >> I would argue against having the operation being performed by
> > the
> > > > > > broker.
> > > > > > >> This was not discussed yet but if you see my original email i
> > > > > suggested
> > > > > > >> otherwise from the beginning.
> > > > > > >>
> > > > > > >>>
> > > > > > >>> Here is an alternative approach by applying your idea not in
> > the
> > > > > > broker,
> > > > > > >>> but in the consumer. When new partitions are added, we don't
> > move
> > > > > > >>> existing
> > > > > > >>> data. In KStreams, we first reshuffle the new input data to a
> > new
> > > > > topic
> > > > > > >>> T1
> > > > > > >>> with the old number of partitions and feed T1's data to the
> > rest
> > > of
> > > > > the
> > > > > > >>> pipeline. In the meantime, KStreams reshuffles all existing
> > data
> > > of
> > > > > the
> > > > > > >>> change capture topic to another topic C1 with the new number
> of
> > > > > > >>> partitions.
> > > > > > >>> We can then build the state of the new tasks from C1. Once
> the
> > > new
> > > > > > states
> > > > > > >>> have been fully built, we can cut over the consumption to the
> > > input
> > > > > > topic
> > > > > > >>> and delete T1. This approach works with compacted topic too.
> If
> > > an
> > > > > > >>> application reads from the beginning of a compacted topic,
> the
> > > > > consumer
> > > > > > >>> will reshuffle the portion of the input when the number of
> > > > partitions
> > > > > > >>> doesn't match the number of tasks.
> > > > > > >>>
> > > > > > >> We all wipe this idea from our heads instantly. Mixing Ideas
> > from
> > > an
> > > > > > >> argument is not a resolution strategy
> > > > > > >> just leads to horrible horrible software.
> > > > > > >>
> > > > > > >>
> > > > > > >>> The pros of this approach are:
> > > > > > >>> 1. No need to copy existing data.
> > > > > > >>> 2. Each consumer group can cut over to the new partitions
> > > > > > independently.
> > > > > > >>> 3. The state is rebuilt from the change capture topic, which
> is
> > > > > cheaper
> > > > > > >>> than rebuilding from the input topic.
> > > > > > >>> 4. Only the KStreams job needs to know the partitioning
> > function.
> > > > > > >>>
> > > > > > >>> The cons of this approach are:
> > > > > > >>> 1. Potentially the same input topic needs to be reshuffled
> more
> > > > than
> > > > > > once
> > > > > > >>> in different consumer groups during the transition phase.
> > > > > > >>>
> > > > > > >>> What do you think?
> > > > > > >>>
> > > > > > >>> Thanks,
> > > > > > >>>
> > > > > > >>> Jun
> > > > > > >>>
> > > > > > >>>
> > > > > > >>>
> > > > > > >>> On Thu, Mar 15, 2018 at 1:04 AM, Jan Filipiak <
> > > > > > Jan.Filipiak@trivago.com>
> > > > > > >>> wrote:
> > > > > > >>>
> > > > > > >>> Hi Jun,
> > > > > > >>>>
> > > > > > >>>> thank you for following me on these thoughts. It was
> important
> > > to
> > > > me
> > > > > > to
> > > > > > >>>> feel that kind of understanding for my arguments.
> > > > > > >>>>
> > > > > > >>>> What I was hoping for (I mentioned this earlier) is that we
> > can
> > > > > model
> > > > > > >>>> the
> > > > > > >>>> case where we do not want to copy the data the exact same
> way
> > as
> > > > the
> > > > > > >>>> case
> > > > > > >>>> when we do copy the data. Maybe you can peek into the mails
> > > before
> > > > > to
> > > > > > >>>> see
> > > > > > >>>> more details for this.
> > > > > > >>>>
> > > > > > >>>> This means we have the same mechanism to transfer consumer
> > > groups
> > > > to
> > > > > > >>>> switch topic. The offset mapping that would be generated
> would
> > > > even
> > > > > be
> > > > > > >>>> simpler End Offset of the Old topic => offset 0 off all the
> > > > > partitions
> > > > > > >>>> of
> > > > > > >>>> the new topic. Then we could model the transition of a
> > non-copy
> > > > > > >>>> expansion
> > > > > > >>>> the exact same way as a copy-expansion.
> > > > > > >>>>
> > > > > > >>>> I know this only works when topic growth by a factor. But
> the
> > > > > benefits
> > > > > > >>>> of
> > > > > > >>>> only growing by a factor are to strong anyways. See
> Clemens's
> > > hint
> > > > > and
> > > > > > >>>> remember that state reshuffling is entirely not needed if
> one
> > > > > doesn't
> > > > > > >>>> want
> > > > > > >>>> to grow processing power.
> > > > > > >>>>
> > > > > > >>>> I think these benefits should be clear, and that there is
> > > > basically
> > > > > no
> > > > > > >>>> downside to what is currently at hand but just makes
> > everything
> > > > > easy.
> > > > > > >>>>
> > > > > > >>>> One thing you need to know is. that if you do not offer
> > > > rebuilding a
> > > > > > log
> > > > > > >>>> compacted topic like i suggest that even if you have
> consumer
> > > > state
> > > > > > >>>> reshuffling. The topic is broken and can not be used to
> > > bootstrap
> > > > > new
> > > > > > >>>> consumers. They don't know if they need to apply a key from
> > and
> > > > old
> > > > > > >>>> partition or not. This is a horrible downside I haven't
> seen a
> > > > > > solution
> > > > > > >>>> for
> > > > > > >>>> in the email conversation.
> > > > > > >>>>
> > > > > > >>>> I argue to:
> > > > > > >>>>
> > > > > > >>>> Only grow topic by a factor always.
> > > > > > >>>> Have the "no copy consumer" transition as the trivial case
> of
> > > the
> > > > > > "copy
> > > > > > >>>> consumer transition".
> > > > > > >>>> If processors needs to be scaled, let them rebuild from the
> > new
> > > > > topic
> > > > > > >>>> and
> > > > > > >>>> leave the old running in the mean time.
> > > > > > >>>> Do not implement key shuffling in streams.
> > > > > > >>>>
> > > > > > >>>> I hope I can convince you especially with the fact how I
> want
> > to
> > > > > > handle
> > > > > > >>>> consumer transition. I think
> > > > > > >>>> you didn't quite understood me there before. I think the
> term
> > > "new
> > > > > > >>>> topic"
> > > > > > >>>> intimidated you a little.
> > > > > > >>>> How we solve this on disc doesn't really matter, If the data
> > > goes
> > > > > into
> > > > > > >>>> the
> > > > > > >>>> same Dir or a different Dir or anything. I do think that it
> > > needs
> > > > to
> > > > > > >>>> involve at least rolling a new segment for the existing
> > > > partitions.
> > > > > > >>>> But most of the transitions should work without restarting
> > > > > consumers.
> > > > > > >>>> (newer consumers with support for this). But with new topic
> i
> > > just
> > > > > > meant
> > > > > > >>>> the topic that now has a different partition count. Plenty
> of
> > > ways
> > > > > to
> > > > > > >>>> handle that (versions, aliases)
> > > > > > >>>>
> > > > > > >>>> Hope I can further get my idea across.
> > > > > > >>>>
> > > > > > >>>> Best Jan
> > > > > > >>>>
> > > > > > >>>>
> > > > > > >>>>
> > > > > > >>>>
> > > > > > >>>>
> > > > > > >>>>
> > > > > > >>>> On 14.03.2018 02:45, Jun Rao wrote:
> > > > > > >>>>
> > > > > > >>>> Hi, Jan,
> > > > > > >>>>>
> > > > > > >>>>> Thanks for sharing your view.
> > > > > > >>>>>
> > > > > > >>>>> I agree with you that recopying the data potentially makes
> > the
> > > > > state
> > > > > > >>>>> management easier since the consumer can just rebuild its
> > state
> > > > > from
> > > > > > >>>>> scratch (i.e., no need for state reshuffling).
> > > > > > >>>>>
> > > > > > >>>>> On the flip slide, I saw a few disadvantages of the
> approach
> > > that
> > > > > you
> > > > > > >>>>> suggested. (1) Building the state from the input topic from
> > > > scratch
> > > > > > is
> > > > > > >>>>> in
> > > > > > >>>>> general less efficient than state reshuffling. Let's say
> one
> > > > > > computes a
> > > > > > >>>>> count per key from an input topic. The former requires
> > reading
> > > > all
> > > > > > >>>>> existing
> > > > > > >>>>> records in the input topic whereas the latter only requires
> > > > reading
> > > > > > >>>>> data
> > > > > > >>>>> proportional to the number of unique keys. (2) The
> switching
> > of
> > > > the
> > > > > > >>>>> topic
> > > > > > >>>>> needs modification to the application. If there are many
> > > > > applications
> > > > > > >>>>> on a
> > > > > > >>>>> topic, coordinating such an effort may not be easy. Also,
> > it's
> > > > not
> > > > > > >>>>> clear
> > > > > > >>>>> how to enforce exactly-once semantic during the switch. (3)
> > If
> > > a
> > > > > > topic
> > > > > > >>>>> doesn't need any state management, recopying the data seems
> > > > > wasteful.
> > > > > > >>>>> In
> > > > > > >>>>> that case, in place partition expansion seems more
> desirable.
> > > > > > >>>>>
> > > > > > >>>>> I understand your concern about adding complexity in
> > KStreams.
> > > > But,
> > > > > > >>>>> perhaps
> > > > > > >>>>> we could iterate on that a bit more to see if it can be
> > > > simplified.
> > > > > > >>>>>
> > > > > > >>>>> Jun
> > > > > > >>>>>
> > > > > > >>>>>
> > > > > > >>>>> On Mon, Mar 12, 2018 at 11:21 PM, Jan Filipiak <
> > > > > > >>>>> Jan.Filipiak@trivago.com>
> > > > > > >>>>> wrote:
> > > > > > >>>>>
> > > > > > >>>>> Hi Jun,
> > > > > > >>>>>
> > > > > > >>>>>> I will focus on point 61 as I think its _the_ fundamental
> > part
> > > > > that
> > > > > > I
> > > > > > >>>>>> cant
> > > > > > >>>>>> get across at the moment.
> > > > > > >>>>>>
> > > > > > >>>>>> Kafka is the platform to have state materialized multiple
> > > times
> > > > > from
> > > > > > >>>>>> one
> > > > > > >>>>>> input. I emphasize this: It is the building block in
> > > > architectures
> > > > > > >>>>>> that
> > > > > > >>>>>> allow you to
> > > > > > >>>>>> have your state maintained multiple times. You put a
> message
> > > in
> > > > > > once,
> > > > > > >>>>>> and
> > > > > > >>>>>> you have it pop out as often as you like. I believe you
> > > > understand
> > > > > > >>>>>> this.
> > > > > > >>>>>>
> > > > > > >>>>>> Now! The path of thinking goes the following: I am using
> > > apache
> > > > > > kafka
> > > > > > >>>>>> and
> > > > > > >>>>>> I _want_ my state multiple times. What am I going todo?
> > > > > > >>>>>>
> > > > > > >>>>>> A) Am I going to take my state that I build up, plunge
> some
> > > sort
> > > > > of
> > > > > > >>>>>> RPC
> > > > > > >>>>>> layer ontop of it, use that RPC layer to throw my records
> > > across
> > > > > > >>>>>> instances?
> > > > > > >>>>>> B) Am I just going to read the damn message twice?
> > > > > > >>>>>>
> > > > > > >>>>>> Approach A is fundamentally flawed and a violation of all
> > that
> > > > is
> > > > > > good
> > > > > > >>>>>> and
> > > > > > >>>>>> holy in kafka deployments. I can not understand how this
> > Idea
> > > > can
> > > > > > >>>>>> come in
> > > > > > >>>>>> the first place.
> > > > > > >>>>>> (I do understand: IQ in streams, they polluted the kafka
> > > streams
> > > > > > >>>>>> codebase
> > > > > > >>>>>> really bad already. It is not funny! I think they are
> > equally
> > > > > flawed
> > > > > > >>>>>> as
> > > > > > >>>>>> A)
> > > > > > >>>>>>
> > > > > > >>>>>> I say, we do what Kafka is good at. We repartition the
> topic
> > > > once.
> > > > > > We
> > > > > > >>>>>> switch the consumers.
> > > > > > >>>>>> (Those that need more partitions are going to rebuild
> their
> > > > state
> > > > > in
> > > > > > >>>>>> multiple partitions by reading the new topic, those that
> > don't
> > > > > just
> > > > > > >>>>>> assign
> > > > > > >>>>>> the new partitions properly)
> > > > > > >>>>>> We switch producers. Done!
> > > > > > >>>>>>
> > > > > > >>>>>> The best thing! It is trivial, hipster stream processor
> will
> > > > have
> > > > > an
> > > > > > >>>>>> easy
> > > > > > >>>>>> time with that aswell. Its so super simple. And simple IS
> > > good!
> > > > > > >>>>>> It is what kafka was build todo. It is how we do it today.
> > > All I
> > > > > am
> > > > > > >>>>>> saying
> > > > > > >>>>>> is that a little broker help doing the producer swap is
> > super
> > > > > > useful.
> > > > > > >>>>>>
> > > > > > >>>>>> For everyone interested in why kafka is so powerful with
> > > > approach
> > > > > B,
> > > > > > >>>>>> please watch https://youtu.be/bEbeZPVo98c?t=1633
> > > > > > >>>>>> I already looked up a good point in time, I think after 5
> > > > minutes
> > > > > > the
> > > > > > >>>>>> "state" topic is handled and you should be able to
> > understand
> > > me
> > > > > > >>>>>> and inch better.
> > > > > > >>>>>>
> > > > > > >>>>>> Please do not do A to the project, it deserves better!
> > > > > > >>>>>>
> > > > > > >>>>>> Best Jan
> > > > > > >>>>>>
> > > > > > >>>>>>
> > > > > > >>>>>>
> > > > > > >>>>>> On 13.03.2018 02:40, Jun Rao wrote:
> > > > > > >>>>>>
> > > > > > >>>>>> Hi, Jan,
> > > > > > >>>>>>
> > > > > > >>>>>>> Thanks for the reply. A few more comments below.
> > > > > > >>>>>>>
> > > > > > >>>>>>> 50. Ok, we can think a bit harder for supporting
> compacted
> > > > > topics.
> > > > > > >>>>>>>
> > > > > > >>>>>>> 51. This is a fundamental design question. In the more
> > common
> > > > > case,
> > > > > > >>>>>>> the
> > > > > > >>>>>>> reason why someone wants to increase the number of
> > partitions
> > > > is
> > > > > > that
> > > > > > >>>>>>> the
> > > > > > >>>>>>> consumer application is slow and one wants to run more
> > > consumer
> > > > > > >>>>>>> instances
> > > > > > >>>>>>> to increase the degree of parallelism. So, fixing the
> > number
> > > of
> > > > > > >>>>>>> running
> > > > > > >>>>>>> consumer instances when expanding the partitions won't
> help
> > > > this
> > > > > > >>>>>>> case.
> > > > > > >>>>>>> If
> > > > > > >>>>>>> we do need to increase the number of consumer instances,
> we
> > > > need
> > > > > to
> > > > > > >>>>>>> somehow
> > > > > > >>>>>>> reshuffle the state of the consumer across instances.
> What
> > we
> > > > > have
> > > > > > >>>>>>> been
> > > > > > >>>>>>> discussing in this KIP is whether we can do this more
> > > > effectively
> > > > > > >>>>>>> through
> > > > > > >>>>>>> the KStream library (e.g. through a 2-phase partition
> > > > expansion).
> > > > > > >>>>>>> This
> > > > > > >>>>>>> will
> > > > > > >>>>>>> add some complexity, but it's probably better than
> everyone
> > > > doing
> > > > > > >>>>>>> this
> > > > > > >>>>>>> in
> > > > > > >>>>>>> the application space. The recopying approach that you
> > > > mentioned
> > > > > > >>>>>>> doesn't
> > > > > > >>>>>>> seem to address the consumer state management issue when
> > the
> > > > > > consumer
> > > > > > >>>>>>> switches from an old to a new topic.
> > > > > > >>>>>>>
> > > > > > >>>>>>> 52. As for your example, it depends on whether the join
> key
> > > is
> > > > > the
> > > > > > >>>>>>> same
> > > > > > >>>>>>> between (A,B) and (B,C). If the join key is the same, we
> > can
> > > > do a
> > > > > > >>>>>>> 2-phase
> > > > > > >>>>>>> partition expansion of A, B, and C together. If the join
> > keys
> > > > are
> > > > > > >>>>>>> different, one would need to repartition the data on a
> > > > different
> > > > > > key
> > > > > > >>>>>>> for
> > > > > > >>>>>>> the second join, then the partition expansion can be done
> > > > > > >>>>>>> independently
> > > > > > >>>>>>> between (A,B) and (B,C).
> > > > > > >>>>>>>
> > > > > > >>>>>>> 53. If you always fix the number of consumer instances,
> we
> > > you
> > > > > > >>>>>>> described
> > > > > > >>>>>>> works. However, as I mentioned in #51, I am not sure how
> > your
> > > > > > >>>>>>> proposal
> > > > > > >>>>>>> deals with consumer states when the number of consumer
> > > > instances
> > > > > > >>>>>>> grows.
> > > > > > >>>>>>> Also, it just seems that it's better to avoid re-copying
> > the
> > > > > > existing
> > > > > > >>>>>>> data.
> > > > > > >>>>>>>
> > > > > > >>>>>>> 60. "just want to throw in my question from the longer
> > email
> > > in
> > > > > the
> > > > > > >>>>>>> other
> > > > > > >>>>>>> Thread here. How will the bloom filter help a new
> consumer
> > to
> > > > > > decide
> > > > > > >>>>>>> to
> > > > > > >>>>>>> apply the key or not?" Not sure that I fully understood
> > your
> > > > > > >>>>>>> question.
> > > > > > >>>>>>> The
> > > > > > >>>>>>> consumer just reads whatever key is in the log. The bloom
> > > > filter
> > > > > > just
> > > > > > >>>>>>> helps
> > > > > > >>>>>>> clean up the old keys.
> > > > > > >>>>>>>
> > > > > > >>>>>>> 61. "Why can we afford having a topic where its
> apparently
> > > not
> > > > > > >>>>>>> possible
> > > > > > >>>>>>> to
> > > > > > >>>>>>> start a new application on? I think this is an overall
> flaw
> > > of
> > > > > the
> > > > > > >>>>>>> discussed idea here. Not playing attention to the overall
> > > > > > >>>>>>> architecture."
> > > > > > >>>>>>> Could you explain a bit more when one can't start a new
> > > > > > application?
> > > > > > >>>>>>>
> > > > > > >>>>>>> Jun
> > > > > > >>>>>>>
> > > > > > >>>>>>>
> > > > > > >>>>>>>
> > > > > > >>>>>>> On Sat, Mar 10, 2018 at 1:40 AM, Jan Filipiak <
> > > > > > >>>>>>> Jan.Filipiak@trivago.com
> > > > > > >>>>>>> wrote:
> > > > > > >>>>>>>
> > > > > > >>>>>>> Hi Jun, thanks for your mail.
> > > > > > >>>>>>>
> > > > > > >>>>>>> Thank you for your questions!
> > > > > > >>>>>>>> I think they are really good and tackle the core of the
> > > > problem
> > > > > I
> > > > > > >>>>>>>> see.
> > > > > > >>>>>>>>
> > > > > > >>>>>>>> I will answer inline, mostly but still want to set the
> > tone
> > > > > here.
> > > > > > >>>>>>>>
> > > > > > >>>>>>>> The core strength of kafka is what Martin once called
> the
> > > > > > >>>>>>>> kappa-Architecture. How does this work?
> > > > > > >>>>>>>> You have everything as a log as in kafka. When you need
> to
> > > > > change
> > > > > > >>>>>>>> something.
> > > > > > >>>>>>>> You create the new version of your application and leave
> > it
> > > > > > running
> > > > > > >>>>>>>> in
> > > > > > >>>>>>>> parallel.
> > > > > > >>>>>>>> Once the new version is good you switch your users to
> use
> > > the
> > > > > new
> > > > > > >>>>>>>> application.
> > > > > > >>>>>>>>
> > > > > > >>>>>>>> The online reshuffling effectively breaks this
> > architecture
> > > > and
> > > > > I
> > > > > > >>>>>>>> think
> > > > > > >>>>>>>> the switch in thinking here is more harmful
> > > > > > >>>>>>>> than any details about the partitioning function to
> allow
> > > > such a
> > > > > > >>>>>>>> change.
> > > > > > >>>>>>>> I
> > > > > > >>>>>>>> feel with my suggestion we are the closest to
> > > > > > >>>>>>>> the original and battle proven architecture and I can
> only
> > > > warn
> > > > > to
> > > > > > >>>>>>>> move
> > > > > > >>>>>>>> away from it.
> > > > > > >>>>>>>>
> > > > > > >>>>>>>> I might have forgotten something, sometimes its hard for
> > me
> > > to
> > > > > > >>>>>>>> getting
> > > > > > >>>>>>>> all
> > > > > > >>>>>>>> the thoughts captured in a mail, but I hope the comments
> > > > inline
> > > > > > will
> > > > > > >>>>>>>> further make my concern clear, and put some emphasis on
> > why
> > > I
> > > > > > >>>>>>>> prefer my
> > > > > > >>>>>>>> solution ;)
> > > > > > >>>>>>>>
> > > > > > >>>>>>>> One thing we should all be aware of when discussing
> this,
> > > and
> > > > I
> > > > > > >>>>>>>> think
> > > > > > >>>>>>>> Dong
> > > > > > >>>>>>>> should have mentioned it (maybe he did).
> > > > > > >>>>>>>> We are not discussing all of this out of thin air but
> > there
> > > is
> > > > > an
> > > > > > >>>>>>>> effort
> > > > > > >>>>>>>> in the Samza project.
> > > > > > >>>>>>>>
> > > > > > >>>>>>>> https://cwiki.apache.org/confluence/display/SAMZA/SEP-
> > 5%3A+
> > > > > > >>>>>>>> Enable+partition+expansion+of+input+streams
> > > > > > >>>>>>>> https://issues.apache.org/jira/browse/SAMZA-1293
> > > > > > >>>>>>>>
> > > > > > >>>>>>>> To be clear. I think SEP-5 (state of last week, dont
> know
> > if
> > > > it
> > > > > > >>>>>>>> adapted
> > > > > > >>>>>>>> to
> > > > > > >>>>>>>> this discussion) is on a way better path than KIP-253,
> > and I
> > > > > can't
> > > > > > >>>>>>>> really
> > > > > > >>>>>>>> explain why.
> > > > > > >>>>>>>>
> > > > > > >>>>>>>> Best Jan,
> > > > > > >>>>>>>>
> > > > > > >>>>>>>> nice weekend everyone
> > > > > > >>>>>>>>
> > > > > > >>>>>>>>
> > > > > > >>>>>>>> On 09.03.2018 03:36, Jun Rao wrote:
> > > > > > >>>>>>>>
> > > > > > >>>>>>>> Hi, Jan,
> > > > > > >>>>>>>>
> > > > > > >>>>>>>> Thanks for the feedback. Just some comments on the
> earlier
> > > > > points
> > > > > > >>>>>>>>> that
> > > > > > >>>>>>>>> you
> > > > > > >>>>>>>>> mentioned.
> > > > > > >>>>>>>>>
> > > > > > >>>>>>>>> 50. You brought up the question of whether existing
> data
> > > > needs
> > > > > to
> > > > > > >>>>>>>>> be
> > > > > > >>>>>>>>> copied
> > > > > > >>>>>>>>> during partition expansion. My understand of your view
> is
> > > > that
> > > > > > >>>>>>>>> avoid
> > > > > > >>>>>>>>> copying existing data will be more efficient, but it
> > > doesn't
> > > > > work
> > > > > > >>>>>>>>> well
> > > > > > >>>>>>>>> with
> > > > > > >>>>>>>>> compacted topics since some keys in the original
> > partitions
> > > > > will
> > > > > > >>>>>>>>> never
> > > > > > >>>>>>>>> be
> > > > > > >>>>>>>>> cleaned. It would be useful to understand your use case
> > of
> > > > > > >>>>>>>>> compacted
> > > > > > >>>>>>>>> topics
> > > > > > >>>>>>>>> a bit more. In the common use case, the data volume in
> a
> > > > > > compacted
> > > > > > >>>>>>>>> topic
> > > > > > >>>>>>>>> may not be large. So, I am not sure if there is a
> strong
> > > need
> > > > > to
> > > > > > >>>>>>>>> expand
> > > > > > >>>>>>>>> partitions in a compacted topic, at least initially.
> > > > > > >>>>>>>>>
> > > > > > >>>>>>>>> I do agree. State is usually smaller. Update rates
> might
> > be
> > > > > also
> > > > > > >>>>>>>>>
> > > > > > >>>>>>>>> competitively high.
> > > > > > >>>>>>>> Doing Log-compaction (even beeing very efficient and
> > > > > configurable)
> > > > > > >>>>>>>> is
> > > > > > >>>>>>>> also
> > > > > > >>>>>>>> a more expensive operation than
> > > > > > >>>>>>>> just discarding old segments. Further if you want to use
> > > more
> > > > > > >>>>>>>> consumers
> > > > > > >>>>>>>> processing the events
> > > > > > >>>>>>>> you also have to grow the number of partitions.
> Especially
> > > for
> > > > > > >>>>>>>> use-cases
> > > > > > >>>>>>>> we do (KIP-213) a tiny state full
> > > > > > >>>>>>>> table might be very expensive to process if it joins
> > > against a
> > > > > > huge
> > > > > > >>>>>>>> table.
> > > > > > >>>>>>>>
> > > > > > >>>>>>>> I can just say we have been in the spot of needing to
> grow
> > > log
> > > > > > >>>>>>>> compacted
> > > > > > >>>>>>>> topics. Mainly for processing power we can bring to the
> > > table.
> > > > > > >>>>>>>>
> > > > > > >>>>>>>> Further i am not at all concerned about the extra spaced
> > > used
> > > > by
> > > > > > >>>>>>>> "garbage
> > > > > > >>>>>>>> keys". I am more concerned about the correctness of
> > innocent
> > > > > > >>>>>>>> consumers.
> > > > > > >>>>>>>> The
> > > > > > >>>>>>>> logic becomes complicated. Say for streams one would
> need
> > to
> > > > > load
> > > > > > >>>>>>>> the
> > > > > > >>>>>>>> record into state but not forward it the topology ( to
> > have
> > > it
> > > > > > >>>>>>>> available
> > > > > > >>>>>>>> for shuffeling). I rather have it simple and a topic
> clean
> > > > > > >>>>>>>> regardless
> > > > > > >>>>>>>> if
> > > > > > >>>>>>>> it
> > > > > > >>>>>>>> still has its old partition count. Especially with
> > multiple
> > > > > > >>>>>>>> partitions
> > > > > > >>>>>>>> growth's I think it becomes insanely hard to to this
> > shuffle
> > > > > > >>>>>>>> correct.
> > > > > > >>>>>>>> Maybe
> > > > > > >>>>>>>> Streams and Samza can do it. Especially if you do
> "hipster
> > > > > stream
> > > > > > >>>>>>>> processing" <https://www.confluent.io/blog
> > > > > > >>>>>>>> /introducing-kafka-streams-
> > > > > > >>>>>>>> stream-processing-made-simple/>. This makes kafka way
> to
> > > > > > >>>>>>>> complicated.
> > > > > > >>>>>>>> With my approach I think its way simpler because the
> topic
> > > has
> > > > > no
> > > > > > >>>>>>>> "history"
> > > > > > >>>>>>>> in terms of partitioning but is always clean.
> > > > > > >>>>>>>>
> > > > > > >>>>>>>>
> > > > > > >>>>>>>> 51. "Growing the topic by an integer factor does not
> > require
> > > > any
> > > > > > >>>>>>>> state
> > > > > > >>>>>>>>
> > > > > > >>>>>>>> redistribution at all." Could you clarify this a bit
> more?
> > > > Let's
> > > > > > say
> > > > > > >>>>>>>>> you
> > > > > > >>>>>>>>> have a consumer app that computes the windowed count
> per
> > > key.
> > > > > If
> > > > > > >>>>>>>>> you
> > > > > > >>>>>>>>> double
> > > > > > >>>>>>>>> the number of partitions from 1 to 2 and grow the
> > consumer
> > > > > > >>>>>>>>> instances
> > > > > > >>>>>>>>> from
> > > > > > >>>>>>>>> 1
> > > > > > >>>>>>>>> to 2, we would need to redistribute some of the counts
> to
> > > the
> > > > > new
> > > > > > >>>>>>>>> consumer
> > > > > > >>>>>>>>> instance. Regarding to linear hashing, it's true that
> it
> > > > won't
> > > > > > >>>>>>>>> solve
> > > > > > >>>>>>>>> the
> > > > > > >>>>>>>>> problem with compacted topics. The main benefit is that
> > it
> > > > > > >>>>>>>>> redistributes
> > > > > > >>>>>>>>> the keys in one partition to no more than two
> partitions,
> > > > which
> > > > > > >>>>>>>>> could
> > > > > > >>>>>>>>> help
> > > > > > >>>>>>>>> redistribute the state.
> > > > > > >>>>>>>>>
> > > > > > >>>>>>>>> You don't need to spin up a new consumer in this case.
> > > every
> > > > > > >>>>>>>>> consumer
> > > > > > >>>>>>>>>
> > > > > > >>>>>>>>> would just read every partition with the (partition %
> > > > num_task)
> > > > > > >>>>>>>> task.
> > > > > > >>>>>>>> it
> > > > > > >>>>>>>> will still have the previous data right there and can go
> > on.
> > > > > > >>>>>>>>
> > > > > > >>>>>>>> This sounds contradictory to what I said before, but
> > please
> > > > bear
> > > > > > >>>>>>>> with
> > > > > > >>>>>>>> me.
> > > > > > >>>>>>>>
> > > > > > >>>>>>>> 52. Good point on coordinating the expansion of 2 topics
> > > that
> > > > > need
> > > > > > >>>>>>>> to
> > > > > > >>>>>>>> be
> > > > > > >>>>>>>>
> > > > > > >>>>>>>> joined together. This is where the 2-phase partition
> > > expansion
> > > > > > could
> > > > > > >>>>>>>>> potentially help. In the first phase, we could add new
> > > > > partitions
> > > > > > >>>>>>>>> to
> > > > > > >>>>>>>>> the 2
> > > > > > >>>>>>>>> topics one at a time but without publishing to the new
> > > > > patitions.
> > > > > > >>>>>>>>> Then,
> > > > > > >>>>>>>>> we
> > > > > > >>>>>>>>> can add new consumer instances to pick up the new
> > > partitions.
> > > > > In
> > > > > > >>>>>>>>> this
> > > > > > >>>>>>>>> transition phase, no reshuffling is needed since no
> data
> > is
> > > > > > coming
> > > > > > >>>>>>>>> from
> > > > > > >>>>>>>>> the
> > > > > > >>>>>>>>> new partitions. Finally, we can enable the publishing
> to
> > > the
> > > > > new
> > > > > > >>>>>>>>> partitions.
> > > > > > >>>>>>>>>
> > > > > > >>>>>>>>> I think its even worse than you think. I would like to
> > > > > introduce
> > > > > > >>>>>>>>> the
> > > > > > >>>>>>>>>
> > > > > > >>>>>>>>> Term
> > > > > > >>>>>>>> transitive copartitioning. Imagine
> > > > > > >>>>>>>> 2 streams application. One joins (A,B) the other (B,C)
> > then
> > > > > there
> > > > > > >>>>>>>> is a
> > > > > > >>>>>>>> transitive copartition requirement for
> > > > > > >>>>>>>> (A,C) to be copartitioned aswell. This can spread
> > > > significantly
> > > > > > and
> > > > > > >>>>>>>> require many consumers to adapt at the same time.
> > > > > > >>>>>>>>
> > > > > > >>>>>>>> It is also not entirely clear to me how you not need
> > > > reshuffling
> > > > > > in
> > > > > > >>>>>>>> this
> > > > > > >>>>>>>> case. If A has a record that never gets updated after
> the
> > > > > > expansion
> > > > > > >>>>>>>> and
> > > > > > >>>>>>>> the
> > > > > > >>>>>>>> coresponding B record moves to a new partition. How
> shall
> > > they
> > > > > > meet
> > > > > > >>>>>>>> w/o
> > > > > > >>>>>>>> shuffle?
> > > > > > >>>>>>>>
> > > > > > >>>>>>>> 53. "Migrating consumer is a step that might be made
> > > completly
> > > > > > >>>>>>>>
> > > > > > >>>>>>>> unnecessary
> > > > > > >>>>>>>>> if - for example streams - takes the gcd as
> partitioning
> > > > scheme
> > > > > > >>>>>>>>> instead
> > > > > > >>>>>>>>> of
> > > > > > >>>>>>>>> enforcing 1 to 1." Not sure that I fully understand
> > this. I
> > > > > think
> > > > > > >>>>>>>>> you
> > > > > > >>>>>>>>> mean
> > > > > > >>>>>>>>> that a consumer application can run more instances than
> > the
> > > > > > number
> > > > > > >>>>>>>>> of
> > > > > > >>>>>>>>> partitions. In that case, the consumer can just
> > > > repartitioning
> > > > > > the
> > > > > > >>>>>>>>> input
> > > > > > >>>>>>>>> data according to the number of instances. This is
> > > possible,
> > > > > but
> > > > > > >>>>>>>>> just
> > > > > > >>>>>>>>> has
> > > > > > >>>>>>>>> the overhead of reshuffling the data.
> > > > > > >>>>>>>>>
> > > > > > >>>>>>>>> No what I meant is ( that is also your question i think
> > > > > Mathias)
> > > > > > >>>>>>>>> that
> > > > > > >>>>>>>>> if
> > > > > > >>>>>>>>>
> > > > > > >>>>>>>>> you grow a topic by a factor.
> > > > > > >>>>>>>> Even if your processor is statefull you can can just
> > assign
> > > > all
> > > > > > the
> > > > > > >>>>>>>> multiples of the previous partition to
> > > > > > >>>>>>>> this consumer and the state to keep processing correctly
> > > will
> > > > be
> > > > > > >>>>>>>> present
> > > > > > >>>>>>>> w/o any shuffling.
> > > > > > >>>>>>>>
> > > > > > >>>>>>>> Say you have an assignment
> > > > > > >>>>>>>> Statefull consumer => partition
> > > > > > >>>>>>>> 0 => 0
> > > > > > >>>>>>>> 1 => 1
> > > > > > >>>>>>>> 2 => 2
> > > > > > >>>>>>>>
> > > > > > >>>>>>>> and you grow you topic by 4 you get,
> > > > > > >>>>>>>>
> > > > > > >>>>>>>> 0 => 0,3,6,9
> > > > > > >>>>>>>> 1 => 1,4,7,10
> > > > > > >>>>>>>> 2 => 2,5,8,11
> > > > > > >>>>>>>>
> > > > > > >>>>>>>> Say your hashcode is 8. 8%3 => 2  before so consumer for
> > > > > > partition 2
> > > > > > >>>>>>>> has
> > > > > > >>>>>>>> it.
> > > > > > >>>>>>>> Now you you have 12 partitions so 8%12 => 8, so it goes
> > into
> > > > > > >>>>>>>> partition
> > > > > > >>>>>>>> 8
> > > > > > >>>>>>>> which is assigned to the same consumer
> > > > > > >>>>>>>> who had 2 before and therefore knows the key.
> > > > > > >>>>>>>>
> > > > > > >>>>>>>> Userland reshuffeling is there as an options. And it
> does
> > > > > exactly
> > > > > > >>>>>>>> what
> > > > > > >>>>>>>> I
> > > > > > >>>>>>>> suggest. And I think its the perfect strategie. All I am
> > > > > > suggestion
> > > > > > >>>>>>>> is
> > > > > > >>>>>>>> broker side support to switch the producers to the newly
> > > > > > partitioned
> > > > > > >>>>>>>> topic.
> > > > > > >>>>>>>> Then the old (to few partition topic) can go away.
> > Remember
> > > > the
> > > > > > >>>>>>>> list
> > > > > > >>>>>>>> of
> > > > > > >>>>>>>> steps in the beginning of this thread. If one has broker
> > > > support
> > > > > > for
> > > > > > >>>>>>>> all
> > > > > > >>>>>>>> where its required and streams support for those that
> > aren’t
> > > > > > >>>>>>>> necessarily.
> > > > > > >>>>>>>> Then one has solved the problem.
> > > > > > >>>>>>>> I repeat it because I think its important. I am really
> > happy
> > > > > that
> > > > > > >>>>>>>> you
> > > > > > >>>>>>>> brought that up! because its 100% what I want just with
> > the
> > > > > > >>>>>>>> differences
> > > > > > >>>>>>>> to
> > > > > > >>>>>>>> have an option to discard the to small topic later
> (after
> > > all
> > > > > > >>>>>>>> consumers
> > > > > > >>>>>>>> adapted). And to have order correct there. I need broker
> > > > support
> > > > > > >>>>>>>> managing
> > > > > > >>>>>>>> the copy process + the produces and fence them against
> > each
> > > > > > other. I
> > > > > > >>>>>>>> also
> > > > > > >>>>>>>> repeat. the copy process can run for weeks in the worst
> > > case.
> > > > > > >>>>>>>> Copying
> > > > > > >>>>>>>> the
> > > > > > >>>>>>>> data is not the longest task migrating consumers might
> > very
> > > > well
> > > > > > be.
> > > > > > >>>>>>>> Once all consumers switched and copying is really up to
> > date
> > > > > > (think
> > > > > > >>>>>>>> ISR
> > > > > > >>>>>>>> like up to date) only then we stop the producer, wait
> for
> > > the
> > > > > copy
> > > > > > >>>>>>>> to
> > > > > > >>>>>>>> finish and use the new topic for producing.
> > > > > > >>>>>>>>
> > > > > > >>>>>>>> After this the topic is perfect in shape. and no one
> needs
> > > to
> > > > > > worry
> > > > > > >>>>>>>> about
> > > > > > >>>>>>>> complicated stuff. (old keys hanging around might arrive
> > in
> > > > some
> > > > > > >>>>>>>> other
> > > > > > >>>>>>>> topic later.....). can only imagine how many tricky bugs
> > > gonna
> > > > > > >>>>>>>> arrive
> > > > > > >>>>>>>> after
> > > > > > >>>>>>>> someone had grown and shrunken is topic 10 times.
> > > > > > >>>>>>>>
> > > > > > >>>>>>>>
> > > > > > >>>>>>>>
> > > > > > >>>>>>>>
> > > > > > >>>>>>>>
> > > > > > >>>>>>>>
> > > > > > >>>>>>>> 54. "The other thing I wanted to mention is that I
> believe
> > > the
> > > > > > >>>>>>>> current
> > > > > > >>>>>>>>
> > > > > > >>>>>>>> suggestion (without copying data over) can be
> implemented
> > in
> > > > > pure
> > > > > > >>>>>>>>> userland
> > > > > > >>>>>>>>> with a custom partitioner and a small feedbackloop from
> > > > > > >>>>>>>>> ProduceResponse
> > > > > > >>>>>>>>> =>
> > > > > > >>>>>>>>> Partitionier in coorporation with a change management
> > > > system."
> > > > > I
> > > > > > am
> > > > > > >>>>>>>>> not
> > > > > > >>>>>>>>> sure a customized partitioner itself solves the
> problem.
> > We
> > > > > > >>>>>>>>> probably
> > > > > > >>>>>>>>> need
> > > > > > >>>>>>>>> some broker side support to enforce when the new
> > partitions
> > > > can
> > > > > > be
> > > > > > >>>>>>>>> used.
> > > > > > >>>>>>>>> We
> > > > > > >>>>>>>>> also need some support on the consumer/kstream side to
> > > > preserve
> > > > > > the
> > > > > > >>>>>>>>> per
> > > > > > >>>>>>>>> key
> > > > > > >>>>>>>>> ordering and potentially migrate the processing state.
> > This
> > > > is
> > > > > > not
> > > > > > >>>>>>>>> trivial
> > > > > > >>>>>>>>> and I am not sure if it's ideal to fully push to the
> > > > > application
> > > > > > >>>>>>>>> space.
> > > > > > >>>>>>>>>
> > > > > > >>>>>>>>> Broker support is defenitly the preferred way here. I
> > have
> > > > > > nothing
> > > > > > >>>>>>>>>
> > > > > > >>>>>>>>> against
> > > > > > >>>>>>>> broker support.
> > > > > > >>>>>>>> I tried to say that for what I would preffer - copying
> the
> > > > data
> > > > > > >>>>>>>> over,
> > > > > > >>>>>>>> at
> > > > > > >>>>>>>> least for log compacted topics -
> > > > > > >>>>>>>> I would require more broker support than the KIP
> currently
> > > > > offers.
> > > > > > >>>>>>>>
> > > > > > >>>>>>>>
> > > > > > >>>>>>>>
> > > > > > >>>>>>>> Jun
> > > > > > >>>>>>>>
> > > > > > >>>>>>>> On Tue, Mar 6, 2018 at 10:33 PM, Jan Filipiak <
> > > > > > >>>>>>>>> Jan.Filipiak@trivago.com
> > > > > > >>>>>>>>> wrote:
> > > > > > >>>>>>>>>
> > > > > > >>>>>>>>> Hi Dong,
> > > > > > >>>>>>>>>
> > > > > > >>>>>>>>> are you actually reading my emails, or are you just
> using
> > > the
> > > > > > >>>>>>>>> thread I
> > > > > > >>>>>>>>>
> > > > > > >>>>>>>>>> started for general announcements regarding the KIP?
> > > > > > >>>>>>>>>>
> > > > > > >>>>>>>>>> I tried to argue really hard against linear hashing.
> > > Growing
> > > > > the
> > > > > > >>>>>>>>>> topic
> > > > > > >>>>>>>>>> by
> > > > > > >>>>>>>>>> an integer factor does not require any state
> > > redistribution
> > > > at
> > > > > > >>>>>>>>>> all. I
> > > > > > >>>>>>>>>> fail
> > > > > > >>>>>>>>>> to see completely where linear hashing helps on log
> > > > compacted
> > > > > > >>>>>>>>>> topics.
> > > > > > >>>>>>>>>>
> > > > > > >>>>>>>>>> If you are not willing to explain to me what I might
> be
> > > > > > >>>>>>>>>> overlooking:
> > > > > > >>>>>>>>>> that
> > > > > > >>>>>>>>>> is fine.
> > > > > > >>>>>>>>>> But I ask you to not reply to my emails then. Please
> > > > > understand
> > > > > > my
> > > > > > >>>>>>>>>> frustration with this.
> > > > > > >>>>>>>>>>
> > > > > > >>>>>>>>>> Best Jan
> > > > > > >>>>>>>>>>
> > > > > > >>>>>>>>>>
> > > > > > >>>>>>>>>>
> > > > > > >>>>>>>>>> On 06.03.2018 19:38, Dong Lin wrote:
> > > > > > >>>>>>>>>>
> > > > > > >>>>>>>>>> Hi everyone,
> > > > > > >>>>>>>>>>
> > > > > > >>>>>>>>>> Thanks for all the comments! It appears that everyone
> > > > prefers
> > > > > > >>>>>>>>>> linear
> > > > > > >>>>>>>>>>
> > > > > > >>>>>>>>>>> hashing because it reduces the amount of state that
> > needs
> > > > to
> > > > > be
> > > > > > >>>>>>>>>>> moved
> > > > > > >>>>>>>>>>> between consumers (for stream processing). The KIP
> has
> > > been
> > > > > > >>>>>>>>>>> updated
> > > > > > >>>>>>>>>>> to
> > > > > > >>>>>>>>>>> use
> > > > > > >>>>>>>>>>> linear hashing.
> > > > > > >>>>>>>>>>>
> > > > > > >>>>>>>>>>> Regarding the migration endeavor: it seems that
> > migrating
> > > > > > >>>>>>>>>>> producer
> > > > > > >>>>>>>>>>> library
> > > > > > >>>>>>>>>>> to use linear hashing should be pretty
> straightforward
> > > > > without
> > > > > > >>>>>>>>>>> much operational endeavor. If we don't upgrade client
> > > > library
> > > > > > to
> > > > > > >>>>>>>>>>> use
> > > > > > >>>>>>>>>>> this
> > > > > > >>>>>>>>>>> KIP, we can not support in-order delivery after
> > partition
> > > > is
> > > > > > >>>>>>>>>>> changed
> > > > > > >>>>>>>>>>> anyway. Suppose we upgrade client library to use this
> > > KIP,
> > > > if
> > > > > > >>>>>>>>>>> partition
> > > > > > >>>>>>>>>>> number is not changed, the key -> partition mapping
> > will
> > > be
> > > > > > >>>>>>>>>>> exactly
> > > > > > >>>>>>>>>>> the
> > > > > > >>>>>>>>>>> same as it is now because it is still determined
> using
> > > > > > >>>>>>>>>>> murmur_hash(key)
> > > > > > >>>>>>>>>>> %
> > > > > > >>>>>>>>>>> original_partition_num. In other words, this change
> is
> > > > > backward
> > > > > > >>>>>>>>>>> compatible.
> > > > > > >>>>>>>>>>>
> > > > > > >>>>>>>>>>> Regarding the load distribution: if we use linear
> > > hashing,
> > > > > the
> > > > > > >>>>>>>>>>> load
> > > > > > >>>>>>>>>>> may
> > > > > > >>>>>>>>>>> be
> > > > > > >>>>>>>>>>> unevenly distributed because those partitions which
> are
> > > not
> > > > > > split
> > > > > > >>>>>>>>>>> may
> > > > > > >>>>>>>>>>> receive twice as much traffic as other partitions
> that
> > > are
> > > > > > split.
> > > > > > >>>>>>>>>>> This
> > > > > > >>>>>>>>>>> issue can be mitigated by creating topic with
> > partitions
> > > > that
> > > > > > are
> > > > > > >>>>>>>>>>> several
> > > > > > >>>>>>>>>>> times the number of consumers. And there will be no
> > > > imbalance
> > > > > > if
> > > > > > >>>>>>>>>>> the
> > > > > > >>>>>>>>>>> partition number is always doubled. So this imbalance
> > > seems
> > > > > > >>>>>>>>>>> acceptable.
> > > > > > >>>>>>>>>>>
> > > > > > >>>>>>>>>>> Regarding storing the partition strategy as per-topic
> > > > config:
> > > > > > It
> > > > > > >>>>>>>>>>> seems
> > > > > > >>>>>>>>>>> not
> > > > > > >>>>>>>>>>> necessary since we can still use murmur_hash as the
> > > default
> > > > > > hash
> > > > > > >>>>>>>>>>> function
> > > > > > >>>>>>>>>>> and additionally apply the linear hashing algorithm
> if
> > > the
> > > > > > >>>>>>>>>>> partition
> > > > > > >>>>>>>>>>> number
> > > > > > >>>>>>>>>>> has increased. Not sure if there is any use-case for
> > > > producer
> > > > > > to
> > > > > > >>>>>>>>>>> use a
> > > > > > >>>>>>>>>>> different hash function. Jason, can you check if
> there
> > is
> > > > > some
> > > > > > >>>>>>>>>>> use-case
> > > > > > >>>>>>>>>>> that I missed for using the per-topic partition
> > strategy?
> > > > > > >>>>>>>>>>>
> > > > > > >>>>>>>>>>> Regarding how to reduce latency (due to state
> > store/load)
> > > > in
> > > > > > >>>>>>>>>>> stream
> > > > > > >>>>>>>>>>> processing consumer when partition number changes: I
> > need
> > > > to
> > > > > > read
> > > > > > >>>>>>>>>>> the
> > > > > > >>>>>>>>>>> Kafka
> > > > > > >>>>>>>>>>> Stream code to understand how Kafka Stream currently
> > > > migrate
> > > > > > >>>>>>>>>>> state
> > > > > > >>>>>>>>>>> between
> > > > > > >>>>>>>>>>> consumers when the application is added/removed for a
> > > given
> > > > > > job.
> > > > > > >>>>>>>>>>> I
> > > > > > >>>>>>>>>>> will
> > > > > > >>>>>>>>>>> reply after I finish reading the documentation and
> > code.
> > > > > > >>>>>>>>>>>
> > > > > > >>>>>>>>>>>
> > > > > > >>>>>>>>>>> Thanks,
> > > > > > >>>>>>>>>>> Dong
> > > > > > >>>>>>>>>>>
> > > > > > >>>>>>>>>>>
> > > > > > >>>>>>>>>>> On Mon, Mar 5, 2018 at 10:43 AM, Jason Gustafson <
> > > > > > >>>>>>>>>>> jason@confluent.io>
> > > > > > >>>>>>>>>>> wrote:
> > > > > > >>>>>>>>>>>
> > > > > > >>>>>>>>>>> Great discussion. I think I'm wondering whether we
> can
> > > > > continue
> > > > > > >>>>>>>>>>> to
> > > > > > >>>>>>>>>>> leave
> > > > > > >>>>>>>>>>>
> > > > > > >>>>>>>>>>> Kafka agnostic to the partitioning strategy. The
> > > challenge
> > > > is
> > > > > > >>>>>>>>>>>
> > > > > > >>>>>>>>>>> communicating
> > > > > > >>>>>>>>>>>> the partitioning logic from producers to consumers
> so
> > > that
> > > > > the
> > > > > > >>>>>>>>>>>> dependencies
> > > > > > >>>>>>>>>>>> between each epoch can be determined. For the sake
> of
> > > > > > >>>>>>>>>>>> discussion,
> > > > > > >>>>>>>>>>>> imagine
> > > > > > >>>>>>>>>>>> you did something like the following:
> > > > > > >>>>>>>>>>>>
> > > > > > >>>>>>>>>>>> 1. The name (and perhaps version) of a partitioning
> > > > strategy
> > > > > > is
> > > > > > >>>>>>>>>>>> stored
> > > > > > >>>>>>>>>>>> in
> > > > > > >>>>>>>>>>>> topic configuration when a topic is created.
> > > > > > >>>>>>>>>>>> 2. The producer looks up the partitioning strategy
> > > before
> > > > > > >>>>>>>>>>>> writing
> > > > > > >>>>>>>>>>>> to
> > > > > > >>>>>>>>>>>> a
> > > > > > >>>>>>>>>>>> topic and includes it in the produce request (for
> > > > fencing).
> > > > > If
> > > > > > >>>>>>>>>>>> it
> > > > > > >>>>>>>>>>>> doesn't
> > > > > > >>>>>>>>>>>> have an implementation for the configured strategy,
> it
> > > > > fails.
> > > > > > >>>>>>>>>>>> 3. The consumer also looks up the partitioning
> > strategy
> > > > and
> > > > > > >>>>>>>>>>>> uses it
> > > > > > >>>>>>>>>>>> to
> > > > > > >>>>>>>>>>>> determine dependencies when reading a new epoch. It
> > > could
> > > > > > either
> > > > > > >>>>>>>>>>>> fail
> > > > > > >>>>>>>>>>>> or
> > > > > > >>>>>>>>>>>> make the most conservative dependency assumptions if
> > it
> > > > > > doesn't
> > > > > > >>>>>>>>>>>> know
> > > > > > >>>>>>>>>>>> how
> > > > > > >>>>>>>>>>>> to
> > > > > > >>>>>>>>>>>> implement the partitioning strategy. For the
> consumer,
> > > the
> > > > > new
> > > > > > >>>>>>>>>>>> interface
> > > > > > >>>>>>>>>>>> might look something like this:
> > > > > > >>>>>>>>>>>>
> > > > > > >>>>>>>>>>>> // Return the partition dependencies following an
> > epoch
> > > > bump
> > > > > > >>>>>>>>>>>> Map<Integer, List<Integer>> dependencies(int
> > > > > > >>>>>>>>>>>> numPartitionsBeforeEpochBump,
> > > > > > >>>>>>>>>>>> int numPartitionsAfterEpochBump)
> > > > > > >>>>>>>>>>>>
> > > > > > >>>>>>>>>>>> The unordered case then is just a particular
> > > > implementation
> > > > > > >>>>>>>>>>>> which
> > > > > > >>>>>>>>>>>> never
> > > > > > >>>>>>>>>>>> has
> > > > > > >>>>>>>>>>>> any epoch dependencies. To implement this, we would
> > need
> > > > > some
> > > > > > >>>>>>>>>>>> way
> > > > > > >>>>>>>>>>>> for
> > > > > > >>>>>>>>>>>> the
> > > > > > >>>>>>>>>>>> consumer to find out how many partitions there were
> in
> > > > each
> > > > > > >>>>>>>>>>>> epoch,
> > > > > > >>>>>>>>>>>> but
> > > > > > >>>>>>>>>>>> maybe that's not too unreasonable.
> > > > > > >>>>>>>>>>>>
> > > > > > >>>>>>>>>>>> Thanks,
> > > > > > >>>>>>>>>>>> Jason
> > > > > > >>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>
> > > > > > >>>>>>>>>>>> On Mon, Mar 5, 2018 at 4:51 AM, Jan Filipiak <
> > > > > > >>>>>>>>>>>> Jan.Filipiak@trivago.com
> > > > > > >>>>>>>>>>>> wrote:
> > > > > > >>>>>>>>>>>>
> > > > > > >>>>>>>>>>>> Hi Dong
> > > > > > >>>>>>>>>>>>
> > > > > > >>>>>>>>>>>> thank you very much for your questions.
> > > > > > >>>>>>>>>>>>
> > > > > > >>>>>>>>>>>> regarding the time spend copying data across:
> > > > > > >>>>>>>>>>>>> It is correct that copying data from a topic with
> one
> > > > > > partition
> > > > > > >>>>>>>>>>>>> mapping
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> to
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> a topic with a different partition mapping takes
> way
> > > > longer
> > > > > > >>>>>>>>>>>>> than
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>> we
> > > > > > >>>>>>>>>>>> can
> > > > > > >>>>>>>>>>>>
> > > > > > >>>>>>>>>>>> stop producers. Tens of minutes is a very optimistic
> > > > > estimate
> > > > > > >>>>>>>>>>>> here.
> > > > > > >>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> Many
> > > > > > >>>>>>>>>>>>> people can not afford copy full steam and therefore
> > > will
> > > > > have
> > > > > > >>>>>>>>>>>>> some
> > > > > > >>>>>>>>>>>>> rate
> > > > > > >>>>>>>>>>>>> limiting in place, this can bump the timespan into
> > the
> > > > > day's.
> > > > > > >>>>>>>>>>>>> The
> > > > > > >>>>>>>>>>>>> good
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> part
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> is that the vast majority of the data can be copied
> > > while
> > > > > the
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>> producers
> > > > > > >>>>>>>>>>>>
> > > > > > >>>>>>>>>>>> are
> > > > > > >>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> still going. One can then, piggyback the consumers
> > > ontop
> > > > of
> > > > > > >>>>>>>>>>>>> this
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>> timeframe,
> > > > > > >>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> by the method mentioned (provide them an mapping
> from
> > > > their
> > > > > > old
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>> offsets
> > > > > > >>>>>>>>>>>>
> > > > > > >>>>>>>>>>>> to
> > > > > > >>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> new offsets in their repartitioned topics. In that
> > way
> > > we
> > > > > > >>>>>>>>>>>>> separate
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>> migration of consumers from migration of producers
> > > > > (decoupling
> > > > > > >>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> these
> > > > > > >>>>>>>>>>>>> is
> > > > > > >>>>>>>>>>>>> what kafka is strongest at). The time to actually
> > swap
> > > > over
> > > > > > the
> > > > > > >>>>>>>>>>>>> producers
> > > > > > >>>>>>>>>>>>> should be kept minimal by ensuring that when a swap
> > > > attempt
> > > > > > is
> > > > > > >>>>>>>>>>>>> started
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> the
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> consumer copying over should be very close to the
> log
> > > end
> > > > > and
> > > > > > >>>>>>>>>>>>> is
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>> expected
> > > > > > >>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> to finish within the next fetch. The operation
> should
> > > > have
> > > > > a
> > > > > > >>>>>>>>>>>>> time-out
> > > > > > >>>>>>>>>>>>> and
> > > > > > >>>>>>>>>>>>> should be "reattemtable".
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> Importance of logcompaction:
> > > > > > >>>>>>>>>>>>> If a producer produces key A, to partiton 0, its
> > > forever
> > > > > > gonna
> > > > > > >>>>>>>>>>>>> be
> > > > > > >>>>>>>>>>>>> there,
> > > > > > >>>>>>>>>>>>> unless it gets deleted. The record might sit in
> there
> > > for
> > > > > > >>>>>>>>>>>>> years. A
> > > > > > >>>>>>>>>>>>> new
> > > > > > >>>>>>>>>>>>> producer started with the new partitions will fail
> to
> > > > > delete
> > > > > > >>>>>>>>>>>>> the
> > > > > > >>>>>>>>>>>>> record
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> in
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> the correct partition. Th record will be there
> > forever
> > > > and
> > > > > > one
> > > > > > >>>>>>>>>>>>> can
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>> not
> > > > > > >>>>>>>>>>>>
> > > > > > >>>>>>>>>>>> reliable bootstrap new consumers. I cannot see how
> > > linear
> > > > > > >>>>>>>>>>>> hashing
> > > > > > >>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> can
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> solve
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> this.
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>> Regarding your skipping of userland copying:
> > > > > > >>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> 100%, copying the data across in userland is, as
> far
> > > as i
> > > > > can
> > > > > > >>>>>>>>>>>>> see,
> > > > > > >>>>>>>>>>>>> only
> > > > > > >>>>>>>>>>>>> a
> > > > > > >>>>>>>>>>>>> usecase for log compacted topics. Even for
> > > logcompaction
> > > > +
> > > > > > >>>>>>>>>>>>> retentions
> > > > > > >>>>>>>>>>>>> it
> > > > > > >>>>>>>>>>>>> should only be opt-in. Why did I bring it up? I
> think
> > > log
> > > > > > >>>>>>>>>>>>> compaction
> > > > > > >>>>>>>>>>>>> is
> > > > > > >>>>>>>>>>>>> a
> > > > > > >>>>>>>>>>>>> very important feature to really embrace kafka as a
> > > "data
> > > > > > >>>>>>>>>>>>> plattform".
> > > > > > >>>>>>>>>>>>> The
> > > > > > >>>>>>>>>>>>> point I also want to make is that copying data this
> > way
> > > > is
> > > > > > >>>>>>>>>>>>> completely
> > > > > > >>>>>>>>>>>>> inline with the kafka architecture. it only
> consists
> > of
> > > > > > reading
> > > > > > >>>>>>>>>>>>> and
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> writing
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> to topics.
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>> I hope it clarifies more why I think we should aim
> for
> > > > more
> > > > > > than
> > > > > > >>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> the
> > > > > > >>>>>>>>>>>>> current KIP. I fear that once the KIP is done not
> > much
> > > > more
> > > > > > >>>>>>>>>>>>> effort
> > > > > > >>>>>>>>>>>>> will
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> be
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> taken.
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>
> > > > > > >>>>>>>>>>>> On 04.03.2018 02:28, Dong Lin wrote:
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> Hey Jan,
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> In the current proposal, the consumer will be
> blocked
> > > on
> > > > > > >>>>>>>>>>>>> waiting
> > > > > > >>>>>>>>>>>>> for
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> other
> > > > > > >>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>> consumers of the group to consume up to a given
> > > offset.
> > > > In
> > > > > > >>>>>>>>>>>>>> most
> > > > > > >>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> cases,
> > > > > > >>>>>>>>>>>>> all
> > > > > > >>>>>>>>>>>>> consumers should be close to the LEO of the
> > partitions
> > > > when
> > > > > > the
> > > > > > >>>>>>>>>>>>> partition
> > > > > > >>>>>>>>>>>>> expansion happens. Thus the time waiting should not
> > be
> > > > long
> > > > > > >>>>>>>>>>>>> e.g.
> > > > > > >>>>>>>>>>>>> on
> > > > > > >>>>>>>>>>>>> the
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> order of seconds. On the other hand, it may take a
> > long
> > > > > time
> > > > > > to
> > > > > > >>>>>>>>>>>>> wait
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> for
> > > > > > >>>>>>>>>>>>>> the entire partition to be copied -- the amount of
> > > time
> > > > is
> > > > > > >>>>>>>>>>>>>> proportional
> > > > > > >>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>> to
> > > > > > >>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>> the amount of existing data in the partition,
> which
> > > can
> > > > > take
> > > > > > >>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> tens of
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> minutes. So the amount of time that we stop
> consumers
> > > may
> > > > > not
> > > > > > >>>>>>>>>>>>> be
> > > > > > >>>>>>>>>>>>> on
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> the
> > > > > > >>>>>>>>>>>>>> same order of magnitude.
> > > > > > >>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>> If we can implement this suggestion without
> copying
> > > data
> > > > > > over
> > > > > > >>>>>>>>>>>>>> in
> > > > > > >>>>>>>>>>>>>> purse
> > > > > > >>>>>>>>>>>>>> userland, it will be much more valuable. Do you
> have
> > > > ideas
> > > > > > on
> > > > > > >>>>>>>>>>>>>> how
> > > > > > >>>>>>>>>>>>>> this
> > > > > > >>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>> can
> > > > > > >>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>> be done?
> > > > > > >>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> Not sure why the current KIP not help people who
> > depend
> > > > on
> > > > > > log
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> compaction.
> > > > > > >>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>> Could you elaborate more on this point?
> > > > > > >>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> Thanks,
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> Dong
> > > > > > >>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>> On Wed, Feb 28, 2018 at 10:55 PM, Jan
> > > > > > >>>>>>>>>>>>>> Filipiak<Jan.Filipiak@trivago.
> > > > > > >>>>>>>>>>>>>> com
> > > > > > >>>>>>>>>>>>>> wrote:
> > > > > > >>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>> Hi Dong,
> > > > > > >>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>> I tried to focus on what the steps are one can
> > > currently
> > > > > > >>>>>>>>>>>>>> perform
> > > > > > >>>>>>>>>>>>>> to
> > > > > > >>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>> expand
> > > > > > >>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>> or shrink a keyed topic while maintaining a top
> > notch
> > > > > > >>>>>>>>>>>>>>> semantics.
> > > > > > >>>>>>>>>>>>>>> I can understand that there might be confusion
> > about
> > > > > > >>>>>>>>>>>>>>> "stopping
> > > > > > >>>>>>>>>>>>>>> the
> > > > > > >>>>>>>>>>>>>>> consumer". It is exactly the same as proposed in
> > the
> > > > KIP.
> > > > > > >>>>>>>>>>>>>>> there
> > > > > > >>>>>>>>>>>>>>> needs
> > > > > > >>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>> to
> > > > > > >>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>> be
> > > > > > >>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>> a time the producers agree on the new
> partitioning.
> > > The
> > > > > > extra
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> semantics I
> > > > > > >>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>> want to put in there is that we have a
> possibility
> > to
> > > > > wait
> > > > > > >>>>>>>>>>>>>>> until
> > > > > > >>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>> all
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> the
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> existing data
> > > > > > >>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>> is copied over into the new partitioning scheme.
> > When
> > > I
> > > > > say
> > > > > > >>>>>>>>>>>>> stopping
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> I
> > > > > > >>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>> think more of having a memory barrier that
> ensures
> > > the
> > > > > > >>>>>>>>>>>>>>> ordering. I
> > > > > > >>>>>>>>>>>>>>> am
> > > > > > >>>>>>>>>>>>>>> still
> > > > > > >>>>>>>>>>>>>>> aming for latencies  on the scale of leader
> > > failovers.
> > > > > > >>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>> Consumers have to explicitly adapt the new
> > > partitioning
> > > > > > >>>>>>>>>>>>>>> scheme
> > > > > > >>>>>>>>>>>>>>> in
> > > > > > >>>>>>>>>>>>>>> the
> > > > > > >>>>>>>>>>>>>>> above scenario. The reason is that in these cases
> > > where
> > > > > you
> > > > > > >>>>>>>>>>>>>>> are
> > > > > > >>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>> dependent
> > > > > > >>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>> on a particular partitioning scheme, you also
> have
> > > > other
> > > > > > >>>>>>>>>>>>>>> topics
> > > > > > >>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>> that
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> have
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> co-partition enforcements or the kind -frequently.
> > > > > Therefore
> > > > > > >>>>>>>>>>>>>> all
> > > > > > >>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>> your
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> other
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> input topics might need to grow accordingly.
> > > > > > >>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>> What I was suggesting was to streamline all these
> > > > > > operations
> > > > > > >>>>>>>>>>>>>>> as
> > > > > > >>>>>>>>>>>>>>> best
> > > > > > >>>>>>>>>>>>>>> as
> > > > > > >>>>>>>>>>>>>>> possible to have "real" partition grow and
> > shrinkage
> > > > > going
> > > > > > >>>>>>>>>>>>>>> on.
> > > > > > >>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>> Migrating
> > > > > > >>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>> the producers to a new partitioning scheme can be
> > > much
> > > > > more
> > > > > > >>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>> streamlined
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> with proper broker support for this. Migrating
> > consumer
> > > > is
> > > > > a
> > > > > > >>>>>>>>>>>>> step
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> that
> > > > > > >>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>> might be made completly unnecessary if - for
> > example
> > > > > > streams
> > > > > > >>>>>>>>>>>>>>> -
> > > > > > >>>>>>>>>>>>>>> takes
> > > > > > >>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>> the
> > > > > > >>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>> gcd as partitioning scheme instead of enforcing 1
> > to
> > > 1.
> > > > > > >>>>>>>>>>>>>>> Connect
> > > > > > >>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>> consumers
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> and other consumers should be fine anyways.
> > > > > > >>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>> I hope this makes more clear where I was aiming
> at.
> > > The
> > > > > rest
> > > > > > >>>>>>>>>>>>> needs
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> to
> > > > > > >>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>> be
> > > > > > >>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>> figured out. The only danger i see is that when
> we
> > > are
> > > > > > >>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>> introducing
> > > > > > >>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>> this
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> feature as supposed in the KIP, it wont help any
> > people
> > > > > > >>>>>>>>>>>>> depending
> > > > > > >>>>>>>>>>>>> on
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> log
> > > > > > >>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>> compaction.
> > > > > > >>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>> The other thing I wanted to mention is that I
> > believe
> > > > the
> > > > > > >>>>>>>>>>>>> current
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> suggestion (without copying data over) can be
> > > implemented
> > > > > in
> > > > > > >>>>>>>>>>>>>> pure
> > > > > > >>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>> userland
> > > > > > >>>>>>>>>>>>>>> with a custom partitioner and a small
> feedbackloop
> > > from
> > > > > > >>>>>>>>>>>>>>> ProduceResponse
> > > > > > >>>>>>>>>>>>>>> =>
> > > > > > >>>>>>>>>>>>>>> Partitionier in coorporation with a change
> > management
> > > > > > system.
> > > > > > >>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>> Best Jan
> > > > > > >>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>> On 28.02.2018 07:13, Dong Lin wrote:
> > > > > > >>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>> Hey Jan,
> > > > > > >>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>> I am not sure if it is acceptable for producer to
> > be
> > > > > > stopped
> > > > > > >>>>>>>>>>>>>>> for a
> > > > > > >>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>> while,
> > > > > > >>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>> particularly for online application which
> requires
> > > low
> > > > > > >>>>>>>>>>>>>>>> latency. I
> > > > > > >>>>>>>>>>>>>>>> am
> > > > > > >>>>>>>>>>>>>>>> also
> > > > > > >>>>>>>>>>>>>>>> not sure how consumers can switch to a new
> topic.
> > > Does
> > > > > > user
> > > > > > >>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>> application
> > > > > > >>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>> needs to explicitly specify a different topic
> for
> > > > > > >>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>> producer/consumer
> > > > > > >>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>> to
> > > > > > >>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> subscribe to? It will be helpful for discussion if
> > you
> > > > can
> > > > > > >>>>>>>>>>>>> provide
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> more
> > > > > > >>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>> detail on the interface change for this solution.
> > > > > > >>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>> Thanks,
> > > > > > >>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>> Dong
> > > > > > >>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>> On Mon, Feb 26, 2018 at 12:48 AM, Jan
> > > > > > >>>>>>>>>>>>>>>> Filipiak<Jan.Filipiak@trivago.
> > > > > > >>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>> com
> > > > > > >>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>> wrote:
> > > > > > >>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>> Hi,
> > > > > > >>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>> just want to throw my though in. In general the
> > > > > > functionality
> > > > > > >>>>>>>>>>>>>> is
> > > > > > >>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>> very
> > > > > > >>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>> usefull, we should though not try to find the
> > > > > architecture
> > > > > > >>>>>>>>>>>>>>>> to
> > > > > > >>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>> hard
> > > > > > >>>>>>>>>>>>>>>>> while
> > > > > > >>>>>>>>>>>>>>>>> implementing.
> > > > > > >>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>> The manual steps would be to
> > > > > > >>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>> create a new topic
> > > > > > >>>>>>>>>>>>>>>>> the mirrormake from the new old topic to the
> new
> > > > topic
> > > > > > >>>>>>>>>>>>>>>>> wait for mirror making to catch up.
> > > > > > >>>>>>>>>>>>>>>>> then put the consumers onto the new topic
> > > > > > >>>>>>>>>>>>>>>>>            (having mirrormaker spit out a
> mapping
> > > > from
> > > > > > old
> > > > > > >>>>>>>>>>>>>>>>> offsets to
> > > > > > >>>>>>>>>>>>>>>>> new
> > > > > > >>>>>>>>>>>>>>>>> offsets:
> > > > > > >>>>>>>>>>>>>>>>>                if topic is increased by factor
> X
> > > > there
> > > > > is
> > > > > > >>>>>>>>>>>>>>>>> gonna
> > > > > > >>>>>>>>>>>>>>>>> be a
> > > > > > >>>>>>>>>>>>>>>>> clean
> > > > > > >>>>>>>>>>>>>>>>> mapping from 1 offset in the old topic to X
> > offsets
> > > > in
> > > > > > the
> > > > > > >>>>>>>>>>>>>>>>> new
> > > > > > >>>>>>>>>>>>>>>>> topic,
> > > > > > >>>>>>>>>>>>>>>>>                if there is no factor then there
> > is
> > > no
> > > > > > >>>>>>>>>>>>>>>>> chance to
> > > > > > >>>>>>>>>>>>>>>>> generate a
> > > > > > >>>>>>>>>>>>>>>>> mapping that can be reasonable used for
> > continuing)
> > > > > > >>>>>>>>>>>>>>>>>            make consumers stop at appropriate
> > > points
> > > > > and
> > > > > > >>>>>>>>>>>>>>>>> continue
> > > > > > >>>>>>>>>>>>>>>>> consumption
> > > > > > >>>>>>>>>>>>>>>>> with offsets from the mapping.
> > > > > > >>>>>>>>>>>>>>>>> have the producers stop for a minimal time.
> > > > > > >>>>>>>>>>>>>>>>> wait for mirrormaker to finish
> > > > > > >>>>>>>>>>>>>>>>> let producer produce with the new metadata.
> > > > > > >>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>> Instead of implementing the approach suggest in
> > the
> > > > KIP
> > > > > > >>>>>>>>>>>>>>>>> which
> > > > > > >>>>>>>>>>>>>>>>> will
> > > > > > >>>>>>>>>>>>>>>>> leave
> > > > > > >>>>>>>>>>>>>>>>> log compacted topic completely crumbled and
> > > unusable.
> > > > > > >>>>>>>>>>>>>>>>> I would much rather try to build infrastructure
> > to
> > > > > > support
> > > > > > >>>>>>>>>>>>>>>>> the
> > > > > > >>>>>>>>>>>>>>>>> mentioned
> > > > > > >>>>>>>>>>>>>>>>> above operations more smoothly.
> > > > > > >>>>>>>>>>>>>>>>> Especially having producers stop and use
> another
> > > > topic
> > > > > is
> > > > > > >>>>>>>>>>>>>>>>> difficult
> > > > > > >>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>> and
> > > > > > >>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>> it would be nice if one can trigger "invalid
> > > > metadata"
> > > > > > >>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>> exceptions
> > > > > > >>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>> for
> > > > > > >>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>> them
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> and
> > > > > > >>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>> if one could give topics aliases so that their
> > > produces
> > > > > > with
> > > > > > >>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>> the
> > > > > > >>>>>>>>>>>>>>>>> old
> > > > > > >>>>>>>>>>>>>>>>> topic
> > > > > > >>>>>>>>>>>>>>>>> will arrive in the new topic.
> > > > > > >>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>> The downsides are obvious I guess ( having the
> > same
> > > > > data
> > > > > > >>>>>>>>>>>>>>>>> twice
> > > > > > >>>>>>>>>>>>>>>>> for
> > > > > > >>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>> the
> > > > > > >>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>> transition period, but kafka tends to scale
> well
> > > with
> > > > > > >>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>> datasize).
> > > > > > >>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>> So
> > > > > > >>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>> its a
> > > > > > >>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>> nicer fit into the architecture.
> > > > > > >>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>> I further want to argument that the functionality
> > by
> > > > the
> > > > > > KIP
> > > > > > >>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>> can
> > > > > > >>>>>>>>>>>>>>>>> completely be implementing in "userland" with a
> > > > custom
> > > > > > >>>>>>>>>>>>>>>>> partitioner
> > > > > > >>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>> that
> > > > > > >>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>> handles the transition as needed. I would
> > > appreciate
> > > > if
> > > > > > >>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>> someone
> > > > > > >>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>> could
> > > > > > >>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>> point
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> out what a custom partitioner couldn't handle in
> this
> > > > case?
> > > > > > >>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>> With the above approach, shrinking a topic
> becomes
> > > the
> > > > > same
> > > > > > >>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>> steps.
> > > > > > >>>>>>>>>>>>>>>>> Without
> > > > > > >>>>>>>>>>>>>>>>> loosing keys in the discontinued partitions.
> > > > > > >>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>> Would love to hear what everyone thinks.
> > > > > > >>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>> Best Jan
> > > > > > >>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>> On 11.02.2018 00:35, Dong Lin wrote:
> > > > > > >>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>> Hi all,
> > > > > > >>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>> I have created KIP-253: Support in-order
> message
> > > > > delivery
> > > > > > >>>>>>>>>>>>>>>>> with
> > > > > > >>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>> partition
> > > > > > >>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>> expansion. See
> > > > > > >>>>>>>>>>>>>>>>>> https://cwiki.apache.org/confl
> > > > > > >>>>>>>>>>>>>>>>>> uence/display/KAFKA/KIP-253%
> > > > > > >>>>>>>>>>>>>>>>>> 3A+Support+in-order+message+de
> > > > > > >>>>>>>>>>>>>>>>>> livery+with+partition+expansio
> > > > > > >>>>>>>>>>>>>>>>>> n
> > > > > > >>>>>>>>>>>>>>>>>> .
> > > > > > >>>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>>> This KIP provides a way to allow messages of
> the
> > > > same
> > > > > > key
> > > > > > >>>>>>>>>>>>>>>>>> from
> > > > > > >>>>>>>>>>>>>>>>>> the
> > > > > > >>>>>>>>>>>>>>>>>> same
> > > > > > >>>>>>>>>>>>>>>>>> producer to be consumed in the same order they
> > are
> > > > > > >>>>>>>>>>>>>>>>>> produced
> > > > > > >>>>>>>>>>>>>>>>>> even
> > > > > > >>>>>>>>>>>>>>>>>> if
> > > > > > >>>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>>> we
> > > > > > >>>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>>> expand partition of the topic.
> > > > > > >>>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>> Thanks,
> > > > > > >>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>> Dong
> > > > > > >>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>>>
> > > > > > >>>>
> > > > > > >>
> > > > > > >>
> > > > > > >
> > > > > >
> > > > >
> > > >
> > >
> >
>

Re: [DISCUSS] KIP-253: Support in-order message delivery with partition expansion

Posted by John Roesler <jo...@confluent.io>.
Hi Jun,

Thanks for the response. I'm very new to this project, but I will share my
perspective. I'm going to say a bunch of stuff that I know you know
already, but just so we're on the same page...

This may also be a good time to get feedback from the other KStreams folks.

Using KStreams as a reference implementation for how stream processing
frameworks may interact with Kafka, I think it's important to eschew
knowledge about how KStreams currently handles internal communication,
making state durable, etc. Both because these details may change, and
because they won't be shared with other stream processors.

=================================
Background

We are looking at a picture like this:

     input input input
         \   |   /
      +-------------+
+-----+ Consumer(s) +-------+
|     +-------------+       |
|                           |
|    KStreams Application   |
|                           |
|     +-------------+       |
+-----+ Producer(s) +-------+
      +-------------+
           /    \
        output output

The inputs and outputs are Kafka topics (and therefore have 1 or more
partitions). We'd have at least 1 input and 0 or more outputs. The
Consumers and Producers are both the official KafkaConsumer and
KafkaProducer.

In general, we'll assume that the input topics are provided by actors over
which we have no control, although we may as well assume they are friendly
and amenable to requests, and also that their promises are trustworthy.
This is important because we must depend on them to uphold some promises:
* That they tell us the schema of the data they publish, and abide by that
schema. Without this, the inputs are essentially garbage.
* That they tell us some defining characteristics of the topics (more on
this in a sec.) and again strictly abide by that promise.

What are the topic characteristics we care about?
1. The name (or name pattern)
2. How the messages are keyed (if at all)
3. Whether the message timestamps are meaningful, and if so, what their
meaning is
4. Assuming the records have identity, whether the partitions partition the
records' identity space
5. Whether the topic completely contains the data set
6. Whether the messages in the topic are ordered

#1 is obvious: without this information, we cannot access the data at all.

For #2, #3, #4, and #6, we may or may not need this information, depending
on the logic of the application. For example, a trivial application that
simply counts all events it sees doesn't care about #2, #3, #4, or #6. But
an application that groups by some attribute can take advantage of #2 and
#4 if the topic data is already keyed and partitioned over that attribute.
Likewise, if the application includes some temporal semantics on a temporal
dimension that is already captured in #3, it may take advantage of that
fact.

Note that #2, #3, #4, and #6 are all optional. If they are not promised, we
can do extra work inside the application to accomplish what we need.
However, if they are promised (and if we depend on that promise), it is
essential that the topic providers uphold those promises, as we may not be
in a position to verify them.

Note also that if they make a promise, but it doesn't happen to line up
with our needs (data is keyed by attr1, but we need it by attr2, or
timestamp is produce-time, but we need it by event-time, etc.), then we
will have to go ahead and do that extra work internally anyway. This also
captures the situation in which two inputs are produced by different
providers, one of which meets our needs, and the other does not. The fact
that we can cope with this situation is the basis for my statement that we
do not require coordination among producers.

(Key Point A): In terms of optimization, #4 and #6 are the most valuable.
If these characteristics happen to line up with our needs, then KStreams
can be incredibly efficient in both time and computational resources.

 #5 is similar to knowing the schema in that it tells us whether the
computation we want to do is possible or not. For example, suppose we have
a topic of "users", and we want to construct a table for querying. If the
user topic doesn't completely contain the dataset, we cannot construct the
table. Note that it doesn't matter whether the topic is compacted or not.
If the topic is complete, I can consume it starting at "earliest" and build
my table. If it is not complete, I can do other computations on it. In both
cases, it may or may not be compacted; it just doesn't matter.

On the output side, the roles are reversed. We provide (or not) exactly the
same set of guarantees to consumers of our outputs, and we likewise must
abide by the promises we make.


=================================
Partition Expansion

With this formation in place, let's talk about partition expansion.

Why do we have partitions in the first place? (let me know if I miss
something here)
* For logical data streams that are themselves partitionable, it allows
producers to operate concurrently without coordination. For example,
streaming data from a sensor in a particle accelerator, the sensor can be
subdivided into a grid and each grid square can produce independently to a
different topic. This may be valuable because the total rate of data
exceeds the throughput to a single broker node or just because it allows
for failure of a single producer to cause the loss of only part of the data.
* The brokers can offer linearly scaling throughput on the number of
partitions by hosting each partition on a separate broker node
* The brokers can host topics that are too large to fit on a single
broker's storage by hosting some partitions on separate broker nodes
* In cases where the use case permits handling partitions independently,
consumers can have algorithmic simplicity by processing the data for
separate partitions in separate threads, avoiding costly and error-prone
concurrent coordination code
* In cases where the use case permits handling partitions independently,
consumers can exceed the total throughput of a single broker-consumer pair
* Just to throw this in as well, in cases where some network links are less
costly than others (or lower latency or more reliable), such as when
brokers, producers, and consumers are running in racks: producer and
consumers can both benefit (independently) by locating work on each
partition in the same rack as the broker hosting that partition.

In other words, we have three actors in this system: producers, brokers,
and consumers, and they all benefit from partitioning for different (but
sometimes related) reasons.

This leads naturally to the conclusion that any of these actors may find
themselves in a sub-optimal or even dangerous situation in which partition
expansion would be the solution. For example, the producer may find that
the existing throughput to the brokers is insufficient to match the data
rate, forcing them to drop data. Or a broker hosting a single partition may
be running out of disk space. Or a consumer node handling a single
partition cannot match the rate of production for that partition, causing
it to fall behind.

I think it's reasonable to assume that all the actors in the system can't
just arbitrarily expand a topic's partition. I think it's reasonable to
align this responsibility with the provider of the data, namely the
producer (the logical producer, not the KafkaProducer class). Therefore,
the producer who finds themselves in trouble can unilaterally expand
partitions to solve their problem.

For the broker or a consumer in trouble, they have only one resort: to
request the producer to expand partitions. This is where it's helpful to
assume the producer is friendly.


Now, let's look at how a KStreams application fits into this scenario.

(Key Point B1): As a consumer, we may find that the producer expands the
partitions of a topic, either for their own benefit or for the brokers. In
this situation, the expand operation MUST NOT violate any promises that
have previously been made to us. This is the essence of KIP-253, to ensure
the maintenance of promises #6 and #4. It would be great if the mechanics
of the expansion required no major disruption to processing or human
intervention.

Specifically, let's say that input partition X splits into X1 and X2. #6
requires that the same old ordering guarantees of Kafka continue to hold.
Obviously, this is what KIP-253's title is about. #4 requires that we
either ensure that X1 and X2 are assigned to the same thread that was
previously assigned X OR that we immediately pause processing and split any
state such that it appears X1 and X2 were *always* separate partitions.

In other words, Option 1 is we treat X1 and X2 as still logically one
partition, equal to X. This is ideal, since in this scenario, partitions
are expanding for external reasons. We don't need to expand our processing
to match. Option 2 requires a major disruption, since we'd have to pause
processing while we split our state. Clearly, KStreams or any other
stateful consumer would advocate for Option 1.


(Corollary to Key Point A): Still on the consumer side, we may find that we
ourselves can benefit from partition expansion of an input. Since we can
cope with the absence of promise #4, partition expansion is not a hard
requirement for us, but assuming we were already benefiting from the major
performance optimizations afforded by #4, it would be nice to be able to
request the producer satisfy our request for partition expansion **and to
be able to benefit from it**.

What does it mean to be able to benefit from partition expansion? Assuming
input topic partition X splits into X1 and X2, in this scenario, we *would*
wish to be able to split our state such that it appears X1 and X2 were
*always* separate partitions. Of course, the conclusion of Key Point B1
still applies: we should be able to continue operating on (X1+X2 = X) as
one partition while asynchronously building the state of X1 and X2
separately.

When it comes to the mechanics of building the state of X1 and X2
separately, we have really just two high-level options. Either this problem
is solved by Kafka itself, giving me a view in which X1 and X2 were always
separate partitions, or I have to do it myself. The latter means that I
have to take on substantially more complexity than I do today:
Bummer 1: My state has to be splittable to begin with, implying at the
least that I need to be able to scan every record in my state, a
requirement that otherwise does not exist.
Bummer 2: After splitting the state  of X1 and X2, I need to be able to
send at least one of those tasks, state included, to another application
node (in order to realize the benefit of the split). This is also a
requirement that does not currently exist.
Bummer 3: In order to actually perform the split, I must know and be able
to execute the exact same partition function the producer of my topic uses.
This introduces a brand-new a priori commitment from my input producers:
(would-be #7: convey the partition function and abide by it). This is a big
restriction over #4, which only requires them to guarantee *that there is a
partition function*. Now they actually have to share the function with me.
And I have to be able to implement and execute it myself. And if the
producer wishes to refine the partition function for an existing topic, we
have another round of coordination, as they have to be sure that I, and all
other consumers, begin using the new function *before* they do. This is
similar to the schema problem, with a similar set of solutions. We would
likely need a partition function registry and another magic byte on every
record to be sure we do this right. Not to mention some way to express
arbitrary partitioning logic over arbitrary data in a way that is portable
across programming languages.

Alternatively, if Kafka gives me a view in which X1 and X2 were always
separate, then I can create tasks for X1 and X2 and allow them to bootstrap
while I continue to process X. Once they are ready, I can coordinate a
transition to stop X's task and switch to X1 and X2. None of those bummers
are present, so this is a significantly better option for me.

(Key Point B2): As a (friendly) producer, we may once again want on our own
to expand partitions, or we may want to satisfy a request from the broker
or our consumers to do so. Again, we MUST NOT violate any promises we have
previously given, and it would be great if the expansion required no major
disruption to processing or human intervention. Additionally, since we are
actually driving the expansion, it would also be great if we could avoid
Bummer 3's coordination problems from the producer's perspective.


======================================
Briefly: KStreams internals

I'm pretty sure you were asking me to comment on the implementation details
of KStreams, so I'll say a few words about it. The most important thing is
that KStreams is still very early in its development. Maybe "early-middle
maturity" is a good way to put it. We are actively discussing more-or-less
major implementation changes to improve performance, footprint,
scalability, and ergonomics. So it may actually be misleading to discuss
deeply how KStreams internally uses Kafka topics.

Nevertheless, it is currently true that KStreams uses Kafka topics for
communication between some internal computation nodes. We partition these
topics as the base unit of concurrency granularity, so it would potentially
be beneficial to be able to expand partitions for some of these internal
topics at some point. However, we can alternatively just overpartition
these internal topics, creating in the low 100s of partitions instead of
the low 10s, for example. (Side note: if Kafka were someday to support
higher numbers of partitions, we could expand this scheme to overpartition
in the 1000s of partitions.) With the option to overpartition, we don't
have a strong need for partition expansion internally.

It is also currently true that KStreams uses Kafka to store a durable
changelog for some of our internal state stores. But we *only* read from
this topic *if* we need to restore a state store after node loss (or to
maintain a hot mirror of the state store), so I think it's unlikely that we
would ever make use of partition expansion on the changelog topics.

But once again, I'd like to emphasize that we may choose an alternative
implementation for either interprocess communication or state durability.


======================================
Concluding thoughts

I know this is a very long email, and I really appreciate you sticking with
me this long. I hope it was useful for syncing our mental picture of this
system. Also, you're far more knowledgeable than I am about this system and
this domain, so please correct me if I've said anything wrong.

To me the key takeaways are that:
- KIP-253 satisfies all we need for correctness, since it contains
solutions to guarantee producers can abide by their promises w.r.t. #4 and
#6.
- From Key Point A: #4 is actually optional for KIP-253, but without it, we
lose a potentially valuable optimization in KStreams (and all other
consumer applications)
- From Corollary to Point A: Without low-level support for partition
expansion with backfill, we cannot employ requesting partition expansion as
a consumer to improve application performance. In that case, to ensure
performance scalability, we would have to discard for all KStreams
applications the performance optimization afforded by #4.
- From Key Point B1: After a partition split, we really need to be able to
seamlessly continue operating as if it had not split.
- From Key Point B2: Since KIP-253 allows us to maintain all our promises,
we have the option of expanding partitions in the topics we produce.
Without a backfill operation, though, our consumers may not be able to
realize the benefits of that split, if they were hoping to.

In general, faced with the possibility of having to coordinate the
partition function with our inputs' producers or with our outputs'
consumers, I would personally lean toward overprovisioning and completely
avoiding resize for our use case. This doesn't mean that it's not useful in
the ecosystem at large without backfill, just that it loses its luster for
me. It also means that we can no longer take advantage of some of our
current optimizations, and in fact that we must introduce an extra hop of
repartitioning on every single input.

I think this is actually a pretty good picture of the opportunities and
challenges that other consumers and producers in the Kafka ecosystem will
face.

I hope this helps!

Thanks,
-John

On Wed, Mar 28, 2018 at 11:51 AM, Jun Rao <ju...@confluent.io> wrote:

> Hi, John,
>
> I actually think it's important to think through how KStreams handles
> partition expansion in this KIP. If we do decide that we truly need
> backfilling, it's much better to think through how to add it now, instead
> of retrofitting it later. It would be useful to outline how both existing
> KStreams jobs and new KStreams jobs work to see if backfilling is really
> needed.
>
> If we can figure out how KStreams works, at least we have one reference
> implementation for other stream processing frameworks that face the same
> issue.
>
> Thanks,
>
> Jun
>
>
> On Tue, Mar 27, 2018 at 4:56 PM, John Roesler <jo...@confluent.io> wrote:
>
> > Hi Jun,
> >
> > That's a good point.
> >
> > Yeah, I don't think it would work too well for existing consumers in the
> > middle of gen 0 to try and switch to a newly backfilled prefix of gen 1.
> > They probably just need to finish up until they get to the end of gen 0
> and
> > transition just as if there were no backfill available yet.
> >
> > This isn't terrible, since consumer applications that care about scaling
> up
> > to match a freshly split partition would wait until after the backfill is
> > available to scale up. The consumer that starts out in gen=0, part=0 is
> > going to be stuck with part=0 and part=3 in gen=1 in my example
> regardless
> > of whether they finish scanning gen=0 before or after the backfill is
> > available.
> >
> > The broker knowing when it's ok to delete gen 0, including its offset
> > mappings, is a big issue, though. I don't have any immediate ideas for
> > solving it, but it doesn't feel impossible. Hopefully, you agree this is
> > outside of KIP-253's scope, so maybe we don't need to worry about it
> right
> > now.
> >
> > I do agree that reshuffling in KStreams effectively solves the
> scalability
> > problem as well, as it decouples the partition count (and the partition
> > scheme) upstream from the parallelism of the streams application. Likely,
> > we will do this in any case. I'm predominantly advocating for follow-on
> > work to enable backfill for the *other* Kafka users that are not
> KStreams.
> >
> > Thanks for your consideration,
> > -John
> >
> > On Tue, Mar 27, 2018 at 6:19 PM, Jun Rao <ju...@confluent.io> wrote:
> >
> > > Hi, John,
> > >
> > > Thanks for the reply. I agree that the backfill approach works cleaner
> > for
> > > newly started consumers. I am just not sure if it's a good primitive to
> > > support for existing consumers. One of the challenges that I see is the
> > > remapping of the offsets. In your approach, we need to copy the
> existing
> > > records from the partitions in generation 0 to generation 1. Those
> > records
> > > will get different offsets in the new generation. The broker will have
> to
> > > store those offset mappings somewhere. When the backfill completes, you
> > can
> > > delete generation 0's data. However, the broker can't throw away the
> > offset
> > > mappings immediately since it doesn't know if there is any existing
> > > consumer still consuming generation 0's records. In a compacted topic,
> > the
> > > broker probably can only safely remove the offset mappings when all
> > records
> > > in generation 0 are removed by the cleaner. This may never happen
> though.
> > >
> > > If we reshuffle the input inside a KStreams job, it obviates the need
> for
> > > offset remapping on the broker.
> > >
> > > Jun
> > >
> > > On Tue, Mar 27, 2018 at 11:34 AM, John Roesler <jo...@confluent.io>
> > wrote:
> > >
> > > > Hey Dong and Jun,
> > > >
> > > > Thanks for the thoughtful responses. If you don't mind, I'll mix my
> > > replies
> > > > together to try for a coherent response. I'm not too familiar with
> > > > mailing-list etiquette, though.
> > > >
> > > > I'm going to keep numbering my points because it makes it easy for
> you
> > > all
> > > > to respond.
> > > >
> > > > Point 1:
> > > > As I read it, KIP-253 is *just* about properly fencing the producers
> > and
> > > > consumers so that you preserve the correct ordering of records during
> > > > partition expansion. This is clearly necessary regardless of anything
> > > else
> > > > we discuss. I think this whole discussion about backfill, consumers,
> > > > streams, etc., is beyond the scope of KIP-253. But it would be
> > cumbersome
> > > > to start a new thread at this point.
> > > >
> > > > I had missed KIP-253's Proposed Change #9 among all the details... I
> > > think
> > > > this is a nice addition to the proposal. One thought is that it's
> > > actually
> > > > irrelevant whether the hash function is linear. This is simply an
> > > algorithm
> > > > for moving a key from one partition to another, so the type of hash
> > > > function need not be a precondition. In fact, it also doesn't matter
> > > > whether the topic is compacted or not, the algorithm works
> regardless.
> > > >
> > > > I think this is a good algorithm to keep in mind, as it might solve a
> > > > variety of problems, but it does have a downside: that the producer
> > won't
> > > > know whether or not K1 was actually in P1, it just knows that K1 was
> in
> > > > P1's keyspace before the new epoch. Therefore, it will have to
> > > > pessimistically send (K1,null) to P1 just in case. But the next time
> K1
> > > > comes along, the producer *also* won't remember that it already
> > retracted
> > > > K1 from P1, so it will have to send (K1,null) *again*. By extension,
> > > every
> > > > time the producer sends to P2, it will also have to send a tombstone
> to
> > > P1,
> > > > which is a pretty big burden. To make the situation worse, if there
> is
> > a
> > > > second split, say P2 becomes P2 and P3, then any key Kx belonging to
> P3
> > > > will also have to be retracted from P2 *and* P1, since the producer
> > can't
> > > > know whether Kx had been last written to P2 or P1. Over a long period
> > of
> > > > time, this clearly becomes a issue, as the producer must send an
> > > arbitrary
> > > > number of retractions along with every update.
> > > >
> > > > In contrast, the proposed backfill operation has an end, and after it
> > > ends,
> > > > everyone can afford to forget that there ever was a different
> partition
> > > > layout.
> > > >
> > > > Really, though, figuring out how to split compacted topics is beyond
> > the
> > > > scope of KIP-253, so I'm not sure #9 really even needs to be in this
> > > KIP...
> > > > We do need in-order delivery during partition expansion. It would be
> > fine
> > > > by me to say that you *cannot* expand partitions of a log-compacted
> > topic
> > > > and call it a day. I think it would be better to tackle that in
> another
> > > > KIP.
> > > >
> > > >
> > > > Point 2:
> > > > Regarding whether the consumer re-shuffles its inputs, this is always
> > on
> > > > the table; any consumer who wants to re-shuffle its input is free to
> do
> > > so.
> > > > But this is currently not required. It's just that the current
> > high-level
> > > > story with Kafka encourages the use of partitions as a unit of
> > > concurrency.
> > > > As long as consumers are single-threaded, they can happily consume a
> > > single
> > > > partition without concurrency control of any kind. This is a key
> aspect
> > > to
> > > > this system that lets folks design high-throughput systems on top of
> it
> > > > surprisingly easily. If all consumers were instead
> encouraged/required
> > to
> > > > implement a repartition of their own, then the consumer becomes
> > > > significantly more complex, requiring either the consumer to first
> > > produce
> > > > to its own intermediate repartition topic or to ensure that consumer
> > > > threads have a reliable, high-bandwith channel of communication with
> > > every
> > > > other consumer thread.
> > > >
> > > > Either of those tradeoffs may be reasonable for a particular user of
> > > Kafka,
> > > > but I don't know if we're in a position to say that they are
> reasonable
> > > for
> > > > *every* user of Kafka.
> > > >
> > > >
> > > > Point 3:
> > > > Regarding Jun's point about this use case, "(3) stateful and
> > maintaining
> > > > the
> > > > states in a local store", I agree that they may use a framework
> *like*
> > > > Kafka Streams, but that is not the same as using Kafka Streams. This
> is
> > > why
> > > > I think it's better to solve it in Core: because it is then solved
> for
> > > > KStreams and also for everything else that facilitates local state
> > > > maintenance. To me, Streams is a member of the category of "stream
> > > > processing frameworks", which is itself a subcategory of "things
> > > requiring
> > > > local state maintenence". I'm not sure if it makes sense to assert
> that
> > > > Streams is a sufficient and practical replacement for everything in
> > > "things
> > > > requiring local state maintenence".
> > > >
> > > > But, yes, I do agree that per-key ordering is an absolute
> requirement,
> > > > therefore I think that KIP-253 itself is a necessary step. Regarding
> > the
> > > > coupling of the state store partitioning to the topic partitioning,
> > yes,
> > > > this is an issue we are discussing solutions to right now. We may go
> > > ahead
> > > > and introduce an overpartition layer on our inputs to solve it, but
> > then
> > > > again, if we get the ability to split partitions with backfill, we
> may
> > > not
> > > > need to!
> > > >
> > > >
> > > > Point 4:
> > > > On this:
> > > >
> > > > > Regarding thought 2: If we don't care about the stream use-case,
> then
> > > the
> > > > > current KIP probably has already addressed problem without
> requiring
> > > > > consumer to know the partition function. If we care about the
> stream
> > > > > use-case, we already need coordination across producers of
> different
> > > > > topics, i.e. the same partition function needs to be used by
> > producers
> > > of
> > > > > topics A and B in order to join topics A and B. Thus, it might be
> > > > > reasonable to extend coordination a bit and say we need
> coordination
> > > > across
> > > > > clients (i.e. producer and consumer), such that consumer knows the
> > > > > partition function used by producer. If we do so, then we can let
> > > > consumer
> > > > > re-copy data for the change log topic using the same partition
> > function
> > > > as
> > > > > producer. This approach has lower overhead as compared to having
> > > producer
> > > > > re-copy data of the input topic.
> > > > > Also, producer currently does not need to know the data already
> > > produced
> > > > to
> > > > > the topic. If we let producer split/merge partition, it would
> require
> > > > > producer to consume the existing data, which intuitively is the
> task
> > of
> > > > > consumer.
> > > >
> > > >
> > > > I think we do care about use cases *like* Streams, I just don't think
> > we
> > > > should rely on Streams to implement a feature of Core like partition
> > > > expansion.
> > > >
> > > > Note, though, that we (Streams) do not require coordination across
> > > > producers. If two topics are certified to be co-partitioned, then
> > Streams
> > > > apps can make use of that knowledge to optimize their topology
> > (skipping
> > > a
> > > > repartition). But if they don't know whether they are co-partitioned,
> > > then
> > > > they'd better go ahead and repartition within the topology. This is
> the
> > > > current state.
> > > >
> > > > A huge selling point of Kafka is enabling different parts of loosely
> > > > coupled organizations to produce and consume data independently. Some
> > > > coordination between producers and consumers is necessary, like
> > > > coordinating on the names of topics and their schemas. But Kafka's
> > value
> > > > proposition w.r.t. ESBs, etc. is inversely proportional to the amount
> > of
> > > > coordination required. I think it behooves us to be extremely
> skeptical
> > > > about introducing any coordination beyond correctness protocols.
> > > >
> > > > Asking producers and consumers, or even two different producers, to
> > share
> > > > code like the partition function is a pretty huge ask. What if they
> are
> > > > using different languages?
> > > >
> > > > Comparing organizational overhead vs computational overhead, there
> are
> > > > maybe two orders of magnitude difference between them. In other
> words,
> > I
> > > > would happily take on the (linear) overhead of having the producer
> > > re-copy
> > > > the data once during a re-partition in order to save the
> organizational
> > > > overhead of tying all the producers and consumers together across
> > > multiple
> > > > boundaries.
> > > >
> > > > On that last paragraph: note that the producer *did* know the data it
> > > > already produced. It handled it the first time around. Asking it to
> > > > re-produce it into a new partition layout is squarely within its
> scope
> > of
> > > > capabilities. Contrast this with the alternative, asking the consumer
> > to
> > > > re-partition the data. I think this is even less intuitive, when the
> > > > partition function belongs to the producer.
> > > >
> > > >
> > > > Point 5:
> > > > Dong asked this:
> > > >
> > > > > For stream use-case that needs to increase consumer number, the
> > > > > existing consumer can backfill the existing data in the change log
> > > topic
> > > > to
> > > > > the same change log topic with the new partition number, before the
> > new
> > > > set
> > > > > of consumers bootstrap state from the new partitions of the change
> > log
> > > > > topic, right?
> > > >
> > > >
> > > > In this sense, the "consumer" is actually the producer of the
> changelog
> > > > topic, so if we support partition expansion + backfill as a
> > > producer/broker
> > > > operation, then it would be very straightforward for Streams to
> split a
> > > > state store. As you say, they would simply instruct the broker to
> split
> > > the
> > > > changelog topic's partitions, then backfill. Once the backfill is
> > ready,
> > > > they can create a new crop of StandbyTasks to bootstrap the more
> > granular
> > > > state stores and finally switch over to them when they are ready.
> > > >
> > > > But this actually seems to be an argument in favor of split+backfill,
> > so
> > > > maybe I missed the point.
> > > >
> > > > You also asked me to explain why copying the "input" topic is better
> > than
> > > > copying the "changelog" topic. I think they are totally independent,
> > > > actually. For one thing, you can't depend on the existence of a
> > > "changelog"
> > > > topic in general, only within Streams, but Kafka's user base clearly
> > > > exceeds Streams's user base. Plus, you actually also can't depend on
> > the
> > > > existence of a changelog topic within Streams, since that is an
> > optional
> > > > feature of *some* state store implementations. Even in the situation
> > > where
> > > > you do have a changelog topic in Streams, there may be use cases
> where
> > it
> > > > makes sense to expand the partitions of just the input, or just the
> > > > changelog.
> > > >
> > > > The ask for a Core feature of split+backfill is really about
> supporting
> > > the
> > > > use case of splitting partitions in log-compacted topics, regardless
> of
> > > > whether that topic is an "input" or a "changelog" or anything else
> for
> > > that
> > > > matter.
> > > >
> > > >
> > > > Point 6:
> > > > On the concern about the performance overhead of copying data between
> > the
> > > > brokers, I think it's actually a bit overestimated. Splitting a
> topic's
> > > > partition is probably rare, certainly rarer in general than
> > bootstrapping
> > > > new consumers on that topic. If "bootstrapping new consumers" means
> > that
> > > > they have to re-shuffle the data before they consume it, then you
> wind
> > up
> > > > copying the same record multiple times:
> > > >
> > > > (broker: input topic) -> (initial consumer) -> (broker: repartition
> > > topic)
> > > > -> (real consumer)
> > > >
> > > > That's 3x, and it's also 3x for every new record after the split as
> > well,
> > > > since you don't get to stop repartitioning/reshuffling once you
> start.
> > > >
> > > > Whereas if you do a backfill in something like the procedure I
> > outlined,
> > > > you only copy the prefix of the partition before the split, and you
> > send
> > > it
> > > > once to the producer and then once to the new generation partition.
> > Plus,
> > > > assuming we're splitting the partition for the benefit of consumers,
> > > > there's no reason we can't co-locate the post-split partitions on the
> > > same
> > > > host as the pre-split partition, making the second copy a local
> > > filesystem
> > > > operation.
> > > >
> > > > Even if you follow these two copies up with bootstrapping a new
> > consumer,
> > > > it's still rare for this to occur, so you get to amortize these
> copies
> > > over
> > > > the lifetime of the topic, whereas a reshuffle just keeps making
> copies
> > > for
> > > > every new event.
> > > >
> > > > And finally, I really do think that regardless of any performance
> > > concerns
> > > > about this operation, if it preserves loose organizational coupling,
> it
> > > is
> > > > certainly worth it.
> > > >
> > > >
> > > > In conclusion:
> > > > It might actually be a good idea for us to clarify the scope of
> > KIP-253.
> > > If
> > > > we're all agreed that it's a good algorithm for allowing in-order
> > message
> > > > delivery during partition expansion, then we can continue this
> > discussion
> > > > as a new KIP, something like "backfill with partition expansion".
> This
> > > > would let Dong proceed with KIP-253. On the other hand, if it seems
> > like
> > > > this conversation may alter the design of KIP-253, then maybe we
> > *should*
> > > > just finish working it out.
> > > >
> > > > For my part, my only concern about KIP-253 is the one I raised
> earlier.
> > > >
> > > > Thanks again, all, for considering these points,
> > > > -John
> > > >
> > > >
> > > > On Tue, Mar 27, 2018 at 2:10 AM, Dong Lin <li...@gmail.com>
> wrote:
> > > >
> > > > > On Tue, Mar 27, 2018 at 12:04 AM, Dong Lin <li...@gmail.com>
> > > wrote:
> > > > >
> > > > > > Hey Jan,
> > > > > >
> > > > > > Thanks for the enthusiasm in improving Kafka's design. Now that I
> > > have
> > > > > > read through your discussion with Jun, here are my thoughts:
> > > > > >
> > > > > > - The latest proposal should with log compacted topics by
> properly
> > > > > > deleting old messages after a new message with the same key is
> > > > produced.
> > > > > So
> > > > > > it is probably not a concern anymore. Could you comment if there
> is
> > > > still
> > > > > > issue?
> > > > > >
> > > > > > - I wrote the SEP-5 and I am pretty familiar with the motivation
> > and
> > > > the
> > > > > > design of SEP-5. SEP-5 is probably orthornal to the motivation of
> > > this
> > > > > KIP.
> > > > > > The goal of SEP-5 is to allow user to increase task number of an
> > > > existing
> > > > > > Samza job. But if we increase the partition number of input
> topics,
> > > > > > messages may still be consumed out-of-order by tasks in Samza
> which
> > > > cause
> > > > > > incorrect result. Similarly, the approach you proposed does not
> > seem
> > > to
> > > > > > ensure that the messages can be delivered in order, even if we
> can
> > > make
> > > > > > sure that each consumer instance is assigned the set of new
> > > partitions
> > > > > > covering the same set of keys.
> > > > > >
> > > > >
> > > > > Let me correct this comment. The approach of copying data to a new
> > > topic
> > > > > can ensure in-order message delivery suppose we properly migrate
> > > offsets
> > > > > from old topic to new topic.
> > > > >
> > > > >
> > > > > > - I am trying to understand why it is better to copy the data
> > instead
> > > > of
> > > > > > copying the change log topic for streaming use-case. For core
> Kafka
> > > > > > use-case, and for the stream use-case that does not need to
> > increase
> > > > > > consumers, the current KIP already supports in-order delivery
> > without
> > > > the
> > > > > > overhead of copying the data. For stream use-case that needs to
> > > > increase
> > > > > > consumer number, the existing consumer can backfill the existing
> > data
> > > > in
> > > > > > the change log topic to the same change log topic with the new
> > > > partition
> > > > > > number, before the new set of consumers bootstrap state from the
> > new
> > > > > > partitions of the change log topic. If this solution works, then
> > > could
> > > > > you
> > > > > > summarize the advantage of copying the data of input topic as
> > > compared
> > > > to
> > > > > > copying the change log topic? For example, does it enable more
> > > > use-case,
> > > > > > simplify the implementation of Kafka library, or reduce the
> > operation
> > > > > > overhead etc?
> > > > > >
> > > > > > Thanks,
> > > > > > Dong
> > > > > >
> > > > > >
> > > > > > On Wed, Mar 21, 2018 at 6:57 AM, Jan Filipiak <
> > > > Jan.Filipiak@trivago.com>
> > > > > > wrote:
> > > > > >
> > > > > >> Hi Jun,
> > > > > >>
> > > > > >> I was really seeing progress in our conversation but your latest
> > > reply
> > > > > is
> > > > > >> just devastating.
> > > > > >> I though we were getting close being on the same page now it
> feels
> > > > like
> > > > > >> we are in different libraries.
> > > > > >>
> > > > > >> I just quickly slam my answers in here. If they are to brief I
> am
> > > > sorry
> > > > > >> give me a ping and try to go into details more.
> > > > > >> Just want to show that your pro/cons listing is broken.
> > > > > >>
> > > > > >> Best Jan
> > > > > >>
> > > > > >> and want to get rid of this horrible compromise
> > > > > >>
> > > > > >>
> > > > > >> On 19.03.2018 05:48, Jun Rao wrote:
> > > > > >>
> > > > > >>> Hi, Jan,
> > > > > >>>
> > > > > >>> Thanks for the discussion. Great points.
> > > > > >>>
> > > > > >>> Let me try to summarize the approach that you are proposing. On
> > the
> > > > > >>> broker
> > > > > >>> side, we reshuffle the existing data in a topic from current
> > > > partitions
> > > > > >>> to
> > > > > >>> the new partitions. Once the reshuffle fully catches up, switch
> > the
> > > > > >>> consumers to start consuming from the new partitions. If a
> > consumer
> > > > > needs
> > > > > >>> to rebuild its local state (due to partition changes), let the
> > > > consumer
> > > > > >>> rebuild its state by reading all existing data from the new
> > > > partitions.
> > > > > >>> Once all consumers have switches over, cut over the producer to
> > the
> > > > new
> > > > > >>> partitions.
> > > > > >>>
> > > > > >>> The pros for this approach are that :
> > > > > >>> 1. There is just one way to rebuild the local state, which is
> > > > simpler.
> > > > > >>>
> > > > > >> true thanks
> > > > > >>
> > > > > >>>
> > > > > >>> The cons for this approach are:
> > > > > >>> 1. Need to copy existing data.
> > > > > >>>
> > > > > >> Very unfair and not correct. It does not require you to copy
> over
> > > > > >> existing data. It _allows_ you to copy all existing data.
> > > > > >>
> > > > > >> 2. The cutover of the producer is a bit complicated since it
> needs
> > > to
> > > > > >>> coordinate with all consumer groups.
> > > > > >>>
> > > > > >> Also not true. I explicitly tried to make clear that there is
> only
> > > one
> > > > > >> special consumer (in the case of actually copying data)
> > coordination
> > > > is
> > > > > >> required.
> > > > > >>
> > > > > >>> 3. The rebuilding of the state in the consumer is from the
> input
> > > > topic,
> > > > > >>> which can be more expensive than rebuilding from the existing
> > > state.
> > > > > >>>
> > > > > >> true, but rebuilding state is only required if you want to
> > increase
> > > > > >> processing power, so we assume this is at hand.
> > > > > >>
> > > > > >>> 4. The broker potentially has to know the partitioning
> function.
> > If
> > > > > this
> > > > > >>> needs to be customized at the topic level, it can be a bit
> messy.
> > > > > >>>
> > > > > >> I would argue against having the operation being performed by
> the
> > > > > broker.
> > > > > >> This was not discussed yet but if you see my original email i
> > > > suggested
> > > > > >> otherwise from the beginning.
> > > > > >>
> > > > > >>>
> > > > > >>> Here is an alternative approach by applying your idea not in
> the
> > > > > broker,
> > > > > >>> but in the consumer. When new partitions are added, we don't
> move
> > > > > >>> existing
> > > > > >>> data. In KStreams, we first reshuffle the new input data to a
> new
> > > > topic
> > > > > >>> T1
> > > > > >>> with the old number of partitions and feed T1's data to the
> rest
> > of
> > > > the
> > > > > >>> pipeline. In the meantime, KStreams reshuffles all existing
> data
> > of
> > > > the
> > > > > >>> change capture topic to another topic C1 with the new number of
> > > > > >>> partitions.
> > > > > >>> We can then build the state of the new tasks from C1. Once the
> > new
> > > > > states
> > > > > >>> have been fully built, we can cut over the consumption to the
> > input
> > > > > topic
> > > > > >>> and delete T1. This approach works with compacted topic too. If
> > an
> > > > > >>> application reads from the beginning of a compacted topic, the
> > > > consumer
> > > > > >>> will reshuffle the portion of the input when the number of
> > > partitions
> > > > > >>> doesn't match the number of tasks.
> > > > > >>>
> > > > > >> We all wipe this idea from our heads instantly. Mixing Ideas
> from
> > an
> > > > > >> argument is not a resolution strategy
> > > > > >> just leads to horrible horrible software.
> > > > > >>
> > > > > >>
> > > > > >>> The pros of this approach are:
> > > > > >>> 1. No need to copy existing data.
> > > > > >>> 2. Each consumer group can cut over to the new partitions
> > > > > independently.
> > > > > >>> 3. The state is rebuilt from the change capture topic, which is
> > > > cheaper
> > > > > >>> than rebuilding from the input topic.
> > > > > >>> 4. Only the KStreams job needs to know the partitioning
> function.
> > > > > >>>
> > > > > >>> The cons of this approach are:
> > > > > >>> 1. Potentially the same input topic needs to be reshuffled more
> > > than
> > > > > once
> > > > > >>> in different consumer groups during the transition phase.
> > > > > >>>
> > > > > >>> What do you think?
> > > > > >>>
> > > > > >>> Thanks,
> > > > > >>>
> > > > > >>> Jun
> > > > > >>>
> > > > > >>>
> > > > > >>>
> > > > > >>> On Thu, Mar 15, 2018 at 1:04 AM, Jan Filipiak <
> > > > > Jan.Filipiak@trivago.com>
> > > > > >>> wrote:
> > > > > >>>
> > > > > >>> Hi Jun,
> > > > > >>>>
> > > > > >>>> thank you for following me on these thoughts. It was important
> > to
> > > me
> > > > > to
> > > > > >>>> feel that kind of understanding for my arguments.
> > > > > >>>>
> > > > > >>>> What I was hoping for (I mentioned this earlier) is that we
> can
> > > > model
> > > > > >>>> the
> > > > > >>>> case where we do not want to copy the data the exact same way
> as
> > > the
> > > > > >>>> case
> > > > > >>>> when we do copy the data. Maybe you can peek into the mails
> > before
> > > > to
> > > > > >>>> see
> > > > > >>>> more details for this.
> > > > > >>>>
> > > > > >>>> This means we have the same mechanism to transfer consumer
> > groups
> > > to
> > > > > >>>> switch topic. The offset mapping that would be generated would
> > > even
> > > > be
> > > > > >>>> simpler End Offset of the Old topic => offset 0 off all the
> > > > partitions
> > > > > >>>> of
> > > > > >>>> the new topic. Then we could model the transition of a
> non-copy
> > > > > >>>> expansion
> > > > > >>>> the exact same way as a copy-expansion.
> > > > > >>>>
> > > > > >>>> I know this only works when topic growth by a factor. But the
> > > > benefits
> > > > > >>>> of
> > > > > >>>> only growing by a factor are to strong anyways. See Clemens's
> > hint
> > > > and
> > > > > >>>> remember that state reshuffling is entirely not needed if one
> > > > doesn't
> > > > > >>>> want
> > > > > >>>> to grow processing power.
> > > > > >>>>
> > > > > >>>> I think these benefits should be clear, and that there is
> > > basically
> > > > no
> > > > > >>>> downside to what is currently at hand but just makes
> everything
> > > > easy.
> > > > > >>>>
> > > > > >>>> One thing you need to know is. that if you do not offer
> > > rebuilding a
> > > > > log
> > > > > >>>> compacted topic like i suggest that even if you have consumer
> > > state
> > > > > >>>> reshuffling. The topic is broken and can not be used to
> > bootstrap
> > > > new
> > > > > >>>> consumers. They don't know if they need to apply a key from
> and
> > > old
> > > > > >>>> partition or not. This is a horrible downside I haven't seen a
> > > > > solution
> > > > > >>>> for
> > > > > >>>> in the email conversation.
> > > > > >>>>
> > > > > >>>> I argue to:
> > > > > >>>>
> > > > > >>>> Only grow topic by a factor always.
> > > > > >>>> Have the "no copy consumer" transition as the trivial case of
> > the
> > > > > "copy
> > > > > >>>> consumer transition".
> > > > > >>>> If processors needs to be scaled, let them rebuild from the
> new
> > > > topic
> > > > > >>>> and
> > > > > >>>> leave the old running in the mean time.
> > > > > >>>> Do not implement key shuffling in streams.
> > > > > >>>>
> > > > > >>>> I hope I can convince you especially with the fact how I want
> to
> > > > > handle
> > > > > >>>> consumer transition. I think
> > > > > >>>> you didn't quite understood me there before. I think the term
> > "new
> > > > > >>>> topic"
> > > > > >>>> intimidated you a little.
> > > > > >>>> How we solve this on disc doesn't really matter, If the data
> > goes
> > > > into
> > > > > >>>> the
> > > > > >>>> same Dir or a different Dir or anything. I do think that it
> > needs
> > > to
> > > > > >>>> involve at least rolling a new segment for the existing
> > > partitions.
> > > > > >>>> But most of the transitions should work without restarting
> > > > consumers.
> > > > > >>>> (newer consumers with support for this). But with new topic i
> > just
> > > > > meant
> > > > > >>>> the topic that now has a different partition count. Plenty of
> > ways
> > > > to
> > > > > >>>> handle that (versions, aliases)
> > > > > >>>>
> > > > > >>>> Hope I can further get my idea across.
> > > > > >>>>
> > > > > >>>> Best Jan
> > > > > >>>>
> > > > > >>>>
> > > > > >>>>
> > > > > >>>>
> > > > > >>>>
> > > > > >>>>
> > > > > >>>> On 14.03.2018 02:45, Jun Rao wrote:
> > > > > >>>>
> > > > > >>>> Hi, Jan,
> > > > > >>>>>
> > > > > >>>>> Thanks for sharing your view.
> > > > > >>>>>
> > > > > >>>>> I agree with you that recopying the data potentially makes
> the
> > > > state
> > > > > >>>>> management easier since the consumer can just rebuild its
> state
> > > > from
> > > > > >>>>> scratch (i.e., no need for state reshuffling).
> > > > > >>>>>
> > > > > >>>>> On the flip slide, I saw a few disadvantages of the approach
> > that
> > > > you
> > > > > >>>>> suggested. (1) Building the state from the input topic from
> > > scratch
> > > > > is
> > > > > >>>>> in
> > > > > >>>>> general less efficient than state reshuffling. Let's say one
> > > > > computes a
> > > > > >>>>> count per key from an input topic. The former requires
> reading
> > > all
> > > > > >>>>> existing
> > > > > >>>>> records in the input topic whereas the latter only requires
> > > reading
> > > > > >>>>> data
> > > > > >>>>> proportional to the number of unique keys. (2) The switching
> of
> > > the
> > > > > >>>>> topic
> > > > > >>>>> needs modification to the application. If there are many
> > > > applications
> > > > > >>>>> on a
> > > > > >>>>> topic, coordinating such an effort may not be easy. Also,
> it's
> > > not
> > > > > >>>>> clear
> > > > > >>>>> how to enforce exactly-once semantic during the switch. (3)
> If
> > a
> > > > > topic
> > > > > >>>>> doesn't need any state management, recopying the data seems
> > > > wasteful.
> > > > > >>>>> In
> > > > > >>>>> that case, in place partition expansion seems more desirable.
> > > > > >>>>>
> > > > > >>>>> I understand your concern about adding complexity in
> KStreams.
> > > But,
> > > > > >>>>> perhaps
> > > > > >>>>> we could iterate on that a bit more to see if it can be
> > > simplified.
> > > > > >>>>>
> > > > > >>>>> Jun
> > > > > >>>>>
> > > > > >>>>>
> > > > > >>>>> On Mon, Mar 12, 2018 at 11:21 PM, Jan Filipiak <
> > > > > >>>>> Jan.Filipiak@trivago.com>
> > > > > >>>>> wrote:
> > > > > >>>>>
> > > > > >>>>> Hi Jun,
> > > > > >>>>>
> > > > > >>>>>> I will focus on point 61 as I think its _the_ fundamental
> part
> > > > that
> > > > > I
> > > > > >>>>>> cant
> > > > > >>>>>> get across at the moment.
> > > > > >>>>>>
> > > > > >>>>>> Kafka is the platform to have state materialized multiple
> > times
> > > > from
> > > > > >>>>>> one
> > > > > >>>>>> input. I emphasize this: It is the building block in
> > > architectures
> > > > > >>>>>> that
> > > > > >>>>>> allow you to
> > > > > >>>>>> have your state maintained multiple times. You put a message
> > in
> > > > > once,
> > > > > >>>>>> and
> > > > > >>>>>> you have it pop out as often as you like. I believe you
> > > understand
> > > > > >>>>>> this.
> > > > > >>>>>>
> > > > > >>>>>> Now! The path of thinking goes the following: I am using
> > apache
> > > > > kafka
> > > > > >>>>>> and
> > > > > >>>>>> I _want_ my state multiple times. What am I going todo?
> > > > > >>>>>>
> > > > > >>>>>> A) Am I going to take my state that I build up, plunge some
> > sort
> > > > of
> > > > > >>>>>> RPC
> > > > > >>>>>> layer ontop of it, use that RPC layer to throw my records
> > across
> > > > > >>>>>> instances?
> > > > > >>>>>> B) Am I just going to read the damn message twice?
> > > > > >>>>>>
> > > > > >>>>>> Approach A is fundamentally flawed and a violation of all
> that
> > > is
> > > > > good
> > > > > >>>>>> and
> > > > > >>>>>> holy in kafka deployments. I can not understand how this
> Idea
> > > can
> > > > > >>>>>> come in
> > > > > >>>>>> the first place.
> > > > > >>>>>> (I do understand: IQ in streams, they polluted the kafka
> > streams
> > > > > >>>>>> codebase
> > > > > >>>>>> really bad already. It is not funny! I think they are
> equally
> > > > flawed
> > > > > >>>>>> as
> > > > > >>>>>> A)
> > > > > >>>>>>
> > > > > >>>>>> I say, we do what Kafka is good at. We repartition the topic
> > > once.
> > > > > We
> > > > > >>>>>> switch the consumers.
> > > > > >>>>>> (Those that need more partitions are going to rebuild their
> > > state
> > > > in
> > > > > >>>>>> multiple partitions by reading the new topic, those that
> don't
> > > > just
> > > > > >>>>>> assign
> > > > > >>>>>> the new partitions properly)
> > > > > >>>>>> We switch producers. Done!
> > > > > >>>>>>
> > > > > >>>>>> The best thing! It is trivial, hipster stream processor will
> > > have
> > > > an
> > > > > >>>>>> easy
> > > > > >>>>>> time with that aswell. Its so super simple. And simple IS
> > good!
> > > > > >>>>>> It is what kafka was build todo. It is how we do it today.
> > All I
> > > > am
> > > > > >>>>>> saying
> > > > > >>>>>> is that a little broker help doing the producer swap is
> super
> > > > > useful.
> > > > > >>>>>>
> > > > > >>>>>> For everyone interested in why kafka is so powerful with
> > > approach
> > > > B,
> > > > > >>>>>> please watch https://youtu.be/bEbeZPVo98c?t=1633
> > > > > >>>>>> I already looked up a good point in time, I think after 5
> > > minutes
> > > > > the
> > > > > >>>>>> "state" topic is handled and you should be able to
> understand
> > me
> > > > > >>>>>> and inch better.
> > > > > >>>>>>
> > > > > >>>>>> Please do not do A to the project, it deserves better!
> > > > > >>>>>>
> > > > > >>>>>> Best Jan
> > > > > >>>>>>
> > > > > >>>>>>
> > > > > >>>>>>
> > > > > >>>>>> On 13.03.2018 02:40, Jun Rao wrote:
> > > > > >>>>>>
> > > > > >>>>>> Hi, Jan,
> > > > > >>>>>>
> > > > > >>>>>>> Thanks for the reply. A few more comments below.
> > > > > >>>>>>>
> > > > > >>>>>>> 50. Ok, we can think a bit harder for supporting compacted
> > > > topics.
> > > > > >>>>>>>
> > > > > >>>>>>> 51. This is a fundamental design question. In the more
> common
> > > > case,
> > > > > >>>>>>> the
> > > > > >>>>>>> reason why someone wants to increase the number of
> partitions
> > > is
> > > > > that
> > > > > >>>>>>> the
> > > > > >>>>>>> consumer application is slow and one wants to run more
> > consumer
> > > > > >>>>>>> instances
> > > > > >>>>>>> to increase the degree of parallelism. So, fixing the
> number
> > of
> > > > > >>>>>>> running
> > > > > >>>>>>> consumer instances when expanding the partitions won't help
> > > this
> > > > > >>>>>>> case.
> > > > > >>>>>>> If
> > > > > >>>>>>> we do need to increase the number of consumer instances, we
> > > need
> > > > to
> > > > > >>>>>>> somehow
> > > > > >>>>>>> reshuffle the state of the consumer across instances. What
> we
> > > > have
> > > > > >>>>>>> been
> > > > > >>>>>>> discussing in this KIP is whether we can do this more
> > > effectively
> > > > > >>>>>>> through
> > > > > >>>>>>> the KStream library (e.g. through a 2-phase partition
> > > expansion).
> > > > > >>>>>>> This
> > > > > >>>>>>> will
> > > > > >>>>>>> add some complexity, but it's probably better than everyone
> > > doing
> > > > > >>>>>>> this
> > > > > >>>>>>> in
> > > > > >>>>>>> the application space. The recopying approach that you
> > > mentioned
> > > > > >>>>>>> doesn't
> > > > > >>>>>>> seem to address the consumer state management issue when
> the
> > > > > consumer
> > > > > >>>>>>> switches from an old to a new topic.
> > > > > >>>>>>>
> > > > > >>>>>>> 52. As for your example, it depends on whether the join key
> > is
> > > > the
> > > > > >>>>>>> same
> > > > > >>>>>>> between (A,B) and (B,C). If the join key is the same, we
> can
> > > do a
> > > > > >>>>>>> 2-phase
> > > > > >>>>>>> partition expansion of A, B, and C together. If the join
> keys
> > > are
> > > > > >>>>>>> different, one would need to repartition the data on a
> > > different
> > > > > key
> > > > > >>>>>>> for
> > > > > >>>>>>> the second join, then the partition expansion can be done
> > > > > >>>>>>> independently
> > > > > >>>>>>> between (A,B) and (B,C).
> > > > > >>>>>>>
> > > > > >>>>>>> 53. If you always fix the number of consumer instances, we
> > you
> > > > > >>>>>>> described
> > > > > >>>>>>> works. However, as I mentioned in #51, I am not sure how
> your
> > > > > >>>>>>> proposal
> > > > > >>>>>>> deals with consumer states when the number of consumer
> > > instances
> > > > > >>>>>>> grows.
> > > > > >>>>>>> Also, it just seems that it's better to avoid re-copying
> the
> > > > > existing
> > > > > >>>>>>> data.
> > > > > >>>>>>>
> > > > > >>>>>>> 60. "just want to throw in my question from the longer
> email
> > in
> > > > the
> > > > > >>>>>>> other
> > > > > >>>>>>> Thread here. How will the bloom filter help a new consumer
> to
> > > > > decide
> > > > > >>>>>>> to
> > > > > >>>>>>> apply the key or not?" Not sure that I fully understood
> your
> > > > > >>>>>>> question.
> > > > > >>>>>>> The
> > > > > >>>>>>> consumer just reads whatever key is in the log. The bloom
> > > filter
> > > > > just
> > > > > >>>>>>> helps
> > > > > >>>>>>> clean up the old keys.
> > > > > >>>>>>>
> > > > > >>>>>>> 61. "Why can we afford having a topic where its apparently
> > not
> > > > > >>>>>>> possible
> > > > > >>>>>>> to
> > > > > >>>>>>> start a new application on? I think this is an overall flaw
> > of
> > > > the
> > > > > >>>>>>> discussed idea here. Not playing attention to the overall
> > > > > >>>>>>> architecture."
> > > > > >>>>>>> Could you explain a bit more when one can't start a new
> > > > > application?
> > > > > >>>>>>>
> > > > > >>>>>>> Jun
> > > > > >>>>>>>
> > > > > >>>>>>>
> > > > > >>>>>>>
> > > > > >>>>>>> On Sat, Mar 10, 2018 at 1:40 AM, Jan Filipiak <
> > > > > >>>>>>> Jan.Filipiak@trivago.com
> > > > > >>>>>>> wrote:
> > > > > >>>>>>>
> > > > > >>>>>>> Hi Jun, thanks for your mail.
> > > > > >>>>>>>
> > > > > >>>>>>> Thank you for your questions!
> > > > > >>>>>>>> I think they are really good and tackle the core of the
> > > problem
> > > > I
> > > > > >>>>>>>> see.
> > > > > >>>>>>>>
> > > > > >>>>>>>> I will answer inline, mostly but still want to set the
> tone
> > > > here.
> > > > > >>>>>>>>
> > > > > >>>>>>>> The core strength of kafka is what Martin once called the
> > > > > >>>>>>>> kappa-Architecture. How does this work?
> > > > > >>>>>>>> You have everything as a log as in kafka. When you need to
> > > > change
> > > > > >>>>>>>> something.
> > > > > >>>>>>>> You create the new version of your application and leave
> it
> > > > > running
> > > > > >>>>>>>> in
> > > > > >>>>>>>> parallel.
> > > > > >>>>>>>> Once the new version is good you switch your users to use
> > the
> > > > new
> > > > > >>>>>>>> application.
> > > > > >>>>>>>>
> > > > > >>>>>>>> The online reshuffling effectively breaks this
> architecture
> > > and
> > > > I
> > > > > >>>>>>>> think
> > > > > >>>>>>>> the switch in thinking here is more harmful
> > > > > >>>>>>>> than any details about the partitioning function to allow
> > > such a
> > > > > >>>>>>>> change.
> > > > > >>>>>>>> I
> > > > > >>>>>>>> feel with my suggestion we are the closest to
> > > > > >>>>>>>> the original and battle proven architecture and I can only
> > > warn
> > > > to
> > > > > >>>>>>>> move
> > > > > >>>>>>>> away from it.
> > > > > >>>>>>>>
> > > > > >>>>>>>> I might have forgotten something, sometimes its hard for
> me
> > to
> > > > > >>>>>>>> getting
> > > > > >>>>>>>> all
> > > > > >>>>>>>> the thoughts captured in a mail, but I hope the comments
> > > inline
> > > > > will
> > > > > >>>>>>>> further make my concern clear, and put some emphasis on
> why
> > I
> > > > > >>>>>>>> prefer my
> > > > > >>>>>>>> solution ;)
> > > > > >>>>>>>>
> > > > > >>>>>>>> One thing we should all be aware of when discussing this,
> > and
> > > I
> > > > > >>>>>>>> think
> > > > > >>>>>>>> Dong
> > > > > >>>>>>>> should have mentioned it (maybe he did).
> > > > > >>>>>>>> We are not discussing all of this out of thin air but
> there
> > is
> > > > an
> > > > > >>>>>>>> effort
> > > > > >>>>>>>> in the Samza project.
> > > > > >>>>>>>>
> > > > > >>>>>>>> https://cwiki.apache.org/confluence/display/SAMZA/SEP-
> 5%3A+
> > > > > >>>>>>>> Enable+partition+expansion+of+input+streams
> > > > > >>>>>>>> https://issues.apache.org/jira/browse/SAMZA-1293
> > > > > >>>>>>>>
> > > > > >>>>>>>> To be clear. I think SEP-5 (state of last week, dont know
> if
> > > it
> > > > > >>>>>>>> adapted
> > > > > >>>>>>>> to
> > > > > >>>>>>>> this discussion) is on a way better path than KIP-253,
> and I
> > > > can't
> > > > > >>>>>>>> really
> > > > > >>>>>>>> explain why.
> > > > > >>>>>>>>
> > > > > >>>>>>>> Best Jan,
> > > > > >>>>>>>>
> > > > > >>>>>>>> nice weekend everyone
> > > > > >>>>>>>>
> > > > > >>>>>>>>
> > > > > >>>>>>>> On 09.03.2018 03:36, Jun Rao wrote:
> > > > > >>>>>>>>
> > > > > >>>>>>>> Hi, Jan,
> > > > > >>>>>>>>
> > > > > >>>>>>>> Thanks for the feedback. Just some comments on the earlier
> > > > points
> > > > > >>>>>>>>> that
> > > > > >>>>>>>>> you
> > > > > >>>>>>>>> mentioned.
> > > > > >>>>>>>>>
> > > > > >>>>>>>>> 50. You brought up the question of whether existing data
> > > needs
> > > > to
> > > > > >>>>>>>>> be
> > > > > >>>>>>>>> copied
> > > > > >>>>>>>>> during partition expansion. My understand of your view is
> > > that
> > > > > >>>>>>>>> avoid
> > > > > >>>>>>>>> copying existing data will be more efficient, but it
> > doesn't
> > > > work
> > > > > >>>>>>>>> well
> > > > > >>>>>>>>> with
> > > > > >>>>>>>>> compacted topics since some keys in the original
> partitions
> > > > will
> > > > > >>>>>>>>> never
> > > > > >>>>>>>>> be
> > > > > >>>>>>>>> cleaned. It would be useful to understand your use case
> of
> > > > > >>>>>>>>> compacted
> > > > > >>>>>>>>> topics
> > > > > >>>>>>>>> a bit more. In the common use case, the data volume in a
> > > > > compacted
> > > > > >>>>>>>>> topic
> > > > > >>>>>>>>> may not be large. So, I am not sure if there is a strong
> > need
> > > > to
> > > > > >>>>>>>>> expand
> > > > > >>>>>>>>> partitions in a compacted topic, at least initially.
> > > > > >>>>>>>>>
> > > > > >>>>>>>>> I do agree. State is usually smaller. Update rates might
> be
> > > > also
> > > > > >>>>>>>>>
> > > > > >>>>>>>>> competitively high.
> > > > > >>>>>>>> Doing Log-compaction (even beeing very efficient and
> > > > configurable)
> > > > > >>>>>>>> is
> > > > > >>>>>>>> also
> > > > > >>>>>>>> a more expensive operation than
> > > > > >>>>>>>> just discarding old segments. Further if you want to use
> > more
> > > > > >>>>>>>> consumers
> > > > > >>>>>>>> processing the events
> > > > > >>>>>>>> you also have to grow the number of partitions. Especially
> > for
> > > > > >>>>>>>> use-cases
> > > > > >>>>>>>> we do (KIP-213) a tiny state full
> > > > > >>>>>>>> table might be very expensive to process if it joins
> > against a
> > > > > huge
> > > > > >>>>>>>> table.
> > > > > >>>>>>>>
> > > > > >>>>>>>> I can just say we have been in the spot of needing to grow
> > log
> > > > > >>>>>>>> compacted
> > > > > >>>>>>>> topics. Mainly for processing power we can bring to the
> > table.
> > > > > >>>>>>>>
> > > > > >>>>>>>> Further i am not at all concerned about the extra spaced
> > used
> > > by
> > > > > >>>>>>>> "garbage
> > > > > >>>>>>>> keys". I am more concerned about the correctness of
> innocent
> > > > > >>>>>>>> consumers.
> > > > > >>>>>>>> The
> > > > > >>>>>>>> logic becomes complicated. Say for streams one would need
> to
> > > > load
> > > > > >>>>>>>> the
> > > > > >>>>>>>> record into state but not forward it the topology ( to
> have
> > it
> > > > > >>>>>>>> available
> > > > > >>>>>>>> for shuffeling). I rather have it simple and a topic clean
> > > > > >>>>>>>> regardless
> > > > > >>>>>>>> if
> > > > > >>>>>>>> it
> > > > > >>>>>>>> still has its old partition count. Especially with
> multiple
> > > > > >>>>>>>> partitions
> > > > > >>>>>>>> growth's I think it becomes insanely hard to to this
> shuffle
> > > > > >>>>>>>> correct.
> > > > > >>>>>>>> Maybe
> > > > > >>>>>>>> Streams and Samza can do it. Especially if you do "hipster
> > > > stream
> > > > > >>>>>>>> processing" <https://www.confluent.io/blog
> > > > > >>>>>>>> /introducing-kafka-streams-
> > > > > >>>>>>>> stream-processing-made-simple/>. This makes kafka way to
> > > > > >>>>>>>> complicated.
> > > > > >>>>>>>> With my approach I think its way simpler because the topic
> > has
> > > > no
> > > > > >>>>>>>> "history"
> > > > > >>>>>>>> in terms of partitioning but is always clean.
> > > > > >>>>>>>>
> > > > > >>>>>>>>
> > > > > >>>>>>>> 51. "Growing the topic by an integer factor does not
> require
> > > any
> > > > > >>>>>>>> state
> > > > > >>>>>>>>
> > > > > >>>>>>>> redistribution at all." Could you clarify this a bit more?
> > > Let's
> > > > > say
> > > > > >>>>>>>>> you
> > > > > >>>>>>>>> have a consumer app that computes the windowed count per
> > key.
> > > > If
> > > > > >>>>>>>>> you
> > > > > >>>>>>>>> double
> > > > > >>>>>>>>> the number of partitions from 1 to 2 and grow the
> consumer
> > > > > >>>>>>>>> instances
> > > > > >>>>>>>>> from
> > > > > >>>>>>>>> 1
> > > > > >>>>>>>>> to 2, we would need to redistribute some of the counts to
> > the
> > > > new
> > > > > >>>>>>>>> consumer
> > > > > >>>>>>>>> instance. Regarding to linear hashing, it's true that it
> > > won't
> > > > > >>>>>>>>> solve
> > > > > >>>>>>>>> the
> > > > > >>>>>>>>> problem with compacted topics. The main benefit is that
> it
> > > > > >>>>>>>>> redistributes
> > > > > >>>>>>>>> the keys in one partition to no more than two partitions,
> > > which
> > > > > >>>>>>>>> could
> > > > > >>>>>>>>> help
> > > > > >>>>>>>>> redistribute the state.
> > > > > >>>>>>>>>
> > > > > >>>>>>>>> You don't need to spin up a new consumer in this case.
> > every
> > > > > >>>>>>>>> consumer
> > > > > >>>>>>>>>
> > > > > >>>>>>>>> would just read every partition with the (partition %
> > > num_task)
> > > > > >>>>>>>> task.
> > > > > >>>>>>>> it
> > > > > >>>>>>>> will still have the previous data right there and can go
> on.
> > > > > >>>>>>>>
> > > > > >>>>>>>> This sounds contradictory to what I said before, but
> please
> > > bear
> > > > > >>>>>>>> with
> > > > > >>>>>>>> me.
> > > > > >>>>>>>>
> > > > > >>>>>>>> 52. Good point on coordinating the expansion of 2 topics
> > that
> > > > need
> > > > > >>>>>>>> to
> > > > > >>>>>>>> be
> > > > > >>>>>>>>
> > > > > >>>>>>>> joined together. This is where the 2-phase partition
> > expansion
> > > > > could
> > > > > >>>>>>>>> potentially help. In the first phase, we could add new
> > > > partitions
> > > > > >>>>>>>>> to
> > > > > >>>>>>>>> the 2
> > > > > >>>>>>>>> topics one at a time but without publishing to the new
> > > > patitions.
> > > > > >>>>>>>>> Then,
> > > > > >>>>>>>>> we
> > > > > >>>>>>>>> can add new consumer instances to pick up the new
> > partitions.
> > > > In
> > > > > >>>>>>>>> this
> > > > > >>>>>>>>> transition phase, no reshuffling is needed since no data
> is
> > > > > coming
> > > > > >>>>>>>>> from
> > > > > >>>>>>>>> the
> > > > > >>>>>>>>> new partitions. Finally, we can enable the publishing to
> > the
> > > > new
> > > > > >>>>>>>>> partitions.
> > > > > >>>>>>>>>
> > > > > >>>>>>>>> I think its even worse than you think. I would like to
> > > > introduce
> > > > > >>>>>>>>> the
> > > > > >>>>>>>>>
> > > > > >>>>>>>>> Term
> > > > > >>>>>>>> transitive copartitioning. Imagine
> > > > > >>>>>>>> 2 streams application. One joins (A,B) the other (B,C)
> then
> > > > there
> > > > > >>>>>>>> is a
> > > > > >>>>>>>> transitive copartition requirement for
> > > > > >>>>>>>> (A,C) to be copartitioned aswell. This can spread
> > > significantly
> > > > > and
> > > > > >>>>>>>> require many consumers to adapt at the same time.
> > > > > >>>>>>>>
> > > > > >>>>>>>> It is also not entirely clear to me how you not need
> > > reshuffling
> > > > > in
> > > > > >>>>>>>> this
> > > > > >>>>>>>> case. If A has a record that never gets updated after the
> > > > > expansion
> > > > > >>>>>>>> and
> > > > > >>>>>>>> the
> > > > > >>>>>>>> coresponding B record moves to a new partition. How shall
> > they
> > > > > meet
> > > > > >>>>>>>> w/o
> > > > > >>>>>>>> shuffle?
> > > > > >>>>>>>>
> > > > > >>>>>>>> 53. "Migrating consumer is a step that might be made
> > completly
> > > > > >>>>>>>>
> > > > > >>>>>>>> unnecessary
> > > > > >>>>>>>>> if - for example streams - takes the gcd as partitioning
> > > scheme
> > > > > >>>>>>>>> instead
> > > > > >>>>>>>>> of
> > > > > >>>>>>>>> enforcing 1 to 1." Not sure that I fully understand
> this. I
> > > > think
> > > > > >>>>>>>>> you
> > > > > >>>>>>>>> mean
> > > > > >>>>>>>>> that a consumer application can run more instances than
> the
> > > > > number
> > > > > >>>>>>>>> of
> > > > > >>>>>>>>> partitions. In that case, the consumer can just
> > > repartitioning
> > > > > the
> > > > > >>>>>>>>> input
> > > > > >>>>>>>>> data according to the number of instances. This is
> > possible,
> > > > but
> > > > > >>>>>>>>> just
> > > > > >>>>>>>>> has
> > > > > >>>>>>>>> the overhead of reshuffling the data.
> > > > > >>>>>>>>>
> > > > > >>>>>>>>> No what I meant is ( that is also your question i think
> > > > Mathias)
> > > > > >>>>>>>>> that
> > > > > >>>>>>>>> if
> > > > > >>>>>>>>>
> > > > > >>>>>>>>> you grow a topic by a factor.
> > > > > >>>>>>>> Even if your processor is statefull you can can just
> assign
> > > all
> > > > > the
> > > > > >>>>>>>> multiples of the previous partition to
> > > > > >>>>>>>> this consumer and the state to keep processing correctly
> > will
> > > be
> > > > > >>>>>>>> present
> > > > > >>>>>>>> w/o any shuffling.
> > > > > >>>>>>>>
> > > > > >>>>>>>> Say you have an assignment
> > > > > >>>>>>>> Statefull consumer => partition
> > > > > >>>>>>>> 0 => 0
> > > > > >>>>>>>> 1 => 1
> > > > > >>>>>>>> 2 => 2
> > > > > >>>>>>>>
> > > > > >>>>>>>> and you grow you topic by 4 you get,
> > > > > >>>>>>>>
> > > > > >>>>>>>> 0 => 0,3,6,9
> > > > > >>>>>>>> 1 => 1,4,7,10
> > > > > >>>>>>>> 2 => 2,5,8,11
> > > > > >>>>>>>>
> > > > > >>>>>>>> Say your hashcode is 8. 8%3 => 2  before so consumer for
> > > > > partition 2
> > > > > >>>>>>>> has
> > > > > >>>>>>>> it.
> > > > > >>>>>>>> Now you you have 12 partitions so 8%12 => 8, so it goes
> into
> > > > > >>>>>>>> partition
> > > > > >>>>>>>> 8
> > > > > >>>>>>>> which is assigned to the same consumer
> > > > > >>>>>>>> who had 2 before and therefore knows the key.
> > > > > >>>>>>>>
> > > > > >>>>>>>> Userland reshuffeling is there as an options. And it does
> > > > exactly
> > > > > >>>>>>>> what
> > > > > >>>>>>>> I
> > > > > >>>>>>>> suggest. And I think its the perfect strategie. All I am
> > > > > suggestion
> > > > > >>>>>>>> is
> > > > > >>>>>>>> broker side support to switch the producers to the newly
> > > > > partitioned
> > > > > >>>>>>>> topic.
> > > > > >>>>>>>> Then the old (to few partition topic) can go away.
> Remember
> > > the
> > > > > >>>>>>>> list
> > > > > >>>>>>>> of
> > > > > >>>>>>>> steps in the beginning of this thread. If one has broker
> > > support
> > > > > for
> > > > > >>>>>>>> all
> > > > > >>>>>>>> where its required and streams support for those that
> aren’t
> > > > > >>>>>>>> necessarily.
> > > > > >>>>>>>> Then one has solved the problem.
> > > > > >>>>>>>> I repeat it because I think its important. I am really
> happy
> > > > that
> > > > > >>>>>>>> you
> > > > > >>>>>>>> brought that up! because its 100% what I want just with
> the
> > > > > >>>>>>>> differences
> > > > > >>>>>>>> to
> > > > > >>>>>>>> have an option to discard the to small topic later (after
> > all
> > > > > >>>>>>>> consumers
> > > > > >>>>>>>> adapted). And to have order correct there. I need broker
> > > support
> > > > > >>>>>>>> managing
> > > > > >>>>>>>> the copy process + the produces and fence them against
> each
> > > > > other. I
> > > > > >>>>>>>> also
> > > > > >>>>>>>> repeat. the copy process can run for weeks in the worst
> > case.
> > > > > >>>>>>>> Copying
> > > > > >>>>>>>> the
> > > > > >>>>>>>> data is not the longest task migrating consumers might
> very
> > > well
> > > > > be.
> > > > > >>>>>>>> Once all consumers switched and copying is really up to
> date
> > > > > (think
> > > > > >>>>>>>> ISR
> > > > > >>>>>>>> like up to date) only then we stop the producer, wait for
> > the
> > > > copy
> > > > > >>>>>>>> to
> > > > > >>>>>>>> finish and use the new topic for producing.
> > > > > >>>>>>>>
> > > > > >>>>>>>> After this the topic is perfect in shape. and no one needs
> > to
> > > > > worry
> > > > > >>>>>>>> about
> > > > > >>>>>>>> complicated stuff. (old keys hanging around might arrive
> in
> > > some
> > > > > >>>>>>>> other
> > > > > >>>>>>>> topic later.....). can only imagine how many tricky bugs
> > gonna
> > > > > >>>>>>>> arrive
> > > > > >>>>>>>> after
> > > > > >>>>>>>> someone had grown and shrunken is topic 10 times.
> > > > > >>>>>>>>
> > > > > >>>>>>>>
> > > > > >>>>>>>>
> > > > > >>>>>>>>
> > > > > >>>>>>>>
> > > > > >>>>>>>>
> > > > > >>>>>>>> 54. "The other thing I wanted to mention is that I believe
> > the
> > > > > >>>>>>>> current
> > > > > >>>>>>>>
> > > > > >>>>>>>> suggestion (without copying data over) can be implemented
> in
> > > > pure
> > > > > >>>>>>>>> userland
> > > > > >>>>>>>>> with a custom partitioner and a small feedbackloop from
> > > > > >>>>>>>>> ProduceResponse
> > > > > >>>>>>>>> =>
> > > > > >>>>>>>>> Partitionier in coorporation with a change management
> > > system."
> > > > I
> > > > > am
> > > > > >>>>>>>>> not
> > > > > >>>>>>>>> sure a customized partitioner itself solves the problem.
> We
> > > > > >>>>>>>>> probably
> > > > > >>>>>>>>> need
> > > > > >>>>>>>>> some broker side support to enforce when the new
> partitions
> > > can
> > > > > be
> > > > > >>>>>>>>> used.
> > > > > >>>>>>>>> We
> > > > > >>>>>>>>> also need some support on the consumer/kstream side to
> > > preserve
> > > > > the
> > > > > >>>>>>>>> per
> > > > > >>>>>>>>> key
> > > > > >>>>>>>>> ordering and potentially migrate the processing state.
> This
> > > is
> > > > > not
> > > > > >>>>>>>>> trivial
> > > > > >>>>>>>>> and I am not sure if it's ideal to fully push to the
> > > > application
> > > > > >>>>>>>>> space.
> > > > > >>>>>>>>>
> > > > > >>>>>>>>> Broker support is defenitly the preferred way here. I
> have
> > > > > nothing
> > > > > >>>>>>>>>
> > > > > >>>>>>>>> against
> > > > > >>>>>>>> broker support.
> > > > > >>>>>>>> I tried to say that for what I would preffer - copying the
> > > data
> > > > > >>>>>>>> over,
> > > > > >>>>>>>> at
> > > > > >>>>>>>> least for log compacted topics -
> > > > > >>>>>>>> I would require more broker support than the KIP currently
> > > > offers.
> > > > > >>>>>>>>
> > > > > >>>>>>>>
> > > > > >>>>>>>>
> > > > > >>>>>>>> Jun
> > > > > >>>>>>>>
> > > > > >>>>>>>> On Tue, Mar 6, 2018 at 10:33 PM, Jan Filipiak <
> > > > > >>>>>>>>> Jan.Filipiak@trivago.com
> > > > > >>>>>>>>> wrote:
> > > > > >>>>>>>>>
> > > > > >>>>>>>>> Hi Dong,
> > > > > >>>>>>>>>
> > > > > >>>>>>>>> are you actually reading my emails, or are you just using
> > the
> > > > > >>>>>>>>> thread I
> > > > > >>>>>>>>>
> > > > > >>>>>>>>>> started for general announcements regarding the KIP?
> > > > > >>>>>>>>>>
> > > > > >>>>>>>>>> I tried to argue really hard against linear hashing.
> > Growing
> > > > the
> > > > > >>>>>>>>>> topic
> > > > > >>>>>>>>>> by
> > > > > >>>>>>>>>> an integer factor does not require any state
> > redistribution
> > > at
> > > > > >>>>>>>>>> all. I
> > > > > >>>>>>>>>> fail
> > > > > >>>>>>>>>> to see completely where linear hashing helps on log
> > > compacted
> > > > > >>>>>>>>>> topics.
> > > > > >>>>>>>>>>
> > > > > >>>>>>>>>> If you are not willing to explain to me what I might be
> > > > > >>>>>>>>>> overlooking:
> > > > > >>>>>>>>>> that
> > > > > >>>>>>>>>> is fine.
> > > > > >>>>>>>>>> But I ask you to not reply to my emails then. Please
> > > > understand
> > > > > my
> > > > > >>>>>>>>>> frustration with this.
> > > > > >>>>>>>>>>
> > > > > >>>>>>>>>> Best Jan
> > > > > >>>>>>>>>>
> > > > > >>>>>>>>>>
> > > > > >>>>>>>>>>
> > > > > >>>>>>>>>> On 06.03.2018 19:38, Dong Lin wrote:
> > > > > >>>>>>>>>>
> > > > > >>>>>>>>>> Hi everyone,
> > > > > >>>>>>>>>>
> > > > > >>>>>>>>>> Thanks for all the comments! It appears that everyone
> > > prefers
> > > > > >>>>>>>>>> linear
> > > > > >>>>>>>>>>
> > > > > >>>>>>>>>>> hashing because it reduces the amount of state that
> needs
> > > to
> > > > be
> > > > > >>>>>>>>>>> moved
> > > > > >>>>>>>>>>> between consumers (for stream processing). The KIP has
> > been
> > > > > >>>>>>>>>>> updated
> > > > > >>>>>>>>>>> to
> > > > > >>>>>>>>>>> use
> > > > > >>>>>>>>>>> linear hashing.
> > > > > >>>>>>>>>>>
> > > > > >>>>>>>>>>> Regarding the migration endeavor: it seems that
> migrating
> > > > > >>>>>>>>>>> producer
> > > > > >>>>>>>>>>> library
> > > > > >>>>>>>>>>> to use linear hashing should be pretty straightforward
> > > > without
> > > > > >>>>>>>>>>> much operational endeavor. If we don't upgrade client
> > > library
> > > > > to
> > > > > >>>>>>>>>>> use
> > > > > >>>>>>>>>>> this
> > > > > >>>>>>>>>>> KIP, we can not support in-order delivery after
> partition
> > > is
> > > > > >>>>>>>>>>> changed
> > > > > >>>>>>>>>>> anyway. Suppose we upgrade client library to use this
> > KIP,
> > > if
> > > > > >>>>>>>>>>> partition
> > > > > >>>>>>>>>>> number is not changed, the key -> partition mapping
> will
> > be
> > > > > >>>>>>>>>>> exactly
> > > > > >>>>>>>>>>> the
> > > > > >>>>>>>>>>> same as it is now because it is still determined using
> > > > > >>>>>>>>>>> murmur_hash(key)
> > > > > >>>>>>>>>>> %
> > > > > >>>>>>>>>>> original_partition_num. In other words, this change is
> > > > backward
> > > > > >>>>>>>>>>> compatible.
> > > > > >>>>>>>>>>>
> > > > > >>>>>>>>>>> Regarding the load distribution: if we use linear
> > hashing,
> > > > the
> > > > > >>>>>>>>>>> load
> > > > > >>>>>>>>>>> may
> > > > > >>>>>>>>>>> be
> > > > > >>>>>>>>>>> unevenly distributed because those partitions which are
> > not
> > > > > split
> > > > > >>>>>>>>>>> may
> > > > > >>>>>>>>>>> receive twice as much traffic as other partitions that
> > are
> > > > > split.
> > > > > >>>>>>>>>>> This
> > > > > >>>>>>>>>>> issue can be mitigated by creating topic with
> partitions
> > > that
> > > > > are
> > > > > >>>>>>>>>>> several
> > > > > >>>>>>>>>>> times the number of consumers. And there will be no
> > > imbalance
> > > > > if
> > > > > >>>>>>>>>>> the
> > > > > >>>>>>>>>>> partition number is always doubled. So this imbalance
> > seems
> > > > > >>>>>>>>>>> acceptable.
> > > > > >>>>>>>>>>>
> > > > > >>>>>>>>>>> Regarding storing the partition strategy as per-topic
> > > config:
> > > > > It
> > > > > >>>>>>>>>>> seems
> > > > > >>>>>>>>>>> not
> > > > > >>>>>>>>>>> necessary since we can still use murmur_hash as the
> > default
> > > > > hash
> > > > > >>>>>>>>>>> function
> > > > > >>>>>>>>>>> and additionally apply the linear hashing algorithm if
> > the
> > > > > >>>>>>>>>>> partition
> > > > > >>>>>>>>>>> number
> > > > > >>>>>>>>>>> has increased. Not sure if there is any use-case for
> > > producer
> > > > > to
> > > > > >>>>>>>>>>> use a
> > > > > >>>>>>>>>>> different hash function. Jason, can you check if there
> is
> > > > some
> > > > > >>>>>>>>>>> use-case
> > > > > >>>>>>>>>>> that I missed for using the per-topic partition
> strategy?
> > > > > >>>>>>>>>>>
> > > > > >>>>>>>>>>> Regarding how to reduce latency (due to state
> store/load)
> > > in
> > > > > >>>>>>>>>>> stream
> > > > > >>>>>>>>>>> processing consumer when partition number changes: I
> need
> > > to
> > > > > read
> > > > > >>>>>>>>>>> the
> > > > > >>>>>>>>>>> Kafka
> > > > > >>>>>>>>>>> Stream code to understand how Kafka Stream currently
> > > migrate
> > > > > >>>>>>>>>>> state
> > > > > >>>>>>>>>>> between
> > > > > >>>>>>>>>>> consumers when the application is added/removed for a
> > given
> > > > > job.
> > > > > >>>>>>>>>>> I
> > > > > >>>>>>>>>>> will
> > > > > >>>>>>>>>>> reply after I finish reading the documentation and
> code.
> > > > > >>>>>>>>>>>
> > > > > >>>>>>>>>>>
> > > > > >>>>>>>>>>> Thanks,
> > > > > >>>>>>>>>>> Dong
> > > > > >>>>>>>>>>>
> > > > > >>>>>>>>>>>
> > > > > >>>>>>>>>>> On Mon, Mar 5, 2018 at 10:43 AM, Jason Gustafson <
> > > > > >>>>>>>>>>> jason@confluent.io>
> > > > > >>>>>>>>>>> wrote:
> > > > > >>>>>>>>>>>
> > > > > >>>>>>>>>>> Great discussion. I think I'm wondering whether we can
> > > > continue
> > > > > >>>>>>>>>>> to
> > > > > >>>>>>>>>>> leave
> > > > > >>>>>>>>>>>
> > > > > >>>>>>>>>>> Kafka agnostic to the partitioning strategy. The
> > challenge
> > > is
> > > > > >>>>>>>>>>>
> > > > > >>>>>>>>>>> communicating
> > > > > >>>>>>>>>>>> the partitioning logic from producers to consumers so
> > that
> > > > the
> > > > > >>>>>>>>>>>> dependencies
> > > > > >>>>>>>>>>>> between each epoch can be determined. For the sake of
> > > > > >>>>>>>>>>>> discussion,
> > > > > >>>>>>>>>>>> imagine
> > > > > >>>>>>>>>>>> you did something like the following:
> > > > > >>>>>>>>>>>>
> > > > > >>>>>>>>>>>> 1. The name (and perhaps version) of a partitioning
> > > strategy
> > > > > is
> > > > > >>>>>>>>>>>> stored
> > > > > >>>>>>>>>>>> in
> > > > > >>>>>>>>>>>> topic configuration when a topic is created.
> > > > > >>>>>>>>>>>> 2. The producer looks up the partitioning strategy
> > before
> > > > > >>>>>>>>>>>> writing
> > > > > >>>>>>>>>>>> to
> > > > > >>>>>>>>>>>> a
> > > > > >>>>>>>>>>>> topic and includes it in the produce request (for
> > > fencing).
> > > > If
> > > > > >>>>>>>>>>>> it
> > > > > >>>>>>>>>>>> doesn't
> > > > > >>>>>>>>>>>> have an implementation for the configured strategy, it
> > > > fails.
> > > > > >>>>>>>>>>>> 3. The consumer also looks up the partitioning
> strategy
> > > and
> > > > > >>>>>>>>>>>> uses it
> > > > > >>>>>>>>>>>> to
> > > > > >>>>>>>>>>>> determine dependencies when reading a new epoch. It
> > could
> > > > > either
> > > > > >>>>>>>>>>>> fail
> > > > > >>>>>>>>>>>> or
> > > > > >>>>>>>>>>>> make the most conservative dependency assumptions if
> it
> > > > > doesn't
> > > > > >>>>>>>>>>>> know
> > > > > >>>>>>>>>>>> how
> > > > > >>>>>>>>>>>> to
> > > > > >>>>>>>>>>>> implement the partitioning strategy. For the consumer,
> > the
> > > > new
> > > > > >>>>>>>>>>>> interface
> > > > > >>>>>>>>>>>> might look something like this:
> > > > > >>>>>>>>>>>>
> > > > > >>>>>>>>>>>> // Return the partition dependencies following an
> epoch
> > > bump
> > > > > >>>>>>>>>>>> Map<Integer, List<Integer>> dependencies(int
> > > > > >>>>>>>>>>>> numPartitionsBeforeEpochBump,
> > > > > >>>>>>>>>>>> int numPartitionsAfterEpochBump)
> > > > > >>>>>>>>>>>>
> > > > > >>>>>>>>>>>> The unordered case then is just a particular
> > > implementation
> > > > > >>>>>>>>>>>> which
> > > > > >>>>>>>>>>>> never
> > > > > >>>>>>>>>>>> has
> > > > > >>>>>>>>>>>> any epoch dependencies. To implement this, we would
> need
> > > > some
> > > > > >>>>>>>>>>>> way
> > > > > >>>>>>>>>>>> for
> > > > > >>>>>>>>>>>> the
> > > > > >>>>>>>>>>>> consumer to find out how many partitions there were in
> > > each
> > > > > >>>>>>>>>>>> epoch,
> > > > > >>>>>>>>>>>> but
> > > > > >>>>>>>>>>>> maybe that's not too unreasonable.
> > > > > >>>>>>>>>>>>
> > > > > >>>>>>>>>>>> Thanks,
> > > > > >>>>>>>>>>>> Jason
> > > > > >>>>>>>>>>>>
> > > > > >>>>>>>>>>>>
> > > > > >>>>>>>>>>>> On Mon, Mar 5, 2018 at 4:51 AM, Jan Filipiak <
> > > > > >>>>>>>>>>>> Jan.Filipiak@trivago.com
> > > > > >>>>>>>>>>>> wrote:
> > > > > >>>>>>>>>>>>
> > > > > >>>>>>>>>>>> Hi Dong
> > > > > >>>>>>>>>>>>
> > > > > >>>>>>>>>>>> thank you very much for your questions.
> > > > > >>>>>>>>>>>>
> > > > > >>>>>>>>>>>> regarding the time spend copying data across:
> > > > > >>>>>>>>>>>>> It is correct that copying data from a topic with one
> > > > > partition
> > > > > >>>>>>>>>>>>> mapping
> > > > > >>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>> to
> > > > > >>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>> a topic with a different partition mapping takes way
> > > longer
> > > > > >>>>>>>>>>>>> than
> > > > > >>>>>>>>>>>>>
> > > > > >>>>>>>>>>>> we
> > > > > >>>>>>>>>>>> can
> > > > > >>>>>>>>>>>>
> > > > > >>>>>>>>>>>> stop producers. Tens of minutes is a very optimistic
> > > > estimate
> > > > > >>>>>>>>>>>> here.
> > > > > >>>>>>>>>>>>
> > > > > >>>>>>>>>>>>> Many
> > > > > >>>>>>>>>>>>> people can not afford copy full steam and therefore
> > will
> > > > have
> > > > > >>>>>>>>>>>>> some
> > > > > >>>>>>>>>>>>> rate
> > > > > >>>>>>>>>>>>> limiting in place, this can bump the timespan into
> the
> > > > day's.
> > > > > >>>>>>>>>>>>> The
> > > > > >>>>>>>>>>>>> good
> > > > > >>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>> part
> > > > > >>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>> is that the vast majority of the data can be copied
> > while
> > > > the
> > > > > >>>>>>>>>>>>>
> > > > > >>>>>>>>>>>> producers
> > > > > >>>>>>>>>>>>
> > > > > >>>>>>>>>>>> are
> > > > > >>>>>>>>>>>>
> > > > > >>>>>>>>>>>>> still going. One can then, piggyback the consumers
> > ontop
> > > of
> > > > > >>>>>>>>>>>>> this
> > > > > >>>>>>>>>>>>>
> > > > > >>>>>>>>>>>> timeframe,
> > > > > >>>>>>>>>>>>
> > > > > >>>>>>>>>>>>> by the method mentioned (provide them an mapping from
> > > their
> > > > > old
> > > > > >>>>>>>>>>>>>
> > > > > >>>>>>>>>>>> offsets
> > > > > >>>>>>>>>>>>
> > > > > >>>>>>>>>>>> to
> > > > > >>>>>>>>>>>>
> > > > > >>>>>>>>>>>>> new offsets in their repartitioned topics. In that
> way
> > we
> > > > > >>>>>>>>>>>>> separate
> > > > > >>>>>>>>>>>>>
> > > > > >>>>>>>>>>>> migration of consumers from migration of producers
> > > > (decoupling
> > > > > >>>>>>>>>>>>
> > > > > >>>>>>>>>>>>> these
> > > > > >>>>>>>>>>>>> is
> > > > > >>>>>>>>>>>>> what kafka is strongest at). The time to actually
> swap
> > > over
> > > > > the
> > > > > >>>>>>>>>>>>> producers
> > > > > >>>>>>>>>>>>> should be kept minimal by ensuring that when a swap
> > > attempt
> > > > > is
> > > > > >>>>>>>>>>>>> started
> > > > > >>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>> the
> > > > > >>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>> consumer copying over should be very close to the log
> > end
> > > > and
> > > > > >>>>>>>>>>>>> is
> > > > > >>>>>>>>>>>>>
> > > > > >>>>>>>>>>>> expected
> > > > > >>>>>>>>>>>>
> > > > > >>>>>>>>>>>>> to finish within the next fetch. The operation should
> > > have
> > > > a
> > > > > >>>>>>>>>>>>> time-out
> > > > > >>>>>>>>>>>>> and
> > > > > >>>>>>>>>>>>> should be "reattemtable".
> > > > > >>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>> Importance of logcompaction:
> > > > > >>>>>>>>>>>>> If a producer produces key A, to partiton 0, its
> > forever
> > > > > gonna
> > > > > >>>>>>>>>>>>> be
> > > > > >>>>>>>>>>>>> there,
> > > > > >>>>>>>>>>>>> unless it gets deleted. The record might sit in there
> > for
> > > > > >>>>>>>>>>>>> years. A
> > > > > >>>>>>>>>>>>> new
> > > > > >>>>>>>>>>>>> producer started with the new partitions will fail to
> > > > delete
> > > > > >>>>>>>>>>>>> the
> > > > > >>>>>>>>>>>>> record
> > > > > >>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>> in
> > > > > >>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>> the correct partition. Th record will be there
> forever
> > > and
> > > > > one
> > > > > >>>>>>>>>>>>> can
> > > > > >>>>>>>>>>>>>
> > > > > >>>>>>>>>>>> not
> > > > > >>>>>>>>>>>>
> > > > > >>>>>>>>>>>> reliable bootstrap new consumers. I cannot see how
> > linear
> > > > > >>>>>>>>>>>> hashing
> > > > > >>>>>>>>>>>>
> > > > > >>>>>>>>>>>>> can
> > > > > >>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>> solve
> > > > > >>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>> this.
> > > > > >>>>>>>>>>>>>
> > > > > >>>>>>>>>>>> Regarding your skipping of userland copying:
> > > > > >>>>>>>>>>>>
> > > > > >>>>>>>>>>>>> 100%, copying the data across in userland is, as far
> > as i
> > > > can
> > > > > >>>>>>>>>>>>> see,
> > > > > >>>>>>>>>>>>> only
> > > > > >>>>>>>>>>>>> a
> > > > > >>>>>>>>>>>>> usecase for log compacted topics. Even for
> > logcompaction
> > > +
> > > > > >>>>>>>>>>>>> retentions
> > > > > >>>>>>>>>>>>> it
> > > > > >>>>>>>>>>>>> should only be opt-in. Why did I bring it up? I think
> > log
> > > > > >>>>>>>>>>>>> compaction
> > > > > >>>>>>>>>>>>> is
> > > > > >>>>>>>>>>>>> a
> > > > > >>>>>>>>>>>>> very important feature to really embrace kafka as a
> > "data
> > > > > >>>>>>>>>>>>> plattform".
> > > > > >>>>>>>>>>>>> The
> > > > > >>>>>>>>>>>>> point I also want to make is that copying data this
> way
> > > is
> > > > > >>>>>>>>>>>>> completely
> > > > > >>>>>>>>>>>>> inline with the kafka architecture. it only consists
> of
> > > > > reading
> > > > > >>>>>>>>>>>>> and
> > > > > >>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>> writing
> > > > > >>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>> to topics.
> > > > > >>>>>>>>>>>>>
> > > > > >>>>>>>>>>>> I hope it clarifies more why I think we should aim for
> > > more
> > > > > than
> > > > > >>>>>>>>>>>>
> > > > > >>>>>>>>>>>>> the
> > > > > >>>>>>>>>>>>> current KIP. I fear that once the KIP is done not
> much
> > > more
> > > > > >>>>>>>>>>>>> effort
> > > > > >>>>>>>>>>>>> will
> > > > > >>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>> be
> > > > > >>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>> taken.
> > > > > >>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>
> > > > > >>>>>>>>>>>> On 04.03.2018 02:28, Dong Lin wrote:
> > > > > >>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>> Hey Jan,
> > > > > >>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>> In the current proposal, the consumer will be blocked
> > on
> > > > > >>>>>>>>>>>>> waiting
> > > > > >>>>>>>>>>>>> for
> > > > > >>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>> other
> > > > > >>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>> consumers of the group to consume up to a given
> > offset.
> > > In
> > > > > >>>>>>>>>>>>>> most
> > > > > >>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>> cases,
> > > > > >>>>>>>>>>>>> all
> > > > > >>>>>>>>>>>>> consumers should be close to the LEO of the
> partitions
> > > when
> > > > > the
> > > > > >>>>>>>>>>>>> partition
> > > > > >>>>>>>>>>>>> expansion happens. Thus the time waiting should not
> be
> > > long
> > > > > >>>>>>>>>>>>> e.g.
> > > > > >>>>>>>>>>>>> on
> > > > > >>>>>>>>>>>>> the
> > > > > >>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>> order of seconds. On the other hand, it may take a
> long
> > > > time
> > > > > to
> > > > > >>>>>>>>>>>>> wait
> > > > > >>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>> for
> > > > > >>>>>>>>>>>>>> the entire partition to be copied -- the amount of
> > time
> > > is
> > > > > >>>>>>>>>>>>>> proportional
> > > > > >>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>> to
> > > > > >>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>> the amount of existing data in the partition, which
> > can
> > > > take
> > > > > >>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>> tens of
> > > > > >>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>> minutes. So the amount of time that we stop consumers
> > may
> > > > not
> > > > > >>>>>>>>>>>>> be
> > > > > >>>>>>>>>>>>> on
> > > > > >>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>> the
> > > > > >>>>>>>>>>>>>> same order of magnitude.
> > > > > >>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>> If we can implement this suggestion without copying
> > data
> > > > > over
> > > > > >>>>>>>>>>>>>> in
> > > > > >>>>>>>>>>>>>> purse
> > > > > >>>>>>>>>>>>>> userland, it will be much more valuable. Do you have
> > > ideas
> > > > > on
> > > > > >>>>>>>>>>>>>> how
> > > > > >>>>>>>>>>>>>> this
> > > > > >>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>> can
> > > > > >>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>> be done?
> > > > > >>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>> Not sure why the current KIP not help people who
> depend
> > > on
> > > > > log
> > > > > >>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>> compaction.
> > > > > >>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>> Could you elaborate more on this point?
> > > > > >>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>> Thanks,
> > > > > >>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>> Dong
> > > > > >>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>> On Wed, Feb 28, 2018 at 10:55 PM, Jan
> > > > > >>>>>>>>>>>>>> Filipiak<Jan.Filipiak@trivago.
> > > > > >>>>>>>>>>>>>> com
> > > > > >>>>>>>>>>>>>> wrote:
> > > > > >>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>> Hi Dong,
> > > > > >>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>> I tried to focus on what the steps are one can
> > currently
> > > > > >>>>>>>>>>>>>> perform
> > > > > >>>>>>>>>>>>>> to
> > > > > >>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>> expand
> > > > > >>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>> or shrink a keyed topic while maintaining a top
> notch
> > > > > >>>>>>>>>>>>>>> semantics.
> > > > > >>>>>>>>>>>>>>> I can understand that there might be confusion
> about
> > > > > >>>>>>>>>>>>>>> "stopping
> > > > > >>>>>>>>>>>>>>> the
> > > > > >>>>>>>>>>>>>>> consumer". It is exactly the same as proposed in
> the
> > > KIP.
> > > > > >>>>>>>>>>>>>>> there
> > > > > >>>>>>>>>>>>>>> needs
> > > > > >>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>> to
> > > > > >>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>> be
> > > > > >>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>> a time the producers agree on the new partitioning.
> > The
> > > > > extra
> > > > > >>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>> semantics I
> > > > > >>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>> want to put in there is that we have a possibility
> to
> > > > wait
> > > > > >>>>>>>>>>>>>>> until
> > > > > >>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>> all
> > > > > >>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>> the
> > > > > >>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>> existing data
> > > > > >>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>> is copied over into the new partitioning scheme.
> When
> > I
> > > > say
> > > > > >>>>>>>>>>>>> stopping
> > > > > >>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>> I
> > > > > >>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>> think more of having a memory barrier that ensures
> > the
> > > > > >>>>>>>>>>>>>>> ordering. I
> > > > > >>>>>>>>>>>>>>> am
> > > > > >>>>>>>>>>>>>>> still
> > > > > >>>>>>>>>>>>>>> aming for latencies  on the scale of leader
> > failovers.
> > > > > >>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>> Consumers have to explicitly adapt the new
> > partitioning
> > > > > >>>>>>>>>>>>>>> scheme
> > > > > >>>>>>>>>>>>>>> in
> > > > > >>>>>>>>>>>>>>> the
> > > > > >>>>>>>>>>>>>>> above scenario. The reason is that in these cases
> > where
> > > > you
> > > > > >>>>>>>>>>>>>>> are
> > > > > >>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>> dependent
> > > > > >>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>> on a particular partitioning scheme, you also have
> > > other
> > > > > >>>>>>>>>>>>>>> topics
> > > > > >>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>> that
> > > > > >>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>> have
> > > > > >>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>> co-partition enforcements or the kind -frequently.
> > > > Therefore
> > > > > >>>>>>>>>>>>>> all
> > > > > >>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>> your
> > > > > >>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>> other
> > > > > >>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>> input topics might need to grow accordingly.
> > > > > >>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>> What I was suggesting was to streamline all these
> > > > > operations
> > > > > >>>>>>>>>>>>>>> as
> > > > > >>>>>>>>>>>>>>> best
> > > > > >>>>>>>>>>>>>>> as
> > > > > >>>>>>>>>>>>>>> possible to have "real" partition grow and
> shrinkage
> > > > going
> > > > > >>>>>>>>>>>>>>> on.
> > > > > >>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>> Migrating
> > > > > >>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>> the producers to a new partitioning scheme can be
> > much
> > > > more
> > > > > >>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>> streamlined
> > > > > >>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>> with proper broker support for this. Migrating
> consumer
> > > is
> > > > a
> > > > > >>>>>>>>>>>>> step
> > > > > >>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>> that
> > > > > >>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>> might be made completly unnecessary if - for
> example
> > > > > streams
> > > > > >>>>>>>>>>>>>>> -
> > > > > >>>>>>>>>>>>>>> takes
> > > > > >>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>> the
> > > > > >>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>> gcd as partitioning scheme instead of enforcing 1
> to
> > 1.
> > > > > >>>>>>>>>>>>>>> Connect
> > > > > >>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>> consumers
> > > > > >>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>> and other consumers should be fine anyways.
> > > > > >>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>> I hope this makes more clear where I was aiming at.
> > The
> > > > rest
> > > > > >>>>>>>>>>>>> needs
> > > > > >>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>> to
> > > > > >>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>> be
> > > > > >>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>> figured out. The only danger i see is that when we
> > are
> > > > > >>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>> introducing
> > > > > >>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>> this
> > > > > >>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>> feature as supposed in the KIP, it wont help any
> people
> > > > > >>>>>>>>>>>>> depending
> > > > > >>>>>>>>>>>>> on
> > > > > >>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>> log
> > > > > >>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>> compaction.
> > > > > >>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>> The other thing I wanted to mention is that I
> believe
> > > the
> > > > > >>>>>>>>>>>>> current
> > > > > >>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>> suggestion (without copying data over) can be
> > implemented
> > > > in
> > > > > >>>>>>>>>>>>>> pure
> > > > > >>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>> userland
> > > > > >>>>>>>>>>>>>>> with a custom partitioner and a small feedbackloop
> > from
> > > > > >>>>>>>>>>>>>>> ProduceResponse
> > > > > >>>>>>>>>>>>>>> =>
> > > > > >>>>>>>>>>>>>>> Partitionier in coorporation with a change
> management
> > > > > system.
> > > > > >>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>> Best Jan
> > > > > >>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>> On 28.02.2018 07:13, Dong Lin wrote:
> > > > > >>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>> Hey Jan,
> > > > > >>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>> I am not sure if it is acceptable for producer to
> be
> > > > > stopped
> > > > > >>>>>>>>>>>>>>> for a
> > > > > >>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>> while,
> > > > > >>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>> particularly for online application which requires
> > low
> > > > > >>>>>>>>>>>>>>>> latency. I
> > > > > >>>>>>>>>>>>>>>> am
> > > > > >>>>>>>>>>>>>>>> also
> > > > > >>>>>>>>>>>>>>>> not sure how consumers can switch to a new topic.
> > Does
> > > > > user
> > > > > >>>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>> application
> > > > > >>>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>> needs to explicitly specify a different topic for
> > > > > >>>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>> producer/consumer
> > > > > >>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>> to
> > > > > >>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>> subscribe to? It will be helpful for discussion if
> you
> > > can
> > > > > >>>>>>>>>>>>> provide
> > > > > >>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>> more
> > > > > >>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>> detail on the interface change for this solution.
> > > > > >>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>> Thanks,
> > > > > >>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>> Dong
> > > > > >>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>> On Mon, Feb 26, 2018 at 12:48 AM, Jan
> > > > > >>>>>>>>>>>>>>>> Filipiak<Jan.Filipiak@trivago.
> > > > > >>>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>> com
> > > > > >>>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>> wrote:
> > > > > >>>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>> Hi,
> > > > > >>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>> just want to throw my though in. In general the
> > > > > functionality
> > > > > >>>>>>>>>>>>>> is
> > > > > >>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>> very
> > > > > >>>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>> usefull, we should though not try to find the
> > > > architecture
> > > > > >>>>>>>>>>>>>>>> to
> > > > > >>>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>> hard
> > > > > >>>>>>>>>>>>>>>>> while
> > > > > >>>>>>>>>>>>>>>>> implementing.
> > > > > >>>>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>>> The manual steps would be to
> > > > > >>>>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>>> create a new topic
> > > > > >>>>>>>>>>>>>>>>> the mirrormake from the new old topic to the new
> > > topic
> > > > > >>>>>>>>>>>>>>>>> wait for mirror making to catch up.
> > > > > >>>>>>>>>>>>>>>>> then put the consumers onto the new topic
> > > > > >>>>>>>>>>>>>>>>>            (having mirrormaker spit out a mapping
> > > from
> > > > > old
> > > > > >>>>>>>>>>>>>>>>> offsets to
> > > > > >>>>>>>>>>>>>>>>> new
> > > > > >>>>>>>>>>>>>>>>> offsets:
> > > > > >>>>>>>>>>>>>>>>>                if topic is increased by factor X
> > > there
> > > > is
> > > > > >>>>>>>>>>>>>>>>> gonna
> > > > > >>>>>>>>>>>>>>>>> be a
> > > > > >>>>>>>>>>>>>>>>> clean
> > > > > >>>>>>>>>>>>>>>>> mapping from 1 offset in the old topic to X
> offsets
> > > in
> > > > > the
> > > > > >>>>>>>>>>>>>>>>> new
> > > > > >>>>>>>>>>>>>>>>> topic,
> > > > > >>>>>>>>>>>>>>>>>                if there is no factor then there
> is
> > no
> > > > > >>>>>>>>>>>>>>>>> chance to
> > > > > >>>>>>>>>>>>>>>>> generate a
> > > > > >>>>>>>>>>>>>>>>> mapping that can be reasonable used for
> continuing)
> > > > > >>>>>>>>>>>>>>>>>            make consumers stop at appropriate
> > points
> > > > and
> > > > > >>>>>>>>>>>>>>>>> continue
> > > > > >>>>>>>>>>>>>>>>> consumption
> > > > > >>>>>>>>>>>>>>>>> with offsets from the mapping.
> > > > > >>>>>>>>>>>>>>>>> have the producers stop for a minimal time.
> > > > > >>>>>>>>>>>>>>>>> wait for mirrormaker to finish
> > > > > >>>>>>>>>>>>>>>>> let producer produce with the new metadata.
> > > > > >>>>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>>> Instead of implementing the approach suggest in
> the
> > > KIP
> > > > > >>>>>>>>>>>>>>>>> which
> > > > > >>>>>>>>>>>>>>>>> will
> > > > > >>>>>>>>>>>>>>>>> leave
> > > > > >>>>>>>>>>>>>>>>> log compacted topic completely crumbled and
> > unusable.
> > > > > >>>>>>>>>>>>>>>>> I would much rather try to build infrastructure
> to
> > > > > support
> > > > > >>>>>>>>>>>>>>>>> the
> > > > > >>>>>>>>>>>>>>>>> mentioned
> > > > > >>>>>>>>>>>>>>>>> above operations more smoothly.
> > > > > >>>>>>>>>>>>>>>>> Especially having producers stop and use another
> > > topic
> > > > is
> > > > > >>>>>>>>>>>>>>>>> difficult
> > > > > >>>>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>>> and
> > > > > >>>>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>>> it would be nice if one can trigger "invalid
> > > metadata"
> > > > > >>>>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>> exceptions
> > > > > >>>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>> for
> > > > > >>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>> them
> > > > > >>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>> and
> > > > > >>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>> if one could give topics aliases so that their
> > produces
> > > > > with
> > > > > >>>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>>> the
> > > > > >>>>>>>>>>>>>>>>> old
> > > > > >>>>>>>>>>>>>>>>> topic
> > > > > >>>>>>>>>>>>>>>>> will arrive in the new topic.
> > > > > >>>>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>>> The downsides are obvious I guess ( having the
> same
> > > > data
> > > > > >>>>>>>>>>>>>>>>> twice
> > > > > >>>>>>>>>>>>>>>>> for
> > > > > >>>>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>>> the
> > > > > >>>>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>>> transition period, but kafka tends to scale well
> > with
> > > > > >>>>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>> datasize).
> > > > > >>>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>> So
> > > > > >>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>> its a
> > > > > >>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>> nicer fit into the architecture.
> > > > > >>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>> I further want to argument that the functionality
> by
> > > the
> > > > > KIP
> > > > > >>>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>>> can
> > > > > >>>>>>>>>>>>>>>>> completely be implementing in "userland" with a
> > > custom
> > > > > >>>>>>>>>>>>>>>>> partitioner
> > > > > >>>>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>>> that
> > > > > >>>>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>>> handles the transition as needed. I would
> > appreciate
> > > if
> > > > > >>>>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>> someone
> > > > > >>>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>> could
> > > > > >>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>> point
> > > > > >>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>> out what a custom partitioner couldn't handle in this
> > > case?
> > > > > >>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>> With the above approach, shrinking a topic becomes
> > the
> > > > same
> > > > > >>>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>>> steps.
> > > > > >>>>>>>>>>>>>>>>> Without
> > > > > >>>>>>>>>>>>>>>>> loosing keys in the discontinued partitions.
> > > > > >>>>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>>> Would love to hear what everyone thinks.
> > > > > >>>>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>>> Best Jan
> > > > > >>>>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>>> On 11.02.2018 00:35, Dong Lin wrote:
> > > > > >>>>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>>> Hi all,
> > > > > >>>>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>>> I have created KIP-253: Support in-order message
> > > > delivery
> > > > > >>>>>>>>>>>>>>>>> with
> > > > > >>>>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>>> partition
> > > > > >>>>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>>> expansion. See
> > > > > >>>>>>>>>>>>>>>>>> https://cwiki.apache.org/confl
> > > > > >>>>>>>>>>>>>>>>>> uence/display/KAFKA/KIP-253%
> > > > > >>>>>>>>>>>>>>>>>> 3A+Support+in-order+message+de
> > > > > >>>>>>>>>>>>>>>>>> livery+with+partition+expansio
> > > > > >>>>>>>>>>>>>>>>>> n
> > > > > >>>>>>>>>>>>>>>>>> .
> > > > > >>>>>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>>>> This KIP provides a way to allow messages of the
> > > same
> > > > > key
> > > > > >>>>>>>>>>>>>>>>>> from
> > > > > >>>>>>>>>>>>>>>>>> the
> > > > > >>>>>>>>>>>>>>>>>> same
> > > > > >>>>>>>>>>>>>>>>>> producer to be consumed in the same order they
> are
> > > > > >>>>>>>>>>>>>>>>>> produced
> > > > > >>>>>>>>>>>>>>>>>> even
> > > > > >>>>>>>>>>>>>>>>>> if
> > > > > >>>>>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>>>> we
> > > > > >>>>>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>>>> expand partition of the topic.
> > > > > >>>>>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>>> Thanks,
> > > > > >>>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>> Dong
> > > > > >>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>>>>
> > > > > >>>>
> > > > > >>
> > > > > >>
> > > > > >
> > > > >
> > > >
> > >
> >
>

Re: [DISCUSS] KIP-253: Support in-order message delivery with partition expansion

Posted by Jun Rao <ju...@confluent.io>.
Hi, John,

I actually think it's important to think through how KStreams handles
partition expansion in this KIP. If we do decide that we truly need
backfilling, it's much better to think through how to add it now, instead
of retrofitting it later. It would be useful to outline how both existing
KStreams jobs and new KStreams jobs work to see if backfilling is really
needed.

If we can figure out how KStreams works, at least we have one reference
implementation for other stream processing frameworks that face the same
issue.

Thanks,

Jun


On Tue, Mar 27, 2018 at 4:56 PM, John Roesler <jo...@confluent.io> wrote:

> Hi Jun,
>
> That's a good point.
>
> Yeah, I don't think it would work too well for existing consumers in the
> middle of gen 0 to try and switch to a newly backfilled prefix of gen 1.
> They probably just need to finish up until they get to the end of gen 0 and
> transition just as if there were no backfill available yet.
>
> This isn't terrible, since consumer applications that care about scaling up
> to match a freshly split partition would wait until after the backfill is
> available to scale up. The consumer that starts out in gen=0, part=0 is
> going to be stuck with part=0 and part=3 in gen=1 in my example regardless
> of whether they finish scanning gen=0 before or after the backfill is
> available.
>
> The broker knowing when it's ok to delete gen 0, including its offset
> mappings, is a big issue, though. I don't have any immediate ideas for
> solving it, but it doesn't feel impossible. Hopefully, you agree this is
> outside of KIP-253's scope, so maybe we don't need to worry about it right
> now.
>
> I do agree that reshuffling in KStreams effectively solves the scalability
> problem as well, as it decouples the partition count (and the partition
> scheme) upstream from the parallelism of the streams application. Likely,
> we will do this in any case. I'm predominantly advocating for follow-on
> work to enable backfill for the *other* Kafka users that are not KStreams.
>
> Thanks for your consideration,
> -John
>
> On Tue, Mar 27, 2018 at 6:19 PM, Jun Rao <ju...@confluent.io> wrote:
>
> > Hi, John,
> >
> > Thanks for the reply. I agree that the backfill approach works cleaner
> for
> > newly started consumers. I am just not sure if it's a good primitive to
> > support for existing consumers. One of the challenges that I see is the
> > remapping of the offsets. In your approach, we need to copy the existing
> > records from the partitions in generation 0 to generation 1. Those
> records
> > will get different offsets in the new generation. The broker will have to
> > store those offset mappings somewhere. When the backfill completes, you
> can
> > delete generation 0's data. However, the broker can't throw away the
> offset
> > mappings immediately since it doesn't know if there is any existing
> > consumer still consuming generation 0's records. In a compacted topic,
> the
> > broker probably can only safely remove the offset mappings when all
> records
> > in generation 0 are removed by the cleaner. This may never happen though.
> >
> > If we reshuffle the input inside a KStreams job, it obviates the need for
> > offset remapping on the broker.
> >
> > Jun
> >
> > On Tue, Mar 27, 2018 at 11:34 AM, John Roesler <jo...@confluent.io>
> wrote:
> >
> > > Hey Dong and Jun,
> > >
> > > Thanks for the thoughtful responses. If you don't mind, I'll mix my
> > replies
> > > together to try for a coherent response. I'm not too familiar with
> > > mailing-list etiquette, though.
> > >
> > > I'm going to keep numbering my points because it makes it easy for you
> > all
> > > to respond.
> > >
> > > Point 1:
> > > As I read it, KIP-253 is *just* about properly fencing the producers
> and
> > > consumers so that you preserve the correct ordering of records during
> > > partition expansion. This is clearly necessary regardless of anything
> > else
> > > we discuss. I think this whole discussion about backfill, consumers,
> > > streams, etc., is beyond the scope of KIP-253. But it would be
> cumbersome
> > > to start a new thread at this point.
> > >
> > > I had missed KIP-253's Proposed Change #9 among all the details... I
> > think
> > > this is a nice addition to the proposal. One thought is that it's
> > actually
> > > irrelevant whether the hash function is linear. This is simply an
> > algorithm
> > > for moving a key from one partition to another, so the type of hash
> > > function need not be a precondition. In fact, it also doesn't matter
> > > whether the topic is compacted or not, the algorithm works regardless.
> > >
> > > I think this is a good algorithm to keep in mind, as it might solve a
> > > variety of problems, but it does have a downside: that the producer
> won't
> > > know whether or not K1 was actually in P1, it just knows that K1 was in
> > > P1's keyspace before the new epoch. Therefore, it will have to
> > > pessimistically send (K1,null) to P1 just in case. But the next time K1
> > > comes along, the producer *also* won't remember that it already
> retracted
> > > K1 from P1, so it will have to send (K1,null) *again*. By extension,
> > every
> > > time the producer sends to P2, it will also have to send a tombstone to
> > P1,
> > > which is a pretty big burden. To make the situation worse, if there is
> a
> > > second split, say P2 becomes P2 and P3, then any key Kx belonging to P3
> > > will also have to be retracted from P2 *and* P1, since the producer
> can't
> > > know whether Kx had been last written to P2 or P1. Over a long period
> of
> > > time, this clearly becomes a issue, as the producer must send an
> > arbitrary
> > > number of retractions along with every update.
> > >
> > > In contrast, the proposed backfill operation has an end, and after it
> > ends,
> > > everyone can afford to forget that there ever was a different partition
> > > layout.
> > >
> > > Really, though, figuring out how to split compacted topics is beyond
> the
> > > scope of KIP-253, so I'm not sure #9 really even needs to be in this
> > KIP...
> > > We do need in-order delivery during partition expansion. It would be
> fine
> > > by me to say that you *cannot* expand partitions of a log-compacted
> topic
> > > and call it a day. I think it would be better to tackle that in another
> > > KIP.
> > >
> > >
> > > Point 2:
> > > Regarding whether the consumer re-shuffles its inputs, this is always
> on
> > > the table; any consumer who wants to re-shuffle its input is free to do
> > so.
> > > But this is currently not required. It's just that the current
> high-level
> > > story with Kafka encourages the use of partitions as a unit of
> > concurrency.
> > > As long as consumers are single-threaded, they can happily consume a
> > single
> > > partition without concurrency control of any kind. This is a key aspect
> > to
> > > this system that lets folks design high-throughput systems on top of it
> > > surprisingly easily. If all consumers were instead encouraged/required
> to
> > > implement a repartition of their own, then the consumer becomes
> > > significantly more complex, requiring either the consumer to first
> > produce
> > > to its own intermediate repartition topic or to ensure that consumer
> > > threads have a reliable, high-bandwith channel of communication with
> > every
> > > other consumer thread.
> > >
> > > Either of those tradeoffs may be reasonable for a particular user of
> > Kafka,
> > > but I don't know if we're in a position to say that they are reasonable
> > for
> > > *every* user of Kafka.
> > >
> > >
> > > Point 3:
> > > Regarding Jun's point about this use case, "(3) stateful and
> maintaining
> > > the
> > > states in a local store", I agree that they may use a framework *like*
> > > Kafka Streams, but that is not the same as using Kafka Streams. This is
> > why
> > > I think it's better to solve it in Core: because it is then solved for
> > > KStreams and also for everything else that facilitates local state
> > > maintenance. To me, Streams is a member of the category of "stream
> > > processing frameworks", which is itself a subcategory of "things
> > requiring
> > > local state maintenence". I'm not sure if it makes sense to assert that
> > > Streams is a sufficient and practical replacement for everything in
> > "things
> > > requiring local state maintenence".
> > >
> > > But, yes, I do agree that per-key ordering is an absolute requirement,
> > > therefore I think that KIP-253 itself is a necessary step. Regarding
> the
> > > coupling of the state store partitioning to the topic partitioning,
> yes,
> > > this is an issue we are discussing solutions to right now. We may go
> > ahead
> > > and introduce an overpartition layer on our inputs to solve it, but
> then
> > > again, if we get the ability to split partitions with backfill, we may
> > not
> > > need to!
> > >
> > >
> > > Point 4:
> > > On this:
> > >
> > > > Regarding thought 2: If we don't care about the stream use-case, then
> > the
> > > > current KIP probably has already addressed problem without requiring
> > > > consumer to know the partition function. If we care about the stream
> > > > use-case, we already need coordination across producers of different
> > > > topics, i.e. the same partition function needs to be used by
> producers
> > of
> > > > topics A and B in order to join topics A and B. Thus, it might be
> > > > reasonable to extend coordination a bit and say we need coordination
> > > across
> > > > clients (i.e. producer and consumer), such that consumer knows the
> > > > partition function used by producer. If we do so, then we can let
> > > consumer
> > > > re-copy data for the change log topic using the same partition
> function
> > > as
> > > > producer. This approach has lower overhead as compared to having
> > producer
> > > > re-copy data of the input topic.
> > > > Also, producer currently does not need to know the data already
> > produced
> > > to
> > > > the topic. If we let producer split/merge partition, it would require
> > > > producer to consume the existing data, which intuitively is the task
> of
> > > > consumer.
> > >
> > >
> > > I think we do care about use cases *like* Streams, I just don't think
> we
> > > should rely on Streams to implement a feature of Core like partition
> > > expansion.
> > >
> > > Note, though, that we (Streams) do not require coordination across
> > > producers. If two topics are certified to be co-partitioned, then
> Streams
> > > apps can make use of that knowledge to optimize their topology
> (skipping
> > a
> > > repartition). But if they don't know whether they are co-partitioned,
> > then
> > > they'd better go ahead and repartition within the topology. This is the
> > > current state.
> > >
> > > A huge selling point of Kafka is enabling different parts of loosely
> > > coupled organizations to produce and consume data independently. Some
> > > coordination between producers and consumers is necessary, like
> > > coordinating on the names of topics and their schemas. But Kafka's
> value
> > > proposition w.r.t. ESBs, etc. is inversely proportional to the amount
> of
> > > coordination required. I think it behooves us to be extremely skeptical
> > > about introducing any coordination beyond correctness protocols.
> > >
> > > Asking producers and consumers, or even two different producers, to
> share
> > > code like the partition function is a pretty huge ask. What if they are
> > > using different languages?
> > >
> > > Comparing organizational overhead vs computational overhead, there are
> > > maybe two orders of magnitude difference between them. In other words,
> I
> > > would happily take on the (linear) overhead of having the producer
> > re-copy
> > > the data once during a re-partition in order to save the organizational
> > > overhead of tying all the producers and consumers together across
> > multiple
> > > boundaries.
> > >
> > > On that last paragraph: note that the producer *did* know the data it
> > > already produced. It handled it the first time around. Asking it to
> > > re-produce it into a new partition layout is squarely within its scope
> of
> > > capabilities. Contrast this with the alternative, asking the consumer
> to
> > > re-partition the data. I think this is even less intuitive, when the
> > > partition function belongs to the producer.
> > >
> > >
> > > Point 5:
> > > Dong asked this:
> > >
> > > > For stream use-case that needs to increase consumer number, the
> > > > existing consumer can backfill the existing data in the change log
> > topic
> > > to
> > > > the same change log topic with the new partition number, before the
> new
> > > set
> > > > of consumers bootstrap state from the new partitions of the change
> log
> > > > topic, right?
> > >
> > >
> > > In this sense, the "consumer" is actually the producer of the changelog
> > > topic, so if we support partition expansion + backfill as a
> > producer/broker
> > > operation, then it would be very straightforward for Streams to split a
> > > state store. As you say, they would simply instruct the broker to split
> > the
> > > changelog topic's partitions, then backfill. Once the backfill is
> ready,
> > > they can create a new crop of StandbyTasks to bootstrap the more
> granular
> > > state stores and finally switch over to them when they are ready.
> > >
> > > But this actually seems to be an argument in favor of split+backfill,
> so
> > > maybe I missed the point.
> > >
> > > You also asked me to explain why copying the "input" topic is better
> than
> > > copying the "changelog" topic. I think they are totally independent,
> > > actually. For one thing, you can't depend on the existence of a
> > "changelog"
> > > topic in general, only within Streams, but Kafka's user base clearly
> > > exceeds Streams's user base. Plus, you actually also can't depend on
> the
> > > existence of a changelog topic within Streams, since that is an
> optional
> > > feature of *some* state store implementations. Even in the situation
> > where
> > > you do have a changelog topic in Streams, there may be use cases where
> it
> > > makes sense to expand the partitions of just the input, or just the
> > > changelog.
> > >
> > > The ask for a Core feature of split+backfill is really about supporting
> > the
> > > use case of splitting partitions in log-compacted topics, regardless of
> > > whether that topic is an "input" or a "changelog" or anything else for
> > that
> > > matter.
> > >
> > >
> > > Point 6:
> > > On the concern about the performance overhead of copying data between
> the
> > > brokers, I think it's actually a bit overestimated. Splitting a topic's
> > > partition is probably rare, certainly rarer in general than
> bootstrapping
> > > new consumers on that topic. If "bootstrapping new consumers" means
> that
> > > they have to re-shuffle the data before they consume it, then you wind
> up
> > > copying the same record multiple times:
> > >
> > > (broker: input topic) -> (initial consumer) -> (broker: repartition
> > topic)
> > > -> (real consumer)
> > >
> > > That's 3x, and it's also 3x for every new record after the split as
> well,
> > > since you don't get to stop repartitioning/reshuffling once you start.
> > >
> > > Whereas if you do a backfill in something like the procedure I
> outlined,
> > > you only copy the prefix of the partition before the split, and you
> send
> > it
> > > once to the producer and then once to the new generation partition.
> Plus,
> > > assuming we're splitting the partition for the benefit of consumers,
> > > there's no reason we can't co-locate the post-split partitions on the
> > same
> > > host as the pre-split partition, making the second copy a local
> > filesystem
> > > operation.
> > >
> > > Even if you follow these two copies up with bootstrapping a new
> consumer,
> > > it's still rare for this to occur, so you get to amortize these copies
> > over
> > > the lifetime of the topic, whereas a reshuffle just keeps making copies
> > for
> > > every new event.
> > >
> > > And finally, I really do think that regardless of any performance
> > concerns
> > > about this operation, if it preserves loose organizational coupling, it
> > is
> > > certainly worth it.
> > >
> > >
> > > In conclusion:
> > > It might actually be a good idea for us to clarify the scope of
> KIP-253.
> > If
> > > we're all agreed that it's a good algorithm for allowing in-order
> message
> > > delivery during partition expansion, then we can continue this
> discussion
> > > as a new KIP, something like "backfill with partition expansion". This
> > > would let Dong proceed with KIP-253. On the other hand, if it seems
> like
> > > this conversation may alter the design of KIP-253, then maybe we
> *should*
> > > just finish working it out.
> > >
> > > For my part, my only concern about KIP-253 is the one I raised earlier.
> > >
> > > Thanks again, all, for considering these points,
> > > -John
> > >
> > >
> > > On Tue, Mar 27, 2018 at 2:10 AM, Dong Lin <li...@gmail.com> wrote:
> > >
> > > > On Tue, Mar 27, 2018 at 12:04 AM, Dong Lin <li...@gmail.com>
> > wrote:
> > > >
> > > > > Hey Jan,
> > > > >
> > > > > Thanks for the enthusiasm in improving Kafka's design. Now that I
> > have
> > > > > read through your discussion with Jun, here are my thoughts:
> > > > >
> > > > > - The latest proposal should with log compacted topics by properly
> > > > > deleting old messages after a new message with the same key is
> > > produced.
> > > > So
> > > > > it is probably not a concern anymore. Could you comment if there is
> > > still
> > > > > issue?
> > > > >
> > > > > - I wrote the SEP-5 and I am pretty familiar with the motivation
> and
> > > the
> > > > > design of SEP-5. SEP-5 is probably orthornal to the motivation of
> > this
> > > > KIP.
> > > > > The goal of SEP-5 is to allow user to increase task number of an
> > > existing
> > > > > Samza job. But if we increase the partition number of input topics,
> > > > > messages may still be consumed out-of-order by tasks in Samza which
> > > cause
> > > > > incorrect result. Similarly, the approach you proposed does not
> seem
> > to
> > > > > ensure that the messages can be delivered in order, even if we can
> > make
> > > > > sure that each consumer instance is assigned the set of new
> > partitions
> > > > > covering the same set of keys.
> > > > >
> > > >
> > > > Let me correct this comment. The approach of copying data to a new
> > topic
> > > > can ensure in-order message delivery suppose we properly migrate
> > offsets
> > > > from old topic to new topic.
> > > >
> > > >
> > > > > - I am trying to understand why it is better to copy the data
> instead
> > > of
> > > > > copying the change log topic for streaming use-case. For core Kafka
> > > > > use-case, and for the stream use-case that does not need to
> increase
> > > > > consumers, the current KIP already supports in-order delivery
> without
> > > the
> > > > > overhead of copying the data. For stream use-case that needs to
> > > increase
> > > > > consumer number, the existing consumer can backfill the existing
> data
> > > in
> > > > > the change log topic to the same change log topic with the new
> > > partition
> > > > > number, before the new set of consumers bootstrap state from the
> new
> > > > > partitions of the change log topic. If this solution works, then
> > could
> > > > you
> > > > > summarize the advantage of copying the data of input topic as
> > compared
> > > to
> > > > > copying the change log topic? For example, does it enable more
> > > use-case,
> > > > > simplify the implementation of Kafka library, or reduce the
> operation
> > > > > overhead etc?
> > > > >
> > > > > Thanks,
> > > > > Dong
> > > > >
> > > > >
> > > > > On Wed, Mar 21, 2018 at 6:57 AM, Jan Filipiak <
> > > Jan.Filipiak@trivago.com>
> > > > > wrote:
> > > > >
> > > > >> Hi Jun,
> > > > >>
> > > > >> I was really seeing progress in our conversation but your latest
> > reply
> > > > is
> > > > >> just devastating.
> > > > >> I though we were getting close being on the same page now it feels
> > > like
> > > > >> we are in different libraries.
> > > > >>
> > > > >> I just quickly slam my answers in here. If they are to brief I am
> > > sorry
> > > > >> give me a ping and try to go into details more.
> > > > >> Just want to show that your pro/cons listing is broken.
> > > > >>
> > > > >> Best Jan
> > > > >>
> > > > >> and want to get rid of this horrible compromise
> > > > >>
> > > > >>
> > > > >> On 19.03.2018 05:48, Jun Rao wrote:
> > > > >>
> > > > >>> Hi, Jan,
> > > > >>>
> > > > >>> Thanks for the discussion. Great points.
> > > > >>>
> > > > >>> Let me try to summarize the approach that you are proposing. On
> the
> > > > >>> broker
> > > > >>> side, we reshuffle the existing data in a topic from current
> > > partitions
> > > > >>> to
> > > > >>> the new partitions. Once the reshuffle fully catches up, switch
> the
> > > > >>> consumers to start consuming from the new partitions. If a
> consumer
> > > > needs
> > > > >>> to rebuild its local state (due to partition changes), let the
> > > consumer
> > > > >>> rebuild its state by reading all existing data from the new
> > > partitions.
> > > > >>> Once all consumers have switches over, cut over the producer to
> the
> > > new
> > > > >>> partitions.
> > > > >>>
> > > > >>> The pros for this approach are that :
> > > > >>> 1. There is just one way to rebuild the local state, which is
> > > simpler.
> > > > >>>
> > > > >> true thanks
> > > > >>
> > > > >>>
> > > > >>> The cons for this approach are:
> > > > >>> 1. Need to copy existing data.
> > > > >>>
> > > > >> Very unfair and not correct. It does not require you to copy over
> > > > >> existing data. It _allows_ you to copy all existing data.
> > > > >>
> > > > >> 2. The cutover of the producer is a bit complicated since it needs
> > to
> > > > >>> coordinate with all consumer groups.
> > > > >>>
> > > > >> Also not true. I explicitly tried to make clear that there is only
> > one
> > > > >> special consumer (in the case of actually copying data)
> coordination
> > > is
> > > > >> required.
> > > > >>
> > > > >>> 3. The rebuilding of the state in the consumer is from the input
> > > topic,
> > > > >>> which can be more expensive than rebuilding from the existing
> > state.
> > > > >>>
> > > > >> true, but rebuilding state is only required if you want to
> increase
> > > > >> processing power, so we assume this is at hand.
> > > > >>
> > > > >>> 4. The broker potentially has to know the partitioning function.
> If
> > > > this
> > > > >>> needs to be customized at the topic level, it can be a bit messy.
> > > > >>>
> > > > >> I would argue against having the operation being performed by the
> > > > broker.
> > > > >> This was not discussed yet but if you see my original email i
> > > suggested
> > > > >> otherwise from the beginning.
> > > > >>
> > > > >>>
> > > > >>> Here is an alternative approach by applying your idea not in the
> > > > broker,
> > > > >>> but in the consumer. When new partitions are added, we don't move
> > > > >>> existing
> > > > >>> data. In KStreams, we first reshuffle the new input data to a new
> > > topic
> > > > >>> T1
> > > > >>> with the old number of partitions and feed T1's data to the rest
> of
> > > the
> > > > >>> pipeline. In the meantime, KStreams reshuffles all existing data
> of
> > > the
> > > > >>> change capture topic to another topic C1 with the new number of
> > > > >>> partitions.
> > > > >>> We can then build the state of the new tasks from C1. Once the
> new
> > > > states
> > > > >>> have been fully built, we can cut over the consumption to the
> input
> > > > topic
> > > > >>> and delete T1. This approach works with compacted topic too. If
> an
> > > > >>> application reads from the beginning of a compacted topic, the
> > > consumer
> > > > >>> will reshuffle the portion of the input when the number of
> > partitions
> > > > >>> doesn't match the number of tasks.
> > > > >>>
> > > > >> We all wipe this idea from our heads instantly. Mixing Ideas from
> an
> > > > >> argument is not a resolution strategy
> > > > >> just leads to horrible horrible software.
> > > > >>
> > > > >>
> > > > >>> The pros of this approach are:
> > > > >>> 1. No need to copy existing data.
> > > > >>> 2. Each consumer group can cut over to the new partitions
> > > > independently.
> > > > >>> 3. The state is rebuilt from the change capture topic, which is
> > > cheaper
> > > > >>> than rebuilding from the input topic.
> > > > >>> 4. Only the KStreams job needs to know the partitioning function.
> > > > >>>
> > > > >>> The cons of this approach are:
> > > > >>> 1. Potentially the same input topic needs to be reshuffled more
> > than
> > > > once
> > > > >>> in different consumer groups during the transition phase.
> > > > >>>
> > > > >>> What do you think?
> > > > >>>
> > > > >>> Thanks,
> > > > >>>
> > > > >>> Jun
> > > > >>>
> > > > >>>
> > > > >>>
> > > > >>> On Thu, Mar 15, 2018 at 1:04 AM, Jan Filipiak <
> > > > Jan.Filipiak@trivago.com>
> > > > >>> wrote:
> > > > >>>
> > > > >>> Hi Jun,
> > > > >>>>
> > > > >>>> thank you for following me on these thoughts. It was important
> to
> > me
> > > > to
> > > > >>>> feel that kind of understanding for my arguments.
> > > > >>>>
> > > > >>>> What I was hoping for (I mentioned this earlier) is that we can
> > > model
> > > > >>>> the
> > > > >>>> case where we do not want to copy the data the exact same way as
> > the
> > > > >>>> case
> > > > >>>> when we do copy the data. Maybe you can peek into the mails
> before
> > > to
> > > > >>>> see
> > > > >>>> more details for this.
> > > > >>>>
> > > > >>>> This means we have the same mechanism to transfer consumer
> groups
> > to
> > > > >>>> switch topic. The offset mapping that would be generated would
> > even
> > > be
> > > > >>>> simpler End Offset of the Old topic => offset 0 off all the
> > > partitions
> > > > >>>> of
> > > > >>>> the new topic. Then we could model the transition of a non-copy
> > > > >>>> expansion
> > > > >>>> the exact same way as a copy-expansion.
> > > > >>>>
> > > > >>>> I know this only works when topic growth by a factor. But the
> > > benefits
> > > > >>>> of
> > > > >>>> only growing by a factor are to strong anyways. See Clemens's
> hint
> > > and
> > > > >>>> remember that state reshuffling is entirely not needed if one
> > > doesn't
> > > > >>>> want
> > > > >>>> to grow processing power.
> > > > >>>>
> > > > >>>> I think these benefits should be clear, and that there is
> > basically
> > > no
> > > > >>>> downside to what is currently at hand but just makes everything
> > > easy.
> > > > >>>>
> > > > >>>> One thing you need to know is. that if you do not offer
> > rebuilding a
> > > > log
> > > > >>>> compacted topic like i suggest that even if you have consumer
> > state
> > > > >>>> reshuffling. The topic is broken and can not be used to
> bootstrap
> > > new
> > > > >>>> consumers. They don't know if they need to apply a key from and
> > old
> > > > >>>> partition or not. This is a horrible downside I haven't seen a
> > > > solution
> > > > >>>> for
> > > > >>>> in the email conversation.
> > > > >>>>
> > > > >>>> I argue to:
> > > > >>>>
> > > > >>>> Only grow topic by a factor always.
> > > > >>>> Have the "no copy consumer" transition as the trivial case of
> the
> > > > "copy
> > > > >>>> consumer transition".
> > > > >>>> If processors needs to be scaled, let them rebuild from the new
> > > topic
> > > > >>>> and
> > > > >>>> leave the old running in the mean time.
> > > > >>>> Do not implement key shuffling in streams.
> > > > >>>>
> > > > >>>> I hope I can convince you especially with the fact how I want to
> > > > handle
> > > > >>>> consumer transition. I think
> > > > >>>> you didn't quite understood me there before. I think the term
> "new
> > > > >>>> topic"
> > > > >>>> intimidated you a little.
> > > > >>>> How we solve this on disc doesn't really matter, If the data
> goes
> > > into
> > > > >>>> the
> > > > >>>> same Dir or a different Dir or anything. I do think that it
> needs
> > to
> > > > >>>> involve at least rolling a new segment for the existing
> > partitions.
> > > > >>>> But most of the transitions should work without restarting
> > > consumers.
> > > > >>>> (newer consumers with support for this). But with new topic i
> just
> > > > meant
> > > > >>>> the topic that now has a different partition count. Plenty of
> ways
> > > to
> > > > >>>> handle that (versions, aliases)
> > > > >>>>
> > > > >>>> Hope I can further get my idea across.
> > > > >>>>
> > > > >>>> Best Jan
> > > > >>>>
> > > > >>>>
> > > > >>>>
> > > > >>>>
> > > > >>>>
> > > > >>>>
> > > > >>>> On 14.03.2018 02:45, Jun Rao wrote:
> > > > >>>>
> > > > >>>> Hi, Jan,
> > > > >>>>>
> > > > >>>>> Thanks for sharing your view.
> > > > >>>>>
> > > > >>>>> I agree with you that recopying the data potentially makes the
> > > state
> > > > >>>>> management easier since the consumer can just rebuild its state
> > > from
> > > > >>>>> scratch (i.e., no need for state reshuffling).
> > > > >>>>>
> > > > >>>>> On the flip slide, I saw a few disadvantages of the approach
> that
> > > you
> > > > >>>>> suggested. (1) Building the state from the input topic from
> > scratch
> > > > is
> > > > >>>>> in
> > > > >>>>> general less efficient than state reshuffling. Let's say one
> > > > computes a
> > > > >>>>> count per key from an input topic. The former requires reading
> > all
> > > > >>>>> existing
> > > > >>>>> records in the input topic whereas the latter only requires
> > reading
> > > > >>>>> data
> > > > >>>>> proportional to the number of unique keys. (2) The switching of
> > the
> > > > >>>>> topic
> > > > >>>>> needs modification to the application. If there are many
> > > applications
> > > > >>>>> on a
> > > > >>>>> topic, coordinating such an effort may not be easy. Also, it's
> > not
> > > > >>>>> clear
> > > > >>>>> how to enforce exactly-once semantic during the switch. (3) If
> a
> > > > topic
> > > > >>>>> doesn't need any state management, recopying the data seems
> > > wasteful.
> > > > >>>>> In
> > > > >>>>> that case, in place partition expansion seems more desirable.
> > > > >>>>>
> > > > >>>>> I understand your concern about adding complexity in KStreams.
> > But,
> > > > >>>>> perhaps
> > > > >>>>> we could iterate on that a bit more to see if it can be
> > simplified.
> > > > >>>>>
> > > > >>>>> Jun
> > > > >>>>>
> > > > >>>>>
> > > > >>>>> On Mon, Mar 12, 2018 at 11:21 PM, Jan Filipiak <
> > > > >>>>> Jan.Filipiak@trivago.com>
> > > > >>>>> wrote:
> > > > >>>>>
> > > > >>>>> Hi Jun,
> > > > >>>>>
> > > > >>>>>> I will focus on point 61 as I think its _the_ fundamental part
> > > that
> > > > I
> > > > >>>>>> cant
> > > > >>>>>> get across at the moment.
> > > > >>>>>>
> > > > >>>>>> Kafka is the platform to have state materialized multiple
> times
> > > from
> > > > >>>>>> one
> > > > >>>>>> input. I emphasize this: It is the building block in
> > architectures
> > > > >>>>>> that
> > > > >>>>>> allow you to
> > > > >>>>>> have your state maintained multiple times. You put a message
> in
> > > > once,
> > > > >>>>>> and
> > > > >>>>>> you have it pop out as often as you like. I believe you
> > understand
> > > > >>>>>> this.
> > > > >>>>>>
> > > > >>>>>> Now! The path of thinking goes the following: I am using
> apache
> > > > kafka
> > > > >>>>>> and
> > > > >>>>>> I _want_ my state multiple times. What am I going todo?
> > > > >>>>>>
> > > > >>>>>> A) Am I going to take my state that I build up, plunge some
> sort
> > > of
> > > > >>>>>> RPC
> > > > >>>>>> layer ontop of it, use that RPC layer to throw my records
> across
> > > > >>>>>> instances?
> > > > >>>>>> B) Am I just going to read the damn message twice?
> > > > >>>>>>
> > > > >>>>>> Approach A is fundamentally flawed and a violation of all that
> > is
> > > > good
> > > > >>>>>> and
> > > > >>>>>> holy in kafka deployments. I can not understand how this Idea
> > can
> > > > >>>>>> come in
> > > > >>>>>> the first place.
> > > > >>>>>> (I do understand: IQ in streams, they polluted the kafka
> streams
> > > > >>>>>> codebase
> > > > >>>>>> really bad already. It is not funny! I think they are equally
> > > flawed
> > > > >>>>>> as
> > > > >>>>>> A)
> > > > >>>>>>
> > > > >>>>>> I say, we do what Kafka is good at. We repartition the topic
> > once.
> > > > We
> > > > >>>>>> switch the consumers.
> > > > >>>>>> (Those that need more partitions are going to rebuild their
> > state
> > > in
> > > > >>>>>> multiple partitions by reading the new topic, those that don't
> > > just
> > > > >>>>>> assign
> > > > >>>>>> the new partitions properly)
> > > > >>>>>> We switch producers. Done!
> > > > >>>>>>
> > > > >>>>>> The best thing! It is trivial, hipster stream processor will
> > have
> > > an
> > > > >>>>>> easy
> > > > >>>>>> time with that aswell. Its so super simple. And simple IS
> good!
> > > > >>>>>> It is what kafka was build todo. It is how we do it today.
> All I
> > > am
> > > > >>>>>> saying
> > > > >>>>>> is that a little broker help doing the producer swap is super
> > > > useful.
> > > > >>>>>>
> > > > >>>>>> For everyone interested in why kafka is so powerful with
> > approach
> > > B,
> > > > >>>>>> please watch https://youtu.be/bEbeZPVo98c?t=1633
> > > > >>>>>> I already looked up a good point in time, I think after 5
> > minutes
> > > > the
> > > > >>>>>> "state" topic is handled and you should be able to understand
> me
> > > > >>>>>> and inch better.
> > > > >>>>>>
> > > > >>>>>> Please do not do A to the project, it deserves better!
> > > > >>>>>>
> > > > >>>>>> Best Jan
> > > > >>>>>>
> > > > >>>>>>
> > > > >>>>>>
> > > > >>>>>> On 13.03.2018 02:40, Jun Rao wrote:
> > > > >>>>>>
> > > > >>>>>> Hi, Jan,
> > > > >>>>>>
> > > > >>>>>>> Thanks for the reply. A few more comments below.
> > > > >>>>>>>
> > > > >>>>>>> 50. Ok, we can think a bit harder for supporting compacted
> > > topics.
> > > > >>>>>>>
> > > > >>>>>>> 51. This is a fundamental design question. In the more common
> > > case,
> > > > >>>>>>> the
> > > > >>>>>>> reason why someone wants to increase the number of partitions
> > is
> > > > that
> > > > >>>>>>> the
> > > > >>>>>>> consumer application is slow and one wants to run more
> consumer
> > > > >>>>>>> instances
> > > > >>>>>>> to increase the degree of parallelism. So, fixing the number
> of
> > > > >>>>>>> running
> > > > >>>>>>> consumer instances when expanding the partitions won't help
> > this
> > > > >>>>>>> case.
> > > > >>>>>>> If
> > > > >>>>>>> we do need to increase the number of consumer instances, we
> > need
> > > to
> > > > >>>>>>> somehow
> > > > >>>>>>> reshuffle the state of the consumer across instances. What we
> > > have
> > > > >>>>>>> been
> > > > >>>>>>> discussing in this KIP is whether we can do this more
> > effectively
> > > > >>>>>>> through
> > > > >>>>>>> the KStream library (e.g. through a 2-phase partition
> > expansion).
> > > > >>>>>>> This
> > > > >>>>>>> will
> > > > >>>>>>> add some complexity, but it's probably better than everyone
> > doing
> > > > >>>>>>> this
> > > > >>>>>>> in
> > > > >>>>>>> the application space. The recopying approach that you
> > mentioned
> > > > >>>>>>> doesn't
> > > > >>>>>>> seem to address the consumer state management issue when the
> > > > consumer
> > > > >>>>>>> switches from an old to a new topic.
> > > > >>>>>>>
> > > > >>>>>>> 52. As for your example, it depends on whether the join key
> is
> > > the
> > > > >>>>>>> same
> > > > >>>>>>> between (A,B) and (B,C). If the join key is the same, we can
> > do a
> > > > >>>>>>> 2-phase
> > > > >>>>>>> partition expansion of A, B, and C together. If the join keys
> > are
> > > > >>>>>>> different, one would need to repartition the data on a
> > different
> > > > key
> > > > >>>>>>> for
> > > > >>>>>>> the second join, then the partition expansion can be done
> > > > >>>>>>> independently
> > > > >>>>>>> between (A,B) and (B,C).
> > > > >>>>>>>
> > > > >>>>>>> 53. If you always fix the number of consumer instances, we
> you
> > > > >>>>>>> described
> > > > >>>>>>> works. However, as I mentioned in #51, I am not sure how your
> > > > >>>>>>> proposal
> > > > >>>>>>> deals with consumer states when the number of consumer
> > instances
> > > > >>>>>>> grows.
> > > > >>>>>>> Also, it just seems that it's better to avoid re-copying the
> > > > existing
> > > > >>>>>>> data.
> > > > >>>>>>>
> > > > >>>>>>> 60. "just want to throw in my question from the longer email
> in
> > > the
> > > > >>>>>>> other
> > > > >>>>>>> Thread here. How will the bloom filter help a new consumer to
> > > > decide
> > > > >>>>>>> to
> > > > >>>>>>> apply the key or not?" Not sure that I fully understood your
> > > > >>>>>>> question.
> > > > >>>>>>> The
> > > > >>>>>>> consumer just reads whatever key is in the log. The bloom
> > filter
> > > > just
> > > > >>>>>>> helps
> > > > >>>>>>> clean up the old keys.
> > > > >>>>>>>
> > > > >>>>>>> 61. "Why can we afford having a topic where its apparently
> not
> > > > >>>>>>> possible
> > > > >>>>>>> to
> > > > >>>>>>> start a new application on? I think this is an overall flaw
> of
> > > the
> > > > >>>>>>> discussed idea here. Not playing attention to the overall
> > > > >>>>>>> architecture."
> > > > >>>>>>> Could you explain a bit more when one can't start a new
> > > > application?
> > > > >>>>>>>
> > > > >>>>>>> Jun
> > > > >>>>>>>
> > > > >>>>>>>
> > > > >>>>>>>
> > > > >>>>>>> On Sat, Mar 10, 2018 at 1:40 AM, Jan Filipiak <
> > > > >>>>>>> Jan.Filipiak@trivago.com
> > > > >>>>>>> wrote:
> > > > >>>>>>>
> > > > >>>>>>> Hi Jun, thanks for your mail.
> > > > >>>>>>>
> > > > >>>>>>> Thank you for your questions!
> > > > >>>>>>>> I think they are really good and tackle the core of the
> > problem
> > > I
> > > > >>>>>>>> see.
> > > > >>>>>>>>
> > > > >>>>>>>> I will answer inline, mostly but still want to set the tone
> > > here.
> > > > >>>>>>>>
> > > > >>>>>>>> The core strength of kafka is what Martin once called the
> > > > >>>>>>>> kappa-Architecture. How does this work?
> > > > >>>>>>>> You have everything as a log as in kafka. When you need to
> > > change
> > > > >>>>>>>> something.
> > > > >>>>>>>> You create the new version of your application and leave it
> > > > running
> > > > >>>>>>>> in
> > > > >>>>>>>> parallel.
> > > > >>>>>>>> Once the new version is good you switch your users to use
> the
> > > new
> > > > >>>>>>>> application.
> > > > >>>>>>>>
> > > > >>>>>>>> The online reshuffling effectively breaks this architecture
> > and
> > > I
> > > > >>>>>>>> think
> > > > >>>>>>>> the switch in thinking here is more harmful
> > > > >>>>>>>> than any details about the partitioning function to allow
> > such a
> > > > >>>>>>>> change.
> > > > >>>>>>>> I
> > > > >>>>>>>> feel with my suggestion we are the closest to
> > > > >>>>>>>> the original and battle proven architecture and I can only
> > warn
> > > to
> > > > >>>>>>>> move
> > > > >>>>>>>> away from it.
> > > > >>>>>>>>
> > > > >>>>>>>> I might have forgotten something, sometimes its hard for me
> to
> > > > >>>>>>>> getting
> > > > >>>>>>>> all
> > > > >>>>>>>> the thoughts captured in a mail, but I hope the comments
> > inline
> > > > will
> > > > >>>>>>>> further make my concern clear, and put some emphasis on why
> I
> > > > >>>>>>>> prefer my
> > > > >>>>>>>> solution ;)
> > > > >>>>>>>>
> > > > >>>>>>>> One thing we should all be aware of when discussing this,
> and
> > I
> > > > >>>>>>>> think
> > > > >>>>>>>> Dong
> > > > >>>>>>>> should have mentioned it (maybe he did).
> > > > >>>>>>>> We are not discussing all of this out of thin air but there
> is
> > > an
> > > > >>>>>>>> effort
> > > > >>>>>>>> in the Samza project.
> > > > >>>>>>>>
> > > > >>>>>>>> https://cwiki.apache.org/confluence/display/SAMZA/SEP-5%3A+
> > > > >>>>>>>> Enable+partition+expansion+of+input+streams
> > > > >>>>>>>> https://issues.apache.org/jira/browse/SAMZA-1293
> > > > >>>>>>>>
> > > > >>>>>>>> To be clear. I think SEP-5 (state of last week, dont know if
> > it
> > > > >>>>>>>> adapted
> > > > >>>>>>>> to
> > > > >>>>>>>> this discussion) is on a way better path than KIP-253, and I
> > > can't
> > > > >>>>>>>> really
> > > > >>>>>>>> explain why.
> > > > >>>>>>>>
> > > > >>>>>>>> Best Jan,
> > > > >>>>>>>>
> > > > >>>>>>>> nice weekend everyone
> > > > >>>>>>>>
> > > > >>>>>>>>
> > > > >>>>>>>> On 09.03.2018 03:36, Jun Rao wrote:
> > > > >>>>>>>>
> > > > >>>>>>>> Hi, Jan,
> > > > >>>>>>>>
> > > > >>>>>>>> Thanks for the feedback. Just some comments on the earlier
> > > points
> > > > >>>>>>>>> that
> > > > >>>>>>>>> you
> > > > >>>>>>>>> mentioned.
> > > > >>>>>>>>>
> > > > >>>>>>>>> 50. You brought up the question of whether existing data
> > needs
> > > to
> > > > >>>>>>>>> be
> > > > >>>>>>>>> copied
> > > > >>>>>>>>> during partition expansion. My understand of your view is
> > that
> > > > >>>>>>>>> avoid
> > > > >>>>>>>>> copying existing data will be more efficient, but it
> doesn't
> > > work
> > > > >>>>>>>>> well
> > > > >>>>>>>>> with
> > > > >>>>>>>>> compacted topics since some keys in the original partitions
> > > will
> > > > >>>>>>>>> never
> > > > >>>>>>>>> be
> > > > >>>>>>>>> cleaned. It would be useful to understand your use case of
> > > > >>>>>>>>> compacted
> > > > >>>>>>>>> topics
> > > > >>>>>>>>> a bit more. In the common use case, the data volume in a
> > > > compacted
> > > > >>>>>>>>> topic
> > > > >>>>>>>>> may not be large. So, I am not sure if there is a strong
> need
> > > to
> > > > >>>>>>>>> expand
> > > > >>>>>>>>> partitions in a compacted topic, at least initially.
> > > > >>>>>>>>>
> > > > >>>>>>>>> I do agree. State is usually smaller. Update rates might be
> > > also
> > > > >>>>>>>>>
> > > > >>>>>>>>> competitively high.
> > > > >>>>>>>> Doing Log-compaction (even beeing very efficient and
> > > configurable)
> > > > >>>>>>>> is
> > > > >>>>>>>> also
> > > > >>>>>>>> a more expensive operation than
> > > > >>>>>>>> just discarding old segments. Further if you want to use
> more
> > > > >>>>>>>> consumers
> > > > >>>>>>>> processing the events
> > > > >>>>>>>> you also have to grow the number of partitions. Especially
> for
> > > > >>>>>>>> use-cases
> > > > >>>>>>>> we do (KIP-213) a tiny state full
> > > > >>>>>>>> table might be very expensive to process if it joins
> against a
> > > > huge
> > > > >>>>>>>> table.
> > > > >>>>>>>>
> > > > >>>>>>>> I can just say we have been in the spot of needing to grow
> log
> > > > >>>>>>>> compacted
> > > > >>>>>>>> topics. Mainly for processing power we can bring to the
> table.
> > > > >>>>>>>>
> > > > >>>>>>>> Further i am not at all concerned about the extra spaced
> used
> > by
> > > > >>>>>>>> "garbage
> > > > >>>>>>>> keys". I am more concerned about the correctness of innocent
> > > > >>>>>>>> consumers.
> > > > >>>>>>>> The
> > > > >>>>>>>> logic becomes complicated. Say for streams one would need to
> > > load
> > > > >>>>>>>> the
> > > > >>>>>>>> record into state but not forward it the topology ( to have
> it
> > > > >>>>>>>> available
> > > > >>>>>>>> for shuffeling). I rather have it simple and a topic clean
> > > > >>>>>>>> regardless
> > > > >>>>>>>> if
> > > > >>>>>>>> it
> > > > >>>>>>>> still has its old partition count. Especially with multiple
> > > > >>>>>>>> partitions
> > > > >>>>>>>> growth's I think it becomes insanely hard to to this shuffle
> > > > >>>>>>>> correct.
> > > > >>>>>>>> Maybe
> > > > >>>>>>>> Streams and Samza can do it. Especially if you do "hipster
> > > stream
> > > > >>>>>>>> processing" <https://www.confluent.io/blog
> > > > >>>>>>>> /introducing-kafka-streams-
> > > > >>>>>>>> stream-processing-made-simple/>. This makes kafka way to
> > > > >>>>>>>> complicated.
> > > > >>>>>>>> With my approach I think its way simpler because the topic
> has
> > > no
> > > > >>>>>>>> "history"
> > > > >>>>>>>> in terms of partitioning but is always clean.
> > > > >>>>>>>>
> > > > >>>>>>>>
> > > > >>>>>>>> 51. "Growing the topic by an integer factor does not require
> > any
> > > > >>>>>>>> state
> > > > >>>>>>>>
> > > > >>>>>>>> redistribution at all." Could you clarify this a bit more?
> > Let's
> > > > say
> > > > >>>>>>>>> you
> > > > >>>>>>>>> have a consumer app that computes the windowed count per
> key.
> > > If
> > > > >>>>>>>>> you
> > > > >>>>>>>>> double
> > > > >>>>>>>>> the number of partitions from 1 to 2 and grow the consumer
> > > > >>>>>>>>> instances
> > > > >>>>>>>>> from
> > > > >>>>>>>>> 1
> > > > >>>>>>>>> to 2, we would need to redistribute some of the counts to
> the
> > > new
> > > > >>>>>>>>> consumer
> > > > >>>>>>>>> instance. Regarding to linear hashing, it's true that it
> > won't
> > > > >>>>>>>>> solve
> > > > >>>>>>>>> the
> > > > >>>>>>>>> problem with compacted topics. The main benefit is that it
> > > > >>>>>>>>> redistributes
> > > > >>>>>>>>> the keys in one partition to no more than two partitions,
> > which
> > > > >>>>>>>>> could
> > > > >>>>>>>>> help
> > > > >>>>>>>>> redistribute the state.
> > > > >>>>>>>>>
> > > > >>>>>>>>> You don't need to spin up a new consumer in this case.
> every
> > > > >>>>>>>>> consumer
> > > > >>>>>>>>>
> > > > >>>>>>>>> would just read every partition with the (partition %
> > num_task)
> > > > >>>>>>>> task.
> > > > >>>>>>>> it
> > > > >>>>>>>> will still have the previous data right there and can go on.
> > > > >>>>>>>>
> > > > >>>>>>>> This sounds contradictory to what I said before, but please
> > bear
> > > > >>>>>>>> with
> > > > >>>>>>>> me.
> > > > >>>>>>>>
> > > > >>>>>>>> 52. Good point on coordinating the expansion of 2 topics
> that
> > > need
> > > > >>>>>>>> to
> > > > >>>>>>>> be
> > > > >>>>>>>>
> > > > >>>>>>>> joined together. This is where the 2-phase partition
> expansion
> > > > could
> > > > >>>>>>>>> potentially help. In the first phase, we could add new
> > > partitions
> > > > >>>>>>>>> to
> > > > >>>>>>>>> the 2
> > > > >>>>>>>>> topics one at a time but without publishing to the new
> > > patitions.
> > > > >>>>>>>>> Then,
> > > > >>>>>>>>> we
> > > > >>>>>>>>> can add new consumer instances to pick up the new
> partitions.
> > > In
> > > > >>>>>>>>> this
> > > > >>>>>>>>> transition phase, no reshuffling is needed since no data is
> > > > coming
> > > > >>>>>>>>> from
> > > > >>>>>>>>> the
> > > > >>>>>>>>> new partitions. Finally, we can enable the publishing to
> the
> > > new
> > > > >>>>>>>>> partitions.
> > > > >>>>>>>>>
> > > > >>>>>>>>> I think its even worse than you think. I would like to
> > > introduce
> > > > >>>>>>>>> the
> > > > >>>>>>>>>
> > > > >>>>>>>>> Term
> > > > >>>>>>>> transitive copartitioning. Imagine
> > > > >>>>>>>> 2 streams application. One joins (A,B) the other (B,C) then
> > > there
> > > > >>>>>>>> is a
> > > > >>>>>>>> transitive copartition requirement for
> > > > >>>>>>>> (A,C) to be copartitioned aswell. This can spread
> > significantly
> > > > and
> > > > >>>>>>>> require many consumers to adapt at the same time.
> > > > >>>>>>>>
> > > > >>>>>>>> It is also not entirely clear to me how you not need
> > reshuffling
> > > > in
> > > > >>>>>>>> this
> > > > >>>>>>>> case. If A has a record that never gets updated after the
> > > > expansion
> > > > >>>>>>>> and
> > > > >>>>>>>> the
> > > > >>>>>>>> coresponding B record moves to a new partition. How shall
> they
> > > > meet
> > > > >>>>>>>> w/o
> > > > >>>>>>>> shuffle?
> > > > >>>>>>>>
> > > > >>>>>>>> 53. "Migrating consumer is a step that might be made
> completly
> > > > >>>>>>>>
> > > > >>>>>>>> unnecessary
> > > > >>>>>>>>> if - for example streams - takes the gcd as partitioning
> > scheme
> > > > >>>>>>>>> instead
> > > > >>>>>>>>> of
> > > > >>>>>>>>> enforcing 1 to 1." Not sure that I fully understand this. I
> > > think
> > > > >>>>>>>>> you
> > > > >>>>>>>>> mean
> > > > >>>>>>>>> that a consumer application can run more instances than the
> > > > number
> > > > >>>>>>>>> of
> > > > >>>>>>>>> partitions. In that case, the consumer can just
> > repartitioning
> > > > the
> > > > >>>>>>>>> input
> > > > >>>>>>>>> data according to the number of instances. This is
> possible,
> > > but
> > > > >>>>>>>>> just
> > > > >>>>>>>>> has
> > > > >>>>>>>>> the overhead of reshuffling the data.
> > > > >>>>>>>>>
> > > > >>>>>>>>> No what I meant is ( that is also your question i think
> > > Mathias)
> > > > >>>>>>>>> that
> > > > >>>>>>>>> if
> > > > >>>>>>>>>
> > > > >>>>>>>>> you grow a topic by a factor.
> > > > >>>>>>>> Even if your processor is statefull you can can just assign
> > all
> > > > the
> > > > >>>>>>>> multiples of the previous partition to
> > > > >>>>>>>> this consumer and the state to keep processing correctly
> will
> > be
> > > > >>>>>>>> present
> > > > >>>>>>>> w/o any shuffling.
> > > > >>>>>>>>
> > > > >>>>>>>> Say you have an assignment
> > > > >>>>>>>> Statefull consumer => partition
> > > > >>>>>>>> 0 => 0
> > > > >>>>>>>> 1 => 1
> > > > >>>>>>>> 2 => 2
> > > > >>>>>>>>
> > > > >>>>>>>> and you grow you topic by 4 you get,
> > > > >>>>>>>>
> > > > >>>>>>>> 0 => 0,3,6,9
> > > > >>>>>>>> 1 => 1,4,7,10
> > > > >>>>>>>> 2 => 2,5,8,11
> > > > >>>>>>>>
> > > > >>>>>>>> Say your hashcode is 8. 8%3 => 2  before so consumer for
> > > > partition 2
> > > > >>>>>>>> has
> > > > >>>>>>>> it.
> > > > >>>>>>>> Now you you have 12 partitions so 8%12 => 8, so it goes into
> > > > >>>>>>>> partition
> > > > >>>>>>>> 8
> > > > >>>>>>>> which is assigned to the same consumer
> > > > >>>>>>>> who had 2 before and therefore knows the key.
> > > > >>>>>>>>
> > > > >>>>>>>> Userland reshuffeling is there as an options. And it does
> > > exactly
> > > > >>>>>>>> what
> > > > >>>>>>>> I
> > > > >>>>>>>> suggest. And I think its the perfect strategie. All I am
> > > > suggestion
> > > > >>>>>>>> is
> > > > >>>>>>>> broker side support to switch the producers to the newly
> > > > partitioned
> > > > >>>>>>>> topic.
> > > > >>>>>>>> Then the old (to few partition topic) can go away.  Remember
> > the
> > > > >>>>>>>> list
> > > > >>>>>>>> of
> > > > >>>>>>>> steps in the beginning of this thread. If one has broker
> > support
> > > > for
> > > > >>>>>>>> all
> > > > >>>>>>>> where its required and streams support for those that aren’t
> > > > >>>>>>>> necessarily.
> > > > >>>>>>>> Then one has solved the problem.
> > > > >>>>>>>> I repeat it because I think its important. I am really happy
> > > that
> > > > >>>>>>>> you
> > > > >>>>>>>> brought that up! because its 100% what I want just with the
> > > > >>>>>>>> differences
> > > > >>>>>>>> to
> > > > >>>>>>>> have an option to discard the to small topic later (after
> all
> > > > >>>>>>>> consumers
> > > > >>>>>>>> adapted). And to have order correct there. I need broker
> > support
> > > > >>>>>>>> managing
> > > > >>>>>>>> the copy process + the produces and fence them against each
> > > > other. I
> > > > >>>>>>>> also
> > > > >>>>>>>> repeat. the copy process can run for weeks in the worst
> case.
> > > > >>>>>>>> Copying
> > > > >>>>>>>> the
> > > > >>>>>>>> data is not the longest task migrating consumers might very
> > well
> > > > be.
> > > > >>>>>>>> Once all consumers switched and copying is really up to date
> > > > (think
> > > > >>>>>>>> ISR
> > > > >>>>>>>> like up to date) only then we stop the producer, wait for
> the
> > > copy
> > > > >>>>>>>> to
> > > > >>>>>>>> finish and use the new topic for producing.
> > > > >>>>>>>>
> > > > >>>>>>>> After this the topic is perfect in shape. and no one needs
> to
> > > > worry
> > > > >>>>>>>> about
> > > > >>>>>>>> complicated stuff. (old keys hanging around might arrive in
> > some
> > > > >>>>>>>> other
> > > > >>>>>>>> topic later.....). can only imagine how many tricky bugs
> gonna
> > > > >>>>>>>> arrive
> > > > >>>>>>>> after
> > > > >>>>>>>> someone had grown and shrunken is topic 10 times.
> > > > >>>>>>>>
> > > > >>>>>>>>
> > > > >>>>>>>>
> > > > >>>>>>>>
> > > > >>>>>>>>
> > > > >>>>>>>>
> > > > >>>>>>>> 54. "The other thing I wanted to mention is that I believe
> the
> > > > >>>>>>>> current
> > > > >>>>>>>>
> > > > >>>>>>>> suggestion (without copying data over) can be implemented in
> > > pure
> > > > >>>>>>>>> userland
> > > > >>>>>>>>> with a custom partitioner and a small feedbackloop from
> > > > >>>>>>>>> ProduceResponse
> > > > >>>>>>>>> =>
> > > > >>>>>>>>> Partitionier in coorporation with a change management
> > system."
> > > I
> > > > am
> > > > >>>>>>>>> not
> > > > >>>>>>>>> sure a customized partitioner itself solves the problem. We
> > > > >>>>>>>>> probably
> > > > >>>>>>>>> need
> > > > >>>>>>>>> some broker side support to enforce when the new partitions
> > can
> > > > be
> > > > >>>>>>>>> used.
> > > > >>>>>>>>> We
> > > > >>>>>>>>> also need some support on the consumer/kstream side to
> > preserve
> > > > the
> > > > >>>>>>>>> per
> > > > >>>>>>>>> key
> > > > >>>>>>>>> ordering and potentially migrate the processing state. This
> > is
> > > > not
> > > > >>>>>>>>> trivial
> > > > >>>>>>>>> and I am not sure if it's ideal to fully push to the
> > > application
> > > > >>>>>>>>> space.
> > > > >>>>>>>>>
> > > > >>>>>>>>> Broker support is defenitly the preferred way here. I have
> > > > nothing
> > > > >>>>>>>>>
> > > > >>>>>>>>> against
> > > > >>>>>>>> broker support.
> > > > >>>>>>>> I tried to say that for what I would preffer - copying the
> > data
> > > > >>>>>>>> over,
> > > > >>>>>>>> at
> > > > >>>>>>>> least for log compacted topics -
> > > > >>>>>>>> I would require more broker support than the KIP currently
> > > offers.
> > > > >>>>>>>>
> > > > >>>>>>>>
> > > > >>>>>>>>
> > > > >>>>>>>> Jun
> > > > >>>>>>>>
> > > > >>>>>>>> On Tue, Mar 6, 2018 at 10:33 PM, Jan Filipiak <
> > > > >>>>>>>>> Jan.Filipiak@trivago.com
> > > > >>>>>>>>> wrote:
> > > > >>>>>>>>>
> > > > >>>>>>>>> Hi Dong,
> > > > >>>>>>>>>
> > > > >>>>>>>>> are you actually reading my emails, or are you just using
> the
> > > > >>>>>>>>> thread I
> > > > >>>>>>>>>
> > > > >>>>>>>>>> started for general announcements regarding the KIP?
> > > > >>>>>>>>>>
> > > > >>>>>>>>>> I tried to argue really hard against linear hashing.
> Growing
> > > the
> > > > >>>>>>>>>> topic
> > > > >>>>>>>>>> by
> > > > >>>>>>>>>> an integer factor does not require any state
> redistribution
> > at
> > > > >>>>>>>>>> all. I
> > > > >>>>>>>>>> fail
> > > > >>>>>>>>>> to see completely where linear hashing helps on log
> > compacted
> > > > >>>>>>>>>> topics.
> > > > >>>>>>>>>>
> > > > >>>>>>>>>> If you are not willing to explain to me what I might be
> > > > >>>>>>>>>> overlooking:
> > > > >>>>>>>>>> that
> > > > >>>>>>>>>> is fine.
> > > > >>>>>>>>>> But I ask you to not reply to my emails then. Please
> > > understand
> > > > my
> > > > >>>>>>>>>> frustration with this.
> > > > >>>>>>>>>>
> > > > >>>>>>>>>> Best Jan
> > > > >>>>>>>>>>
> > > > >>>>>>>>>>
> > > > >>>>>>>>>>
> > > > >>>>>>>>>> On 06.03.2018 19:38, Dong Lin wrote:
> > > > >>>>>>>>>>
> > > > >>>>>>>>>> Hi everyone,
> > > > >>>>>>>>>>
> > > > >>>>>>>>>> Thanks for all the comments! It appears that everyone
> > prefers
> > > > >>>>>>>>>> linear
> > > > >>>>>>>>>>
> > > > >>>>>>>>>>> hashing because it reduces the amount of state that needs
> > to
> > > be
> > > > >>>>>>>>>>> moved
> > > > >>>>>>>>>>> between consumers (for stream processing). The KIP has
> been
> > > > >>>>>>>>>>> updated
> > > > >>>>>>>>>>> to
> > > > >>>>>>>>>>> use
> > > > >>>>>>>>>>> linear hashing.
> > > > >>>>>>>>>>>
> > > > >>>>>>>>>>> Regarding the migration endeavor: it seems that migrating
> > > > >>>>>>>>>>> producer
> > > > >>>>>>>>>>> library
> > > > >>>>>>>>>>> to use linear hashing should be pretty straightforward
> > > without
> > > > >>>>>>>>>>> much operational endeavor. If we don't upgrade client
> > library
> > > > to
> > > > >>>>>>>>>>> use
> > > > >>>>>>>>>>> this
> > > > >>>>>>>>>>> KIP, we can not support in-order delivery after partition
> > is
> > > > >>>>>>>>>>> changed
> > > > >>>>>>>>>>> anyway. Suppose we upgrade client library to use this
> KIP,
> > if
> > > > >>>>>>>>>>> partition
> > > > >>>>>>>>>>> number is not changed, the key -> partition mapping will
> be
> > > > >>>>>>>>>>> exactly
> > > > >>>>>>>>>>> the
> > > > >>>>>>>>>>> same as it is now because it is still determined using
> > > > >>>>>>>>>>> murmur_hash(key)
> > > > >>>>>>>>>>> %
> > > > >>>>>>>>>>> original_partition_num. In other words, this change is
> > > backward
> > > > >>>>>>>>>>> compatible.
> > > > >>>>>>>>>>>
> > > > >>>>>>>>>>> Regarding the load distribution: if we use linear
> hashing,
> > > the
> > > > >>>>>>>>>>> load
> > > > >>>>>>>>>>> may
> > > > >>>>>>>>>>> be
> > > > >>>>>>>>>>> unevenly distributed because those partitions which are
> not
> > > > split
> > > > >>>>>>>>>>> may
> > > > >>>>>>>>>>> receive twice as much traffic as other partitions that
> are
> > > > split.
> > > > >>>>>>>>>>> This
> > > > >>>>>>>>>>> issue can be mitigated by creating topic with partitions
> > that
> > > > are
> > > > >>>>>>>>>>> several
> > > > >>>>>>>>>>> times the number of consumers. And there will be no
> > imbalance
> > > > if
> > > > >>>>>>>>>>> the
> > > > >>>>>>>>>>> partition number is always doubled. So this imbalance
> seems
> > > > >>>>>>>>>>> acceptable.
> > > > >>>>>>>>>>>
> > > > >>>>>>>>>>> Regarding storing the partition strategy as per-topic
> > config:
> > > > It
> > > > >>>>>>>>>>> seems
> > > > >>>>>>>>>>> not
> > > > >>>>>>>>>>> necessary since we can still use murmur_hash as the
> default
> > > > hash
> > > > >>>>>>>>>>> function
> > > > >>>>>>>>>>> and additionally apply the linear hashing algorithm if
> the
> > > > >>>>>>>>>>> partition
> > > > >>>>>>>>>>> number
> > > > >>>>>>>>>>> has increased. Not sure if there is any use-case for
> > producer
> > > > to
> > > > >>>>>>>>>>> use a
> > > > >>>>>>>>>>> different hash function. Jason, can you check if there is
> > > some
> > > > >>>>>>>>>>> use-case
> > > > >>>>>>>>>>> that I missed for using the per-topic partition strategy?
> > > > >>>>>>>>>>>
> > > > >>>>>>>>>>> Regarding how to reduce latency (due to state store/load)
> > in
> > > > >>>>>>>>>>> stream
> > > > >>>>>>>>>>> processing consumer when partition number changes: I need
> > to
> > > > read
> > > > >>>>>>>>>>> the
> > > > >>>>>>>>>>> Kafka
> > > > >>>>>>>>>>> Stream code to understand how Kafka Stream currently
> > migrate
> > > > >>>>>>>>>>> state
> > > > >>>>>>>>>>> between
> > > > >>>>>>>>>>> consumers when the application is added/removed for a
> given
> > > > job.
> > > > >>>>>>>>>>> I
> > > > >>>>>>>>>>> will
> > > > >>>>>>>>>>> reply after I finish reading the documentation and code.
> > > > >>>>>>>>>>>
> > > > >>>>>>>>>>>
> > > > >>>>>>>>>>> Thanks,
> > > > >>>>>>>>>>> Dong
> > > > >>>>>>>>>>>
> > > > >>>>>>>>>>>
> > > > >>>>>>>>>>> On Mon, Mar 5, 2018 at 10:43 AM, Jason Gustafson <
> > > > >>>>>>>>>>> jason@confluent.io>
> > > > >>>>>>>>>>> wrote:
> > > > >>>>>>>>>>>
> > > > >>>>>>>>>>> Great discussion. I think I'm wondering whether we can
> > > continue
> > > > >>>>>>>>>>> to
> > > > >>>>>>>>>>> leave
> > > > >>>>>>>>>>>
> > > > >>>>>>>>>>> Kafka agnostic to the partitioning strategy. The
> challenge
> > is
> > > > >>>>>>>>>>>
> > > > >>>>>>>>>>> communicating
> > > > >>>>>>>>>>>> the partitioning logic from producers to consumers so
> that
> > > the
> > > > >>>>>>>>>>>> dependencies
> > > > >>>>>>>>>>>> between each epoch can be determined. For the sake of
> > > > >>>>>>>>>>>> discussion,
> > > > >>>>>>>>>>>> imagine
> > > > >>>>>>>>>>>> you did something like the following:
> > > > >>>>>>>>>>>>
> > > > >>>>>>>>>>>> 1. The name (and perhaps version) of a partitioning
> > strategy
> > > > is
> > > > >>>>>>>>>>>> stored
> > > > >>>>>>>>>>>> in
> > > > >>>>>>>>>>>> topic configuration when a topic is created.
> > > > >>>>>>>>>>>> 2. The producer looks up the partitioning strategy
> before
> > > > >>>>>>>>>>>> writing
> > > > >>>>>>>>>>>> to
> > > > >>>>>>>>>>>> a
> > > > >>>>>>>>>>>> topic and includes it in the produce request (for
> > fencing).
> > > If
> > > > >>>>>>>>>>>> it
> > > > >>>>>>>>>>>> doesn't
> > > > >>>>>>>>>>>> have an implementation for the configured strategy, it
> > > fails.
> > > > >>>>>>>>>>>> 3. The consumer also looks up the partitioning strategy
> > and
> > > > >>>>>>>>>>>> uses it
> > > > >>>>>>>>>>>> to
> > > > >>>>>>>>>>>> determine dependencies when reading a new epoch. It
> could
> > > > either
> > > > >>>>>>>>>>>> fail
> > > > >>>>>>>>>>>> or
> > > > >>>>>>>>>>>> make the most conservative dependency assumptions if it
> > > > doesn't
> > > > >>>>>>>>>>>> know
> > > > >>>>>>>>>>>> how
> > > > >>>>>>>>>>>> to
> > > > >>>>>>>>>>>> implement the partitioning strategy. For the consumer,
> the
> > > new
> > > > >>>>>>>>>>>> interface
> > > > >>>>>>>>>>>> might look something like this:
> > > > >>>>>>>>>>>>
> > > > >>>>>>>>>>>> // Return the partition dependencies following an epoch
> > bump
> > > > >>>>>>>>>>>> Map<Integer, List<Integer>> dependencies(int
> > > > >>>>>>>>>>>> numPartitionsBeforeEpochBump,
> > > > >>>>>>>>>>>> int numPartitionsAfterEpochBump)
> > > > >>>>>>>>>>>>
> > > > >>>>>>>>>>>> The unordered case then is just a particular
> > implementation
> > > > >>>>>>>>>>>> which
> > > > >>>>>>>>>>>> never
> > > > >>>>>>>>>>>> has
> > > > >>>>>>>>>>>> any epoch dependencies. To implement this, we would need
> > > some
> > > > >>>>>>>>>>>> way
> > > > >>>>>>>>>>>> for
> > > > >>>>>>>>>>>> the
> > > > >>>>>>>>>>>> consumer to find out how many partitions there were in
> > each
> > > > >>>>>>>>>>>> epoch,
> > > > >>>>>>>>>>>> but
> > > > >>>>>>>>>>>> maybe that's not too unreasonable.
> > > > >>>>>>>>>>>>
> > > > >>>>>>>>>>>> Thanks,
> > > > >>>>>>>>>>>> Jason
> > > > >>>>>>>>>>>>
> > > > >>>>>>>>>>>>
> > > > >>>>>>>>>>>> On Mon, Mar 5, 2018 at 4:51 AM, Jan Filipiak <
> > > > >>>>>>>>>>>> Jan.Filipiak@trivago.com
> > > > >>>>>>>>>>>> wrote:
> > > > >>>>>>>>>>>>
> > > > >>>>>>>>>>>> Hi Dong
> > > > >>>>>>>>>>>>
> > > > >>>>>>>>>>>> thank you very much for your questions.
> > > > >>>>>>>>>>>>
> > > > >>>>>>>>>>>> regarding the time spend copying data across:
> > > > >>>>>>>>>>>>> It is correct that copying data from a topic with one
> > > > partition
> > > > >>>>>>>>>>>>> mapping
> > > > >>>>>>>>>>>>>
> > > > >>>>>>>>>>>>> to
> > > > >>>>>>>>>>>>>
> > > > >>>>>>>>>>>>> a topic with a different partition mapping takes way
> > longer
> > > > >>>>>>>>>>>>> than
> > > > >>>>>>>>>>>>>
> > > > >>>>>>>>>>>> we
> > > > >>>>>>>>>>>> can
> > > > >>>>>>>>>>>>
> > > > >>>>>>>>>>>> stop producers. Tens of minutes is a very optimistic
> > > estimate
> > > > >>>>>>>>>>>> here.
> > > > >>>>>>>>>>>>
> > > > >>>>>>>>>>>>> Many
> > > > >>>>>>>>>>>>> people can not afford copy full steam and therefore
> will
> > > have
> > > > >>>>>>>>>>>>> some
> > > > >>>>>>>>>>>>> rate
> > > > >>>>>>>>>>>>> limiting in place, this can bump the timespan into the
> > > day's.
> > > > >>>>>>>>>>>>> The
> > > > >>>>>>>>>>>>> good
> > > > >>>>>>>>>>>>>
> > > > >>>>>>>>>>>>> part
> > > > >>>>>>>>>>>>>
> > > > >>>>>>>>>>>>> is that the vast majority of the data can be copied
> while
> > > the
> > > > >>>>>>>>>>>>>
> > > > >>>>>>>>>>>> producers
> > > > >>>>>>>>>>>>
> > > > >>>>>>>>>>>> are
> > > > >>>>>>>>>>>>
> > > > >>>>>>>>>>>>> still going. One can then, piggyback the consumers
> ontop
> > of
> > > > >>>>>>>>>>>>> this
> > > > >>>>>>>>>>>>>
> > > > >>>>>>>>>>>> timeframe,
> > > > >>>>>>>>>>>>
> > > > >>>>>>>>>>>>> by the method mentioned (provide them an mapping from
> > their
> > > > old
> > > > >>>>>>>>>>>>>
> > > > >>>>>>>>>>>> offsets
> > > > >>>>>>>>>>>>
> > > > >>>>>>>>>>>> to
> > > > >>>>>>>>>>>>
> > > > >>>>>>>>>>>>> new offsets in their repartitioned topics. In that way
> we
> > > > >>>>>>>>>>>>> separate
> > > > >>>>>>>>>>>>>
> > > > >>>>>>>>>>>> migration of consumers from migration of producers
> > > (decoupling
> > > > >>>>>>>>>>>>
> > > > >>>>>>>>>>>>> these
> > > > >>>>>>>>>>>>> is
> > > > >>>>>>>>>>>>> what kafka is strongest at). The time to actually swap
> > over
> > > > the
> > > > >>>>>>>>>>>>> producers
> > > > >>>>>>>>>>>>> should be kept minimal by ensuring that when a swap
> > attempt
> > > > is
> > > > >>>>>>>>>>>>> started
> > > > >>>>>>>>>>>>>
> > > > >>>>>>>>>>>>> the
> > > > >>>>>>>>>>>>>
> > > > >>>>>>>>>>>>> consumer copying over should be very close to the log
> end
> > > and
> > > > >>>>>>>>>>>>> is
> > > > >>>>>>>>>>>>>
> > > > >>>>>>>>>>>> expected
> > > > >>>>>>>>>>>>
> > > > >>>>>>>>>>>>> to finish within the next fetch. The operation should
> > have
> > > a
> > > > >>>>>>>>>>>>> time-out
> > > > >>>>>>>>>>>>> and
> > > > >>>>>>>>>>>>> should be "reattemtable".
> > > > >>>>>>>>>>>>>
> > > > >>>>>>>>>>>>> Importance of logcompaction:
> > > > >>>>>>>>>>>>> If a producer produces key A, to partiton 0, its
> forever
> > > > gonna
> > > > >>>>>>>>>>>>> be
> > > > >>>>>>>>>>>>> there,
> > > > >>>>>>>>>>>>> unless it gets deleted. The record might sit in there
> for
> > > > >>>>>>>>>>>>> years. A
> > > > >>>>>>>>>>>>> new
> > > > >>>>>>>>>>>>> producer started with the new partitions will fail to
> > > delete
> > > > >>>>>>>>>>>>> the
> > > > >>>>>>>>>>>>> record
> > > > >>>>>>>>>>>>>
> > > > >>>>>>>>>>>>> in
> > > > >>>>>>>>>>>>>
> > > > >>>>>>>>>>>>> the correct partition. Th record will be there forever
> > and
> > > > one
> > > > >>>>>>>>>>>>> can
> > > > >>>>>>>>>>>>>
> > > > >>>>>>>>>>>> not
> > > > >>>>>>>>>>>>
> > > > >>>>>>>>>>>> reliable bootstrap new consumers. I cannot see how
> linear
> > > > >>>>>>>>>>>> hashing
> > > > >>>>>>>>>>>>
> > > > >>>>>>>>>>>>> can
> > > > >>>>>>>>>>>>>
> > > > >>>>>>>>>>>>> solve
> > > > >>>>>>>>>>>>>
> > > > >>>>>>>>>>>>> this.
> > > > >>>>>>>>>>>>>
> > > > >>>>>>>>>>>> Regarding your skipping of userland copying:
> > > > >>>>>>>>>>>>
> > > > >>>>>>>>>>>>> 100%, copying the data across in userland is, as far
> as i
> > > can
> > > > >>>>>>>>>>>>> see,
> > > > >>>>>>>>>>>>> only
> > > > >>>>>>>>>>>>> a
> > > > >>>>>>>>>>>>> usecase for log compacted topics. Even for
> logcompaction
> > +
> > > > >>>>>>>>>>>>> retentions
> > > > >>>>>>>>>>>>> it
> > > > >>>>>>>>>>>>> should only be opt-in. Why did I bring it up? I think
> log
> > > > >>>>>>>>>>>>> compaction
> > > > >>>>>>>>>>>>> is
> > > > >>>>>>>>>>>>> a
> > > > >>>>>>>>>>>>> very important feature to really embrace kafka as a
> "data
> > > > >>>>>>>>>>>>> plattform".
> > > > >>>>>>>>>>>>> The
> > > > >>>>>>>>>>>>> point I also want to make is that copying data this way
> > is
> > > > >>>>>>>>>>>>> completely
> > > > >>>>>>>>>>>>> inline with the kafka architecture. it only consists of
> > > > reading
> > > > >>>>>>>>>>>>> and
> > > > >>>>>>>>>>>>>
> > > > >>>>>>>>>>>>> writing
> > > > >>>>>>>>>>>>>
> > > > >>>>>>>>>>>>> to topics.
> > > > >>>>>>>>>>>>>
> > > > >>>>>>>>>>>> I hope it clarifies more why I think we should aim for
> > more
> > > > than
> > > > >>>>>>>>>>>>
> > > > >>>>>>>>>>>>> the
> > > > >>>>>>>>>>>>> current KIP. I fear that once the KIP is done not much
> > more
> > > > >>>>>>>>>>>>> effort
> > > > >>>>>>>>>>>>> will
> > > > >>>>>>>>>>>>>
> > > > >>>>>>>>>>>>> be
> > > > >>>>>>>>>>>>>
> > > > >>>>>>>>>>>>> taken.
> > > > >>>>>>>>>>>>>
> > > > >>>>>>>>>>>>
> > > > >>>>>>>>>>>> On 04.03.2018 02:28, Dong Lin wrote:
> > > > >>>>>>>>>>>>>
> > > > >>>>>>>>>>>>> Hey Jan,
> > > > >>>>>>>>>>>>>
> > > > >>>>>>>>>>>>> In the current proposal, the consumer will be blocked
> on
> > > > >>>>>>>>>>>>> waiting
> > > > >>>>>>>>>>>>> for
> > > > >>>>>>>>>>>>>
> > > > >>>>>>>>>>>>> other
> > > > >>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>> consumers of the group to consume up to a given
> offset.
> > In
> > > > >>>>>>>>>>>>>> most
> > > > >>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>> cases,
> > > > >>>>>>>>>>>>> all
> > > > >>>>>>>>>>>>> consumers should be close to the LEO of the partitions
> > when
> > > > the
> > > > >>>>>>>>>>>>> partition
> > > > >>>>>>>>>>>>> expansion happens. Thus the time waiting should not be
> > long
> > > > >>>>>>>>>>>>> e.g.
> > > > >>>>>>>>>>>>> on
> > > > >>>>>>>>>>>>> the
> > > > >>>>>>>>>>>>>
> > > > >>>>>>>>>>>>> order of seconds. On the other hand, it may take a long
> > > time
> > > > to
> > > > >>>>>>>>>>>>> wait
> > > > >>>>>>>>>>>>>
> > > > >>>>>>>>>>>>> for
> > > > >>>>>>>>>>>>>> the entire partition to be copied -- the amount of
> time
> > is
> > > > >>>>>>>>>>>>>> proportional
> > > > >>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>> to
> > > > >>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>> the amount of existing data in the partition, which
> can
> > > take
> > > > >>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>> tens of
> > > > >>>>>>>>>>>>>
> > > > >>>>>>>>>>>>> minutes. So the amount of time that we stop consumers
> may
> > > not
> > > > >>>>>>>>>>>>> be
> > > > >>>>>>>>>>>>> on
> > > > >>>>>>>>>>>>>
> > > > >>>>>>>>>>>>> the
> > > > >>>>>>>>>>>>>> same order of magnitude.
> > > > >>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>> If we can implement this suggestion without copying
> data
> > > > over
> > > > >>>>>>>>>>>>>> in
> > > > >>>>>>>>>>>>>> purse
> > > > >>>>>>>>>>>>>> userland, it will be much more valuable. Do you have
> > ideas
> > > > on
> > > > >>>>>>>>>>>>>> how
> > > > >>>>>>>>>>>>>> this
> > > > >>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>> can
> > > > >>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>> be done?
> > > > >>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>> Not sure why the current KIP not help people who depend
> > on
> > > > log
> > > > >>>>>>>>>>>>>
> > > > >>>>>>>>>>>>> compaction.
> > > > >>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>> Could you elaborate more on this point?
> > > > >>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>> Thanks,
> > > > >>>>>>>>>>>>>
> > > > >>>>>>>>>>>>> Dong
> > > > >>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>> On Wed, Feb 28, 2018 at 10:55 PM, Jan
> > > > >>>>>>>>>>>>>> Filipiak<Jan.Filipiak@trivago.
> > > > >>>>>>>>>>>>>> com
> > > > >>>>>>>>>>>>>> wrote:
> > > > >>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>> Hi Dong,
> > > > >>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>> I tried to focus on what the steps are one can
> currently
> > > > >>>>>>>>>>>>>> perform
> > > > >>>>>>>>>>>>>> to
> > > > >>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>> expand
> > > > >>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>> or shrink a keyed topic while maintaining a top notch
> > > > >>>>>>>>>>>>>>> semantics.
> > > > >>>>>>>>>>>>>>> I can understand that there might be confusion about
> > > > >>>>>>>>>>>>>>> "stopping
> > > > >>>>>>>>>>>>>>> the
> > > > >>>>>>>>>>>>>>> consumer". It is exactly the same as proposed in the
> > KIP.
> > > > >>>>>>>>>>>>>>> there
> > > > >>>>>>>>>>>>>>> needs
> > > > >>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>> to
> > > > >>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>> be
> > > > >>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>> a time the producers agree on the new partitioning.
> The
> > > > extra
> > > > >>>>>>>>>>>>>
> > > > >>>>>>>>>>>>> semantics I
> > > > >>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>> want to put in there is that we have a possibility to
> > > wait
> > > > >>>>>>>>>>>>>>> until
> > > > >>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>> all
> > > > >>>>>>>>>>>>>
> > > > >>>>>>>>>>>>> the
> > > > >>>>>>>>>>>>>
> > > > >>>>>>>>>>>>> existing data
> > > > >>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>> is copied over into the new partitioning scheme. When
> I
> > > say
> > > > >>>>>>>>>>>>> stopping
> > > > >>>>>>>>>>>>>
> > > > >>>>>>>>>>>>> I
> > > > >>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>> think more of having a memory barrier that ensures
> the
> > > > >>>>>>>>>>>>>>> ordering. I
> > > > >>>>>>>>>>>>>>> am
> > > > >>>>>>>>>>>>>>> still
> > > > >>>>>>>>>>>>>>> aming for latencies  on the scale of leader
> failovers.
> > > > >>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>> Consumers have to explicitly adapt the new
> partitioning
> > > > >>>>>>>>>>>>>>> scheme
> > > > >>>>>>>>>>>>>>> in
> > > > >>>>>>>>>>>>>>> the
> > > > >>>>>>>>>>>>>>> above scenario. The reason is that in these cases
> where
> > > you
> > > > >>>>>>>>>>>>>>> are
> > > > >>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>> dependent
> > > > >>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>> on a particular partitioning scheme, you also have
> > other
> > > > >>>>>>>>>>>>>>> topics
> > > > >>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>> that
> > > > >>>>>>>>>>>>>
> > > > >>>>>>>>>>>>> have
> > > > >>>>>>>>>>>>>
> > > > >>>>>>>>>>>>> co-partition enforcements or the kind -frequently.
> > > Therefore
> > > > >>>>>>>>>>>>>> all
> > > > >>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>> your
> > > > >>>>>>>>>>>>>
> > > > >>>>>>>>>>>>> other
> > > > >>>>>>>>>>>>>
> > > > >>>>>>>>>>>>> input topics might need to grow accordingly.
> > > > >>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>> What I was suggesting was to streamline all these
> > > > operations
> > > > >>>>>>>>>>>>>>> as
> > > > >>>>>>>>>>>>>>> best
> > > > >>>>>>>>>>>>>>> as
> > > > >>>>>>>>>>>>>>> possible to have "real" partition grow and shrinkage
> > > going
> > > > >>>>>>>>>>>>>>> on.
> > > > >>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>> Migrating
> > > > >>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>> the producers to a new partitioning scheme can be
> much
> > > more
> > > > >>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>> streamlined
> > > > >>>>>>>>>>>>>
> > > > >>>>>>>>>>>>> with proper broker support for this. Migrating consumer
> > is
> > > a
> > > > >>>>>>>>>>>>> step
> > > > >>>>>>>>>>>>>
> > > > >>>>>>>>>>>>> that
> > > > >>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>> might be made completly unnecessary if - for example
> > > > streams
> > > > >>>>>>>>>>>>>>> -
> > > > >>>>>>>>>>>>>>> takes
> > > > >>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>> the
> > > > >>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>> gcd as partitioning scheme instead of enforcing 1 to
> 1.
> > > > >>>>>>>>>>>>>>> Connect
> > > > >>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>> consumers
> > > > >>>>>>>>>>>>>
> > > > >>>>>>>>>>>>> and other consumers should be fine anyways.
> > > > >>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>> I hope this makes more clear where I was aiming at.
> The
> > > rest
> > > > >>>>>>>>>>>>> needs
> > > > >>>>>>>>>>>>>
> > > > >>>>>>>>>>>>> to
> > > > >>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>> be
> > > > >>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>> figured out. The only danger i see is that when we
> are
> > > > >>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>> introducing
> > > > >>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>> this
> > > > >>>>>>>>>>>>>
> > > > >>>>>>>>>>>>> feature as supposed in the KIP, it wont help any people
> > > > >>>>>>>>>>>>> depending
> > > > >>>>>>>>>>>>> on
> > > > >>>>>>>>>>>>>
> > > > >>>>>>>>>>>>> log
> > > > >>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>> compaction.
> > > > >>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>> The other thing I wanted to mention is that I believe
> > the
> > > > >>>>>>>>>>>>> current
> > > > >>>>>>>>>>>>>
> > > > >>>>>>>>>>>>> suggestion (without copying data over) can be
> implemented
> > > in
> > > > >>>>>>>>>>>>>> pure
> > > > >>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>> userland
> > > > >>>>>>>>>>>>>>> with a custom partitioner and a small feedbackloop
> from
> > > > >>>>>>>>>>>>>>> ProduceResponse
> > > > >>>>>>>>>>>>>>> =>
> > > > >>>>>>>>>>>>>>> Partitionier in coorporation with a change management
> > > > system.
> > > > >>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>> Best Jan
> > > > >>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>> On 28.02.2018 07:13, Dong Lin wrote:
> > > > >>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>> Hey Jan,
> > > > >>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>> I am not sure if it is acceptable for producer to be
> > > > stopped
> > > > >>>>>>>>>>>>>>> for a
> > > > >>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>> while,
> > > > >>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>> particularly for online application which requires
> low
> > > > >>>>>>>>>>>>>>>> latency. I
> > > > >>>>>>>>>>>>>>>> am
> > > > >>>>>>>>>>>>>>>> also
> > > > >>>>>>>>>>>>>>>> not sure how consumers can switch to a new topic.
> Does
> > > > user
> > > > >>>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>> application
> > > > >>>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>> needs to explicitly specify a different topic for
> > > > >>>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>> producer/consumer
> > > > >>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>> to
> > > > >>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>> subscribe to? It will be helpful for discussion if you
> > can
> > > > >>>>>>>>>>>>> provide
> > > > >>>>>>>>>>>>>
> > > > >>>>>>>>>>>>> more
> > > > >>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>> detail on the interface change for this solution.
> > > > >>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>> Thanks,
> > > > >>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>> Dong
> > > > >>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>> On Mon, Feb 26, 2018 at 12:48 AM, Jan
> > > > >>>>>>>>>>>>>>>> Filipiak<Jan.Filipiak@trivago.
> > > > >>>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>> com
> > > > >>>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>> wrote:
> > > > >>>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>> Hi,
> > > > >>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>> just want to throw my though in. In general the
> > > > functionality
> > > > >>>>>>>>>>>>>> is
> > > > >>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>> very
> > > > >>>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>> usefull, we should though not try to find the
> > > architecture
> > > > >>>>>>>>>>>>>>>> to
> > > > >>>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>> hard
> > > > >>>>>>>>>>>>>>>>> while
> > > > >>>>>>>>>>>>>>>>> implementing.
> > > > >>>>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>>> The manual steps would be to
> > > > >>>>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>>> create a new topic
> > > > >>>>>>>>>>>>>>>>> the mirrormake from the new old topic to the new
> > topic
> > > > >>>>>>>>>>>>>>>>> wait for mirror making to catch up.
> > > > >>>>>>>>>>>>>>>>> then put the consumers onto the new topic
> > > > >>>>>>>>>>>>>>>>>            (having mirrormaker spit out a mapping
> > from
> > > > old
> > > > >>>>>>>>>>>>>>>>> offsets to
> > > > >>>>>>>>>>>>>>>>> new
> > > > >>>>>>>>>>>>>>>>> offsets:
> > > > >>>>>>>>>>>>>>>>>                if topic is increased by factor X
> > there
> > > is
> > > > >>>>>>>>>>>>>>>>> gonna
> > > > >>>>>>>>>>>>>>>>> be a
> > > > >>>>>>>>>>>>>>>>> clean
> > > > >>>>>>>>>>>>>>>>> mapping from 1 offset in the old topic to X offsets
> > in
> > > > the
> > > > >>>>>>>>>>>>>>>>> new
> > > > >>>>>>>>>>>>>>>>> topic,
> > > > >>>>>>>>>>>>>>>>>                if there is no factor then there is
> no
> > > > >>>>>>>>>>>>>>>>> chance to
> > > > >>>>>>>>>>>>>>>>> generate a
> > > > >>>>>>>>>>>>>>>>> mapping that can be reasonable used for continuing)
> > > > >>>>>>>>>>>>>>>>>            make consumers stop at appropriate
> points
> > > and
> > > > >>>>>>>>>>>>>>>>> continue
> > > > >>>>>>>>>>>>>>>>> consumption
> > > > >>>>>>>>>>>>>>>>> with offsets from the mapping.
> > > > >>>>>>>>>>>>>>>>> have the producers stop for a minimal time.
> > > > >>>>>>>>>>>>>>>>> wait for mirrormaker to finish
> > > > >>>>>>>>>>>>>>>>> let producer produce with the new metadata.
> > > > >>>>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>>> Instead of implementing the approach suggest in the
> > KIP
> > > > >>>>>>>>>>>>>>>>> which
> > > > >>>>>>>>>>>>>>>>> will
> > > > >>>>>>>>>>>>>>>>> leave
> > > > >>>>>>>>>>>>>>>>> log compacted topic completely crumbled and
> unusable.
> > > > >>>>>>>>>>>>>>>>> I would much rather try to build infrastructure to
> > > > support
> > > > >>>>>>>>>>>>>>>>> the
> > > > >>>>>>>>>>>>>>>>> mentioned
> > > > >>>>>>>>>>>>>>>>> above operations more smoothly.
> > > > >>>>>>>>>>>>>>>>> Especially having producers stop and use another
> > topic
> > > is
> > > > >>>>>>>>>>>>>>>>> difficult
> > > > >>>>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>>> and
> > > > >>>>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>>> it would be nice if one can trigger "invalid
> > metadata"
> > > > >>>>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>> exceptions
> > > > >>>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>> for
> > > > >>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>> them
> > > > >>>>>>>>>>>>>
> > > > >>>>>>>>>>>>> and
> > > > >>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>> if one could give topics aliases so that their
> produces
> > > > with
> > > > >>>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>>> the
> > > > >>>>>>>>>>>>>>>>> old
> > > > >>>>>>>>>>>>>>>>> topic
> > > > >>>>>>>>>>>>>>>>> will arrive in the new topic.
> > > > >>>>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>>> The downsides are obvious I guess ( having the same
> > > data
> > > > >>>>>>>>>>>>>>>>> twice
> > > > >>>>>>>>>>>>>>>>> for
> > > > >>>>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>>> the
> > > > >>>>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>>> transition period, but kafka tends to scale well
> with
> > > > >>>>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>> datasize).
> > > > >>>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>> So
> > > > >>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>> its a
> > > > >>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>> nicer fit into the architecture.
> > > > >>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>> I further want to argument that the functionality by
> > the
> > > > KIP
> > > > >>>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>>> can
> > > > >>>>>>>>>>>>>>>>> completely be implementing in "userland" with a
> > custom
> > > > >>>>>>>>>>>>>>>>> partitioner
> > > > >>>>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>>> that
> > > > >>>>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>>> handles the transition as needed. I would
> appreciate
> > if
> > > > >>>>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>> someone
> > > > >>>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>> could
> > > > >>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>> point
> > > > >>>>>>>>>>>>>
> > > > >>>>>>>>>>>>> out what a custom partitioner couldn't handle in this
> > case?
> > > > >>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>> With the above approach, shrinking a topic becomes
> the
> > > same
> > > > >>>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>>> steps.
> > > > >>>>>>>>>>>>>>>>> Without
> > > > >>>>>>>>>>>>>>>>> loosing keys in the discontinued partitions.
> > > > >>>>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>>> Would love to hear what everyone thinks.
> > > > >>>>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>>> Best Jan
> > > > >>>>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>>> On 11.02.2018 00:35, Dong Lin wrote:
> > > > >>>>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>>> Hi all,
> > > > >>>>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>>> I have created KIP-253: Support in-order message
> > > delivery
> > > > >>>>>>>>>>>>>>>>> with
> > > > >>>>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>>> partition
> > > > >>>>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>>> expansion. See
> > > > >>>>>>>>>>>>>>>>>> https://cwiki.apache.org/confl
> > > > >>>>>>>>>>>>>>>>>> uence/display/KAFKA/KIP-253%
> > > > >>>>>>>>>>>>>>>>>> 3A+Support+in-order+message+de
> > > > >>>>>>>>>>>>>>>>>> livery+with+partition+expansio
> > > > >>>>>>>>>>>>>>>>>> n
> > > > >>>>>>>>>>>>>>>>>> .
> > > > >>>>>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>>>> This KIP provides a way to allow messages of the
> > same
> > > > key
> > > > >>>>>>>>>>>>>>>>>> from
> > > > >>>>>>>>>>>>>>>>>> the
> > > > >>>>>>>>>>>>>>>>>> same
> > > > >>>>>>>>>>>>>>>>>> producer to be consumed in the same order they are
> > > > >>>>>>>>>>>>>>>>>> produced
> > > > >>>>>>>>>>>>>>>>>> even
> > > > >>>>>>>>>>>>>>>>>> if
> > > > >>>>>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>>>> we
> > > > >>>>>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>>>> expand partition of the topic.
> > > > >>>>>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>>> Thanks,
> > > > >>>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>> Dong
> > > > >>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>>>>
> > > > >>>>
> > > > >>
> > > > >>
> > > > >
> > > >
> > >
> >
>

Re: [DISCUSS] KIP-253: Support in-order message delivery with partition expansion

Posted by John Roesler <jo...@confluent.io>.
Hi Jun,

That's a good point.

Yeah, I don't think it would work too well for existing consumers in the
middle of gen 0 to try and switch to a newly backfilled prefix of gen 1.
They probably just need to finish up until they get to the end of gen 0 and
transition just as if there were no backfill available yet.

This isn't terrible, since consumer applications that care about scaling up
to match a freshly split partition would wait until after the backfill is
available to scale up. The consumer that starts out in gen=0, part=0 is
going to be stuck with part=0 and part=3 in gen=1 in my example regardless
of whether they finish scanning gen=0 before or after the backfill is
available.

The broker knowing when it's ok to delete gen 0, including its offset
mappings, is a big issue, though. I don't have any immediate ideas for
solving it, but it doesn't feel impossible. Hopefully, you agree this is
outside of KIP-253's scope, so maybe we don't need to worry about it right
now.

I do agree that reshuffling in KStreams effectively solves the scalability
problem as well, as it decouples the partition count (and the partition
scheme) upstream from the parallelism of the streams application. Likely,
we will do this in any case. I'm predominantly advocating for follow-on
work to enable backfill for the *other* Kafka users that are not KStreams.

Thanks for your consideration,
-John

On Tue, Mar 27, 2018 at 6:19 PM, Jun Rao <ju...@confluent.io> wrote:

> Hi, John,
>
> Thanks for the reply. I agree that the backfill approach works cleaner for
> newly started consumers. I am just not sure if it's a good primitive to
> support for existing consumers. One of the challenges that I see is the
> remapping of the offsets. In your approach, we need to copy the existing
> records from the partitions in generation 0 to generation 1. Those records
> will get different offsets in the new generation. The broker will have to
> store those offset mappings somewhere. When the backfill completes, you can
> delete generation 0's data. However, the broker can't throw away the offset
> mappings immediately since it doesn't know if there is any existing
> consumer still consuming generation 0's records. In a compacted topic, the
> broker probably can only safely remove the offset mappings when all records
> in generation 0 are removed by the cleaner. This may never happen though.
>
> If we reshuffle the input inside a KStreams job, it obviates the need for
> offset remapping on the broker.
>
> Jun
>
> On Tue, Mar 27, 2018 at 11:34 AM, John Roesler <jo...@confluent.io> wrote:
>
> > Hey Dong and Jun,
> >
> > Thanks for the thoughtful responses. If you don't mind, I'll mix my
> replies
> > together to try for a coherent response. I'm not too familiar with
> > mailing-list etiquette, though.
> >
> > I'm going to keep numbering my points because it makes it easy for you
> all
> > to respond.
> >
> > Point 1:
> > As I read it, KIP-253 is *just* about properly fencing the producers and
> > consumers so that you preserve the correct ordering of records during
> > partition expansion. This is clearly necessary regardless of anything
> else
> > we discuss. I think this whole discussion about backfill, consumers,
> > streams, etc., is beyond the scope of KIP-253. But it would be cumbersome
> > to start a new thread at this point.
> >
> > I had missed KIP-253's Proposed Change #9 among all the details... I
> think
> > this is a nice addition to the proposal. One thought is that it's
> actually
> > irrelevant whether the hash function is linear. This is simply an
> algorithm
> > for moving a key from one partition to another, so the type of hash
> > function need not be a precondition. In fact, it also doesn't matter
> > whether the topic is compacted or not, the algorithm works regardless.
> >
> > I think this is a good algorithm to keep in mind, as it might solve a
> > variety of problems, but it does have a downside: that the producer won't
> > know whether or not K1 was actually in P1, it just knows that K1 was in
> > P1's keyspace before the new epoch. Therefore, it will have to
> > pessimistically send (K1,null) to P1 just in case. But the next time K1
> > comes along, the producer *also* won't remember that it already retracted
> > K1 from P1, so it will have to send (K1,null) *again*. By extension,
> every
> > time the producer sends to P2, it will also have to send a tombstone to
> P1,
> > which is a pretty big burden. To make the situation worse, if there is a
> > second split, say P2 becomes P2 and P3, then any key Kx belonging to P3
> > will also have to be retracted from P2 *and* P1, since the producer can't
> > know whether Kx had been last written to P2 or P1. Over a long period of
> > time, this clearly becomes a issue, as the producer must send an
> arbitrary
> > number of retractions along with every update.
> >
> > In contrast, the proposed backfill operation has an end, and after it
> ends,
> > everyone can afford to forget that there ever was a different partition
> > layout.
> >
> > Really, though, figuring out how to split compacted topics is beyond the
> > scope of KIP-253, so I'm not sure #9 really even needs to be in this
> KIP...
> > We do need in-order delivery during partition expansion. It would be fine
> > by me to say that you *cannot* expand partitions of a log-compacted topic
> > and call it a day. I think it would be better to tackle that in another
> > KIP.
> >
> >
> > Point 2:
> > Regarding whether the consumer re-shuffles its inputs, this is always on
> > the table; any consumer who wants to re-shuffle its input is free to do
> so.
> > But this is currently not required. It's just that the current high-level
> > story with Kafka encourages the use of partitions as a unit of
> concurrency.
> > As long as consumers are single-threaded, they can happily consume a
> single
> > partition without concurrency control of any kind. This is a key aspect
> to
> > this system that lets folks design high-throughput systems on top of it
> > surprisingly easily. If all consumers were instead encouraged/required to
> > implement a repartition of their own, then the consumer becomes
> > significantly more complex, requiring either the consumer to first
> produce
> > to its own intermediate repartition topic or to ensure that consumer
> > threads have a reliable, high-bandwith channel of communication with
> every
> > other consumer thread.
> >
> > Either of those tradeoffs may be reasonable for a particular user of
> Kafka,
> > but I don't know if we're in a position to say that they are reasonable
> for
> > *every* user of Kafka.
> >
> >
> > Point 3:
> > Regarding Jun's point about this use case, "(3) stateful and maintaining
> > the
> > states in a local store", I agree that they may use a framework *like*
> > Kafka Streams, but that is not the same as using Kafka Streams. This is
> why
> > I think it's better to solve it in Core: because it is then solved for
> > KStreams and also for everything else that facilitates local state
> > maintenance. To me, Streams is a member of the category of "stream
> > processing frameworks", which is itself a subcategory of "things
> requiring
> > local state maintenence". I'm not sure if it makes sense to assert that
> > Streams is a sufficient and practical replacement for everything in
> "things
> > requiring local state maintenence".
> >
> > But, yes, I do agree that per-key ordering is an absolute requirement,
> > therefore I think that KIP-253 itself is a necessary step. Regarding the
> > coupling of the state store partitioning to the topic partitioning, yes,
> > this is an issue we are discussing solutions to right now. We may go
> ahead
> > and introduce an overpartition layer on our inputs to solve it, but then
> > again, if we get the ability to split partitions with backfill, we may
> not
> > need to!
> >
> >
> > Point 4:
> > On this:
> >
> > > Regarding thought 2: If we don't care about the stream use-case, then
> the
> > > current KIP probably has already addressed problem without requiring
> > > consumer to know the partition function. If we care about the stream
> > > use-case, we already need coordination across producers of different
> > > topics, i.e. the same partition function needs to be used by producers
> of
> > > topics A and B in order to join topics A and B. Thus, it might be
> > > reasonable to extend coordination a bit and say we need coordination
> > across
> > > clients (i.e. producer and consumer), such that consumer knows the
> > > partition function used by producer. If we do so, then we can let
> > consumer
> > > re-copy data for the change log topic using the same partition function
> > as
> > > producer. This approach has lower overhead as compared to having
> producer
> > > re-copy data of the input topic.
> > > Also, producer currently does not need to know the data already
> produced
> > to
> > > the topic. If we let producer split/merge partition, it would require
> > > producer to consume the existing data, which intuitively is the task of
> > > consumer.
> >
> >
> > I think we do care about use cases *like* Streams, I just don't think we
> > should rely on Streams to implement a feature of Core like partition
> > expansion.
> >
> > Note, though, that we (Streams) do not require coordination across
> > producers. If two topics are certified to be co-partitioned, then Streams
> > apps can make use of that knowledge to optimize their topology (skipping
> a
> > repartition). But if they don't know whether they are co-partitioned,
> then
> > they'd better go ahead and repartition within the topology. This is the
> > current state.
> >
> > A huge selling point of Kafka is enabling different parts of loosely
> > coupled organizations to produce and consume data independently. Some
> > coordination between producers and consumers is necessary, like
> > coordinating on the names of topics and their schemas. But Kafka's value
> > proposition w.r.t. ESBs, etc. is inversely proportional to the amount of
> > coordination required. I think it behooves us to be extremely skeptical
> > about introducing any coordination beyond correctness protocols.
> >
> > Asking producers and consumers, or even two different producers, to share
> > code like the partition function is a pretty huge ask. What if they are
> > using different languages?
> >
> > Comparing organizational overhead vs computational overhead, there are
> > maybe two orders of magnitude difference between them. In other words, I
> > would happily take on the (linear) overhead of having the producer
> re-copy
> > the data once during a re-partition in order to save the organizational
> > overhead of tying all the producers and consumers together across
> multiple
> > boundaries.
> >
> > On that last paragraph: note that the producer *did* know the data it
> > already produced. It handled it the first time around. Asking it to
> > re-produce it into a new partition layout is squarely within its scope of
> > capabilities. Contrast this with the alternative, asking the consumer to
> > re-partition the data. I think this is even less intuitive, when the
> > partition function belongs to the producer.
> >
> >
> > Point 5:
> > Dong asked this:
> >
> > > For stream use-case that needs to increase consumer number, the
> > > existing consumer can backfill the existing data in the change log
> topic
> > to
> > > the same change log topic with the new partition number, before the new
> > set
> > > of consumers bootstrap state from the new partitions of the change log
> > > topic, right?
> >
> >
> > In this sense, the "consumer" is actually the producer of the changelog
> > topic, so if we support partition expansion + backfill as a
> producer/broker
> > operation, then it would be very straightforward for Streams to split a
> > state store. As you say, they would simply instruct the broker to split
> the
> > changelog topic's partitions, then backfill. Once the backfill is ready,
> > they can create a new crop of StandbyTasks to bootstrap the more granular
> > state stores and finally switch over to them when they are ready.
> >
> > But this actually seems to be an argument in favor of split+backfill, so
> > maybe I missed the point.
> >
> > You also asked me to explain why copying the "input" topic is better than
> > copying the "changelog" topic. I think they are totally independent,
> > actually. For one thing, you can't depend on the existence of a
> "changelog"
> > topic in general, only within Streams, but Kafka's user base clearly
> > exceeds Streams's user base. Plus, you actually also can't depend on the
> > existence of a changelog topic within Streams, since that is an optional
> > feature of *some* state store implementations. Even in the situation
> where
> > you do have a changelog topic in Streams, there may be use cases where it
> > makes sense to expand the partitions of just the input, or just the
> > changelog.
> >
> > The ask for a Core feature of split+backfill is really about supporting
> the
> > use case of splitting partitions in log-compacted topics, regardless of
> > whether that topic is an "input" or a "changelog" or anything else for
> that
> > matter.
> >
> >
> > Point 6:
> > On the concern about the performance overhead of copying data between the
> > brokers, I think it's actually a bit overestimated. Splitting a topic's
> > partition is probably rare, certainly rarer in general than bootstrapping
> > new consumers on that topic. If "bootstrapping new consumers" means that
> > they have to re-shuffle the data before they consume it, then you wind up
> > copying the same record multiple times:
> >
> > (broker: input topic) -> (initial consumer) -> (broker: repartition
> topic)
> > -> (real consumer)
> >
> > That's 3x, and it's also 3x for every new record after the split as well,
> > since you don't get to stop repartitioning/reshuffling once you start.
> >
> > Whereas if you do a backfill in something like the procedure I outlined,
> > you only copy the prefix of the partition before the split, and you send
> it
> > once to the producer and then once to the new generation partition. Plus,
> > assuming we're splitting the partition for the benefit of consumers,
> > there's no reason we can't co-locate the post-split partitions on the
> same
> > host as the pre-split partition, making the second copy a local
> filesystem
> > operation.
> >
> > Even if you follow these two copies up with bootstrapping a new consumer,
> > it's still rare for this to occur, so you get to amortize these copies
> over
> > the lifetime of the topic, whereas a reshuffle just keeps making copies
> for
> > every new event.
> >
> > And finally, I really do think that regardless of any performance
> concerns
> > about this operation, if it preserves loose organizational coupling, it
> is
> > certainly worth it.
> >
> >
> > In conclusion:
> > It might actually be a good idea for us to clarify the scope of KIP-253.
> If
> > we're all agreed that it's a good algorithm for allowing in-order message
> > delivery during partition expansion, then we can continue this discussion
> > as a new KIP, something like "backfill with partition expansion". This
> > would let Dong proceed with KIP-253. On the other hand, if it seems like
> > this conversation may alter the design of KIP-253, then maybe we *should*
> > just finish working it out.
> >
> > For my part, my only concern about KIP-253 is the one I raised earlier.
> >
> > Thanks again, all, for considering these points,
> > -John
> >
> >
> > On Tue, Mar 27, 2018 at 2:10 AM, Dong Lin <li...@gmail.com> wrote:
> >
> > > On Tue, Mar 27, 2018 at 12:04 AM, Dong Lin <li...@gmail.com>
> wrote:
> > >
> > > > Hey Jan,
> > > >
> > > > Thanks for the enthusiasm in improving Kafka's design. Now that I
> have
> > > > read through your discussion with Jun, here are my thoughts:
> > > >
> > > > - The latest proposal should with log compacted topics by properly
> > > > deleting old messages after a new message with the same key is
> > produced.
> > > So
> > > > it is probably not a concern anymore. Could you comment if there is
> > still
> > > > issue?
> > > >
> > > > - I wrote the SEP-5 and I am pretty familiar with the motivation and
> > the
> > > > design of SEP-5. SEP-5 is probably orthornal to the motivation of
> this
> > > KIP.
> > > > The goal of SEP-5 is to allow user to increase task number of an
> > existing
> > > > Samza job. But if we increase the partition number of input topics,
> > > > messages may still be consumed out-of-order by tasks in Samza which
> > cause
> > > > incorrect result. Similarly, the approach you proposed does not seem
> to
> > > > ensure that the messages can be delivered in order, even if we can
> make
> > > > sure that each consumer instance is assigned the set of new
> partitions
> > > > covering the same set of keys.
> > > >
> > >
> > > Let me correct this comment. The approach of copying data to a new
> topic
> > > can ensure in-order message delivery suppose we properly migrate
> offsets
> > > from old topic to new topic.
> > >
> > >
> > > > - I am trying to understand why it is better to copy the data instead
> > of
> > > > copying the change log topic for streaming use-case. For core Kafka
> > > > use-case, and for the stream use-case that does not need to increase
> > > > consumers, the current KIP already supports in-order delivery without
> > the
> > > > overhead of copying the data. For stream use-case that needs to
> > increase
> > > > consumer number, the existing consumer can backfill the existing data
> > in
> > > > the change log topic to the same change log topic with the new
> > partition
> > > > number, before the new set of consumers bootstrap state from the new
> > > > partitions of the change log topic. If this solution works, then
> could
> > > you
> > > > summarize the advantage of copying the data of input topic as
> compared
> > to
> > > > copying the change log topic? For example, does it enable more
> > use-case,
> > > > simplify the implementation of Kafka library, or reduce the operation
> > > > overhead etc?
> > > >
> > > > Thanks,
> > > > Dong
> > > >
> > > >
> > > > On Wed, Mar 21, 2018 at 6:57 AM, Jan Filipiak <
> > Jan.Filipiak@trivago.com>
> > > > wrote:
> > > >
> > > >> Hi Jun,
> > > >>
> > > >> I was really seeing progress in our conversation but your latest
> reply
> > > is
> > > >> just devastating.
> > > >> I though we were getting close being on the same page now it feels
> > like
> > > >> we are in different libraries.
> > > >>
> > > >> I just quickly slam my answers in here. If they are to brief I am
> > sorry
> > > >> give me a ping and try to go into details more.
> > > >> Just want to show that your pro/cons listing is broken.
> > > >>
> > > >> Best Jan
> > > >>
> > > >> and want to get rid of this horrible compromise
> > > >>
> > > >>
> > > >> On 19.03.2018 05:48, Jun Rao wrote:
> > > >>
> > > >>> Hi, Jan,
> > > >>>
> > > >>> Thanks for the discussion. Great points.
> > > >>>
> > > >>> Let me try to summarize the approach that you are proposing. On the
> > > >>> broker
> > > >>> side, we reshuffle the existing data in a topic from current
> > partitions
> > > >>> to
> > > >>> the new partitions. Once the reshuffle fully catches up, switch the
> > > >>> consumers to start consuming from the new partitions. If a consumer
> > > needs
> > > >>> to rebuild its local state (due to partition changes), let the
> > consumer
> > > >>> rebuild its state by reading all existing data from the new
> > partitions.
> > > >>> Once all consumers have switches over, cut over the producer to the
> > new
> > > >>> partitions.
> > > >>>
> > > >>> The pros for this approach are that :
> > > >>> 1. There is just one way to rebuild the local state, which is
> > simpler.
> > > >>>
> > > >> true thanks
> > > >>
> > > >>>
> > > >>> The cons for this approach are:
> > > >>> 1. Need to copy existing data.
> > > >>>
> > > >> Very unfair and not correct. It does not require you to copy over
> > > >> existing data. It _allows_ you to copy all existing data.
> > > >>
> > > >> 2. The cutover of the producer is a bit complicated since it needs
> to
> > > >>> coordinate with all consumer groups.
> > > >>>
> > > >> Also not true. I explicitly tried to make clear that there is only
> one
> > > >> special consumer (in the case of actually copying data) coordination
> > is
> > > >> required.
> > > >>
> > > >>> 3. The rebuilding of the state in the consumer is from the input
> > topic,
> > > >>> which can be more expensive than rebuilding from the existing
> state.
> > > >>>
> > > >> true, but rebuilding state is only required if you want to increase
> > > >> processing power, so we assume this is at hand.
> > > >>
> > > >>> 4. The broker potentially has to know the partitioning function. If
> > > this
> > > >>> needs to be customized at the topic level, it can be a bit messy.
> > > >>>
> > > >> I would argue against having the operation being performed by the
> > > broker.
> > > >> This was not discussed yet but if you see my original email i
> > suggested
> > > >> otherwise from the beginning.
> > > >>
> > > >>>
> > > >>> Here is an alternative approach by applying your idea not in the
> > > broker,
> > > >>> but in the consumer. When new partitions are added, we don't move
> > > >>> existing
> > > >>> data. In KStreams, we first reshuffle the new input data to a new
> > topic
> > > >>> T1
> > > >>> with the old number of partitions and feed T1's data to the rest of
> > the
> > > >>> pipeline. In the meantime, KStreams reshuffles all existing data of
> > the
> > > >>> change capture topic to another topic C1 with the new number of
> > > >>> partitions.
> > > >>> We can then build the state of the new tasks from C1. Once the new
> > > states
> > > >>> have been fully built, we can cut over the consumption to the input
> > > topic
> > > >>> and delete T1. This approach works with compacted topic too. If an
> > > >>> application reads from the beginning of a compacted topic, the
> > consumer
> > > >>> will reshuffle the portion of the input when the number of
> partitions
> > > >>> doesn't match the number of tasks.
> > > >>>
> > > >> We all wipe this idea from our heads instantly. Mixing Ideas from an
> > > >> argument is not a resolution strategy
> > > >> just leads to horrible horrible software.
> > > >>
> > > >>
> > > >>> The pros of this approach are:
> > > >>> 1. No need to copy existing data.
> > > >>> 2. Each consumer group can cut over to the new partitions
> > > independently.
> > > >>> 3. The state is rebuilt from the change capture topic, which is
> > cheaper
> > > >>> than rebuilding from the input topic.
> > > >>> 4. Only the KStreams job needs to know the partitioning function.
> > > >>>
> > > >>> The cons of this approach are:
> > > >>> 1. Potentially the same input topic needs to be reshuffled more
> than
> > > once
> > > >>> in different consumer groups during the transition phase.
> > > >>>
> > > >>> What do you think?
> > > >>>
> > > >>> Thanks,
> > > >>>
> > > >>> Jun
> > > >>>
> > > >>>
> > > >>>
> > > >>> On Thu, Mar 15, 2018 at 1:04 AM, Jan Filipiak <
> > > Jan.Filipiak@trivago.com>
> > > >>> wrote:
> > > >>>
> > > >>> Hi Jun,
> > > >>>>
> > > >>>> thank you for following me on these thoughts. It was important to
> me
> > > to
> > > >>>> feel that kind of understanding for my arguments.
> > > >>>>
> > > >>>> What I was hoping for (I mentioned this earlier) is that we can
> > model
> > > >>>> the
> > > >>>> case where we do not want to copy the data the exact same way as
> the
> > > >>>> case
> > > >>>> when we do copy the data. Maybe you can peek into the mails before
> > to
> > > >>>> see
> > > >>>> more details for this.
> > > >>>>
> > > >>>> This means we have the same mechanism to transfer consumer groups
> to
> > > >>>> switch topic. The offset mapping that would be generated would
> even
> > be
> > > >>>> simpler End Offset of the Old topic => offset 0 off all the
> > partitions
> > > >>>> of
> > > >>>> the new topic. Then we could model the transition of a non-copy
> > > >>>> expansion
> > > >>>> the exact same way as a copy-expansion.
> > > >>>>
> > > >>>> I know this only works when topic growth by a factor. But the
> > benefits
> > > >>>> of
> > > >>>> only growing by a factor are to strong anyways. See Clemens's hint
> > and
> > > >>>> remember that state reshuffling is entirely not needed if one
> > doesn't
> > > >>>> want
> > > >>>> to grow processing power.
> > > >>>>
> > > >>>> I think these benefits should be clear, and that there is
> basically
> > no
> > > >>>> downside to what is currently at hand but just makes everything
> > easy.
> > > >>>>
> > > >>>> One thing you need to know is. that if you do not offer
> rebuilding a
> > > log
> > > >>>> compacted topic like i suggest that even if you have consumer
> state
> > > >>>> reshuffling. The topic is broken and can not be used to bootstrap
> > new
> > > >>>> consumers. They don't know if they need to apply a key from and
> old
> > > >>>> partition or not. This is a horrible downside I haven't seen a
> > > solution
> > > >>>> for
> > > >>>> in the email conversation.
> > > >>>>
> > > >>>> I argue to:
> > > >>>>
> > > >>>> Only grow topic by a factor always.
> > > >>>> Have the "no copy consumer" transition as the trivial case of the
> > > "copy
> > > >>>> consumer transition".
> > > >>>> If processors needs to be scaled, let them rebuild from the new
> > topic
> > > >>>> and
> > > >>>> leave the old running in the mean time.
> > > >>>> Do not implement key shuffling in streams.
> > > >>>>
> > > >>>> I hope I can convince you especially with the fact how I want to
> > > handle
> > > >>>> consumer transition. I think
> > > >>>> you didn't quite understood me there before. I think the term "new
> > > >>>> topic"
> > > >>>> intimidated you a little.
> > > >>>> How we solve this on disc doesn't really matter, If the data goes
> > into
> > > >>>> the
> > > >>>> same Dir or a different Dir or anything. I do think that it needs
> to
> > > >>>> involve at least rolling a new segment for the existing
> partitions.
> > > >>>> But most of the transitions should work without restarting
> > consumers.
> > > >>>> (newer consumers with support for this). But with new topic i just
> > > meant
> > > >>>> the topic that now has a different partition count. Plenty of ways
> > to
> > > >>>> handle that (versions, aliases)
> > > >>>>
> > > >>>> Hope I can further get my idea across.
> > > >>>>
> > > >>>> Best Jan
> > > >>>>
> > > >>>>
> > > >>>>
> > > >>>>
> > > >>>>
> > > >>>>
> > > >>>> On 14.03.2018 02:45, Jun Rao wrote:
> > > >>>>
> > > >>>> Hi, Jan,
> > > >>>>>
> > > >>>>> Thanks for sharing your view.
> > > >>>>>
> > > >>>>> I agree with you that recopying the data potentially makes the
> > state
> > > >>>>> management easier since the consumer can just rebuild its state
> > from
> > > >>>>> scratch (i.e., no need for state reshuffling).
> > > >>>>>
> > > >>>>> On the flip slide, I saw a few disadvantages of the approach that
> > you
> > > >>>>> suggested. (1) Building the state from the input topic from
> scratch
> > > is
> > > >>>>> in
> > > >>>>> general less efficient than state reshuffling. Let's say one
> > > computes a
> > > >>>>> count per key from an input topic. The former requires reading
> all
> > > >>>>> existing
> > > >>>>> records in the input topic whereas the latter only requires
> reading
> > > >>>>> data
> > > >>>>> proportional to the number of unique keys. (2) The switching of
> the
> > > >>>>> topic
> > > >>>>> needs modification to the application. If there are many
> > applications
> > > >>>>> on a
> > > >>>>> topic, coordinating such an effort may not be easy. Also, it's
> not
> > > >>>>> clear
> > > >>>>> how to enforce exactly-once semantic during the switch. (3) If a
> > > topic
> > > >>>>> doesn't need any state management, recopying the data seems
> > wasteful.
> > > >>>>> In
> > > >>>>> that case, in place partition expansion seems more desirable.
> > > >>>>>
> > > >>>>> I understand your concern about adding complexity in KStreams.
> But,
> > > >>>>> perhaps
> > > >>>>> we could iterate on that a bit more to see if it can be
> simplified.
> > > >>>>>
> > > >>>>> Jun
> > > >>>>>
> > > >>>>>
> > > >>>>> On Mon, Mar 12, 2018 at 11:21 PM, Jan Filipiak <
> > > >>>>> Jan.Filipiak@trivago.com>
> > > >>>>> wrote:
> > > >>>>>
> > > >>>>> Hi Jun,
> > > >>>>>
> > > >>>>>> I will focus on point 61 as I think its _the_ fundamental part
> > that
> > > I
> > > >>>>>> cant
> > > >>>>>> get across at the moment.
> > > >>>>>>
> > > >>>>>> Kafka is the platform to have state materialized multiple times
> > from
> > > >>>>>> one
> > > >>>>>> input. I emphasize this: It is the building block in
> architectures
> > > >>>>>> that
> > > >>>>>> allow you to
> > > >>>>>> have your state maintained multiple times. You put a message in
> > > once,
> > > >>>>>> and
> > > >>>>>> you have it pop out as often as you like. I believe you
> understand
> > > >>>>>> this.
> > > >>>>>>
> > > >>>>>> Now! The path of thinking goes the following: I am using apache
> > > kafka
> > > >>>>>> and
> > > >>>>>> I _want_ my state multiple times. What am I going todo?
> > > >>>>>>
> > > >>>>>> A) Am I going to take my state that I build up, plunge some sort
> > of
> > > >>>>>> RPC
> > > >>>>>> layer ontop of it, use that RPC layer to throw my records across
> > > >>>>>> instances?
> > > >>>>>> B) Am I just going to read the damn message twice?
> > > >>>>>>
> > > >>>>>> Approach A is fundamentally flawed and a violation of all that
> is
> > > good
> > > >>>>>> and
> > > >>>>>> holy in kafka deployments. I can not understand how this Idea
> can
> > > >>>>>> come in
> > > >>>>>> the first place.
> > > >>>>>> (I do understand: IQ in streams, they polluted the kafka streams
> > > >>>>>> codebase
> > > >>>>>> really bad already. It is not funny! I think they are equally
> > flawed
> > > >>>>>> as
> > > >>>>>> A)
> > > >>>>>>
> > > >>>>>> I say, we do what Kafka is good at. We repartition the topic
> once.
> > > We
> > > >>>>>> switch the consumers.
> > > >>>>>> (Those that need more partitions are going to rebuild their
> state
> > in
> > > >>>>>> multiple partitions by reading the new topic, those that don't
> > just
> > > >>>>>> assign
> > > >>>>>> the new partitions properly)
> > > >>>>>> We switch producers. Done!
> > > >>>>>>
> > > >>>>>> The best thing! It is trivial, hipster stream processor will
> have
> > an
> > > >>>>>> easy
> > > >>>>>> time with that aswell. Its so super simple. And simple IS good!
> > > >>>>>> It is what kafka was build todo. It is how we do it today. All I
> > am
> > > >>>>>> saying
> > > >>>>>> is that a little broker help doing the producer swap is super
> > > useful.
> > > >>>>>>
> > > >>>>>> For everyone interested in why kafka is so powerful with
> approach
> > B,
> > > >>>>>> please watch https://youtu.be/bEbeZPVo98c?t=1633
> > > >>>>>> I already looked up a good point in time, I think after 5
> minutes
> > > the
> > > >>>>>> "state" topic is handled and you should be able to understand me
> > > >>>>>> and inch better.
> > > >>>>>>
> > > >>>>>> Please do not do A to the project, it deserves better!
> > > >>>>>>
> > > >>>>>> Best Jan
> > > >>>>>>
> > > >>>>>>
> > > >>>>>>
> > > >>>>>> On 13.03.2018 02:40, Jun Rao wrote:
> > > >>>>>>
> > > >>>>>> Hi, Jan,
> > > >>>>>>
> > > >>>>>>> Thanks for the reply. A few more comments below.
> > > >>>>>>>
> > > >>>>>>> 50. Ok, we can think a bit harder for supporting compacted
> > topics.
> > > >>>>>>>
> > > >>>>>>> 51. This is a fundamental design question. In the more common
> > case,
> > > >>>>>>> the
> > > >>>>>>> reason why someone wants to increase the number of partitions
> is
> > > that
> > > >>>>>>> the
> > > >>>>>>> consumer application is slow and one wants to run more consumer
> > > >>>>>>> instances
> > > >>>>>>> to increase the degree of parallelism. So, fixing the number of
> > > >>>>>>> running
> > > >>>>>>> consumer instances when expanding the partitions won't help
> this
> > > >>>>>>> case.
> > > >>>>>>> If
> > > >>>>>>> we do need to increase the number of consumer instances, we
> need
> > to
> > > >>>>>>> somehow
> > > >>>>>>> reshuffle the state of the consumer across instances. What we
> > have
> > > >>>>>>> been
> > > >>>>>>> discussing in this KIP is whether we can do this more
> effectively
> > > >>>>>>> through
> > > >>>>>>> the KStream library (e.g. through a 2-phase partition
> expansion).
> > > >>>>>>> This
> > > >>>>>>> will
> > > >>>>>>> add some complexity, but it's probably better than everyone
> doing
> > > >>>>>>> this
> > > >>>>>>> in
> > > >>>>>>> the application space. The recopying approach that you
> mentioned
> > > >>>>>>> doesn't
> > > >>>>>>> seem to address the consumer state management issue when the
> > > consumer
> > > >>>>>>> switches from an old to a new topic.
> > > >>>>>>>
> > > >>>>>>> 52. As for your example, it depends on whether the join key is
> > the
> > > >>>>>>> same
> > > >>>>>>> between (A,B) and (B,C). If the join key is the same, we can
> do a
> > > >>>>>>> 2-phase
> > > >>>>>>> partition expansion of A, B, and C together. If the join keys
> are
> > > >>>>>>> different, one would need to repartition the data on a
> different
> > > key
> > > >>>>>>> for
> > > >>>>>>> the second join, then the partition expansion can be done
> > > >>>>>>> independently
> > > >>>>>>> between (A,B) and (B,C).
> > > >>>>>>>
> > > >>>>>>> 53. If you always fix the number of consumer instances, we you
> > > >>>>>>> described
> > > >>>>>>> works. However, as I mentioned in #51, I am not sure how your
> > > >>>>>>> proposal
> > > >>>>>>> deals with consumer states when the number of consumer
> instances
> > > >>>>>>> grows.
> > > >>>>>>> Also, it just seems that it's better to avoid re-copying the
> > > existing
> > > >>>>>>> data.
> > > >>>>>>>
> > > >>>>>>> 60. "just want to throw in my question from the longer email in
> > the
> > > >>>>>>> other
> > > >>>>>>> Thread here. How will the bloom filter help a new consumer to
> > > decide
> > > >>>>>>> to
> > > >>>>>>> apply the key or not?" Not sure that I fully understood your
> > > >>>>>>> question.
> > > >>>>>>> The
> > > >>>>>>> consumer just reads whatever key is in the log. The bloom
> filter
> > > just
> > > >>>>>>> helps
> > > >>>>>>> clean up the old keys.
> > > >>>>>>>
> > > >>>>>>> 61. "Why can we afford having a topic where its apparently not
> > > >>>>>>> possible
> > > >>>>>>> to
> > > >>>>>>> start a new application on? I think this is an overall flaw of
> > the
> > > >>>>>>> discussed idea here. Not playing attention to the overall
> > > >>>>>>> architecture."
> > > >>>>>>> Could you explain a bit more when one can't start a new
> > > application?
> > > >>>>>>>
> > > >>>>>>> Jun
> > > >>>>>>>
> > > >>>>>>>
> > > >>>>>>>
> > > >>>>>>> On Sat, Mar 10, 2018 at 1:40 AM, Jan Filipiak <
> > > >>>>>>> Jan.Filipiak@trivago.com
> > > >>>>>>> wrote:
> > > >>>>>>>
> > > >>>>>>> Hi Jun, thanks for your mail.
> > > >>>>>>>
> > > >>>>>>> Thank you for your questions!
> > > >>>>>>>> I think they are really good and tackle the core of the
> problem
> > I
> > > >>>>>>>> see.
> > > >>>>>>>>
> > > >>>>>>>> I will answer inline, mostly but still want to set the tone
> > here.
> > > >>>>>>>>
> > > >>>>>>>> The core strength of kafka is what Martin once called the
> > > >>>>>>>> kappa-Architecture. How does this work?
> > > >>>>>>>> You have everything as a log as in kafka. When you need to
> > change
> > > >>>>>>>> something.
> > > >>>>>>>> You create the new version of your application and leave it
> > > running
> > > >>>>>>>> in
> > > >>>>>>>> parallel.
> > > >>>>>>>> Once the new version is good you switch your users to use the
> > new
> > > >>>>>>>> application.
> > > >>>>>>>>
> > > >>>>>>>> The online reshuffling effectively breaks this architecture
> and
> > I
> > > >>>>>>>> think
> > > >>>>>>>> the switch in thinking here is more harmful
> > > >>>>>>>> than any details about the partitioning function to allow
> such a
> > > >>>>>>>> change.
> > > >>>>>>>> I
> > > >>>>>>>> feel with my suggestion we are the closest to
> > > >>>>>>>> the original and battle proven architecture and I can only
> warn
> > to
> > > >>>>>>>> move
> > > >>>>>>>> away from it.
> > > >>>>>>>>
> > > >>>>>>>> I might have forgotten something, sometimes its hard for me to
> > > >>>>>>>> getting
> > > >>>>>>>> all
> > > >>>>>>>> the thoughts captured in a mail, but I hope the comments
> inline
> > > will
> > > >>>>>>>> further make my concern clear, and put some emphasis on why I
> > > >>>>>>>> prefer my
> > > >>>>>>>> solution ;)
> > > >>>>>>>>
> > > >>>>>>>> One thing we should all be aware of when discussing this, and
> I
> > > >>>>>>>> think
> > > >>>>>>>> Dong
> > > >>>>>>>> should have mentioned it (maybe he did).
> > > >>>>>>>> We are not discussing all of this out of thin air but there is
> > an
> > > >>>>>>>> effort
> > > >>>>>>>> in the Samza project.
> > > >>>>>>>>
> > > >>>>>>>> https://cwiki.apache.org/confluence/display/SAMZA/SEP-5%3A+
> > > >>>>>>>> Enable+partition+expansion+of+input+streams
> > > >>>>>>>> https://issues.apache.org/jira/browse/SAMZA-1293
> > > >>>>>>>>
> > > >>>>>>>> To be clear. I think SEP-5 (state of last week, dont know if
> it
> > > >>>>>>>> adapted
> > > >>>>>>>> to
> > > >>>>>>>> this discussion) is on a way better path than KIP-253, and I
> > can't
> > > >>>>>>>> really
> > > >>>>>>>> explain why.
> > > >>>>>>>>
> > > >>>>>>>> Best Jan,
> > > >>>>>>>>
> > > >>>>>>>> nice weekend everyone
> > > >>>>>>>>
> > > >>>>>>>>
> > > >>>>>>>> On 09.03.2018 03:36, Jun Rao wrote:
> > > >>>>>>>>
> > > >>>>>>>> Hi, Jan,
> > > >>>>>>>>
> > > >>>>>>>> Thanks for the feedback. Just some comments on the earlier
> > points
> > > >>>>>>>>> that
> > > >>>>>>>>> you
> > > >>>>>>>>> mentioned.
> > > >>>>>>>>>
> > > >>>>>>>>> 50. You brought up the question of whether existing data
> needs
> > to
> > > >>>>>>>>> be
> > > >>>>>>>>> copied
> > > >>>>>>>>> during partition expansion. My understand of your view is
> that
> > > >>>>>>>>> avoid
> > > >>>>>>>>> copying existing data will be more efficient, but it doesn't
> > work
> > > >>>>>>>>> well
> > > >>>>>>>>> with
> > > >>>>>>>>> compacted topics since some keys in the original partitions
> > will
> > > >>>>>>>>> never
> > > >>>>>>>>> be
> > > >>>>>>>>> cleaned. It would be useful to understand your use case of
> > > >>>>>>>>> compacted
> > > >>>>>>>>> topics
> > > >>>>>>>>> a bit more. In the common use case, the data volume in a
> > > compacted
> > > >>>>>>>>> topic
> > > >>>>>>>>> may not be large. So, I am not sure if there is a strong need
> > to
> > > >>>>>>>>> expand
> > > >>>>>>>>> partitions in a compacted topic, at least initially.
> > > >>>>>>>>>
> > > >>>>>>>>> I do agree. State is usually smaller. Update rates might be
> > also
> > > >>>>>>>>>
> > > >>>>>>>>> competitively high.
> > > >>>>>>>> Doing Log-compaction (even beeing very efficient and
> > configurable)
> > > >>>>>>>> is
> > > >>>>>>>> also
> > > >>>>>>>> a more expensive operation than
> > > >>>>>>>> just discarding old segments. Further if you want to use more
> > > >>>>>>>> consumers
> > > >>>>>>>> processing the events
> > > >>>>>>>> you also have to grow the number of partitions. Especially for
> > > >>>>>>>> use-cases
> > > >>>>>>>> we do (KIP-213) a tiny state full
> > > >>>>>>>> table might be very expensive to process if it joins against a
> > > huge
> > > >>>>>>>> table.
> > > >>>>>>>>
> > > >>>>>>>> I can just say we have been in the spot of needing to grow log
> > > >>>>>>>> compacted
> > > >>>>>>>> topics. Mainly for processing power we can bring to the table.
> > > >>>>>>>>
> > > >>>>>>>> Further i am not at all concerned about the extra spaced used
> by
> > > >>>>>>>> "garbage
> > > >>>>>>>> keys". I am more concerned about the correctness of innocent
> > > >>>>>>>> consumers.
> > > >>>>>>>> The
> > > >>>>>>>> logic becomes complicated. Say for streams one would need to
> > load
> > > >>>>>>>> the
> > > >>>>>>>> record into state but not forward it the topology ( to have it
> > > >>>>>>>> available
> > > >>>>>>>> for shuffeling). I rather have it simple and a topic clean
> > > >>>>>>>> regardless
> > > >>>>>>>> if
> > > >>>>>>>> it
> > > >>>>>>>> still has its old partition count. Especially with multiple
> > > >>>>>>>> partitions
> > > >>>>>>>> growth's I think it becomes insanely hard to to this shuffle
> > > >>>>>>>> correct.
> > > >>>>>>>> Maybe
> > > >>>>>>>> Streams and Samza can do it. Especially if you do "hipster
> > stream
> > > >>>>>>>> processing" <https://www.confluent.io/blog
> > > >>>>>>>> /introducing-kafka-streams-
> > > >>>>>>>> stream-processing-made-simple/>. This makes kafka way to
> > > >>>>>>>> complicated.
> > > >>>>>>>> With my approach I think its way simpler because the topic has
> > no
> > > >>>>>>>> "history"
> > > >>>>>>>> in terms of partitioning but is always clean.
> > > >>>>>>>>
> > > >>>>>>>>
> > > >>>>>>>> 51. "Growing the topic by an integer factor does not require
> any
> > > >>>>>>>> state
> > > >>>>>>>>
> > > >>>>>>>> redistribution at all." Could you clarify this a bit more?
> Let's
> > > say
> > > >>>>>>>>> you
> > > >>>>>>>>> have a consumer app that computes the windowed count per key.
> > If
> > > >>>>>>>>> you
> > > >>>>>>>>> double
> > > >>>>>>>>> the number of partitions from 1 to 2 and grow the consumer
> > > >>>>>>>>> instances
> > > >>>>>>>>> from
> > > >>>>>>>>> 1
> > > >>>>>>>>> to 2, we would need to redistribute some of the counts to the
> > new
> > > >>>>>>>>> consumer
> > > >>>>>>>>> instance. Regarding to linear hashing, it's true that it
> won't
> > > >>>>>>>>> solve
> > > >>>>>>>>> the
> > > >>>>>>>>> problem with compacted topics. The main benefit is that it
> > > >>>>>>>>> redistributes
> > > >>>>>>>>> the keys in one partition to no more than two partitions,
> which
> > > >>>>>>>>> could
> > > >>>>>>>>> help
> > > >>>>>>>>> redistribute the state.
> > > >>>>>>>>>
> > > >>>>>>>>> You don't need to spin up a new consumer in this case. every
> > > >>>>>>>>> consumer
> > > >>>>>>>>>
> > > >>>>>>>>> would just read every partition with the (partition %
> num_task)
> > > >>>>>>>> task.
> > > >>>>>>>> it
> > > >>>>>>>> will still have the previous data right there and can go on.
> > > >>>>>>>>
> > > >>>>>>>> This sounds contradictory to what I said before, but please
> bear
> > > >>>>>>>> with
> > > >>>>>>>> me.
> > > >>>>>>>>
> > > >>>>>>>> 52. Good point on coordinating the expansion of 2 topics that
> > need
> > > >>>>>>>> to
> > > >>>>>>>> be
> > > >>>>>>>>
> > > >>>>>>>> joined together. This is where the 2-phase partition expansion
> > > could
> > > >>>>>>>>> potentially help. In the first phase, we could add new
> > partitions
> > > >>>>>>>>> to
> > > >>>>>>>>> the 2
> > > >>>>>>>>> topics one at a time but without publishing to the new
> > patitions.
> > > >>>>>>>>> Then,
> > > >>>>>>>>> we
> > > >>>>>>>>> can add new consumer instances to pick up the new partitions.
> > In
> > > >>>>>>>>> this
> > > >>>>>>>>> transition phase, no reshuffling is needed since no data is
> > > coming
> > > >>>>>>>>> from
> > > >>>>>>>>> the
> > > >>>>>>>>> new partitions. Finally, we can enable the publishing to the
> > new
> > > >>>>>>>>> partitions.
> > > >>>>>>>>>
> > > >>>>>>>>> I think its even worse than you think. I would like to
> > introduce
> > > >>>>>>>>> the
> > > >>>>>>>>>
> > > >>>>>>>>> Term
> > > >>>>>>>> transitive copartitioning. Imagine
> > > >>>>>>>> 2 streams application. One joins (A,B) the other (B,C) then
> > there
> > > >>>>>>>> is a
> > > >>>>>>>> transitive copartition requirement for
> > > >>>>>>>> (A,C) to be copartitioned aswell. This can spread
> significantly
> > > and
> > > >>>>>>>> require many consumers to adapt at the same time.
> > > >>>>>>>>
> > > >>>>>>>> It is also not entirely clear to me how you not need
> reshuffling
> > > in
> > > >>>>>>>> this
> > > >>>>>>>> case. If A has a record that never gets updated after the
> > > expansion
> > > >>>>>>>> and
> > > >>>>>>>> the
> > > >>>>>>>> coresponding B record moves to a new partition. How shall they
> > > meet
> > > >>>>>>>> w/o
> > > >>>>>>>> shuffle?
> > > >>>>>>>>
> > > >>>>>>>> 53. "Migrating consumer is a step that might be made completly
> > > >>>>>>>>
> > > >>>>>>>> unnecessary
> > > >>>>>>>>> if - for example streams - takes the gcd as partitioning
> scheme
> > > >>>>>>>>> instead
> > > >>>>>>>>> of
> > > >>>>>>>>> enforcing 1 to 1." Not sure that I fully understand this. I
> > think
> > > >>>>>>>>> you
> > > >>>>>>>>> mean
> > > >>>>>>>>> that a consumer application can run more instances than the
> > > number
> > > >>>>>>>>> of
> > > >>>>>>>>> partitions. In that case, the consumer can just
> repartitioning
> > > the
> > > >>>>>>>>> input
> > > >>>>>>>>> data according to the number of instances. This is possible,
> > but
> > > >>>>>>>>> just
> > > >>>>>>>>> has
> > > >>>>>>>>> the overhead of reshuffling the data.
> > > >>>>>>>>>
> > > >>>>>>>>> No what I meant is ( that is also your question i think
> > Mathias)
> > > >>>>>>>>> that
> > > >>>>>>>>> if
> > > >>>>>>>>>
> > > >>>>>>>>> you grow a topic by a factor.
> > > >>>>>>>> Even if your processor is statefull you can can just assign
> all
> > > the
> > > >>>>>>>> multiples of the previous partition to
> > > >>>>>>>> this consumer and the state to keep processing correctly will
> be
> > > >>>>>>>> present
> > > >>>>>>>> w/o any shuffling.
> > > >>>>>>>>
> > > >>>>>>>> Say you have an assignment
> > > >>>>>>>> Statefull consumer => partition
> > > >>>>>>>> 0 => 0
> > > >>>>>>>> 1 => 1
> > > >>>>>>>> 2 => 2
> > > >>>>>>>>
> > > >>>>>>>> and you grow you topic by 4 you get,
> > > >>>>>>>>
> > > >>>>>>>> 0 => 0,3,6,9
> > > >>>>>>>> 1 => 1,4,7,10
> > > >>>>>>>> 2 => 2,5,8,11
> > > >>>>>>>>
> > > >>>>>>>> Say your hashcode is 8. 8%3 => 2  before so consumer for
> > > partition 2
> > > >>>>>>>> has
> > > >>>>>>>> it.
> > > >>>>>>>> Now you you have 12 partitions so 8%12 => 8, so it goes into
> > > >>>>>>>> partition
> > > >>>>>>>> 8
> > > >>>>>>>> which is assigned to the same consumer
> > > >>>>>>>> who had 2 before and therefore knows the key.
> > > >>>>>>>>
> > > >>>>>>>> Userland reshuffeling is there as an options. And it does
> > exactly
> > > >>>>>>>> what
> > > >>>>>>>> I
> > > >>>>>>>> suggest. And I think its the perfect strategie. All I am
> > > suggestion
> > > >>>>>>>> is
> > > >>>>>>>> broker side support to switch the producers to the newly
> > > partitioned
> > > >>>>>>>> topic.
> > > >>>>>>>> Then the old (to few partition topic) can go away.  Remember
> the
> > > >>>>>>>> list
> > > >>>>>>>> of
> > > >>>>>>>> steps in the beginning of this thread. If one has broker
> support
> > > for
> > > >>>>>>>> all
> > > >>>>>>>> where its required and streams support for those that aren’t
> > > >>>>>>>> necessarily.
> > > >>>>>>>> Then one has solved the problem.
> > > >>>>>>>> I repeat it because I think its important. I am really happy
> > that
> > > >>>>>>>> you
> > > >>>>>>>> brought that up! because its 100% what I want just with the
> > > >>>>>>>> differences
> > > >>>>>>>> to
> > > >>>>>>>> have an option to discard the to small topic later (after all
> > > >>>>>>>> consumers
> > > >>>>>>>> adapted). And to have order correct there. I need broker
> support
> > > >>>>>>>> managing
> > > >>>>>>>> the copy process + the produces and fence them against each
> > > other. I
> > > >>>>>>>> also
> > > >>>>>>>> repeat. the copy process can run for weeks in the worst case.
> > > >>>>>>>> Copying
> > > >>>>>>>> the
> > > >>>>>>>> data is not the longest task migrating consumers might very
> well
> > > be.
> > > >>>>>>>> Once all consumers switched and copying is really up to date
> > > (think
> > > >>>>>>>> ISR
> > > >>>>>>>> like up to date) only then we stop the producer, wait for the
> > copy
> > > >>>>>>>> to
> > > >>>>>>>> finish and use the new topic for producing.
> > > >>>>>>>>
> > > >>>>>>>> After this the topic is perfect in shape. and no one needs to
> > > worry
> > > >>>>>>>> about
> > > >>>>>>>> complicated stuff. (old keys hanging around might arrive in
> some
> > > >>>>>>>> other
> > > >>>>>>>> topic later.....). can only imagine how many tricky bugs gonna
> > > >>>>>>>> arrive
> > > >>>>>>>> after
> > > >>>>>>>> someone had grown and shrunken is topic 10 times.
> > > >>>>>>>>
> > > >>>>>>>>
> > > >>>>>>>>
> > > >>>>>>>>
> > > >>>>>>>>
> > > >>>>>>>>
> > > >>>>>>>> 54. "The other thing I wanted to mention is that I believe the
> > > >>>>>>>> current
> > > >>>>>>>>
> > > >>>>>>>> suggestion (without copying data over) can be implemented in
> > pure
> > > >>>>>>>>> userland
> > > >>>>>>>>> with a custom partitioner and a small feedbackloop from
> > > >>>>>>>>> ProduceResponse
> > > >>>>>>>>> =>
> > > >>>>>>>>> Partitionier in coorporation with a change management
> system."
> > I
> > > am
> > > >>>>>>>>> not
> > > >>>>>>>>> sure a customized partitioner itself solves the problem. We
> > > >>>>>>>>> probably
> > > >>>>>>>>> need
> > > >>>>>>>>> some broker side support to enforce when the new partitions
> can
> > > be
> > > >>>>>>>>> used.
> > > >>>>>>>>> We
> > > >>>>>>>>> also need some support on the consumer/kstream side to
> preserve
> > > the
> > > >>>>>>>>> per
> > > >>>>>>>>> key
> > > >>>>>>>>> ordering and potentially migrate the processing state. This
> is
> > > not
> > > >>>>>>>>> trivial
> > > >>>>>>>>> and I am not sure if it's ideal to fully push to the
> > application
> > > >>>>>>>>> space.
> > > >>>>>>>>>
> > > >>>>>>>>> Broker support is defenitly the preferred way here. I have
> > > nothing
> > > >>>>>>>>>
> > > >>>>>>>>> against
> > > >>>>>>>> broker support.
> > > >>>>>>>> I tried to say that for what I would preffer - copying the
> data
> > > >>>>>>>> over,
> > > >>>>>>>> at
> > > >>>>>>>> least for log compacted topics -
> > > >>>>>>>> I would require more broker support than the KIP currently
> > offers.
> > > >>>>>>>>
> > > >>>>>>>>
> > > >>>>>>>>
> > > >>>>>>>> Jun
> > > >>>>>>>>
> > > >>>>>>>> On Tue, Mar 6, 2018 at 10:33 PM, Jan Filipiak <
> > > >>>>>>>>> Jan.Filipiak@trivago.com
> > > >>>>>>>>> wrote:
> > > >>>>>>>>>
> > > >>>>>>>>> Hi Dong,
> > > >>>>>>>>>
> > > >>>>>>>>> are you actually reading my emails, or are you just using the
> > > >>>>>>>>> thread I
> > > >>>>>>>>>
> > > >>>>>>>>>> started for general announcements regarding the KIP?
> > > >>>>>>>>>>
> > > >>>>>>>>>> I tried to argue really hard against linear hashing. Growing
> > the
> > > >>>>>>>>>> topic
> > > >>>>>>>>>> by
> > > >>>>>>>>>> an integer factor does not require any state redistribution
> at
> > > >>>>>>>>>> all. I
> > > >>>>>>>>>> fail
> > > >>>>>>>>>> to see completely where linear hashing helps on log
> compacted
> > > >>>>>>>>>> topics.
> > > >>>>>>>>>>
> > > >>>>>>>>>> If you are not willing to explain to me what I might be
> > > >>>>>>>>>> overlooking:
> > > >>>>>>>>>> that
> > > >>>>>>>>>> is fine.
> > > >>>>>>>>>> But I ask you to not reply to my emails then. Please
> > understand
> > > my
> > > >>>>>>>>>> frustration with this.
> > > >>>>>>>>>>
> > > >>>>>>>>>> Best Jan
> > > >>>>>>>>>>
> > > >>>>>>>>>>
> > > >>>>>>>>>>
> > > >>>>>>>>>> On 06.03.2018 19:38, Dong Lin wrote:
> > > >>>>>>>>>>
> > > >>>>>>>>>> Hi everyone,
> > > >>>>>>>>>>
> > > >>>>>>>>>> Thanks for all the comments! It appears that everyone
> prefers
> > > >>>>>>>>>> linear
> > > >>>>>>>>>>
> > > >>>>>>>>>>> hashing because it reduces the amount of state that needs
> to
> > be
> > > >>>>>>>>>>> moved
> > > >>>>>>>>>>> between consumers (for stream processing). The KIP has been
> > > >>>>>>>>>>> updated
> > > >>>>>>>>>>> to
> > > >>>>>>>>>>> use
> > > >>>>>>>>>>> linear hashing.
> > > >>>>>>>>>>>
> > > >>>>>>>>>>> Regarding the migration endeavor: it seems that migrating
> > > >>>>>>>>>>> producer
> > > >>>>>>>>>>> library
> > > >>>>>>>>>>> to use linear hashing should be pretty straightforward
> > without
> > > >>>>>>>>>>> much operational endeavor. If we don't upgrade client
> library
> > > to
> > > >>>>>>>>>>> use
> > > >>>>>>>>>>> this
> > > >>>>>>>>>>> KIP, we can not support in-order delivery after partition
> is
> > > >>>>>>>>>>> changed
> > > >>>>>>>>>>> anyway. Suppose we upgrade client library to use this KIP,
> if
> > > >>>>>>>>>>> partition
> > > >>>>>>>>>>> number is not changed, the key -> partition mapping will be
> > > >>>>>>>>>>> exactly
> > > >>>>>>>>>>> the
> > > >>>>>>>>>>> same as it is now because it is still determined using
> > > >>>>>>>>>>> murmur_hash(key)
> > > >>>>>>>>>>> %
> > > >>>>>>>>>>> original_partition_num. In other words, this change is
> > backward
> > > >>>>>>>>>>> compatible.
> > > >>>>>>>>>>>
> > > >>>>>>>>>>> Regarding the load distribution: if we use linear hashing,
> > the
> > > >>>>>>>>>>> load
> > > >>>>>>>>>>> may
> > > >>>>>>>>>>> be
> > > >>>>>>>>>>> unevenly distributed because those partitions which are not
> > > split
> > > >>>>>>>>>>> may
> > > >>>>>>>>>>> receive twice as much traffic as other partitions that are
> > > split.
> > > >>>>>>>>>>> This
> > > >>>>>>>>>>> issue can be mitigated by creating topic with partitions
> that
> > > are
> > > >>>>>>>>>>> several
> > > >>>>>>>>>>> times the number of consumers. And there will be no
> imbalance
> > > if
> > > >>>>>>>>>>> the
> > > >>>>>>>>>>> partition number is always doubled. So this imbalance seems
> > > >>>>>>>>>>> acceptable.
> > > >>>>>>>>>>>
> > > >>>>>>>>>>> Regarding storing the partition strategy as per-topic
> config:
> > > It
> > > >>>>>>>>>>> seems
> > > >>>>>>>>>>> not
> > > >>>>>>>>>>> necessary since we can still use murmur_hash as the default
> > > hash
> > > >>>>>>>>>>> function
> > > >>>>>>>>>>> and additionally apply the linear hashing algorithm if the
> > > >>>>>>>>>>> partition
> > > >>>>>>>>>>> number
> > > >>>>>>>>>>> has increased. Not sure if there is any use-case for
> producer
> > > to
> > > >>>>>>>>>>> use a
> > > >>>>>>>>>>> different hash function. Jason, can you check if there is
> > some
> > > >>>>>>>>>>> use-case
> > > >>>>>>>>>>> that I missed for using the per-topic partition strategy?
> > > >>>>>>>>>>>
> > > >>>>>>>>>>> Regarding how to reduce latency (due to state store/load)
> in
> > > >>>>>>>>>>> stream
> > > >>>>>>>>>>> processing consumer when partition number changes: I need
> to
> > > read
> > > >>>>>>>>>>> the
> > > >>>>>>>>>>> Kafka
> > > >>>>>>>>>>> Stream code to understand how Kafka Stream currently
> migrate
> > > >>>>>>>>>>> state
> > > >>>>>>>>>>> between
> > > >>>>>>>>>>> consumers when the application is added/removed for a given
> > > job.
> > > >>>>>>>>>>> I
> > > >>>>>>>>>>> will
> > > >>>>>>>>>>> reply after I finish reading the documentation and code.
> > > >>>>>>>>>>>
> > > >>>>>>>>>>>
> > > >>>>>>>>>>> Thanks,
> > > >>>>>>>>>>> Dong
> > > >>>>>>>>>>>
> > > >>>>>>>>>>>
> > > >>>>>>>>>>> On Mon, Mar 5, 2018 at 10:43 AM, Jason Gustafson <
> > > >>>>>>>>>>> jason@confluent.io>
> > > >>>>>>>>>>> wrote:
> > > >>>>>>>>>>>
> > > >>>>>>>>>>> Great discussion. I think I'm wondering whether we can
> > continue
> > > >>>>>>>>>>> to
> > > >>>>>>>>>>> leave
> > > >>>>>>>>>>>
> > > >>>>>>>>>>> Kafka agnostic to the partitioning strategy. The challenge
> is
> > > >>>>>>>>>>>
> > > >>>>>>>>>>> communicating
> > > >>>>>>>>>>>> the partitioning logic from producers to consumers so that
> > the
> > > >>>>>>>>>>>> dependencies
> > > >>>>>>>>>>>> between each epoch can be determined. For the sake of
> > > >>>>>>>>>>>> discussion,
> > > >>>>>>>>>>>> imagine
> > > >>>>>>>>>>>> you did something like the following:
> > > >>>>>>>>>>>>
> > > >>>>>>>>>>>> 1. The name (and perhaps version) of a partitioning
> strategy
> > > is
> > > >>>>>>>>>>>> stored
> > > >>>>>>>>>>>> in
> > > >>>>>>>>>>>> topic configuration when a topic is created.
> > > >>>>>>>>>>>> 2. The producer looks up the partitioning strategy before
> > > >>>>>>>>>>>> writing
> > > >>>>>>>>>>>> to
> > > >>>>>>>>>>>> a
> > > >>>>>>>>>>>> topic and includes it in the produce request (for
> fencing).
> > If
> > > >>>>>>>>>>>> it
> > > >>>>>>>>>>>> doesn't
> > > >>>>>>>>>>>> have an implementation for the configured strategy, it
> > fails.
> > > >>>>>>>>>>>> 3. The consumer also looks up the partitioning strategy
> and
> > > >>>>>>>>>>>> uses it
> > > >>>>>>>>>>>> to
> > > >>>>>>>>>>>> determine dependencies when reading a new epoch. It could
> > > either
> > > >>>>>>>>>>>> fail
> > > >>>>>>>>>>>> or
> > > >>>>>>>>>>>> make the most conservative dependency assumptions if it
> > > doesn't
> > > >>>>>>>>>>>> know
> > > >>>>>>>>>>>> how
> > > >>>>>>>>>>>> to
> > > >>>>>>>>>>>> implement the partitioning strategy. For the consumer, the
> > new
> > > >>>>>>>>>>>> interface
> > > >>>>>>>>>>>> might look something like this:
> > > >>>>>>>>>>>>
> > > >>>>>>>>>>>> // Return the partition dependencies following an epoch
> bump
> > > >>>>>>>>>>>> Map<Integer, List<Integer>> dependencies(int
> > > >>>>>>>>>>>> numPartitionsBeforeEpochBump,
> > > >>>>>>>>>>>> int numPartitionsAfterEpochBump)
> > > >>>>>>>>>>>>
> > > >>>>>>>>>>>> The unordered case then is just a particular
> implementation
> > > >>>>>>>>>>>> which
> > > >>>>>>>>>>>> never
> > > >>>>>>>>>>>> has
> > > >>>>>>>>>>>> any epoch dependencies. To implement this, we would need
> > some
> > > >>>>>>>>>>>> way
> > > >>>>>>>>>>>> for
> > > >>>>>>>>>>>> the
> > > >>>>>>>>>>>> consumer to find out how many partitions there were in
> each
> > > >>>>>>>>>>>> epoch,
> > > >>>>>>>>>>>> but
> > > >>>>>>>>>>>> maybe that's not too unreasonable.
> > > >>>>>>>>>>>>
> > > >>>>>>>>>>>> Thanks,
> > > >>>>>>>>>>>> Jason
> > > >>>>>>>>>>>>
> > > >>>>>>>>>>>>
> > > >>>>>>>>>>>> On Mon, Mar 5, 2018 at 4:51 AM, Jan Filipiak <
> > > >>>>>>>>>>>> Jan.Filipiak@trivago.com
> > > >>>>>>>>>>>> wrote:
> > > >>>>>>>>>>>>
> > > >>>>>>>>>>>> Hi Dong
> > > >>>>>>>>>>>>
> > > >>>>>>>>>>>> thank you very much for your questions.
> > > >>>>>>>>>>>>
> > > >>>>>>>>>>>> regarding the time spend copying data across:
> > > >>>>>>>>>>>>> It is correct that copying data from a topic with one
> > > partition
> > > >>>>>>>>>>>>> mapping
> > > >>>>>>>>>>>>>
> > > >>>>>>>>>>>>> to
> > > >>>>>>>>>>>>>
> > > >>>>>>>>>>>>> a topic with a different partition mapping takes way
> longer
> > > >>>>>>>>>>>>> than
> > > >>>>>>>>>>>>>
> > > >>>>>>>>>>>> we
> > > >>>>>>>>>>>> can
> > > >>>>>>>>>>>>
> > > >>>>>>>>>>>> stop producers. Tens of minutes is a very optimistic
> > estimate
> > > >>>>>>>>>>>> here.
> > > >>>>>>>>>>>>
> > > >>>>>>>>>>>>> Many
> > > >>>>>>>>>>>>> people can not afford copy full steam and therefore will
> > have
> > > >>>>>>>>>>>>> some
> > > >>>>>>>>>>>>> rate
> > > >>>>>>>>>>>>> limiting in place, this can bump the timespan into the
> > day's.
> > > >>>>>>>>>>>>> The
> > > >>>>>>>>>>>>> good
> > > >>>>>>>>>>>>>
> > > >>>>>>>>>>>>> part
> > > >>>>>>>>>>>>>
> > > >>>>>>>>>>>>> is that the vast majority of the data can be copied while
> > the
> > > >>>>>>>>>>>>>
> > > >>>>>>>>>>>> producers
> > > >>>>>>>>>>>>
> > > >>>>>>>>>>>> are
> > > >>>>>>>>>>>>
> > > >>>>>>>>>>>>> still going. One can then, piggyback the consumers ontop
> of
> > > >>>>>>>>>>>>> this
> > > >>>>>>>>>>>>>
> > > >>>>>>>>>>>> timeframe,
> > > >>>>>>>>>>>>
> > > >>>>>>>>>>>>> by the method mentioned (provide them an mapping from
> their
> > > old
> > > >>>>>>>>>>>>>
> > > >>>>>>>>>>>> offsets
> > > >>>>>>>>>>>>
> > > >>>>>>>>>>>> to
> > > >>>>>>>>>>>>
> > > >>>>>>>>>>>>> new offsets in their repartitioned topics. In that way we
> > > >>>>>>>>>>>>> separate
> > > >>>>>>>>>>>>>
> > > >>>>>>>>>>>> migration of consumers from migration of producers
> > (decoupling
> > > >>>>>>>>>>>>
> > > >>>>>>>>>>>>> these
> > > >>>>>>>>>>>>> is
> > > >>>>>>>>>>>>> what kafka is strongest at). The time to actually swap
> over
> > > the
> > > >>>>>>>>>>>>> producers
> > > >>>>>>>>>>>>> should be kept minimal by ensuring that when a swap
> attempt
> > > is
> > > >>>>>>>>>>>>> started
> > > >>>>>>>>>>>>>
> > > >>>>>>>>>>>>> the
> > > >>>>>>>>>>>>>
> > > >>>>>>>>>>>>> consumer copying over should be very close to the log end
> > and
> > > >>>>>>>>>>>>> is
> > > >>>>>>>>>>>>>
> > > >>>>>>>>>>>> expected
> > > >>>>>>>>>>>>
> > > >>>>>>>>>>>>> to finish within the next fetch. The operation should
> have
> > a
> > > >>>>>>>>>>>>> time-out
> > > >>>>>>>>>>>>> and
> > > >>>>>>>>>>>>> should be "reattemtable".
> > > >>>>>>>>>>>>>
> > > >>>>>>>>>>>>> Importance of logcompaction:
> > > >>>>>>>>>>>>> If a producer produces key A, to partiton 0, its forever
> > > gonna
> > > >>>>>>>>>>>>> be
> > > >>>>>>>>>>>>> there,
> > > >>>>>>>>>>>>> unless it gets deleted. The record might sit in there for
> > > >>>>>>>>>>>>> years. A
> > > >>>>>>>>>>>>> new
> > > >>>>>>>>>>>>> producer started with the new partitions will fail to
> > delete
> > > >>>>>>>>>>>>> the
> > > >>>>>>>>>>>>> record
> > > >>>>>>>>>>>>>
> > > >>>>>>>>>>>>> in
> > > >>>>>>>>>>>>>
> > > >>>>>>>>>>>>> the correct partition. Th record will be there forever
> and
> > > one
> > > >>>>>>>>>>>>> can
> > > >>>>>>>>>>>>>
> > > >>>>>>>>>>>> not
> > > >>>>>>>>>>>>
> > > >>>>>>>>>>>> reliable bootstrap new consumers. I cannot see how linear
> > > >>>>>>>>>>>> hashing
> > > >>>>>>>>>>>>
> > > >>>>>>>>>>>>> can
> > > >>>>>>>>>>>>>
> > > >>>>>>>>>>>>> solve
> > > >>>>>>>>>>>>>
> > > >>>>>>>>>>>>> this.
> > > >>>>>>>>>>>>>
> > > >>>>>>>>>>>> Regarding your skipping of userland copying:
> > > >>>>>>>>>>>>
> > > >>>>>>>>>>>>> 100%, copying the data across in userland is, as far as i
> > can
> > > >>>>>>>>>>>>> see,
> > > >>>>>>>>>>>>> only
> > > >>>>>>>>>>>>> a
> > > >>>>>>>>>>>>> usecase for log compacted topics. Even for logcompaction
> +
> > > >>>>>>>>>>>>> retentions
> > > >>>>>>>>>>>>> it
> > > >>>>>>>>>>>>> should only be opt-in. Why did I bring it up? I think log
> > > >>>>>>>>>>>>> compaction
> > > >>>>>>>>>>>>> is
> > > >>>>>>>>>>>>> a
> > > >>>>>>>>>>>>> very important feature to really embrace kafka as a "data
> > > >>>>>>>>>>>>> plattform".
> > > >>>>>>>>>>>>> The
> > > >>>>>>>>>>>>> point I also want to make is that copying data this way
> is
> > > >>>>>>>>>>>>> completely
> > > >>>>>>>>>>>>> inline with the kafka architecture. it only consists of
> > > reading
> > > >>>>>>>>>>>>> and
> > > >>>>>>>>>>>>>
> > > >>>>>>>>>>>>> writing
> > > >>>>>>>>>>>>>
> > > >>>>>>>>>>>>> to topics.
> > > >>>>>>>>>>>>>
> > > >>>>>>>>>>>> I hope it clarifies more why I think we should aim for
> more
> > > than
> > > >>>>>>>>>>>>
> > > >>>>>>>>>>>>> the
> > > >>>>>>>>>>>>> current KIP. I fear that once the KIP is done not much
> more
> > > >>>>>>>>>>>>> effort
> > > >>>>>>>>>>>>> will
> > > >>>>>>>>>>>>>
> > > >>>>>>>>>>>>> be
> > > >>>>>>>>>>>>>
> > > >>>>>>>>>>>>> taken.
> > > >>>>>>>>>>>>>
> > > >>>>>>>>>>>>
> > > >>>>>>>>>>>> On 04.03.2018 02:28, Dong Lin wrote:
> > > >>>>>>>>>>>>>
> > > >>>>>>>>>>>>> Hey Jan,
> > > >>>>>>>>>>>>>
> > > >>>>>>>>>>>>> In the current proposal, the consumer will be blocked on
> > > >>>>>>>>>>>>> waiting
> > > >>>>>>>>>>>>> for
> > > >>>>>>>>>>>>>
> > > >>>>>>>>>>>>> other
> > > >>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>> consumers of the group to consume up to a given offset.
> In
> > > >>>>>>>>>>>>>> most
> > > >>>>>>>>>>>>>>
> > > >>>>>>>>>>>>> cases,
> > > >>>>>>>>>>>>> all
> > > >>>>>>>>>>>>> consumers should be close to the LEO of the partitions
> when
> > > the
> > > >>>>>>>>>>>>> partition
> > > >>>>>>>>>>>>> expansion happens. Thus the time waiting should not be
> long
> > > >>>>>>>>>>>>> e.g.
> > > >>>>>>>>>>>>> on
> > > >>>>>>>>>>>>> the
> > > >>>>>>>>>>>>>
> > > >>>>>>>>>>>>> order of seconds. On the other hand, it may take a long
> > time
> > > to
> > > >>>>>>>>>>>>> wait
> > > >>>>>>>>>>>>>
> > > >>>>>>>>>>>>> for
> > > >>>>>>>>>>>>>> the entire partition to be copied -- the amount of time
> is
> > > >>>>>>>>>>>>>> proportional
> > > >>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>> to
> > > >>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>> the amount of existing data in the partition, which can
> > take
> > > >>>>>>>>>>>>>>
> > > >>>>>>>>>>>>> tens of
> > > >>>>>>>>>>>>>
> > > >>>>>>>>>>>>> minutes. So the amount of time that we stop consumers may
> > not
> > > >>>>>>>>>>>>> be
> > > >>>>>>>>>>>>> on
> > > >>>>>>>>>>>>>
> > > >>>>>>>>>>>>> the
> > > >>>>>>>>>>>>>> same order of magnitude.
> > > >>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>> If we can implement this suggestion without copying data
> > > over
> > > >>>>>>>>>>>>>> in
> > > >>>>>>>>>>>>>> purse
> > > >>>>>>>>>>>>>> userland, it will be much more valuable. Do you have
> ideas
> > > on
> > > >>>>>>>>>>>>>> how
> > > >>>>>>>>>>>>>> this
> > > >>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>> can
> > > >>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>> be done?
> > > >>>>>>>>>>>>>>
> > > >>>>>>>>>>>>> Not sure why the current KIP not help people who depend
> on
> > > log
> > > >>>>>>>>>>>>>
> > > >>>>>>>>>>>>> compaction.
> > > >>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>> Could you elaborate more on this point?
> > > >>>>>>>>>>>>>>
> > > >>>>>>>>>>>>> Thanks,
> > > >>>>>>>>>>>>>
> > > >>>>>>>>>>>>> Dong
> > > >>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>> On Wed, Feb 28, 2018 at 10:55 PM, Jan
> > > >>>>>>>>>>>>>> Filipiak<Jan.Filipiak@trivago.
> > > >>>>>>>>>>>>>> com
> > > >>>>>>>>>>>>>> wrote:
> > > >>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>> Hi Dong,
> > > >>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>> I tried to focus on what the steps are one can currently
> > > >>>>>>>>>>>>>> perform
> > > >>>>>>>>>>>>>> to
> > > >>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>> expand
> > > >>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>> or shrink a keyed topic while maintaining a top notch
> > > >>>>>>>>>>>>>>> semantics.
> > > >>>>>>>>>>>>>>> I can understand that there might be confusion about
> > > >>>>>>>>>>>>>>> "stopping
> > > >>>>>>>>>>>>>>> the
> > > >>>>>>>>>>>>>>> consumer". It is exactly the same as proposed in the
> KIP.
> > > >>>>>>>>>>>>>>> there
> > > >>>>>>>>>>>>>>> needs
> > > >>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>> to
> > > >>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>> be
> > > >>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>> a time the producers agree on the new partitioning. The
> > > extra
> > > >>>>>>>>>>>>>
> > > >>>>>>>>>>>>> semantics I
> > > >>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>> want to put in there is that we have a possibility to
> > wait
> > > >>>>>>>>>>>>>>> until
> > > >>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>> all
> > > >>>>>>>>>>>>>
> > > >>>>>>>>>>>>> the
> > > >>>>>>>>>>>>>
> > > >>>>>>>>>>>>> existing data
> > > >>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>> is copied over into the new partitioning scheme. When I
> > say
> > > >>>>>>>>>>>>> stopping
> > > >>>>>>>>>>>>>
> > > >>>>>>>>>>>>> I
> > > >>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>> think more of having a memory barrier that ensures the
> > > >>>>>>>>>>>>>>> ordering. I
> > > >>>>>>>>>>>>>>> am
> > > >>>>>>>>>>>>>>> still
> > > >>>>>>>>>>>>>>> aming for latencies  on the scale of leader failovers.
> > > >>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>> Consumers have to explicitly adapt the new partitioning
> > > >>>>>>>>>>>>>>> scheme
> > > >>>>>>>>>>>>>>> in
> > > >>>>>>>>>>>>>>> the
> > > >>>>>>>>>>>>>>> above scenario. The reason is that in these cases where
> > you
> > > >>>>>>>>>>>>>>> are
> > > >>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>> dependent
> > > >>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>> on a particular partitioning scheme, you also have
> other
> > > >>>>>>>>>>>>>>> topics
> > > >>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>> that
> > > >>>>>>>>>>>>>
> > > >>>>>>>>>>>>> have
> > > >>>>>>>>>>>>>
> > > >>>>>>>>>>>>> co-partition enforcements or the kind -frequently.
> > Therefore
> > > >>>>>>>>>>>>>> all
> > > >>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>> your
> > > >>>>>>>>>>>>>
> > > >>>>>>>>>>>>> other
> > > >>>>>>>>>>>>>
> > > >>>>>>>>>>>>> input topics might need to grow accordingly.
> > > >>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>> What I was suggesting was to streamline all these
> > > operations
> > > >>>>>>>>>>>>>>> as
> > > >>>>>>>>>>>>>>> best
> > > >>>>>>>>>>>>>>> as
> > > >>>>>>>>>>>>>>> possible to have "real" partition grow and shrinkage
> > going
> > > >>>>>>>>>>>>>>> on.
> > > >>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>> Migrating
> > > >>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>> the producers to a new partitioning scheme can be much
> > more
> > > >>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>> streamlined
> > > >>>>>>>>>>>>>
> > > >>>>>>>>>>>>> with proper broker support for this. Migrating consumer
> is
> > a
> > > >>>>>>>>>>>>> step
> > > >>>>>>>>>>>>>
> > > >>>>>>>>>>>>> that
> > > >>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>> might be made completly unnecessary if - for example
> > > streams
> > > >>>>>>>>>>>>>>> -
> > > >>>>>>>>>>>>>>> takes
> > > >>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>> the
> > > >>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>> gcd as partitioning scheme instead of enforcing 1 to 1.
> > > >>>>>>>>>>>>>>> Connect
> > > >>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>> consumers
> > > >>>>>>>>>>>>>
> > > >>>>>>>>>>>>> and other consumers should be fine anyways.
> > > >>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>> I hope this makes more clear where I was aiming at. The
> > rest
> > > >>>>>>>>>>>>> needs
> > > >>>>>>>>>>>>>
> > > >>>>>>>>>>>>> to
> > > >>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>> be
> > > >>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>> figured out. The only danger i see is that when we are
> > > >>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>> introducing
> > > >>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>> this
> > > >>>>>>>>>>>>>
> > > >>>>>>>>>>>>> feature as supposed in the KIP, it wont help any people
> > > >>>>>>>>>>>>> depending
> > > >>>>>>>>>>>>> on
> > > >>>>>>>>>>>>>
> > > >>>>>>>>>>>>> log
> > > >>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>> compaction.
> > > >>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>> The other thing I wanted to mention is that I believe
> the
> > > >>>>>>>>>>>>> current
> > > >>>>>>>>>>>>>
> > > >>>>>>>>>>>>> suggestion (without copying data over) can be implemented
> > in
> > > >>>>>>>>>>>>>> pure
> > > >>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>> userland
> > > >>>>>>>>>>>>>>> with a custom partitioner and a small feedbackloop from
> > > >>>>>>>>>>>>>>> ProduceResponse
> > > >>>>>>>>>>>>>>> =>
> > > >>>>>>>>>>>>>>> Partitionier in coorporation with a change management
> > > system.
> > > >>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>> Best Jan
> > > >>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>> On 28.02.2018 07:13, Dong Lin wrote:
> > > >>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>> Hey Jan,
> > > >>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>> I am not sure if it is acceptable for producer to be
> > > stopped
> > > >>>>>>>>>>>>>>> for a
> > > >>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>> while,
> > > >>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>> particularly for online application which requires low
> > > >>>>>>>>>>>>>>>> latency. I
> > > >>>>>>>>>>>>>>>> am
> > > >>>>>>>>>>>>>>>> also
> > > >>>>>>>>>>>>>>>> not sure how consumers can switch to a new topic. Does
> > > user
> > > >>>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>> application
> > > >>>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>> needs to explicitly specify a different topic for
> > > >>>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>> producer/consumer
> > > >>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>> to
> > > >>>>>>>>>>>>>>
> > > >>>>>>>>>>>>> subscribe to? It will be helpful for discussion if you
> can
> > > >>>>>>>>>>>>> provide
> > > >>>>>>>>>>>>>
> > > >>>>>>>>>>>>> more
> > > >>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>> detail on the interface change for this solution.
> > > >>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>> Thanks,
> > > >>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>> Dong
> > > >>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>> On Mon, Feb 26, 2018 at 12:48 AM, Jan
> > > >>>>>>>>>>>>>>>> Filipiak<Jan.Filipiak@trivago.
> > > >>>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>> com
> > > >>>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>> wrote:
> > > >>>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>> Hi,
> > > >>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>> just want to throw my though in. In general the
> > > functionality
> > > >>>>>>>>>>>>>> is
> > > >>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>> very
> > > >>>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>> usefull, we should though not try to find the
> > architecture
> > > >>>>>>>>>>>>>>>> to
> > > >>>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>> hard
> > > >>>>>>>>>>>>>>>>> while
> > > >>>>>>>>>>>>>>>>> implementing.
> > > >>>>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>>> The manual steps would be to
> > > >>>>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>>> create a new topic
> > > >>>>>>>>>>>>>>>>> the mirrormake from the new old topic to the new
> topic
> > > >>>>>>>>>>>>>>>>> wait for mirror making to catch up.
> > > >>>>>>>>>>>>>>>>> then put the consumers onto the new topic
> > > >>>>>>>>>>>>>>>>>            (having mirrormaker spit out a mapping
> from
> > > old
> > > >>>>>>>>>>>>>>>>> offsets to
> > > >>>>>>>>>>>>>>>>> new
> > > >>>>>>>>>>>>>>>>> offsets:
> > > >>>>>>>>>>>>>>>>>                if topic is increased by factor X
> there
> > is
> > > >>>>>>>>>>>>>>>>> gonna
> > > >>>>>>>>>>>>>>>>> be a
> > > >>>>>>>>>>>>>>>>> clean
> > > >>>>>>>>>>>>>>>>> mapping from 1 offset in the old topic to X offsets
> in
> > > the
> > > >>>>>>>>>>>>>>>>> new
> > > >>>>>>>>>>>>>>>>> topic,
> > > >>>>>>>>>>>>>>>>>                if there is no factor then there is no
> > > >>>>>>>>>>>>>>>>> chance to
> > > >>>>>>>>>>>>>>>>> generate a
> > > >>>>>>>>>>>>>>>>> mapping that can be reasonable used for continuing)
> > > >>>>>>>>>>>>>>>>>            make consumers stop at appropriate points
> > and
> > > >>>>>>>>>>>>>>>>> continue
> > > >>>>>>>>>>>>>>>>> consumption
> > > >>>>>>>>>>>>>>>>> with offsets from the mapping.
> > > >>>>>>>>>>>>>>>>> have the producers stop for a minimal time.
> > > >>>>>>>>>>>>>>>>> wait for mirrormaker to finish
> > > >>>>>>>>>>>>>>>>> let producer produce with the new metadata.
> > > >>>>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>>> Instead of implementing the approach suggest in the
> KIP
> > > >>>>>>>>>>>>>>>>> which
> > > >>>>>>>>>>>>>>>>> will
> > > >>>>>>>>>>>>>>>>> leave
> > > >>>>>>>>>>>>>>>>> log compacted topic completely crumbled and unusable.
> > > >>>>>>>>>>>>>>>>> I would much rather try to build infrastructure to
> > > support
> > > >>>>>>>>>>>>>>>>> the
> > > >>>>>>>>>>>>>>>>> mentioned
> > > >>>>>>>>>>>>>>>>> above operations more smoothly.
> > > >>>>>>>>>>>>>>>>> Especially having producers stop and use another
> topic
> > is
> > > >>>>>>>>>>>>>>>>> difficult
> > > >>>>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>>> and
> > > >>>>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>>> it would be nice if one can trigger "invalid
> metadata"
> > > >>>>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>> exceptions
> > > >>>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>> for
> > > >>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>> them
> > > >>>>>>>>>>>>>
> > > >>>>>>>>>>>>> and
> > > >>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>> if one could give topics aliases so that their produces
> > > with
> > > >>>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>>> the
> > > >>>>>>>>>>>>>>>>> old
> > > >>>>>>>>>>>>>>>>> topic
> > > >>>>>>>>>>>>>>>>> will arrive in the new topic.
> > > >>>>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>>> The downsides are obvious I guess ( having the same
> > data
> > > >>>>>>>>>>>>>>>>> twice
> > > >>>>>>>>>>>>>>>>> for
> > > >>>>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>>> the
> > > >>>>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>>> transition period, but kafka tends to scale well with
> > > >>>>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>> datasize).
> > > >>>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>> So
> > > >>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>> its a
> > > >>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>> nicer fit into the architecture.
> > > >>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>> I further want to argument that the functionality by
> the
> > > KIP
> > > >>>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>>> can
> > > >>>>>>>>>>>>>>>>> completely be implementing in "userland" with a
> custom
> > > >>>>>>>>>>>>>>>>> partitioner
> > > >>>>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>>> that
> > > >>>>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>>> handles the transition as needed. I would appreciate
> if
> > > >>>>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>> someone
> > > >>>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>> could
> > > >>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>> point
> > > >>>>>>>>>>>>>
> > > >>>>>>>>>>>>> out what a custom partitioner couldn't handle in this
> case?
> > > >>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>> With the above approach, shrinking a topic becomes the
> > same
> > > >>>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>>> steps.
> > > >>>>>>>>>>>>>>>>> Without
> > > >>>>>>>>>>>>>>>>> loosing keys in the discontinued partitions.
> > > >>>>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>>> Would love to hear what everyone thinks.
> > > >>>>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>>> Best Jan
> > > >>>>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>>> On 11.02.2018 00:35, Dong Lin wrote:
> > > >>>>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>>> Hi all,
> > > >>>>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>>> I have created KIP-253: Support in-order message
> > delivery
> > > >>>>>>>>>>>>>>>>> with
> > > >>>>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>>> partition
> > > >>>>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>>> expansion. See
> > > >>>>>>>>>>>>>>>>>> https://cwiki.apache.org/confl
> > > >>>>>>>>>>>>>>>>>> uence/display/KAFKA/KIP-253%
> > > >>>>>>>>>>>>>>>>>> 3A+Support+in-order+message+de
> > > >>>>>>>>>>>>>>>>>> livery+with+partition+expansio
> > > >>>>>>>>>>>>>>>>>> n
> > > >>>>>>>>>>>>>>>>>> .
> > > >>>>>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>>>> This KIP provides a way to allow messages of the
> same
> > > key
> > > >>>>>>>>>>>>>>>>>> from
> > > >>>>>>>>>>>>>>>>>> the
> > > >>>>>>>>>>>>>>>>>> same
> > > >>>>>>>>>>>>>>>>>> producer to be consumed in the same order they are
> > > >>>>>>>>>>>>>>>>>> produced
> > > >>>>>>>>>>>>>>>>>> even
> > > >>>>>>>>>>>>>>>>>> if
> > > >>>>>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>>>> we
> > > >>>>>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>>>> expand partition of the topic.
> > > >>>>>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>>> Thanks,
> > > >>>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>> Dong
> > > >>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>>>>
> > > >>>>
> > > >>
> > > >>
> > > >
> > >
> >
>

Re: [DISCUSS] KIP-253: Support in-order message delivery with partition expansion

Posted by Jun Rao <ju...@confluent.io>.
Hi, John,

Thanks for the reply. I agree that the backfill approach works cleaner for
newly started consumers. I am just not sure if it's a good primitive to
support for existing consumers. One of the challenges that I see is the
remapping of the offsets. In your approach, we need to copy the existing
records from the partitions in generation 0 to generation 1. Those records
will get different offsets in the new generation. The broker will have to
store those offset mappings somewhere. When the backfill completes, you can
delete generation 0's data. However, the broker can't throw away the offset
mappings immediately since it doesn't know if there is any existing
consumer still consuming generation 0's records. In a compacted topic, the
broker probably can only safely remove the offset mappings when all records
in generation 0 are removed by the cleaner. This may never happen though.

If we reshuffle the input inside a KStreams job, it obviates the need for
offset remapping on the broker.

Jun

On Tue, Mar 27, 2018 at 11:34 AM, John Roesler <jo...@confluent.io> wrote:

> Hey Dong and Jun,
>
> Thanks for the thoughtful responses. If you don't mind, I'll mix my replies
> together to try for a coherent response. I'm not too familiar with
> mailing-list etiquette, though.
>
> I'm going to keep numbering my points because it makes it easy for you all
> to respond.
>
> Point 1:
> As I read it, KIP-253 is *just* about properly fencing the producers and
> consumers so that you preserve the correct ordering of records during
> partition expansion. This is clearly necessary regardless of anything else
> we discuss. I think this whole discussion about backfill, consumers,
> streams, etc., is beyond the scope of KIP-253. But it would be cumbersome
> to start a new thread at this point.
>
> I had missed KIP-253's Proposed Change #9 among all the details... I think
> this is a nice addition to the proposal. One thought is that it's actually
> irrelevant whether the hash function is linear. This is simply an algorithm
> for moving a key from one partition to another, so the type of hash
> function need not be a precondition. In fact, it also doesn't matter
> whether the topic is compacted or not, the algorithm works regardless.
>
> I think this is a good algorithm to keep in mind, as it might solve a
> variety of problems, but it does have a downside: that the producer won't
> know whether or not K1 was actually in P1, it just knows that K1 was in
> P1's keyspace before the new epoch. Therefore, it will have to
> pessimistically send (K1,null) to P1 just in case. But the next time K1
> comes along, the producer *also* won't remember that it already retracted
> K1 from P1, so it will have to send (K1,null) *again*. By extension, every
> time the producer sends to P2, it will also have to send a tombstone to P1,
> which is a pretty big burden. To make the situation worse, if there is a
> second split, say P2 becomes P2 and P3, then any key Kx belonging to P3
> will also have to be retracted from P2 *and* P1, since the producer can't
> know whether Kx had been last written to P2 or P1. Over a long period of
> time, this clearly becomes a issue, as the producer must send an arbitrary
> number of retractions along with every update.
>
> In contrast, the proposed backfill operation has an end, and after it ends,
> everyone can afford to forget that there ever was a different partition
> layout.
>
> Really, though, figuring out how to split compacted topics is beyond the
> scope of KIP-253, so I'm not sure #9 really even needs to be in this KIP...
> We do need in-order delivery during partition expansion. It would be fine
> by me to say that you *cannot* expand partitions of a log-compacted topic
> and call it a day. I think it would be better to tackle that in another
> KIP.
>
>
> Point 2:
> Regarding whether the consumer re-shuffles its inputs, this is always on
> the table; any consumer who wants to re-shuffle its input is free to do so.
> But this is currently not required. It's just that the current high-level
> story with Kafka encourages the use of partitions as a unit of concurrency.
> As long as consumers are single-threaded, they can happily consume a single
> partition without concurrency control of any kind. This is a key aspect to
> this system that lets folks design high-throughput systems on top of it
> surprisingly easily. If all consumers were instead encouraged/required to
> implement a repartition of their own, then the consumer becomes
> significantly more complex, requiring either the consumer to first produce
> to its own intermediate repartition topic or to ensure that consumer
> threads have a reliable, high-bandwith channel of communication with every
> other consumer thread.
>
> Either of those tradeoffs may be reasonable for a particular user of Kafka,
> but I don't know if we're in a position to say that they are reasonable for
> *every* user of Kafka.
>
>
> Point 3:
> Regarding Jun's point about this use case, "(3) stateful and maintaining
> the
> states in a local store", I agree that they may use a framework *like*
> Kafka Streams, but that is not the same as using Kafka Streams. This is why
> I think it's better to solve it in Core: because it is then solved for
> KStreams and also for everything else that facilitates local state
> maintenance. To me, Streams is a member of the category of "stream
> processing frameworks", which is itself a subcategory of "things requiring
> local state maintenence". I'm not sure if it makes sense to assert that
> Streams is a sufficient and practical replacement for everything in "things
> requiring local state maintenence".
>
> But, yes, I do agree that per-key ordering is an absolute requirement,
> therefore I think that KIP-253 itself is a necessary step. Regarding the
> coupling of the state store partitioning to the topic partitioning, yes,
> this is an issue we are discussing solutions to right now. We may go ahead
> and introduce an overpartition layer on our inputs to solve it, but then
> again, if we get the ability to split partitions with backfill, we may not
> need to!
>
>
> Point 4:
> On this:
>
> > Regarding thought 2: If we don't care about the stream use-case, then the
> > current KIP probably has already addressed problem without requiring
> > consumer to know the partition function. If we care about the stream
> > use-case, we already need coordination across producers of different
> > topics, i.e. the same partition function needs to be used by producers of
> > topics A and B in order to join topics A and B. Thus, it might be
> > reasonable to extend coordination a bit and say we need coordination
> across
> > clients (i.e. producer and consumer), such that consumer knows the
> > partition function used by producer. If we do so, then we can let
> consumer
> > re-copy data for the change log topic using the same partition function
> as
> > producer. This approach has lower overhead as compared to having producer
> > re-copy data of the input topic.
> > Also, producer currently does not need to know the data already produced
> to
> > the topic. If we let producer split/merge partition, it would require
> > producer to consume the existing data, which intuitively is the task of
> > consumer.
>
>
> I think we do care about use cases *like* Streams, I just don't think we
> should rely on Streams to implement a feature of Core like partition
> expansion.
>
> Note, though, that we (Streams) do not require coordination across
> producers. If two topics are certified to be co-partitioned, then Streams
> apps can make use of that knowledge to optimize their topology (skipping a
> repartition). But if they don't know whether they are co-partitioned, then
> they'd better go ahead and repartition within the topology. This is the
> current state.
>
> A huge selling point of Kafka is enabling different parts of loosely
> coupled organizations to produce and consume data independently. Some
> coordination between producers and consumers is necessary, like
> coordinating on the names of topics and their schemas. But Kafka's value
> proposition w.r.t. ESBs, etc. is inversely proportional to the amount of
> coordination required. I think it behooves us to be extremely skeptical
> about introducing any coordination beyond correctness protocols.
>
> Asking producers and consumers, or even two different producers, to share
> code like the partition function is a pretty huge ask. What if they are
> using different languages?
>
> Comparing organizational overhead vs computational overhead, there are
> maybe two orders of magnitude difference between them. In other words, I
> would happily take on the (linear) overhead of having the producer re-copy
> the data once during a re-partition in order to save the organizational
> overhead of tying all the producers and consumers together across multiple
> boundaries.
>
> On that last paragraph: note that the producer *did* know the data it
> already produced. It handled it the first time around. Asking it to
> re-produce it into a new partition layout is squarely within its scope of
> capabilities. Contrast this with the alternative, asking the consumer to
> re-partition the data. I think this is even less intuitive, when the
> partition function belongs to the producer.
>
>
> Point 5:
> Dong asked this:
>
> > For stream use-case that needs to increase consumer number, the
> > existing consumer can backfill the existing data in the change log topic
> to
> > the same change log topic with the new partition number, before the new
> set
> > of consumers bootstrap state from the new partitions of the change log
> > topic, right?
>
>
> In this sense, the "consumer" is actually the producer of the changelog
> topic, so if we support partition expansion + backfill as a producer/broker
> operation, then it would be very straightforward for Streams to split a
> state store. As you say, they would simply instruct the broker to split the
> changelog topic's partitions, then backfill. Once the backfill is ready,
> they can create a new crop of StandbyTasks to bootstrap the more granular
> state stores and finally switch over to them when they are ready.
>
> But this actually seems to be an argument in favor of split+backfill, so
> maybe I missed the point.
>
> You also asked me to explain why copying the "input" topic is better than
> copying the "changelog" topic. I think they are totally independent,
> actually. For one thing, you can't depend on the existence of a "changelog"
> topic in general, only within Streams, but Kafka's user base clearly
> exceeds Streams's user base. Plus, you actually also can't depend on the
> existence of a changelog topic within Streams, since that is an optional
> feature of *some* state store implementations. Even in the situation where
> you do have a changelog topic in Streams, there may be use cases where it
> makes sense to expand the partitions of just the input, or just the
> changelog.
>
> The ask for a Core feature of split+backfill is really about supporting the
> use case of splitting partitions in log-compacted topics, regardless of
> whether that topic is an "input" or a "changelog" or anything else for that
> matter.
>
>
> Point 6:
> On the concern about the performance overhead of copying data between the
> brokers, I think it's actually a bit overestimated. Splitting a topic's
> partition is probably rare, certainly rarer in general than bootstrapping
> new consumers on that topic. If "bootstrapping new consumers" means that
> they have to re-shuffle the data before they consume it, then you wind up
> copying the same record multiple times:
>
> (broker: input topic) -> (initial consumer) -> (broker: repartition topic)
> -> (real consumer)
>
> That's 3x, and it's also 3x for every new record after the split as well,
> since you don't get to stop repartitioning/reshuffling once you start.
>
> Whereas if you do a backfill in something like the procedure I outlined,
> you only copy the prefix of the partition before the split, and you send it
> once to the producer and then once to the new generation partition. Plus,
> assuming we're splitting the partition for the benefit of consumers,
> there's no reason we can't co-locate the post-split partitions on the same
> host as the pre-split partition, making the second copy a local filesystem
> operation.
>
> Even if you follow these two copies up with bootstrapping a new consumer,
> it's still rare for this to occur, so you get to amortize these copies over
> the lifetime of the topic, whereas a reshuffle just keeps making copies for
> every new event.
>
> And finally, I really do think that regardless of any performance concerns
> about this operation, if it preserves loose organizational coupling, it is
> certainly worth it.
>
>
> In conclusion:
> It might actually be a good idea for us to clarify the scope of KIP-253. If
> we're all agreed that it's a good algorithm for allowing in-order message
> delivery during partition expansion, then we can continue this discussion
> as a new KIP, something like "backfill with partition expansion". This
> would let Dong proceed with KIP-253. On the other hand, if it seems like
> this conversation may alter the design of KIP-253, then maybe we *should*
> just finish working it out.
>
> For my part, my only concern about KIP-253 is the one I raised earlier.
>
> Thanks again, all, for considering these points,
> -John
>
>
> On Tue, Mar 27, 2018 at 2:10 AM, Dong Lin <li...@gmail.com> wrote:
>
> > On Tue, Mar 27, 2018 at 12:04 AM, Dong Lin <li...@gmail.com> wrote:
> >
> > > Hey Jan,
> > >
> > > Thanks for the enthusiasm in improving Kafka's design. Now that I have
> > > read through your discussion with Jun, here are my thoughts:
> > >
> > > - The latest proposal should with log compacted topics by properly
> > > deleting old messages after a new message with the same key is
> produced.
> > So
> > > it is probably not a concern anymore. Could you comment if there is
> still
> > > issue?
> > >
> > > - I wrote the SEP-5 and I am pretty familiar with the motivation and
> the
> > > design of SEP-5. SEP-5 is probably orthornal to the motivation of this
> > KIP.
> > > The goal of SEP-5 is to allow user to increase task number of an
> existing
> > > Samza job. But if we increase the partition number of input topics,
> > > messages may still be consumed out-of-order by tasks in Samza which
> cause
> > > incorrect result. Similarly, the approach you proposed does not seem to
> > > ensure that the messages can be delivered in order, even if we can make
> > > sure that each consumer instance is assigned the set of new partitions
> > > covering the same set of keys.
> > >
> >
> > Let me correct this comment. The approach of copying data to a new topic
> > can ensure in-order message delivery suppose we properly migrate offsets
> > from old topic to new topic.
> >
> >
> > > - I am trying to understand why it is better to copy the data instead
> of
> > > copying the change log topic for streaming use-case. For core Kafka
> > > use-case, and for the stream use-case that does not need to increase
> > > consumers, the current KIP already supports in-order delivery without
> the
> > > overhead of copying the data. For stream use-case that needs to
> increase
> > > consumer number, the existing consumer can backfill the existing data
> in
> > > the change log topic to the same change log topic with the new
> partition
> > > number, before the new set of consumers bootstrap state from the new
> > > partitions of the change log topic. If this solution works, then could
> > you
> > > summarize the advantage of copying the data of input topic as compared
> to
> > > copying the change log topic? For example, does it enable more
> use-case,
> > > simplify the implementation of Kafka library, or reduce the operation
> > > overhead etc?
> > >
> > > Thanks,
> > > Dong
> > >
> > >
> > > On Wed, Mar 21, 2018 at 6:57 AM, Jan Filipiak <
> Jan.Filipiak@trivago.com>
> > > wrote:
> > >
> > >> Hi Jun,
> > >>
> > >> I was really seeing progress in our conversation but your latest reply
> > is
> > >> just devastating.
> > >> I though we were getting close being on the same page now it feels
> like
> > >> we are in different libraries.
> > >>
> > >> I just quickly slam my answers in here. If they are to brief I am
> sorry
> > >> give me a ping and try to go into details more.
> > >> Just want to show that your pro/cons listing is broken.
> > >>
> > >> Best Jan
> > >>
> > >> and want to get rid of this horrible compromise
> > >>
> > >>
> > >> On 19.03.2018 05:48, Jun Rao wrote:
> > >>
> > >>> Hi, Jan,
> > >>>
> > >>> Thanks for the discussion. Great points.
> > >>>
> > >>> Let me try to summarize the approach that you are proposing. On the
> > >>> broker
> > >>> side, we reshuffle the existing data in a topic from current
> partitions
> > >>> to
> > >>> the new partitions. Once the reshuffle fully catches up, switch the
> > >>> consumers to start consuming from the new partitions. If a consumer
> > needs
> > >>> to rebuild its local state (due to partition changes), let the
> consumer
> > >>> rebuild its state by reading all existing data from the new
> partitions.
> > >>> Once all consumers have switches over, cut over the producer to the
> new
> > >>> partitions.
> > >>>
> > >>> The pros for this approach are that :
> > >>> 1. There is just one way to rebuild the local state, which is
> simpler.
> > >>>
> > >> true thanks
> > >>
> > >>>
> > >>> The cons for this approach are:
> > >>> 1. Need to copy existing data.
> > >>>
> > >> Very unfair and not correct. It does not require you to copy over
> > >> existing data. It _allows_ you to copy all existing data.
> > >>
> > >> 2. The cutover of the producer is a bit complicated since it needs to
> > >>> coordinate with all consumer groups.
> > >>>
> > >> Also not true. I explicitly tried to make clear that there is only one
> > >> special consumer (in the case of actually copying data) coordination
> is
> > >> required.
> > >>
> > >>> 3. The rebuilding of the state in the consumer is from the input
> topic,
> > >>> which can be more expensive than rebuilding from the existing state.
> > >>>
> > >> true, but rebuilding state is only required if you want to increase
> > >> processing power, so we assume this is at hand.
> > >>
> > >>> 4. The broker potentially has to know the partitioning function. If
> > this
> > >>> needs to be customized at the topic level, it can be a bit messy.
> > >>>
> > >> I would argue against having the operation being performed by the
> > broker.
> > >> This was not discussed yet but if you see my original email i
> suggested
> > >> otherwise from the beginning.
> > >>
> > >>>
> > >>> Here is an alternative approach by applying your idea not in the
> > broker,
> > >>> but in the consumer. When new partitions are added, we don't move
> > >>> existing
> > >>> data. In KStreams, we first reshuffle the new input data to a new
> topic
> > >>> T1
> > >>> with the old number of partitions and feed T1's data to the rest of
> the
> > >>> pipeline. In the meantime, KStreams reshuffles all existing data of
> the
> > >>> change capture topic to another topic C1 with the new number of
> > >>> partitions.
> > >>> We can then build the state of the new tasks from C1. Once the new
> > states
> > >>> have been fully built, we can cut over the consumption to the input
> > topic
> > >>> and delete T1. This approach works with compacted topic too. If an
> > >>> application reads from the beginning of a compacted topic, the
> consumer
> > >>> will reshuffle the portion of the input when the number of partitions
> > >>> doesn't match the number of tasks.
> > >>>
> > >> We all wipe this idea from our heads instantly. Mixing Ideas from an
> > >> argument is not a resolution strategy
> > >> just leads to horrible horrible software.
> > >>
> > >>
> > >>> The pros of this approach are:
> > >>> 1. No need to copy existing data.
> > >>> 2. Each consumer group can cut over to the new partitions
> > independently.
> > >>> 3. The state is rebuilt from the change capture topic, which is
> cheaper
> > >>> than rebuilding from the input topic.
> > >>> 4. Only the KStreams job needs to know the partitioning function.
> > >>>
> > >>> The cons of this approach are:
> > >>> 1. Potentially the same input topic needs to be reshuffled more than
> > once
> > >>> in different consumer groups during the transition phase.
> > >>>
> > >>> What do you think?
> > >>>
> > >>> Thanks,
> > >>>
> > >>> Jun
> > >>>
> > >>>
> > >>>
> > >>> On Thu, Mar 15, 2018 at 1:04 AM, Jan Filipiak <
> > Jan.Filipiak@trivago.com>
> > >>> wrote:
> > >>>
> > >>> Hi Jun,
> > >>>>
> > >>>> thank you for following me on these thoughts. It was important to me
> > to
> > >>>> feel that kind of understanding for my arguments.
> > >>>>
> > >>>> What I was hoping for (I mentioned this earlier) is that we can
> model
> > >>>> the
> > >>>> case where we do not want to copy the data the exact same way as the
> > >>>> case
> > >>>> when we do copy the data. Maybe you can peek into the mails before
> to
> > >>>> see
> > >>>> more details for this.
> > >>>>
> > >>>> This means we have the same mechanism to transfer consumer groups to
> > >>>> switch topic. The offset mapping that would be generated would even
> be
> > >>>> simpler End Offset of the Old topic => offset 0 off all the
> partitions
> > >>>> of
> > >>>> the new topic. Then we could model the transition of a non-copy
> > >>>> expansion
> > >>>> the exact same way as a copy-expansion.
> > >>>>
> > >>>> I know this only works when topic growth by a factor. But the
> benefits
> > >>>> of
> > >>>> only growing by a factor are to strong anyways. See Clemens's hint
> and
> > >>>> remember that state reshuffling is entirely not needed if one
> doesn't
> > >>>> want
> > >>>> to grow processing power.
> > >>>>
> > >>>> I think these benefits should be clear, and that there is basically
> no
> > >>>> downside to what is currently at hand but just makes everything
> easy.
> > >>>>
> > >>>> One thing you need to know is. that if you do not offer rebuilding a
> > log
> > >>>> compacted topic like i suggest that even if you have consumer state
> > >>>> reshuffling. The topic is broken and can not be used to bootstrap
> new
> > >>>> consumers. They don't know if they need to apply a key from and old
> > >>>> partition or not. This is a horrible downside I haven't seen a
> > solution
> > >>>> for
> > >>>> in the email conversation.
> > >>>>
> > >>>> I argue to:
> > >>>>
> > >>>> Only grow topic by a factor always.
> > >>>> Have the "no copy consumer" transition as the trivial case of the
> > "copy
> > >>>> consumer transition".
> > >>>> If processors needs to be scaled, let them rebuild from the new
> topic
> > >>>> and
> > >>>> leave the old running in the mean time.
> > >>>> Do not implement key shuffling in streams.
> > >>>>
> > >>>> I hope I can convince you especially with the fact how I want to
> > handle
> > >>>> consumer transition. I think
> > >>>> you didn't quite understood me there before. I think the term "new
> > >>>> topic"
> > >>>> intimidated you a little.
> > >>>> How we solve this on disc doesn't really matter, If the data goes
> into
> > >>>> the
> > >>>> same Dir or a different Dir or anything. I do think that it needs to
> > >>>> involve at least rolling a new segment for the existing partitions.
> > >>>> But most of the transitions should work without restarting
> consumers.
> > >>>> (newer consumers with support for this). But with new topic i just
> > meant
> > >>>> the topic that now has a different partition count. Plenty of ways
> to
> > >>>> handle that (versions, aliases)
> > >>>>
> > >>>> Hope I can further get my idea across.
> > >>>>
> > >>>> Best Jan
> > >>>>
> > >>>>
> > >>>>
> > >>>>
> > >>>>
> > >>>>
> > >>>> On 14.03.2018 02:45, Jun Rao wrote:
> > >>>>
> > >>>> Hi, Jan,
> > >>>>>
> > >>>>> Thanks for sharing your view.
> > >>>>>
> > >>>>> I agree with you that recopying the data potentially makes the
> state
> > >>>>> management easier since the consumer can just rebuild its state
> from
> > >>>>> scratch (i.e., no need for state reshuffling).
> > >>>>>
> > >>>>> On the flip slide, I saw a few disadvantages of the approach that
> you
> > >>>>> suggested. (1) Building the state from the input topic from scratch
> > is
> > >>>>> in
> > >>>>> general less efficient than state reshuffling. Let's say one
> > computes a
> > >>>>> count per key from an input topic. The former requires reading all
> > >>>>> existing
> > >>>>> records in the input topic whereas the latter only requires reading
> > >>>>> data
> > >>>>> proportional to the number of unique keys. (2) The switching of the
> > >>>>> topic
> > >>>>> needs modification to the application. If there are many
> applications
> > >>>>> on a
> > >>>>> topic, coordinating such an effort may not be easy. Also, it's not
> > >>>>> clear
> > >>>>> how to enforce exactly-once semantic during the switch. (3) If a
> > topic
> > >>>>> doesn't need any state management, recopying the data seems
> wasteful.
> > >>>>> In
> > >>>>> that case, in place partition expansion seems more desirable.
> > >>>>>
> > >>>>> I understand your concern about adding complexity in KStreams. But,
> > >>>>> perhaps
> > >>>>> we could iterate on that a bit more to see if it can be simplified.
> > >>>>>
> > >>>>> Jun
> > >>>>>
> > >>>>>
> > >>>>> On Mon, Mar 12, 2018 at 11:21 PM, Jan Filipiak <
> > >>>>> Jan.Filipiak@trivago.com>
> > >>>>> wrote:
> > >>>>>
> > >>>>> Hi Jun,
> > >>>>>
> > >>>>>> I will focus on point 61 as I think its _the_ fundamental part
> that
> > I
> > >>>>>> cant
> > >>>>>> get across at the moment.
> > >>>>>>
> > >>>>>> Kafka is the platform to have state materialized multiple times
> from
> > >>>>>> one
> > >>>>>> input. I emphasize this: It is the building block in architectures
> > >>>>>> that
> > >>>>>> allow you to
> > >>>>>> have your state maintained multiple times. You put a message in
> > once,
> > >>>>>> and
> > >>>>>> you have it pop out as often as you like. I believe you understand
> > >>>>>> this.
> > >>>>>>
> > >>>>>> Now! The path of thinking goes the following: I am using apache
> > kafka
> > >>>>>> and
> > >>>>>> I _want_ my state multiple times. What am I going todo?
> > >>>>>>
> > >>>>>> A) Am I going to take my state that I build up, plunge some sort
> of
> > >>>>>> RPC
> > >>>>>> layer ontop of it, use that RPC layer to throw my records across
> > >>>>>> instances?
> > >>>>>> B) Am I just going to read the damn message twice?
> > >>>>>>
> > >>>>>> Approach A is fundamentally flawed and a violation of all that is
> > good
> > >>>>>> and
> > >>>>>> holy in kafka deployments. I can not understand how this Idea can
> > >>>>>> come in
> > >>>>>> the first place.
> > >>>>>> (I do understand: IQ in streams, they polluted the kafka streams
> > >>>>>> codebase
> > >>>>>> really bad already. It is not funny! I think they are equally
> flawed
> > >>>>>> as
> > >>>>>> A)
> > >>>>>>
> > >>>>>> I say, we do what Kafka is good at. We repartition the topic once.
> > We
> > >>>>>> switch the consumers.
> > >>>>>> (Those that need more partitions are going to rebuild their state
> in
> > >>>>>> multiple partitions by reading the new topic, those that don't
> just
> > >>>>>> assign
> > >>>>>> the new partitions properly)
> > >>>>>> We switch producers. Done!
> > >>>>>>
> > >>>>>> The best thing! It is trivial, hipster stream processor will have
> an
> > >>>>>> easy
> > >>>>>> time with that aswell. Its so super simple. And simple IS good!
> > >>>>>> It is what kafka was build todo. It is how we do it today. All I
> am
> > >>>>>> saying
> > >>>>>> is that a little broker help doing the producer swap is super
> > useful.
> > >>>>>>
> > >>>>>> For everyone interested in why kafka is so powerful with approach
> B,
> > >>>>>> please watch https://youtu.be/bEbeZPVo98c?t=1633
> > >>>>>> I already looked up a good point in time, I think after 5 minutes
> > the
> > >>>>>> "state" topic is handled and you should be able to understand me
> > >>>>>> and inch better.
> > >>>>>>
> > >>>>>> Please do not do A to the project, it deserves better!
> > >>>>>>
> > >>>>>> Best Jan
> > >>>>>>
> > >>>>>>
> > >>>>>>
> > >>>>>> On 13.03.2018 02:40, Jun Rao wrote:
> > >>>>>>
> > >>>>>> Hi, Jan,
> > >>>>>>
> > >>>>>>> Thanks for the reply. A few more comments below.
> > >>>>>>>
> > >>>>>>> 50. Ok, we can think a bit harder for supporting compacted
> topics.
> > >>>>>>>
> > >>>>>>> 51. This is a fundamental design question. In the more common
> case,
> > >>>>>>> the
> > >>>>>>> reason why someone wants to increase the number of partitions is
> > that
> > >>>>>>> the
> > >>>>>>> consumer application is slow and one wants to run more consumer
> > >>>>>>> instances
> > >>>>>>> to increase the degree of parallelism. So, fixing the number of
> > >>>>>>> running
> > >>>>>>> consumer instances when expanding the partitions won't help this
> > >>>>>>> case.
> > >>>>>>> If
> > >>>>>>> we do need to increase the number of consumer instances, we need
> to
> > >>>>>>> somehow
> > >>>>>>> reshuffle the state of the consumer across instances. What we
> have
> > >>>>>>> been
> > >>>>>>> discussing in this KIP is whether we can do this more effectively
> > >>>>>>> through
> > >>>>>>> the KStream library (e.g. through a 2-phase partition expansion).
> > >>>>>>> This
> > >>>>>>> will
> > >>>>>>> add some complexity, but it's probably better than everyone doing
> > >>>>>>> this
> > >>>>>>> in
> > >>>>>>> the application space. The recopying approach that you mentioned
> > >>>>>>> doesn't
> > >>>>>>> seem to address the consumer state management issue when the
> > consumer
> > >>>>>>> switches from an old to a new topic.
> > >>>>>>>
> > >>>>>>> 52. As for your example, it depends on whether the join key is
> the
> > >>>>>>> same
> > >>>>>>> between (A,B) and (B,C). If the join key is the same, we can do a
> > >>>>>>> 2-phase
> > >>>>>>> partition expansion of A, B, and C together. If the join keys are
> > >>>>>>> different, one would need to repartition the data on a different
> > key
> > >>>>>>> for
> > >>>>>>> the second join, then the partition expansion can be done
> > >>>>>>> independently
> > >>>>>>> between (A,B) and (B,C).
> > >>>>>>>
> > >>>>>>> 53. If you always fix the number of consumer instances, we you
> > >>>>>>> described
> > >>>>>>> works. However, as I mentioned in #51, I am not sure how your
> > >>>>>>> proposal
> > >>>>>>> deals with consumer states when the number of consumer instances
> > >>>>>>> grows.
> > >>>>>>> Also, it just seems that it's better to avoid re-copying the
> > existing
> > >>>>>>> data.
> > >>>>>>>
> > >>>>>>> 60. "just want to throw in my question from the longer email in
> the
> > >>>>>>> other
> > >>>>>>> Thread here. How will the bloom filter help a new consumer to
> > decide
> > >>>>>>> to
> > >>>>>>> apply the key or not?" Not sure that I fully understood your
> > >>>>>>> question.
> > >>>>>>> The
> > >>>>>>> consumer just reads whatever key is in the log. The bloom filter
> > just
> > >>>>>>> helps
> > >>>>>>> clean up the old keys.
> > >>>>>>>
> > >>>>>>> 61. "Why can we afford having a topic where its apparently not
> > >>>>>>> possible
> > >>>>>>> to
> > >>>>>>> start a new application on? I think this is an overall flaw of
> the
> > >>>>>>> discussed idea here. Not playing attention to the overall
> > >>>>>>> architecture."
> > >>>>>>> Could you explain a bit more when one can't start a new
> > application?
> > >>>>>>>
> > >>>>>>> Jun
> > >>>>>>>
> > >>>>>>>
> > >>>>>>>
> > >>>>>>> On Sat, Mar 10, 2018 at 1:40 AM, Jan Filipiak <
> > >>>>>>> Jan.Filipiak@trivago.com
> > >>>>>>> wrote:
> > >>>>>>>
> > >>>>>>> Hi Jun, thanks for your mail.
> > >>>>>>>
> > >>>>>>> Thank you for your questions!
> > >>>>>>>> I think they are really good and tackle the core of the problem
> I
> > >>>>>>>> see.
> > >>>>>>>>
> > >>>>>>>> I will answer inline, mostly but still want to set the tone
> here.
> > >>>>>>>>
> > >>>>>>>> The core strength of kafka is what Martin once called the
> > >>>>>>>> kappa-Architecture. How does this work?
> > >>>>>>>> You have everything as a log as in kafka. When you need to
> change
> > >>>>>>>> something.
> > >>>>>>>> You create the new version of your application and leave it
> > running
> > >>>>>>>> in
> > >>>>>>>> parallel.
> > >>>>>>>> Once the new version is good you switch your users to use the
> new
> > >>>>>>>> application.
> > >>>>>>>>
> > >>>>>>>> The online reshuffling effectively breaks this architecture and
> I
> > >>>>>>>> think
> > >>>>>>>> the switch in thinking here is more harmful
> > >>>>>>>> than any details about the partitioning function to allow such a
> > >>>>>>>> change.
> > >>>>>>>> I
> > >>>>>>>> feel with my suggestion we are the closest to
> > >>>>>>>> the original and battle proven architecture and I can only warn
> to
> > >>>>>>>> move
> > >>>>>>>> away from it.
> > >>>>>>>>
> > >>>>>>>> I might have forgotten something, sometimes its hard for me to
> > >>>>>>>> getting
> > >>>>>>>> all
> > >>>>>>>> the thoughts captured in a mail, but I hope the comments inline
> > will
> > >>>>>>>> further make my concern clear, and put some emphasis on why I
> > >>>>>>>> prefer my
> > >>>>>>>> solution ;)
> > >>>>>>>>
> > >>>>>>>> One thing we should all be aware of when discussing this, and I
> > >>>>>>>> think
> > >>>>>>>> Dong
> > >>>>>>>> should have mentioned it (maybe he did).
> > >>>>>>>> We are not discussing all of this out of thin air but there is
> an
> > >>>>>>>> effort
> > >>>>>>>> in the Samza project.
> > >>>>>>>>
> > >>>>>>>> https://cwiki.apache.org/confluence/display/SAMZA/SEP-5%3A+
> > >>>>>>>> Enable+partition+expansion+of+input+streams
> > >>>>>>>> https://issues.apache.org/jira/browse/SAMZA-1293
> > >>>>>>>>
> > >>>>>>>> To be clear. I think SEP-5 (state of last week, dont know if it
> > >>>>>>>> adapted
> > >>>>>>>> to
> > >>>>>>>> this discussion) is on a way better path than KIP-253, and I
> can't
> > >>>>>>>> really
> > >>>>>>>> explain why.
> > >>>>>>>>
> > >>>>>>>> Best Jan,
> > >>>>>>>>
> > >>>>>>>> nice weekend everyone
> > >>>>>>>>
> > >>>>>>>>
> > >>>>>>>> On 09.03.2018 03:36, Jun Rao wrote:
> > >>>>>>>>
> > >>>>>>>> Hi, Jan,
> > >>>>>>>>
> > >>>>>>>> Thanks for the feedback. Just some comments on the earlier
> points
> > >>>>>>>>> that
> > >>>>>>>>> you
> > >>>>>>>>> mentioned.
> > >>>>>>>>>
> > >>>>>>>>> 50. You brought up the question of whether existing data needs
> to
> > >>>>>>>>> be
> > >>>>>>>>> copied
> > >>>>>>>>> during partition expansion. My understand of your view is that
> > >>>>>>>>> avoid
> > >>>>>>>>> copying existing data will be more efficient, but it doesn't
> work
> > >>>>>>>>> well
> > >>>>>>>>> with
> > >>>>>>>>> compacted topics since some keys in the original partitions
> will
> > >>>>>>>>> never
> > >>>>>>>>> be
> > >>>>>>>>> cleaned. It would be useful to understand your use case of
> > >>>>>>>>> compacted
> > >>>>>>>>> topics
> > >>>>>>>>> a bit more. In the common use case, the data volume in a
> > compacted
> > >>>>>>>>> topic
> > >>>>>>>>> may not be large. So, I am not sure if there is a strong need
> to
> > >>>>>>>>> expand
> > >>>>>>>>> partitions in a compacted topic, at least initially.
> > >>>>>>>>>
> > >>>>>>>>> I do agree. State is usually smaller. Update rates might be
> also
> > >>>>>>>>>
> > >>>>>>>>> competitively high.
> > >>>>>>>> Doing Log-compaction (even beeing very efficient and
> configurable)
> > >>>>>>>> is
> > >>>>>>>> also
> > >>>>>>>> a more expensive operation than
> > >>>>>>>> just discarding old segments. Further if you want to use more
> > >>>>>>>> consumers
> > >>>>>>>> processing the events
> > >>>>>>>> you also have to grow the number of partitions. Especially for
> > >>>>>>>> use-cases
> > >>>>>>>> we do (KIP-213) a tiny state full
> > >>>>>>>> table might be very expensive to process if it joins against a
> > huge
> > >>>>>>>> table.
> > >>>>>>>>
> > >>>>>>>> I can just say we have been in the spot of needing to grow log
> > >>>>>>>> compacted
> > >>>>>>>> topics. Mainly for processing power we can bring to the table.
> > >>>>>>>>
> > >>>>>>>> Further i am not at all concerned about the extra spaced used by
> > >>>>>>>> "garbage
> > >>>>>>>> keys". I am more concerned about the correctness of innocent
> > >>>>>>>> consumers.
> > >>>>>>>> The
> > >>>>>>>> logic becomes complicated. Say for streams one would need to
> load
> > >>>>>>>> the
> > >>>>>>>> record into state but not forward it the topology ( to have it
> > >>>>>>>> available
> > >>>>>>>> for shuffeling). I rather have it simple and a topic clean
> > >>>>>>>> regardless
> > >>>>>>>> if
> > >>>>>>>> it
> > >>>>>>>> still has its old partition count. Especially with multiple
> > >>>>>>>> partitions
> > >>>>>>>> growth's I think it becomes insanely hard to to this shuffle
> > >>>>>>>> correct.
> > >>>>>>>> Maybe
> > >>>>>>>> Streams and Samza can do it. Especially if you do "hipster
> stream
> > >>>>>>>> processing" <https://www.confluent.io/blog
> > >>>>>>>> /introducing-kafka-streams-
> > >>>>>>>> stream-processing-made-simple/>. This makes kafka way to
> > >>>>>>>> complicated.
> > >>>>>>>> With my approach I think its way simpler because the topic has
> no
> > >>>>>>>> "history"
> > >>>>>>>> in terms of partitioning but is always clean.
> > >>>>>>>>
> > >>>>>>>>
> > >>>>>>>> 51. "Growing the topic by an integer factor does not require any
> > >>>>>>>> state
> > >>>>>>>>
> > >>>>>>>> redistribution at all." Could you clarify this a bit more? Let's
> > say
> > >>>>>>>>> you
> > >>>>>>>>> have a consumer app that computes the windowed count per key.
> If
> > >>>>>>>>> you
> > >>>>>>>>> double
> > >>>>>>>>> the number of partitions from 1 to 2 and grow the consumer
> > >>>>>>>>> instances
> > >>>>>>>>> from
> > >>>>>>>>> 1
> > >>>>>>>>> to 2, we would need to redistribute some of the counts to the
> new
> > >>>>>>>>> consumer
> > >>>>>>>>> instance. Regarding to linear hashing, it's true that it won't
> > >>>>>>>>> solve
> > >>>>>>>>> the
> > >>>>>>>>> problem with compacted topics. The main benefit is that it
> > >>>>>>>>> redistributes
> > >>>>>>>>> the keys in one partition to no more than two partitions, which
> > >>>>>>>>> could
> > >>>>>>>>> help
> > >>>>>>>>> redistribute the state.
> > >>>>>>>>>
> > >>>>>>>>> You don't need to spin up a new consumer in this case. every
> > >>>>>>>>> consumer
> > >>>>>>>>>
> > >>>>>>>>> would just read every partition with the (partition % num_task)
> > >>>>>>>> task.
> > >>>>>>>> it
> > >>>>>>>> will still have the previous data right there and can go on.
> > >>>>>>>>
> > >>>>>>>> This sounds contradictory to what I said before, but please bear
> > >>>>>>>> with
> > >>>>>>>> me.
> > >>>>>>>>
> > >>>>>>>> 52. Good point on coordinating the expansion of 2 topics that
> need
> > >>>>>>>> to
> > >>>>>>>> be
> > >>>>>>>>
> > >>>>>>>> joined together. This is where the 2-phase partition expansion
> > could
> > >>>>>>>>> potentially help. In the first phase, we could add new
> partitions
> > >>>>>>>>> to
> > >>>>>>>>> the 2
> > >>>>>>>>> topics one at a time but without publishing to the new
> patitions.
> > >>>>>>>>> Then,
> > >>>>>>>>> we
> > >>>>>>>>> can add new consumer instances to pick up the new partitions.
> In
> > >>>>>>>>> this
> > >>>>>>>>> transition phase, no reshuffling is needed since no data is
> > coming
> > >>>>>>>>> from
> > >>>>>>>>> the
> > >>>>>>>>> new partitions. Finally, we can enable the publishing to the
> new
> > >>>>>>>>> partitions.
> > >>>>>>>>>
> > >>>>>>>>> I think its even worse than you think. I would like to
> introduce
> > >>>>>>>>> the
> > >>>>>>>>>
> > >>>>>>>>> Term
> > >>>>>>>> transitive copartitioning. Imagine
> > >>>>>>>> 2 streams application. One joins (A,B) the other (B,C) then
> there
> > >>>>>>>> is a
> > >>>>>>>> transitive copartition requirement for
> > >>>>>>>> (A,C) to be copartitioned aswell. This can spread significantly
> > and
> > >>>>>>>> require many consumers to adapt at the same time.
> > >>>>>>>>
> > >>>>>>>> It is also not entirely clear to me how you not need reshuffling
> > in
> > >>>>>>>> this
> > >>>>>>>> case. If A has a record that never gets updated after the
> > expansion
> > >>>>>>>> and
> > >>>>>>>> the
> > >>>>>>>> coresponding B record moves to a new partition. How shall they
> > meet
> > >>>>>>>> w/o
> > >>>>>>>> shuffle?
> > >>>>>>>>
> > >>>>>>>> 53. "Migrating consumer is a step that might be made completly
> > >>>>>>>>
> > >>>>>>>> unnecessary
> > >>>>>>>>> if - for example streams - takes the gcd as partitioning scheme
> > >>>>>>>>> instead
> > >>>>>>>>> of
> > >>>>>>>>> enforcing 1 to 1." Not sure that I fully understand this. I
> think
> > >>>>>>>>> you
> > >>>>>>>>> mean
> > >>>>>>>>> that a consumer application can run more instances than the
> > number
> > >>>>>>>>> of
> > >>>>>>>>> partitions. In that case, the consumer can just repartitioning
> > the
> > >>>>>>>>> input
> > >>>>>>>>> data according to the number of instances. This is possible,
> but
> > >>>>>>>>> just
> > >>>>>>>>> has
> > >>>>>>>>> the overhead of reshuffling the data.
> > >>>>>>>>>
> > >>>>>>>>> No what I meant is ( that is also your question i think
> Mathias)
> > >>>>>>>>> that
> > >>>>>>>>> if
> > >>>>>>>>>
> > >>>>>>>>> you grow a topic by a factor.
> > >>>>>>>> Even if your processor is statefull you can can just assign all
> > the
> > >>>>>>>> multiples of the previous partition to
> > >>>>>>>> this consumer and the state to keep processing correctly will be
> > >>>>>>>> present
> > >>>>>>>> w/o any shuffling.
> > >>>>>>>>
> > >>>>>>>> Say you have an assignment
> > >>>>>>>> Statefull consumer => partition
> > >>>>>>>> 0 => 0
> > >>>>>>>> 1 => 1
> > >>>>>>>> 2 => 2
> > >>>>>>>>
> > >>>>>>>> and you grow you topic by 4 you get,
> > >>>>>>>>
> > >>>>>>>> 0 => 0,3,6,9
> > >>>>>>>> 1 => 1,4,7,10
> > >>>>>>>> 2 => 2,5,8,11
> > >>>>>>>>
> > >>>>>>>> Say your hashcode is 8. 8%3 => 2  before so consumer for
> > partition 2
> > >>>>>>>> has
> > >>>>>>>> it.
> > >>>>>>>> Now you you have 12 partitions so 8%12 => 8, so it goes into
> > >>>>>>>> partition
> > >>>>>>>> 8
> > >>>>>>>> which is assigned to the same consumer
> > >>>>>>>> who had 2 before and therefore knows the key.
> > >>>>>>>>
> > >>>>>>>> Userland reshuffeling is there as an options. And it does
> exactly
> > >>>>>>>> what
> > >>>>>>>> I
> > >>>>>>>> suggest. And I think its the perfect strategie. All I am
> > suggestion
> > >>>>>>>> is
> > >>>>>>>> broker side support to switch the producers to the newly
> > partitioned
> > >>>>>>>> topic.
> > >>>>>>>> Then the old (to few partition topic) can go away.  Remember the
> > >>>>>>>> list
> > >>>>>>>> of
> > >>>>>>>> steps in the beginning of this thread. If one has broker support
> > for
> > >>>>>>>> all
> > >>>>>>>> where its required and streams support for those that aren’t
> > >>>>>>>> necessarily.
> > >>>>>>>> Then one has solved the problem.
> > >>>>>>>> I repeat it because I think its important. I am really happy
> that
> > >>>>>>>> you
> > >>>>>>>> brought that up! because its 100% what I want just with the
> > >>>>>>>> differences
> > >>>>>>>> to
> > >>>>>>>> have an option to discard the to small topic later (after all
> > >>>>>>>> consumers
> > >>>>>>>> adapted). And to have order correct there. I need broker support
> > >>>>>>>> managing
> > >>>>>>>> the copy process + the produces and fence them against each
> > other. I
> > >>>>>>>> also
> > >>>>>>>> repeat. the copy process can run for weeks in the worst case.
> > >>>>>>>> Copying
> > >>>>>>>> the
> > >>>>>>>> data is not the longest task migrating consumers might very well
> > be.
> > >>>>>>>> Once all consumers switched and copying is really up to date
> > (think
> > >>>>>>>> ISR
> > >>>>>>>> like up to date) only then we stop the producer, wait for the
> copy
> > >>>>>>>> to
> > >>>>>>>> finish and use the new topic for producing.
> > >>>>>>>>
> > >>>>>>>> After this the topic is perfect in shape. and no one needs to
> > worry
> > >>>>>>>> about
> > >>>>>>>> complicated stuff. (old keys hanging around might arrive in some
> > >>>>>>>> other
> > >>>>>>>> topic later.....). can only imagine how many tricky bugs gonna
> > >>>>>>>> arrive
> > >>>>>>>> after
> > >>>>>>>> someone had grown and shrunken is topic 10 times.
> > >>>>>>>>
> > >>>>>>>>
> > >>>>>>>>
> > >>>>>>>>
> > >>>>>>>>
> > >>>>>>>>
> > >>>>>>>> 54. "The other thing I wanted to mention is that I believe the
> > >>>>>>>> current
> > >>>>>>>>
> > >>>>>>>> suggestion (without copying data over) can be implemented in
> pure
> > >>>>>>>>> userland
> > >>>>>>>>> with a custom partitioner and a small feedbackloop from
> > >>>>>>>>> ProduceResponse
> > >>>>>>>>> =>
> > >>>>>>>>> Partitionier in coorporation with a change management system."
> I
> > am
> > >>>>>>>>> not
> > >>>>>>>>> sure a customized partitioner itself solves the problem. We
> > >>>>>>>>> probably
> > >>>>>>>>> need
> > >>>>>>>>> some broker side support to enforce when the new partitions can
> > be
> > >>>>>>>>> used.
> > >>>>>>>>> We
> > >>>>>>>>> also need some support on the consumer/kstream side to preserve
> > the
> > >>>>>>>>> per
> > >>>>>>>>> key
> > >>>>>>>>> ordering and potentially migrate the processing state. This is
> > not
> > >>>>>>>>> trivial
> > >>>>>>>>> and I am not sure if it's ideal to fully push to the
> application
> > >>>>>>>>> space.
> > >>>>>>>>>
> > >>>>>>>>> Broker support is defenitly the preferred way here. I have
> > nothing
> > >>>>>>>>>
> > >>>>>>>>> against
> > >>>>>>>> broker support.
> > >>>>>>>> I tried to say that for what I would preffer - copying the data
> > >>>>>>>> over,
> > >>>>>>>> at
> > >>>>>>>> least for log compacted topics -
> > >>>>>>>> I would require more broker support than the KIP currently
> offers.
> > >>>>>>>>
> > >>>>>>>>
> > >>>>>>>>
> > >>>>>>>> Jun
> > >>>>>>>>
> > >>>>>>>> On Tue, Mar 6, 2018 at 10:33 PM, Jan Filipiak <
> > >>>>>>>>> Jan.Filipiak@trivago.com
> > >>>>>>>>> wrote:
> > >>>>>>>>>
> > >>>>>>>>> Hi Dong,
> > >>>>>>>>>
> > >>>>>>>>> are you actually reading my emails, or are you just using the
> > >>>>>>>>> thread I
> > >>>>>>>>>
> > >>>>>>>>>> started for general announcements regarding the KIP?
> > >>>>>>>>>>
> > >>>>>>>>>> I tried to argue really hard against linear hashing. Growing
> the
> > >>>>>>>>>> topic
> > >>>>>>>>>> by
> > >>>>>>>>>> an integer factor does not require any state redistribution at
> > >>>>>>>>>> all. I
> > >>>>>>>>>> fail
> > >>>>>>>>>> to see completely where linear hashing helps on log compacted
> > >>>>>>>>>> topics.
> > >>>>>>>>>>
> > >>>>>>>>>> If you are not willing to explain to me what I might be
> > >>>>>>>>>> overlooking:
> > >>>>>>>>>> that
> > >>>>>>>>>> is fine.
> > >>>>>>>>>> But I ask you to not reply to my emails then. Please
> understand
> > my
> > >>>>>>>>>> frustration with this.
> > >>>>>>>>>>
> > >>>>>>>>>> Best Jan
> > >>>>>>>>>>
> > >>>>>>>>>>
> > >>>>>>>>>>
> > >>>>>>>>>> On 06.03.2018 19:38, Dong Lin wrote:
> > >>>>>>>>>>
> > >>>>>>>>>> Hi everyone,
> > >>>>>>>>>>
> > >>>>>>>>>> Thanks for all the comments! It appears that everyone prefers
> > >>>>>>>>>> linear
> > >>>>>>>>>>
> > >>>>>>>>>>> hashing because it reduces the amount of state that needs to
> be
> > >>>>>>>>>>> moved
> > >>>>>>>>>>> between consumers (for stream processing). The KIP has been
> > >>>>>>>>>>> updated
> > >>>>>>>>>>> to
> > >>>>>>>>>>> use
> > >>>>>>>>>>> linear hashing.
> > >>>>>>>>>>>
> > >>>>>>>>>>> Regarding the migration endeavor: it seems that migrating
> > >>>>>>>>>>> producer
> > >>>>>>>>>>> library
> > >>>>>>>>>>> to use linear hashing should be pretty straightforward
> without
> > >>>>>>>>>>> much operational endeavor. If we don't upgrade client library
> > to
> > >>>>>>>>>>> use
> > >>>>>>>>>>> this
> > >>>>>>>>>>> KIP, we can not support in-order delivery after partition is
> > >>>>>>>>>>> changed
> > >>>>>>>>>>> anyway. Suppose we upgrade client library to use this KIP, if
> > >>>>>>>>>>> partition
> > >>>>>>>>>>> number is not changed, the key -> partition mapping will be
> > >>>>>>>>>>> exactly
> > >>>>>>>>>>> the
> > >>>>>>>>>>> same as it is now because it is still determined using
> > >>>>>>>>>>> murmur_hash(key)
> > >>>>>>>>>>> %
> > >>>>>>>>>>> original_partition_num. In other words, this change is
> backward
> > >>>>>>>>>>> compatible.
> > >>>>>>>>>>>
> > >>>>>>>>>>> Regarding the load distribution: if we use linear hashing,
> the
> > >>>>>>>>>>> load
> > >>>>>>>>>>> may
> > >>>>>>>>>>> be
> > >>>>>>>>>>> unevenly distributed because those partitions which are not
> > split
> > >>>>>>>>>>> may
> > >>>>>>>>>>> receive twice as much traffic as other partitions that are
> > split.
> > >>>>>>>>>>> This
> > >>>>>>>>>>> issue can be mitigated by creating topic with partitions that
> > are
> > >>>>>>>>>>> several
> > >>>>>>>>>>> times the number of consumers. And there will be no imbalance
> > if
> > >>>>>>>>>>> the
> > >>>>>>>>>>> partition number is always doubled. So this imbalance seems
> > >>>>>>>>>>> acceptable.
> > >>>>>>>>>>>
> > >>>>>>>>>>> Regarding storing the partition strategy as per-topic config:
> > It
> > >>>>>>>>>>> seems
> > >>>>>>>>>>> not
> > >>>>>>>>>>> necessary since we can still use murmur_hash as the default
> > hash
> > >>>>>>>>>>> function
> > >>>>>>>>>>> and additionally apply the linear hashing algorithm if the
> > >>>>>>>>>>> partition
> > >>>>>>>>>>> number
> > >>>>>>>>>>> has increased. Not sure if there is any use-case for producer
> > to
> > >>>>>>>>>>> use a
> > >>>>>>>>>>> different hash function. Jason, can you check if there is
> some
> > >>>>>>>>>>> use-case
> > >>>>>>>>>>> that I missed for using the per-topic partition strategy?
> > >>>>>>>>>>>
> > >>>>>>>>>>> Regarding how to reduce latency (due to state store/load) in
> > >>>>>>>>>>> stream
> > >>>>>>>>>>> processing consumer when partition number changes: I need to
> > read
> > >>>>>>>>>>> the
> > >>>>>>>>>>> Kafka
> > >>>>>>>>>>> Stream code to understand how Kafka Stream currently migrate
> > >>>>>>>>>>> state
> > >>>>>>>>>>> between
> > >>>>>>>>>>> consumers when the application is added/removed for a given
> > job.
> > >>>>>>>>>>> I
> > >>>>>>>>>>> will
> > >>>>>>>>>>> reply after I finish reading the documentation and code.
> > >>>>>>>>>>>
> > >>>>>>>>>>>
> > >>>>>>>>>>> Thanks,
> > >>>>>>>>>>> Dong
> > >>>>>>>>>>>
> > >>>>>>>>>>>
> > >>>>>>>>>>> On Mon, Mar 5, 2018 at 10:43 AM, Jason Gustafson <
> > >>>>>>>>>>> jason@confluent.io>
> > >>>>>>>>>>> wrote:
> > >>>>>>>>>>>
> > >>>>>>>>>>> Great discussion. I think I'm wondering whether we can
> continue
> > >>>>>>>>>>> to
> > >>>>>>>>>>> leave
> > >>>>>>>>>>>
> > >>>>>>>>>>> Kafka agnostic to the partitioning strategy. The challenge is
> > >>>>>>>>>>>
> > >>>>>>>>>>> communicating
> > >>>>>>>>>>>> the partitioning logic from producers to consumers so that
> the
> > >>>>>>>>>>>> dependencies
> > >>>>>>>>>>>> between each epoch can be determined. For the sake of
> > >>>>>>>>>>>> discussion,
> > >>>>>>>>>>>> imagine
> > >>>>>>>>>>>> you did something like the following:
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> 1. The name (and perhaps version) of a partitioning strategy
> > is
> > >>>>>>>>>>>> stored
> > >>>>>>>>>>>> in
> > >>>>>>>>>>>> topic configuration when a topic is created.
> > >>>>>>>>>>>> 2. The producer looks up the partitioning strategy before
> > >>>>>>>>>>>> writing
> > >>>>>>>>>>>> to
> > >>>>>>>>>>>> a
> > >>>>>>>>>>>> topic and includes it in the produce request (for fencing).
> If
> > >>>>>>>>>>>> it
> > >>>>>>>>>>>> doesn't
> > >>>>>>>>>>>> have an implementation for the configured strategy, it
> fails.
> > >>>>>>>>>>>> 3. The consumer also looks up the partitioning strategy and
> > >>>>>>>>>>>> uses it
> > >>>>>>>>>>>> to
> > >>>>>>>>>>>> determine dependencies when reading a new epoch. It could
> > either
> > >>>>>>>>>>>> fail
> > >>>>>>>>>>>> or
> > >>>>>>>>>>>> make the most conservative dependency assumptions if it
> > doesn't
> > >>>>>>>>>>>> know
> > >>>>>>>>>>>> how
> > >>>>>>>>>>>> to
> > >>>>>>>>>>>> implement the partitioning strategy. For the consumer, the
> new
> > >>>>>>>>>>>> interface
> > >>>>>>>>>>>> might look something like this:
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> // Return the partition dependencies following an epoch bump
> > >>>>>>>>>>>> Map<Integer, List<Integer>> dependencies(int
> > >>>>>>>>>>>> numPartitionsBeforeEpochBump,
> > >>>>>>>>>>>> int numPartitionsAfterEpochBump)
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> The unordered case then is just a particular implementation
> > >>>>>>>>>>>> which
> > >>>>>>>>>>>> never
> > >>>>>>>>>>>> has
> > >>>>>>>>>>>> any epoch dependencies. To implement this, we would need
> some
> > >>>>>>>>>>>> way
> > >>>>>>>>>>>> for
> > >>>>>>>>>>>> the
> > >>>>>>>>>>>> consumer to find out how many partitions there were in each
> > >>>>>>>>>>>> epoch,
> > >>>>>>>>>>>> but
> > >>>>>>>>>>>> maybe that's not too unreasonable.
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> Thanks,
> > >>>>>>>>>>>> Jason
> > >>>>>>>>>>>>
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> On Mon, Mar 5, 2018 at 4:51 AM, Jan Filipiak <
> > >>>>>>>>>>>> Jan.Filipiak@trivago.com
> > >>>>>>>>>>>> wrote:
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> Hi Dong
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> thank you very much for your questions.
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> regarding the time spend copying data across:
> > >>>>>>>>>>>>> It is correct that copying data from a topic with one
> > partition
> > >>>>>>>>>>>>> mapping
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>>> to
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>>> a topic with a different partition mapping takes way longer
> > >>>>>>>>>>>>> than
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>> we
> > >>>>>>>>>>>> can
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> stop producers. Tens of minutes is a very optimistic
> estimate
> > >>>>>>>>>>>> here.
> > >>>>>>>>>>>>
> > >>>>>>>>>>>>> Many
> > >>>>>>>>>>>>> people can not afford copy full steam and therefore will
> have
> > >>>>>>>>>>>>> some
> > >>>>>>>>>>>>> rate
> > >>>>>>>>>>>>> limiting in place, this can bump the timespan into the
> day's.
> > >>>>>>>>>>>>> The
> > >>>>>>>>>>>>> good
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>>> part
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>>> is that the vast majority of the data can be copied while
> the
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>> producers
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> are
> > >>>>>>>>>>>>
> > >>>>>>>>>>>>> still going. One can then, piggyback the consumers ontop of
> > >>>>>>>>>>>>> this
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>> timeframe,
> > >>>>>>>>>>>>
> > >>>>>>>>>>>>> by the method mentioned (provide them an mapping from their
> > old
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>> offsets
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> to
> > >>>>>>>>>>>>
> > >>>>>>>>>>>>> new offsets in their repartitioned topics. In that way we
> > >>>>>>>>>>>>> separate
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>> migration of consumers from migration of producers
> (decoupling
> > >>>>>>>>>>>>
> > >>>>>>>>>>>>> these
> > >>>>>>>>>>>>> is
> > >>>>>>>>>>>>> what kafka is strongest at). The time to actually swap over
> > the
> > >>>>>>>>>>>>> producers
> > >>>>>>>>>>>>> should be kept minimal by ensuring that when a swap attempt
> > is
> > >>>>>>>>>>>>> started
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>>> the
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>>> consumer copying over should be very close to the log end
> and
> > >>>>>>>>>>>>> is
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>> expected
> > >>>>>>>>>>>>
> > >>>>>>>>>>>>> to finish within the next fetch. The operation should have
> a
> > >>>>>>>>>>>>> time-out
> > >>>>>>>>>>>>> and
> > >>>>>>>>>>>>> should be "reattemtable".
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>>> Importance of logcompaction:
> > >>>>>>>>>>>>> If a producer produces key A, to partiton 0, its forever
> > gonna
> > >>>>>>>>>>>>> be
> > >>>>>>>>>>>>> there,
> > >>>>>>>>>>>>> unless it gets deleted. The record might sit in there for
> > >>>>>>>>>>>>> years. A
> > >>>>>>>>>>>>> new
> > >>>>>>>>>>>>> producer started with the new partitions will fail to
> delete
> > >>>>>>>>>>>>> the
> > >>>>>>>>>>>>> record
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>>> in
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>>> the correct partition. Th record will be there forever and
> > one
> > >>>>>>>>>>>>> can
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>> not
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> reliable bootstrap new consumers. I cannot see how linear
> > >>>>>>>>>>>> hashing
> > >>>>>>>>>>>>
> > >>>>>>>>>>>>> can
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>>> solve
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>>> this.
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>> Regarding your skipping of userland copying:
> > >>>>>>>>>>>>
> > >>>>>>>>>>>>> 100%, copying the data across in userland is, as far as i
> can
> > >>>>>>>>>>>>> see,
> > >>>>>>>>>>>>> only
> > >>>>>>>>>>>>> a
> > >>>>>>>>>>>>> usecase for log compacted topics. Even for logcompaction +
> > >>>>>>>>>>>>> retentions
> > >>>>>>>>>>>>> it
> > >>>>>>>>>>>>> should only be opt-in. Why did I bring it up? I think log
> > >>>>>>>>>>>>> compaction
> > >>>>>>>>>>>>> is
> > >>>>>>>>>>>>> a
> > >>>>>>>>>>>>> very important feature to really embrace kafka as a "data
> > >>>>>>>>>>>>> plattform".
> > >>>>>>>>>>>>> The
> > >>>>>>>>>>>>> point I also want to make is that copying data this way is
> > >>>>>>>>>>>>> completely
> > >>>>>>>>>>>>> inline with the kafka architecture. it only consists of
> > reading
> > >>>>>>>>>>>>> and
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>>> writing
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>>> to topics.
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>> I hope it clarifies more why I think we should aim for more
> > than
> > >>>>>>>>>>>>
> > >>>>>>>>>>>>> the
> > >>>>>>>>>>>>> current KIP. I fear that once the KIP is done not much more
> > >>>>>>>>>>>>> effort
> > >>>>>>>>>>>>> will
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>>> be
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>>> taken.
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> On 04.03.2018 02:28, Dong Lin wrote:
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>>> Hey Jan,
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>>> In the current proposal, the consumer will be blocked on
> > >>>>>>>>>>>>> waiting
> > >>>>>>>>>>>>> for
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>>> other
> > >>>>>>>>>>>>>>
> > >>>>>>>>>>>>>> consumers of the group to consume up to a given offset. In
> > >>>>>>>>>>>>>> most
> > >>>>>>>>>>>>>>
> > >>>>>>>>>>>>> cases,
> > >>>>>>>>>>>>> all
> > >>>>>>>>>>>>> consumers should be close to the LEO of the partitions when
> > the
> > >>>>>>>>>>>>> partition
> > >>>>>>>>>>>>> expansion happens. Thus the time waiting should not be long
> > >>>>>>>>>>>>> e.g.
> > >>>>>>>>>>>>> on
> > >>>>>>>>>>>>> the
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>>> order of seconds. On the other hand, it may take a long
> time
> > to
> > >>>>>>>>>>>>> wait
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>>> for
> > >>>>>>>>>>>>>> the entire partition to be copied -- the amount of time is
> > >>>>>>>>>>>>>> proportional
> > >>>>>>>>>>>>>>
> > >>>>>>>>>>>>>> to
> > >>>>>>>>>>>>>>
> > >>>>>>>>>>>>>> the amount of existing data in the partition, which can
> take
> > >>>>>>>>>>>>>>
> > >>>>>>>>>>>>> tens of
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>>> minutes. So the amount of time that we stop consumers may
> not
> > >>>>>>>>>>>>> be
> > >>>>>>>>>>>>> on
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>>> the
> > >>>>>>>>>>>>>> same order of magnitude.
> > >>>>>>>>>>>>>>
> > >>>>>>>>>>>>>> If we can implement this suggestion without copying data
> > over
> > >>>>>>>>>>>>>> in
> > >>>>>>>>>>>>>> purse
> > >>>>>>>>>>>>>> userland, it will be much more valuable. Do you have ideas
> > on
> > >>>>>>>>>>>>>> how
> > >>>>>>>>>>>>>> this
> > >>>>>>>>>>>>>>
> > >>>>>>>>>>>>>> can
> > >>>>>>>>>>>>>>
> > >>>>>>>>>>>>>> be done?
> > >>>>>>>>>>>>>>
> > >>>>>>>>>>>>> Not sure why the current KIP not help people who depend on
> > log
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>>> compaction.
> > >>>>>>>>>>>>>>
> > >>>>>>>>>>>>>> Could you elaborate more on this point?
> > >>>>>>>>>>>>>>
> > >>>>>>>>>>>>> Thanks,
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>>> Dong
> > >>>>>>>>>>>>>>
> > >>>>>>>>>>>>>> On Wed, Feb 28, 2018 at 10:55 PM, Jan
> > >>>>>>>>>>>>>> Filipiak<Jan.Filipiak@trivago.
> > >>>>>>>>>>>>>> com
> > >>>>>>>>>>>>>> wrote:
> > >>>>>>>>>>>>>>
> > >>>>>>>>>>>>>> Hi Dong,
> > >>>>>>>>>>>>>>
> > >>>>>>>>>>>>>> I tried to focus on what the steps are one can currently
> > >>>>>>>>>>>>>> perform
> > >>>>>>>>>>>>>> to
> > >>>>>>>>>>>>>>
> > >>>>>>>>>>>>>> expand
> > >>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>> or shrink a keyed topic while maintaining a top notch
> > >>>>>>>>>>>>>>> semantics.
> > >>>>>>>>>>>>>>> I can understand that there might be confusion about
> > >>>>>>>>>>>>>>> "stopping
> > >>>>>>>>>>>>>>> the
> > >>>>>>>>>>>>>>> consumer". It is exactly the same as proposed in the KIP.
> > >>>>>>>>>>>>>>> there
> > >>>>>>>>>>>>>>> needs
> > >>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>> to
> > >>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>> be
> > >>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>> a time the producers agree on the new partitioning. The
> > extra
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>>> semantics I
> > >>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>> want to put in there is that we have a possibility to
> wait
> > >>>>>>>>>>>>>>> until
> > >>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>> all
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>>> the
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>>> existing data
> > >>>>>>>>>>>>>>
> > >>>>>>>>>>>>>> is copied over into the new partitioning scheme. When I
> say
> > >>>>>>>>>>>>> stopping
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>>> I
> > >>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>> think more of having a memory barrier that ensures the
> > >>>>>>>>>>>>>>> ordering. I
> > >>>>>>>>>>>>>>> am
> > >>>>>>>>>>>>>>> still
> > >>>>>>>>>>>>>>> aming for latencies  on the scale of leader failovers.
> > >>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>> Consumers have to explicitly adapt the new partitioning
> > >>>>>>>>>>>>>>> scheme
> > >>>>>>>>>>>>>>> in
> > >>>>>>>>>>>>>>> the
> > >>>>>>>>>>>>>>> above scenario. The reason is that in these cases where
> you
> > >>>>>>>>>>>>>>> are
> > >>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>> dependent
> > >>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>> on a particular partitioning scheme, you also have other
> > >>>>>>>>>>>>>>> topics
> > >>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>> that
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>>> have
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>>> co-partition enforcements or the kind -frequently.
> Therefore
> > >>>>>>>>>>>>>> all
> > >>>>>>>>>>>>>>
> > >>>>>>>>>>>>>> your
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>>> other
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>>> input topics might need to grow accordingly.
> > >>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>> What I was suggesting was to streamline all these
> > operations
> > >>>>>>>>>>>>>>> as
> > >>>>>>>>>>>>>>> best
> > >>>>>>>>>>>>>>> as
> > >>>>>>>>>>>>>>> possible to have "real" partition grow and shrinkage
> going
> > >>>>>>>>>>>>>>> on.
> > >>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>> Migrating
> > >>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>> the producers to a new partitioning scheme can be much
> more
> > >>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>> streamlined
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>>> with proper broker support for this. Migrating consumer is
> a
> > >>>>>>>>>>>>> step
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>>> that
> > >>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>> might be made completly unnecessary if - for example
> > streams
> > >>>>>>>>>>>>>>> -
> > >>>>>>>>>>>>>>> takes
> > >>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>> the
> > >>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>> gcd as partitioning scheme instead of enforcing 1 to 1.
> > >>>>>>>>>>>>>>> Connect
> > >>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>> consumers
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>>> and other consumers should be fine anyways.
> > >>>>>>>>>>>>>>
> > >>>>>>>>>>>>>> I hope this makes more clear where I was aiming at. The
> rest
> > >>>>>>>>>>>>> needs
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>>> to
> > >>>>>>>>>>>>>>
> > >>>>>>>>>>>>>> be
> > >>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>> figured out. The only danger i see is that when we are
> > >>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>> introducing
> > >>>>>>>>>>>>>>
> > >>>>>>>>>>>>>> this
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>>> feature as supposed in the KIP, it wont help any people
> > >>>>>>>>>>>>> depending
> > >>>>>>>>>>>>> on
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>>> log
> > >>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>> compaction.
> > >>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>> The other thing I wanted to mention is that I believe the
> > >>>>>>>>>>>>> current
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>>> suggestion (without copying data over) can be implemented
> in
> > >>>>>>>>>>>>>> pure
> > >>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>> userland
> > >>>>>>>>>>>>>>> with a custom partitioner and a small feedbackloop from
> > >>>>>>>>>>>>>>> ProduceResponse
> > >>>>>>>>>>>>>>> =>
> > >>>>>>>>>>>>>>> Partitionier in coorporation with a change management
> > system.
> > >>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>> Best Jan
> > >>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>> On 28.02.2018 07:13, Dong Lin wrote:
> > >>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>> Hey Jan,
> > >>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>> I am not sure if it is acceptable for producer to be
> > stopped
> > >>>>>>>>>>>>>>> for a
> > >>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>> while,
> > >>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>> particularly for online application which requires low
> > >>>>>>>>>>>>>>>> latency. I
> > >>>>>>>>>>>>>>>> am
> > >>>>>>>>>>>>>>>> also
> > >>>>>>>>>>>>>>>> not sure how consumers can switch to a new topic. Does
> > user
> > >>>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>> application
> > >>>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>> needs to explicitly specify a different topic for
> > >>>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>> producer/consumer
> > >>>>>>>>>>>>>>
> > >>>>>>>>>>>>>> to
> > >>>>>>>>>>>>>>
> > >>>>>>>>>>>>> subscribe to? It will be helpful for discussion if you can
> > >>>>>>>>>>>>> provide
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>>> more
> > >>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>> detail on the interface change for this solution.
> > >>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>> Thanks,
> > >>>>>>>>>>>>>>
> > >>>>>>>>>>>>>> Dong
> > >>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>> On Mon, Feb 26, 2018 at 12:48 AM, Jan
> > >>>>>>>>>>>>>>>> Filipiak<Jan.Filipiak@trivago.
> > >>>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>> com
> > >>>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>> wrote:
> > >>>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>> Hi,
> > >>>>>>>>>>>>>>
> > >>>>>>>>>>>>>> just want to throw my though in. In general the
> > functionality
> > >>>>>>>>>>>>>> is
> > >>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>> very
> > >>>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>> usefull, we should though not try to find the
> architecture
> > >>>>>>>>>>>>>>>> to
> > >>>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>> hard
> > >>>>>>>>>>>>>>>>> while
> > >>>>>>>>>>>>>>>>> implementing.
> > >>>>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>>> The manual steps would be to
> > >>>>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>>> create a new topic
> > >>>>>>>>>>>>>>>>> the mirrormake from the new old topic to the new topic
> > >>>>>>>>>>>>>>>>> wait for mirror making to catch up.
> > >>>>>>>>>>>>>>>>> then put the consumers onto the new topic
> > >>>>>>>>>>>>>>>>>            (having mirrormaker spit out a mapping from
> > old
> > >>>>>>>>>>>>>>>>> offsets to
> > >>>>>>>>>>>>>>>>> new
> > >>>>>>>>>>>>>>>>> offsets:
> > >>>>>>>>>>>>>>>>>                if topic is increased by factor X there
> is
> > >>>>>>>>>>>>>>>>> gonna
> > >>>>>>>>>>>>>>>>> be a
> > >>>>>>>>>>>>>>>>> clean
> > >>>>>>>>>>>>>>>>> mapping from 1 offset in the old topic to X offsets in
> > the
> > >>>>>>>>>>>>>>>>> new
> > >>>>>>>>>>>>>>>>> topic,
> > >>>>>>>>>>>>>>>>>                if there is no factor then there is no
> > >>>>>>>>>>>>>>>>> chance to
> > >>>>>>>>>>>>>>>>> generate a
> > >>>>>>>>>>>>>>>>> mapping that can be reasonable used for continuing)
> > >>>>>>>>>>>>>>>>>            make consumers stop at appropriate points
> and
> > >>>>>>>>>>>>>>>>> continue
> > >>>>>>>>>>>>>>>>> consumption
> > >>>>>>>>>>>>>>>>> with offsets from the mapping.
> > >>>>>>>>>>>>>>>>> have the producers stop for a minimal time.
> > >>>>>>>>>>>>>>>>> wait for mirrormaker to finish
> > >>>>>>>>>>>>>>>>> let producer produce with the new metadata.
> > >>>>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>>> Instead of implementing the approach suggest in the KIP
> > >>>>>>>>>>>>>>>>> which
> > >>>>>>>>>>>>>>>>> will
> > >>>>>>>>>>>>>>>>> leave
> > >>>>>>>>>>>>>>>>> log compacted topic completely crumbled and unusable.
> > >>>>>>>>>>>>>>>>> I would much rather try to build infrastructure to
> > support
> > >>>>>>>>>>>>>>>>> the
> > >>>>>>>>>>>>>>>>> mentioned
> > >>>>>>>>>>>>>>>>> above operations more smoothly.
> > >>>>>>>>>>>>>>>>> Especially having producers stop and use another topic
> is
> > >>>>>>>>>>>>>>>>> difficult
> > >>>>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>>> and
> > >>>>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>>> it would be nice if one can trigger "invalid metadata"
> > >>>>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>> exceptions
> > >>>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>> for
> > >>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>> them
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>>> and
> > >>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>> if one could give topics aliases so that their produces
> > with
> > >>>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>>> the
> > >>>>>>>>>>>>>>>>> old
> > >>>>>>>>>>>>>>>>> topic
> > >>>>>>>>>>>>>>>>> will arrive in the new topic.
> > >>>>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>>> The downsides are obvious I guess ( having the same
> data
> > >>>>>>>>>>>>>>>>> twice
> > >>>>>>>>>>>>>>>>> for
> > >>>>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>>> the
> > >>>>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>>> transition period, but kafka tends to scale well with
> > >>>>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>> datasize).
> > >>>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>> So
> > >>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>> its a
> > >>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>> nicer fit into the architecture.
> > >>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>> I further want to argument that the functionality by the
> > KIP
> > >>>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>>> can
> > >>>>>>>>>>>>>>>>> completely be implementing in "userland" with a custom
> > >>>>>>>>>>>>>>>>> partitioner
> > >>>>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>>> that
> > >>>>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>>> handles the transition as needed. I would appreciate if
> > >>>>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>> someone
> > >>>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>> could
> > >>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>> point
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>>> out what a custom partitioner couldn't handle in this case?
> > >>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>> With the above approach, shrinking a topic becomes the
> same
> > >>>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>>> steps.
> > >>>>>>>>>>>>>>>>> Without
> > >>>>>>>>>>>>>>>>> loosing keys in the discontinued partitions.
> > >>>>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>>> Would love to hear what everyone thinks.
> > >>>>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>>> Best Jan
> > >>>>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>>> On 11.02.2018 00:35, Dong Lin wrote:
> > >>>>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>>> Hi all,
> > >>>>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>>> I have created KIP-253: Support in-order message
> delivery
> > >>>>>>>>>>>>>>>>> with
> > >>>>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>>> partition
> > >>>>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>>> expansion. See
> > >>>>>>>>>>>>>>>>>> https://cwiki.apache.org/confl
> > >>>>>>>>>>>>>>>>>> uence/display/KAFKA/KIP-253%
> > >>>>>>>>>>>>>>>>>> 3A+Support+in-order+message+de
> > >>>>>>>>>>>>>>>>>> livery+with+partition+expansio
> > >>>>>>>>>>>>>>>>>> n
> > >>>>>>>>>>>>>>>>>> .
> > >>>>>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>>>> This KIP provides a way to allow messages of the same
> > key
> > >>>>>>>>>>>>>>>>>> from
> > >>>>>>>>>>>>>>>>>> the
> > >>>>>>>>>>>>>>>>>> same
> > >>>>>>>>>>>>>>>>>> producer to be consumed in the same order they are
> > >>>>>>>>>>>>>>>>>> produced
> > >>>>>>>>>>>>>>>>>> even
> > >>>>>>>>>>>>>>>>>> if
> > >>>>>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>>>> we
> > >>>>>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>>>> expand partition of the topic.
> > >>>>>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>>> Thanks,
> > >>>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>> Dong
> > >>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>>>>
> > >>>>
> > >>
> > >>
> > >
> >
>

Re: [DISCUSS] KIP-253: Support in-order message delivery with partition expansion

Posted by John Roesler <jo...@confluent.io>.
Hi Dong,

Thanks for the response. I think I'm broadly in agreement with your
statement that with KIP-253 implemented as written, KStreams would be able
to use partition expansion on its various internal topics and processor
threads.

As you say, the reason we can do this is that for internal topics, the
producer and consumer are in the same code base and therefore have full
visibility on the partition function. So the reason for backfill is not
primarily to support expanding KStreams internal topics, but rather to
support partition expansion when the producer and consumer do not already
share code.

Examples of cases where backfill would be useful:
* A KStreams app consumes a log-compacted input
* A KStreams app produces a log-compacted output, which is consumed by an
external stateful system via Kafka Consumer
* In general, stateful usages of Kafka Consumer on log-compacted topics
that were not produced in the same application

So, in conclusion, I remain in support of KIP-253, since it gives us "key
partitioning preservation" (my #4 in topic characteristics above) and
"single-key
ordering preservation" (my #6 above). With these in place, all use cases
can at least not break in the presence of partition expansion.

I'm advocating to add backfill, either in this KIP or a future one, only to
allow those three use cases to *benefit* from partition expansion. In other
words, to allow them to expand their capacity to match expanded partitions.

Thanks,
-John

On Tue, Apr 3, 2018 at 10:38 AM, Dong Lin <li...@gmail.com> wrote:

> Hey John,
>
> Thanks much for your comments!!
>
> I have yet to go through the emails of John/Jun/Guozhang in detail. But let
> me present my idea for how to minimize the delay for state loading for
> stream use-case.
>
> For ease of understanding, let's assume that the initial partition number
> of input topics and change log topic are both 10. And initial number of
> stream processor is also 10. If we only increase initial partition number
> of input topics to 15 without changing number of stream processor, the
> current KIP already guarantees in-order delivery and no state needs to be
> moved between consumers for stream use-case. Next, let's say we want to
> increase the number of processor to expand the processing capacity for
> stream use-case. This requires us to move state between processors which
> will take time. Our goal is to minimize the impact (i.e. delay) for
> processing while we increase the number of processors.
>
> Note that stream processor generally includes both consumer and producer.
> In addition to consume from the input topic, consumer may also need to
> consume from change log topic on startup for recovery. And producer may
> produce state to the change log topic.
>
> The solution will include the following steps:
>
> 1) Increase partition number of the input topic from 10 to 15. Since the
> messages with the same key will still go to the same consume before and
> after the partition expansion, this step can be done without having to move
> state between processors.
>
> 2) Increase partition number of the change log topic from 10 to 15. Note
> that this step can also be done without impacting existing workflow. After
> we increase partition number of the change log topic, key space may split
> and some key will be produced to the newly-added partition. But the same
> key will still go to the same processor (i.e. consumer) before and after
> the partition. Thus this step can also be done without having to move state
> between processors.
>
> 3) Now, let's add 5 new consumers whose groupId is different from the
> existing processor's groupId. Thus these new consumers will not impact
> existing workflow. Each of these new consumers should consume two
> partitions from the earliest offset, where these two partitions are the
> same partitions that will be consumed if the consumers have the same
> groupId as the existing processor's groupId. For example, the first of the
> five consumers will consume partition 0 and partition 10. The purpose of
> these consumers is to rebuild the state (e.g. RocksDB) for the processors
> in advance. Also note that, by design of the current KIP, each consume will
> consume the existing partition of the change log topic up to the offset
> before the partition expansion. Then they will only need to consume the
> state of the new partition of the change log topic.
>
> 4) After consumers have caught up in step 3), we should stop these
> consumers and add 5 new processors to the stream processing job. These 5
> new processors should run in the same location as the previous 5 consumers
> to re-use the state (e.g. RocksDB). And these processors' consumers should
> consume partitions of the change log topic from the committed offset the
> previous 5 consumers so that no state is missed.
>
> One important trick to note here is that, the mapping from partition to
> consumer should also use linear hashing. And we need to remember the
> initial number of processors in the job, 10 in this example, and use this
> number in the linear hashing algorithm. This is pretty much the same as how
> we use linear hashing to map key to partition. In this case, we get an
> identity map from partition -> processor, for both input topic and the
> change log topic. For example, processor 12 will consume partition 12 of
> the input topic and produce state to the partition 12 of the change log
> topic.
>
> There are a few important properties of this solution to note:
>
> - We can increase the number of partitions for input topic and the change
> log topic in any order asynchronously.
> - The expansion of the processors in a given job in step 4) only requires
> the step 3) for the same job. It does not require coordination across
> different jobs for step 3) and 4). Thus different jobs can independently
> expand there capacity without waiting for each other.
> - The logic for 1) and 2) is already supported in the current KIP. The
> logic for 3) and 4) appears to be independent of the core Kafka logic and
> can be implemented separately outside core Kafka. Thus the current KIP is
> probably sufficient after we agree on the efficiency and the correctness of
> the solution. We can have a separate KIP for Kafka Stream to support 3) and
> 4).
>
>
> Cheers,
> Dong
>
>
> On Mon, Apr 2, 2018 at 3:25 PM, Guozhang Wang <wa...@gmail.com> wrote:
>
> > Hey guys, just sharing my two cents here (I promise it will be shorter
> than
> > John's article :).
> >
> > 0. Just to quickly recap, the main discussion point now is how to support
> > "key partitioning preservation" (John's #4 in topic characteristics
> above)
> > beyond the "single-key ordering preservation" that KIP-253 was originally
> > proposed to maintain (John's #6 above).
> >
> > 1. From the streams project, we are actively working on improving the
> > elastic scalability of the library. One of the key features is to
> decouple
> > the input topics from the parallelism model of Streams: i.e. not
> enforcing
> > the topic to be partitioned by the key, not enforcing joining topics to
> be
> > co-partitioned, not relying the number of parallel tasks on the input
> topic
> > partitions. This can be achieved by re-shuffling on the input topics to
> > make sure key-partitioning / co-partitioning on the internal topics. Note
> > the re-shuffling task is purely stateless and hence does not require "key
> > partitioning preservation". Operational-wise it is similar to the
> "creating
> > a new topic with new number of partitions, pipe the data to the new topic
> > and cut over consumers from old topics" idea, just that users can
> > optionally let Streams to handle such rather than doing it manually
> > themselves. There are a few more details on that regard but I will skip
> > since they are not directly related to this discussion.
> >
> > 2. Assuming that 1) above is done, then the only topics involved in the
> > scaling events are all input topics. For these topics the only producers
> /
> > consumers of these topics are controlled by Streams clients themselves,
> and
> > hence achieving "key partitioning preservation" is simpler than
> non-Streams
> > scenarios: consumers know the partitioning scheme that producers are
> using,
> > so that for their stateful operations it is doable to split the local
> state
> > stores accordingly or execute backfilling on its own. Of course, if we
> > decide to do server-side backfilling, it can still help Streams to
> directly
> > rely on that functionality.
> >
> > 3. As John mentioned, another way inside Streams is to do
> over-partitioning
> > on all internal topics; then with 1) Streams would not rely on KIP-253 at
> > all. But personally I'd like to avoid it if possible to reduce Kafka side
> > footprint: say we overpartition each input topic up to 1k, with a
> > reasonable sized stateful topology it can still contribute to tens of
> > thousands of topics to the topic partition capacity of a single cluster.
> >
> > 4. Summing up 1/2/3, I think we should focus more on non-Streams users
> > writing their stateful computations with local states, and think whether
> /
> > how we could enable "key partitioning preservation" for them easily, than
> > to think heavily for Streams library. People may have different opinion
> on
> > how common of a usage pattern it is (I think Jun might be suggesting that
> > for DIY apps people may more likely use remote states so that it is not a
> > problem for them). My opinion is that for non-Streams users such usage
> > pattern could still be large (think: if you are piping data from Kafka to
> > an external data storage which has single-writer requirements for each
> > single shard, even though it is not a stateful computational application
> it
> > may still require "key partitioning preservation"), so I prefer to have
> > backfilling in our KIP than only exposing the API for expansion and
> > requires consumers to have pre-knowledge of the producer's partitioning
> > scheme.
> >
> >
> >
> > Guozhang
> >
> >
> >
> > On Thu, Mar 29, 2018 at 2:33 PM, John Roesler <jo...@confluent.io> wrote:
> >
> > > Hey Dong,
> > >
> > > Congrats on becoming a committer!!!
> > >
> > > Since I just sent a novel-length email, I'll try and keep this one
> brief
> > ;)
> > >
> > > Regarding producer coordination, I'll grant that in that case,
> producers
> > > may coordinate among themselves to produce into the same topic or to
> > > produce co-partitioned topics. Nothing in KStreams or the Kafka
> ecosystem
> > > in general requires such coordination for correctness or in fact for
> any
> > > optional features, though, so I would not say that we require producer
> > > coordination of partition logic. If producers currently coordinate,
> it's
> > > completely optional and their own choice.
> > >
> > > Regarding the portability of partition algorithms, my observation is
> that
> > > systems requiring independent implementations of the same algorithm
> with
> > > 100% correctness are a large source of risk and also a burden on those
> > who
> > > have to maintain them. If people could flawlessly implement algorithms
> in
> > > actual software, the world would be a wonderful place indeed! For a
> > system
> > > as important and widespread as Kafka, I would recommend restricting
> > > limiting such requirements as aggressively as possible.
> > >
> > > I'd agree that we can always revisit decisions like allowing arbitrary
> > > partition functions, but of course, we shouldn't do that in a vacuum.
> > That
> > > feels like the kind of thing we'd need to proactively seek guidance
> from
> > > the users list about. I do think that the general approach of saying
> that
> > > "if you use a custom partitioner, you cannot do partition expansion" is
> > > very reasonable (but I don't think we need to go that far with the
> > current
> > > proposal). It's similar to my statement in my email to Jun that in
> > > principle KStreams doesn't *need* backfill, we only need it if we want
> to
> > > employ partition expansion.
> > >
> > > I reckon that the main motivation for backfill is to support KStreams
> use
> > > cases and also any other use cases involving stateful consumers.
> > >
> > > Thanks for your response, and congrats again!
> > > -John
> > >
> > >
> > > On Wed, Mar 28, 2018 at 1:34 AM, Dong Lin <li...@gmail.com> wrote:
> > >
> > > > Hey John,
> > > >
> > > > Great! Thanks for all the comment. It seems that we agree that the
> > > current
> > > > KIP is in good shape for core Kafka. IMO, what we have been
> discussing
> > in
> > > > the recent email exchanges is mostly about the second step, i.e. how
> to
> > > > address problem for the stream use-case (or stateful processing in
> > > > general).
> > > >
> > > > I will comment inline.
> > > >
> > > >
> > > >
> > > >
> > > > On Tue, Mar 27, 2018 at 4:38 PM, John Roesler <jo...@confluent.io>
> > wrote:
> > > >
> > > > > Thanks for the response, Dong.
> > > > >
> > > > > Here are my answers to your questions:
> > > > >
> > > > > - "Asking producers and consumers, or even two different producers,
> > to
> > > > > > share code like the partition function is a pretty huge ask. What
> > if
> > > > they
> > > > > > are using different languages?". It seems that today we already
> > > require
> > > > > > different producer's to use the same hash function -- otherwise
> > > > messages
> > > > > > with the same key will go to different partitions of the same
> topic
> > > > which
> > > > > > may cause problem for downstream consumption. So not sure if it
> > adds
> > > > any
> > > > > > more constraint by assuming consumers know the hash function of
> > > > producer.
> > > > > > Could you explain more why user would want to use a cusmtom
> > partition
> > > > > > function? Maybe we can check if this is something that can be
> > > supported
> > > > > in
> > > > > > the default Kafka hash function. Also, can you explain more why
> it
> > is
> > > > > > difficuilt to implement the same hash function in different
> > > languages?
> > > > >
> > > > >
> > > > > Sorry, I meant two different producers as in producers to two
> > different
> > > > > topics. This was in response to the suggestion that we already
> > require
> > > > > coordination among producers to different topics in order to
> achieve
> > > > > co-partitioning. I was saying that we do not (and should not).
> > > >
> > > >
> > > > It is probably common for producers of different team to produce
> > message
> > > to
> > > > the same topic. In order to ensure that messages with the same key go
> > to
> > > > same partition, we need producers of different team to share the same
> > > > partition algorithm, which by definition requires coordination among
> > > > producers of different teams in an organization. Even for producers
> of
> > > > different topics, it may be common to require producers to use the
> same
> > > > partition algorithm in order to join two topics for stream
> processing.
> > > Does
> > > > this make it reasonable to say we already require coordination across
> > > > producers?
> > > >
> > > >
> > > > > By design, consumers are currently ignorant of the partitioning
> > scheme.
> > > > It
> > > > > suffices to trust that the producer has partitioned the topic by
> key,
> > > if
> > > > > they claim to have done so. If you don't trust that, or even if you
> > > just
> > > > > need some other partitioning scheme, then you must re-partition it
> > > > > yourself. Nothing we're discussing can or should change that. The
> > value
> > > > of
> > > > > backfill is that it preserves the ability for consumers to avoid
> > > > > re-partitioning before consuming, in the case where they don't need
> > to
> > > > > today.
> > > >
> > > >
> > > > > Regarding shared "hash functions", note that it's a bit inaccurate
> to
> > > > talk
> > > > > about the "hash function" of the producer. Properly speaking, the
> > > > producer
> > > > > has only a "partition function". We do not know that it is a hash.
> > The
> > > > > producer can use any method at their disposal to assign a partition
> > to
> > > a
> > > > > record. The partition function obviously may we written in any
> > > > programming
> > > > > language, so in general it's not something that can be shared
> around
> > > > > without a formal spec or the ability to execute arbitrary
> executables
> > > in
> > > > > arbitrary runtime environments.
> > > > >
> > > >
> > > > Yeah it is probably better to say partition algorithm. I guess it
> > should
> > > > not be difficult to implement same partition algorithms in different
> > > > languages, right? Yes we would need a formal specification of the
> > default
> > > > partition algorithm in the producer. I think that can be documented
> as
> > > part
> > > > of the producer interface.
> > > >
> > > >
> > > > >
> > > > > Why would a producer want a custom partition function? I don't
> > know...
> > > > why
> > > > > did we design the interface so that our users can provide one? In
> > > > general,
> > > > > such systems provide custom partitioners because some data sets may
> > be
> > > > > unbalanced under the default or because they can provide some
> > > interesting
> > > > > functionality built on top of the partitioning scheme, etc. Having
> > > > provided
> > > > > this ability, I don't know why we would remove it.
> > > > >
> > > >
> > > > Yeah it is reasonable to assume that there was reason to support
> custom
> > > > partition function in producer. On the other hand it may also be
> > > reasonable
> > > > to revisit this interface and discuss whether we actually need to
> > support
> > > > custom partition function. If we don't have a good reason, we can
> > choose
> > > > not to support custom partition function in this KIP in a backward
> > > > compatible manner, i.e. user can still use custom partition function
> > but
> > > > they would not get the benefit of in-order delivery when there is
> > > partition
> > > > expansion. What do you think?
> > > >
> > > >
> > > > >
> > > > > - Besides the assumption that consumer needs to share the hash
> > function
> > > > of
> > > > > > producer, is there other organization overhead of the proposal in
> > the
> > > > > > current KIP?
> > > > > >
> > > > >
> > > > > It wasn't clear to me that KIP-253 currently required the producer
> > and
> > > > > consumer to share the partition function, or in fact that it had a
> > hard
> > > > > requirement to abandon the general partition function and use a
> > linear
> > > > hash
> > > > > function instead.
> > > >
> > > >
> > > > > In my reading, there is a requirement to track the metadata about
> > what
> > > > > partitions split into what other partitions during an expansion
> > > > operation.
> > > > > If the partition function is linear, this is easy. If not, you can
> > > always
> > > > > just record that all old partitions split into all new partitions.
> > This
> > > > has
> > > > > the effect of forcing all consumers to wait until the old epoch is
> > > > > completely consumed before starting on the new epoch. But this may
> > be a
> > > > > reasonable tradeoff, and it doesn't otherwise alter your design.
> > > > >
> > > > > You only mention the consumer needing to know that the partition
> > > function
> > > > > is linear, not what the actual function is, so I don't think your
> > > design
> > > > > actually calls for sharing the function. Plus, really all the
> > consumer
> > > > > needs is the metadata about what old-epoch partitions to wait for
> > > before
> > > > > consuming a new-epoch partition. This information is directly
> > captured
> > > in
> > > > > metadata, so I don't think it actually even cares whether the
> > partition
> > > > > function is linear or not.
> > > > >
> > > >
> > > > You are right that the current KIP does not mention it. My comment
> > > related
> > > > to the partition function coordination was related to support the
> > > > stream-use case which we have been discussing so far.
> > > >
> > > >
> > > > > So, no, I really think KIP-253 is in good shape. I was really more
> > > > talking
> > > > > about the part of this thread that's outside of KIP-253's scope,
> > > namely,
> > > > > creating the possibility of backfilling partitions after expansion.
> > > > >
> > > >
> > > > Great! Can you also confirm that the main motivation for backfilling
> > > > partitions after expansion is to support the stream use-case?
> > > >
> > > >
> > > > > - Currently producer can forget about the message that has been
> > > > > > acknowledged by the broker. Thus the producer probably does not
> > know
> > > > most
> > > > > > of the exiting messages in topic, including those messages
> produced
> > > by
> > > > > > other producers. We can have the owner of the producer to
> > > > split+backfill.
> > > > > > In my opion it will be a new program that wraps around the
> existing
> > > > > > producer and consumer classes.
> > > > > >
> > > > >
> > > > > This sounds fine by me!
> > > > >
> > > > > Really, I was just emphasizing that the part of the organization
> that
> > > > > produces a topic shouldn't have to export their partition function
> to
> > > the
> > > > > part(s) of the organization (or other organizations) that consume
> the
> > > > > topic. Whether the backfill operation goes into the Producer
> > interface
> > > is
> > > > > secondary, I think.
> > > > >
> > > > > - Regarding point 5. The argument is in favor of the split+backfill
> > but
> > > > for
> > > > > > changelog topic. And it intends to address the problem for stream
> > > > > use-case
> > > > > > in general. In this KIP we will provide interface (i.e.
> > > > > > PartitionKeyRebalanceListener in the KIP) to be used by sream
> > > use-case
> > > > > and
> > > > > > the goal is that user can flush/re-consume the state as part of
> the
> > > > > > interface implementation regardless of whether there is change
> log
> > > > topic.
> > > > > >
> > > > > > Maybe you are suggesting that the main reason to do
> split+backfill
> > of
> > > > > input
> > > > > > topic is to support log compacted topics? You mentioned in Point
> 1
> > > that
> > > > > log
> > > > > > compacted topics is out of the scope of this KIP. Maybe I could
> > > > > understand
> > > > > > your position better. Regarding Jan's proposal to split
> partitions
> > > with
> > > > > > backfill, do you think this should replace the proposal in the
> > > existing
> > > > > > KIP, or do you think this is something that we should do in
> > addition
> > > to
> > > > > the
> > > > > > existing KIP?
> > > > > >
> > > > >
> > > > > I think that interface is a good/necessary component of KIP-253.
> > > > >
> > > > > I personally (FWIW) feel that KIP-253 is appropriately scoped, but
> I
> > do
> > > > > think its utility will be limited unless there is a later KIP
> > offering
> > > > > backfill. But, maybe unlike Jan, I think it makes sense to try and
> > > tackle
> > > > > the ordering problem independently of backfill, so I'm in support
> of
> > > the
> > > > > current KIP.
> > > > >
> > > > > - Regarding point 6. I guess we can agree that it is better not to
> > have
> > > > the
> > > > > > performance overhread of copying the input data. Before we
> discuss
> > > more
> > > > > on
> > > > > > whether the performance overhead is acceptable or not, I am
> trying
> > to
> > > > > > figure out what is the benefit of introducing this overhread. You
> > > > > mentioned
> > > > > > that the benefit is the loose organizational coupling. By
> > > > "organizational
> > > > > > coupling", are you referring to the requirement that consumer
> needs
> > > to
> > > > > know
> > > > > > the hash function of producer? If so, maybe we can discuss the
> > > use-case
> > > > > of
> > > > > > custom partiton function and see whether we can find a way to
> > support
> > > > > such
> > > > > > use-case without having to copy the input data.
> > > > > >
> > > > >
> > > > > I'm not too sure about what an "input" is in this sense, since we
> are
> > > > just
> > > > > talking about topics. Actually the point I was making there is that
> > > > AKAICT
> > > > > the performance overhead of a backfill is less than any other
> option,
> > > > > assuming you split partitions rarely.
> > > > >
> > > >
> > > > By "input" I was referring to source Kafka topic of a stream
> processing
> > > > job.
> > > >
> > > >
> > > > > Separately, yes, "organizational coupling" increases if producers
> and
> > > > > consumers have to share code, such as the partition function. This
> > > would
> > > > > not be the case if producers could only pick from a menu of a few
> > > > > well-known partition functions, but I think this is a poor
> tradeoff.
> > > > >
> > > >
> > > > Maybe we can revisit the custom partition function and see whether we
> > > > actually need it? Otherwise, I am concerned that every user will pay
> > the
> > > > overhead of data movement to support something that was not really
> > needed
> > > > for most users.
> > > >
> > > >
> > > > >
> > > > > To me, this is two strong arguments in favor of backfill being less
> > > > > expensive than no backfill, but again, I think that particular
> debate
> > > > comes
> > > > > after KIP-253, so I don't want to create the impression of
> opposition
> > > to
> > > > > your proposal.
> > > > >
> > > > >
> > > > > Finally, to respond to a new email I just noticed:
> > > > >
> > > > > > BTW, here is my understanding of the scope of this KIP. We want
> to
> > > > allow
> > > > > > consumers to always consume messages with the same key from the
> > same
> > > > > > producer in the order they are produced. And we need to provide a
> > way
> > > > for
> > > > > > stream use-case to be able to flush/load state when messages with
> > the
> > > > > same
> > > > > > key are migrated between consumers. In addition to ensuring that
> > this
> > > > > goal
> > > > > > is correctly supported, we should do our best to keep the
> > performance
> > > > and
> > > > > > organization overhead of this KIP as low as possible.
> > > > > >
> > > > >
> > > > > I think we're on the same page there! In fact, I would generalize a
> > > > little
> > > > > more and say that the mechanism you've designed provides *all
> > > consumers*
> > > > > the ability "to flush/load state when messages with the same key
> are
> > > > > migrated between consumers", not just Streams.
> > > > >
> > > >
> > > > Thanks for all the comment!
> > > >
> > > >
> > > > >
> > > > > Thanks for the discussion,
> > > > > -John
> > > > >
> > > > >
> > > > >
> > > > > On Tue, Mar 27, 2018 at 3:14 PM, Dong Lin <li...@gmail.com>
> > wrote:
> > > > >
> > > > > > Hey John,
> > > > > >
> > > > > > Thanks much for the detailed comments. Here are my thoughts:
> > > > > >
> > > > > > - The need to delete messages from log compacted topics is mainly
> > for
> > > > > > performance (e.g. storage space) optimization than for
> correctness
> > > for
> > > > > this
> > > > > > KIP. I agree that we probably don't need to focus on this in our
> > > > > discussion
> > > > > > since it is mostly for performance optimization.
> > > > > >
> > > > > > - "Asking producers and consumers, or even two different
> producers,
> > > to
> > > > > > share code like the partition function is a pretty huge ask. What
> > if
> > > > they
> > > > > > are using different languages?". It seems that today we already
> > > require
> > > > > > different producer's to use the same hash function -- otherwise
> > > > messages
> > > > > > with the same key will go to different partitions of the same
> topic
> > > > which
> > > > > > may cause problem for downstream consumption. So not sure if it
> > adds
> > > > any
> > > > > > more constraint by assuming consumers know the hash function of
> > > > producer.
> > > > > > Could you explain more why user would want to use a cusmtom
> > partition
> > > > > > function? Maybe we can check if this is something that can be
> > > supported
> > > > > in
> > > > > > the default Kafka hash function. Also, can you explain more why
> it
> > is
> > > > > > difficuilt to implement the same hash function in different
> > > languages?
> > > > > >
> > > > > > - Besides the assumption that consumer needs to share the hash
> > > function
> > > > > of
> > > > > > producer, is there other organization overhead of the proposal in
> > the
> > > > > > current KIP?
> > > > > >
> > > > > > - Currently producer can forget about the message that has been
> > > > > > acknowledged by the broker. Thus the producer probably does not
> > know
> > > > most
> > > > > > of the exiting messages in topic, including those messages
> produced
> > > by
> > > > > > other producers. We can have the owner of the producer to
> > > > split+backfill.
> > > > > > In my opion it will be a new program that wraps around the
> existing
> > > > > > producer and consumer classes.
> > > > > >
> > > > > > - Regarding point 5. The argument is in favor of the
> split+backfill
> > > but
> > > > > for
> > > > > > changelog topic. And it intends to address the problem for stream
> > > > > use-case
> > > > > > in general. In this KIP we will provide interface (i.e.
> > > > > > PartitionKeyRebalanceListener in the KIP) to be used by sream
> > > use-case
> > > > > and
> > > > > > the goal is that user can flush/re-consume the state as part of
> the
> > > > > > interface implementation regardless of whether there is change
> log
> > > > topic.
> > > > > >
> > > > > > Maybe you are suggesting that the main reason to do
> split+backfill
> > of
> > > > > input
> > > > > > topic is to support log compacted topics? You mentioned in Point
> 1
> > > that
> > > > > log
> > > > > > compacted topics is out of the scope of this KIP. Maybe I could
> > > > > understand
> > > > > > your position better. Regarding Jan's proposal to split
> partitions
> > > with
> > > > > > backfill, do you think this should replace the proposal in the
> > > existing
> > > > > > KIP, or do you think this is something that we should do in
> > addition
> > > to
> > > > > the
> > > > > > existing KIP?
> > > > > >
> > > > > > - Regarding point 6. I guess we can agree that it is better not
> to
> > > have
> > > > > the
> > > > > > performance overhread of copying the input data. Before we
> discuss
> > > more
> > > > > on
> > > > > > whether the performance overhead is acceptable or not, I am
> trying
> > to
> > > > > > figure out what is the benefit of introducing this overhread. You
> > > > > mentioned
> > > > > > that the benefit is the loose organizational coupling. By
> > > > "organizational
> > > > > > coupling", are you referring to the requirement that consumer
> needs
> > > to
> > > > > know
> > > > > > the hash function of producer? If so, maybe we can discuss the
> > > use-case
> > > > > of
> > > > > > custom partiton function and see whether we can find a way to
> > support
> > > > > such
> > > > > > use-case without having to copy the input data.
> > > > > >
> > > > > > Thanks,
> > > > > > Dong
> > > > > >
> > > > > >
> > > > > > On Tue, Mar 27, 2018 at 11:34 AM, John Roesler <
> john@confluent.io>
> > > > > wrote:
> > > > > >
> > > > > > > Hey Dong and Jun,
> > > > > > >
> > > > > > > Thanks for the thoughtful responses. If you don't mind, I'll
> mix
> > my
> > > > > > replies
> > > > > > > together to try for a coherent response. I'm not too familiar
> > with
> > > > > > > mailing-list etiquette, though.
> > > > > > >
> > > > > > > I'm going to keep numbering my points because it makes it easy
> > for
> > > > you
> > > > > > all
> > > > > > > to respond.
> > > > > > >
> > > > > > > Point 1:
> > > > > > > As I read it, KIP-253 is *just* about properly fencing the
> > > producers
> > > > > and
> > > > > > > consumers so that you preserve the correct ordering of records
> > > during
> > > > > > > partition expansion. This is clearly necessary regardless of
> > > anything
> > > > > > else
> > > > > > > we discuss. I think this whole discussion about backfill,
> > > consumers,
> > > > > > > streams, etc., is beyond the scope of KIP-253. But it would be
> > > > > cumbersome
> > > > > > > to start a new thread at this point.
> > > > > > >
> > > > > > > I had missed KIP-253's Proposed Change #9 among all the
> > details...
> > > I
> > > > > > think
> > > > > > > this is a nice addition to the proposal. One thought is that
> it's
> > > > > > actually
> > > > > > > irrelevant whether the hash function is linear. This is simply
> an
> > > > > > algorithm
> > > > > > > for moving a key from one partition to another, so the type of
> > hash
> > > > > > > function need not be a precondition. In fact, it also doesn't
> > > matter
> > > > > > > whether the topic is compacted or not, the algorithm works
> > > > regardless.
> > > > > > >
> > > > > > > I think this is a good algorithm to keep in mind, as it might
> > > solve a
> > > > > > > variety of problems, but it does have a downside: that the
> > producer
> > > > > won't
> > > > > > > know whether or not K1 was actually in P1, it just knows that
> K1
> > > was
> > > > in
> > > > > > > P1's keyspace before the new epoch. Therefore, it will have to
> > > > > > > pessimistically send (K1,null) to P1 just in case. But the next
> > > time
> > > > K1
> > > > > > > comes along, the producer *also* won't remember that it already
> > > > > retracted
> > > > > > > K1 from P1, so it will have to send (K1,null) *again*. By
> > > extension,
> > > > > > every
> > > > > > > time the producer sends to P2, it will also have to send a
> > > tombstone
> > > > to
> > > > > > P1,
> > > > > > > which is a pretty big burden. To make the situation worse, if
> > there
> > > > is
> > > > > a
> > > > > > > second split, say P2 becomes P2 and P3, then any key Kx
> belonging
> > > to
> > > > P3
> > > > > > > will also have to be retracted from P2 *and* P1, since the
> > producer
> > > > > can't
> > > > > > > know whether Kx had been last written to P2 or P1. Over a long
> > > period
> > > > > of
> > > > > > > time, this clearly becomes a issue, as the producer must send
> an
> > > > > > arbitrary
> > > > > > > number of retractions along with every update.
> > > > > > >
> > > > > > > In contrast, the proposed backfill operation has an end, and
> > after
> > > it
> > > > > > ends,
> > > > > > > everyone can afford to forget that there ever was a different
> > > > partition
> > > > > > > layout.
> > > > > > >
> > > > > > > Really, though, figuring out how to split compacted topics is
> > > beyond
> > > > > the
> > > > > > > scope of KIP-253, so I'm not sure #9 really even needs to be in
> > > this
> > > > > > KIP...
> > > > > > > We do need in-order delivery during partition expansion. It
> would
> > > be
> > > > > fine
> > > > > > > by me to say that you *cannot* expand partitions of a
> > log-compacted
> > > > > topic
> > > > > > > and call it a day. I think it would be better to tackle that in
> > > > another
> > > > > > > KIP.
> > > > > > >
> > > > > > >
> > > > > > > Point 2:
> > > > > > > Regarding whether the consumer re-shuffles its inputs, this is
> > > always
> > > > > on
> > > > > > > the table; any consumer who wants to re-shuffle its input is
> free
> > > to
> > > > do
> > > > > > so.
> > > > > > > But this is currently not required. It's just that the current
> > > > > high-level
> > > > > > > story with Kafka encourages the use of partitions as a unit of
> > > > > > concurrency.
> > > > > > > As long as consumers are single-threaded, they can happily
> > consume
> > > a
> > > > > > single
> > > > > > > partition without concurrency control of any kind. This is a
> key
> > > > aspect
> > > > > > to
> > > > > > > this system that lets folks design high-throughput systems on
> top
> > > of
> > > > it
> > > > > > > surprisingly easily. If all consumers were instead
> > > > encouraged/required
> > > > > to
> > > > > > > implement a repartition of their own, then the consumer becomes
> > > > > > > significantly more complex, requiring either the consumer to
> > first
> > > > > > produce
> > > > > > > to its own intermediate repartition topic or to ensure that
> > > consumer
> > > > > > > threads have a reliable, high-bandwith channel of communication
> > > with
> > > > > > every
> > > > > > > other consumer thread.
> > > > > > >
> > > > > > > Either of those tradeoffs may be reasonable for a particular
> user
> > > of
> > > > > > Kafka,
> > > > > > > but I don't know if we're in a position to say that they are
> > > > reasonable
> > > > > > for
> > > > > > > *every* user of Kafka.
> > > > > > >
> > > > > > >
> > > > > > > Point 3:
> > > > > > > Regarding Jun's point about this use case, "(3) stateful and
> > > > > maintaining
> > > > > > > the
> > > > > > > states in a local store", I agree that they may use a framework
> > > > *like*
> > > > > > > Kafka Streams, but that is not the same as using Kafka Streams.
> > > This
> > > > is
> > > > > > why
> > > > > > > I think it's better to solve it in Core: because it is then
> > solved
> > > > for
> > > > > > > KStreams and also for everything else that facilitates local
> > state
> > > > > > > maintenance. To me, Streams is a member of the category of
> > "stream
> > > > > > > processing frameworks", which is itself a subcategory of
> "things
> > > > > > requiring
> > > > > > > local state maintenence". I'm not sure if it makes sense to
> > assert
> > > > that
> > > > > > > Streams is a sufficient and practical replacement for
> everything
> > in
> > > > > > "things
> > > > > > > requiring local state maintenence".
> > > > > > >
> > > > > > > But, yes, I do agree that per-key ordering is an absolute
> > > > requirement,
> > > > > > > therefore I think that KIP-253 itself is a necessary step.
> > > Regarding
> > > > > the
> > > > > > > coupling of the state store partitioning to the topic
> > partitioning,
> > > > > yes,
> > > > > > > this is an issue we are discussing solutions to right now. We
> may
> > > go
> > > > > > ahead
> > > > > > > and introduce an overpartition layer on our inputs to solve it,
> > but
> > > > > then
> > > > > > > again, if we get the ability to split partitions with backfill,
> > we
> > > > may
> > > > > > not
> > > > > > > need to!
> > > > > > >
> > > > > > >
> > > > > > > Point 4:
> > > > > > > On this:
> > > > > > >
> > > > > > > > Regarding thought 2: If we don't care about the stream
> > use-case,
> > > > then
> > > > > > the
> > > > > > > > current KIP probably has already addressed problem without
> > > > requiring
> > > > > > > > consumer to know the partition function. If we care about the
> > > > stream
> > > > > > > > use-case, we already need coordination across producers of
> > > > different
> > > > > > > > topics, i.e. the same partition function needs to be used by
> > > > > producers
> > > > > > of
> > > > > > > > topics A and B in order to join topics A and B. Thus, it
> might
> > be
> > > > > > > > reasonable to extend coordination a bit and say we need
> > > > coordination
> > > > > > > across
> > > > > > > > clients (i.e. producer and consumer), such that consumer
> knows
> > > the
> > > > > > > > partition function used by producer. If we do so, then we can
> > let
> > > > > > > consumer
> > > > > > > > re-copy data for the change log topic using the same
> partition
> > > > > function
> > > > > > > as
> > > > > > > > producer. This approach has lower overhead as compared to
> > having
> > > > > > producer
> > > > > > > > re-copy data of the input topic.
> > > > > > > > Also, producer currently does not need to know the data
> already
> > > > > > produced
> > > > > > > to
> > > > > > > > the topic. If we let producer split/merge partition, it would
> > > > require
> > > > > > > > producer to consume the existing data, which intuitively is
> the
> > > > task
> > > > > of
> > > > > > > > consumer.
> > > > > > >
> > > > > > >
> > > > > > > I think we do care about use cases *like* Streams, I just don't
> > > think
> > > > > we
> > > > > > > should rely on Streams to implement a feature of Core like
> > > partition
> > > > > > > expansion.
> > > > > > >
> > > > > > > Note, though, that we (Streams) do not require coordination
> > across
> > > > > > > producers. If two topics are certified to be co-partitioned,
> then
> > > > > Streams
> > > > > > > apps can make use of that knowledge to optimize their topology
> > > > > (skipping
> > > > > > a
> > > > > > > repartition). But if they don't know whether they are
> > > co-partitioned,
> > > > > > then
> > > > > > > they'd better go ahead and repartition within the topology.
> This
> > is
> > > > the
> > > > > > > current state.
> > > > > > >
> > > > > > > A huge selling point of Kafka is enabling different parts of
> > > loosely
> > > > > > > coupled organizations to produce and consume data
> independently.
> > > Some
> > > > > > > coordination between producers and consumers is necessary, like
> > > > > > > coordinating on the names of topics and their schemas. But
> > Kafka's
> > > > > value
> > > > > > > proposition w.r.t. ESBs, etc. is inversely proportional to the
> > > amount
> > > > > of
> > > > > > > coordination required. I think it behooves us to be extremely
> > > > skeptical
> > > > > > > about introducing any coordination beyond correctness
> protocols.
> > > > > > >
> > > > > > > Asking producers and consumers, or even two different
> producers,
> > to
> > > > > share
> > > > > > > code like the partition function is a pretty huge ask. What if
> > they
> > > > are
> > > > > > > using different languages?
> > > > > > >
> > > > > > > Comparing organizational overhead vs computational overhead,
> > there
> > > > are
> > > > > > > maybe two orders of magnitude difference between them. In other
> > > > words,
> > > > > I
> > > > > > > would happily take on the (linear) overhead of having the
> > producer
> > > > > > re-copy
> > > > > > > the data once during a re-partition in order to save the
> > > > organizational
> > > > > > > overhead of tying all the producers and consumers together
> across
> > > > > > multiple
> > > > > > > boundaries.
> > > > > > >
> > > > > > > On that last paragraph: note that the producer *did* know the
> > data
> > > it
> > > > > > > already produced. It handled it the first time around. Asking
> it
> > to
> > > > > > > re-produce it into a new partition layout is squarely within
> its
> > > > scope
> > > > > of
> > > > > > > capabilities. Contrast this with the alternative, asking the
> > > consumer
> > > > > to
> > > > > > > re-partition the data. I think this is even less intuitive,
> when
> > > the
> > > > > > > partition function belongs to the producer.
> > > > > > >
> > > > > > >
> > > > > > > Point 5:
> > > > > > > Dong asked this:
> > > > > > >
> > > > > > > > For stream use-case that needs to increase consumer number,
> the
> > > > > > > > existing consumer can backfill the existing data in the
> change
> > > log
> > > > > > topic
> > > > > > > to
> > > > > > > > the same change log topic with the new partition number,
> before
> > > the
> > > > > new
> > > > > > > set
> > > > > > > > of consumers bootstrap state from the new partitions of the
> > > change
> > > > > log
> > > > > > > > topic, right?
> > > > > > >
> > > > > > >
> > > > > > > In this sense, the "consumer" is actually the producer of the
> > > > changelog
> > > > > > > topic, so if we support partition expansion + backfill as a
> > > > > > producer/broker
> > > > > > > operation, then it would be very straightforward for Streams to
> > > > split a
> > > > > > > state store. As you say, they would simply instruct the broker
> to
> > > > split
> > > > > > the
> > > > > > > changelog topic's partitions, then backfill. Once the backfill
> is
> > > > > ready,
> > > > > > > they can create a new crop of StandbyTasks to bootstrap the
> more
> > > > > granular
> > > > > > > state stores and finally switch over to them when they are
> ready.
> > > > > > >
> > > > > > > But this actually seems to be an argument in favor of
> > > split+backfill,
> > > > > so
> > > > > > > maybe I missed the point.
> > > > > > >
> > > > > > > You also asked me to explain why copying the "input" topic is
> > > better
> > > > > than
> > > > > > > copying the "changelog" topic. I think they are totally
> > > independent,
> > > > > > > actually. For one thing, you can't depend on the existence of a
> > > > > > "changelog"
> > > > > > > topic in general, only within Streams, but Kafka's user base
> > > clearly
> > > > > > > exceeds Streams's user base. Plus, you actually also can't
> depend
> > > on
> > > > > the
> > > > > > > existence of a changelog topic within Streams, since that is an
> > > > > optional
> > > > > > > feature of *some* state store implementations. Even in the
> > > situation
> > > > > > where
> > > > > > > you do have a changelog topic in Streams, there may be use
> cases
> > > > where
> > > > > it
> > > > > > > makes sense to expand the partitions of just the input, or just
> > the
> > > > > > > changelog.
> > > > > > >
> > > > > > > The ask for a Core feature of split+backfill is really about
> > > > supporting
> > > > > > the
> > > > > > > use case of splitting partitions in log-compacted topics,
> > > regardless
> > > > of
> > > > > > > whether that topic is an "input" or a "changelog" or anything
> > else
> > > > for
> > > > > > that
> > > > > > > matter.
> > > > > > >
> > > > > > >
> > > > > > > Point 6:
> > > > > > > On the concern about the performance overhead of copying data
> > > between
> > > > > the
> > > > > > > brokers, I think it's actually a bit overestimated. Splitting a
> > > > topic's
> > > > > > > partition is probably rare, certainly rarer in general than
> > > > > bootstrapping
> > > > > > > new consumers on that topic. If "bootstrapping new consumers"
> > means
> > > > > that
> > > > > > > they have to re-shuffle the data before they consume it, then
> you
> > > > wind
> > > > > up
> > > > > > > copying the same record multiple times:
> > > > > > >
> > > > > > > (broker: input topic) -> (initial consumer) -> (broker:
> > repartition
> > > > > > topic)
> > > > > > > -> (real consumer)
> > > > > > >
> > > > > > > That's 3x, and it's also 3x for every new record after the
> split
> > as
> > > > > well,
> > > > > > > since you don't get to stop repartitioning/reshuffling once you
> > > > start.
> > > > > > >
> > > > > > > Whereas if you do a backfill in something like the procedure I
> > > > > outlined,
> > > > > > > you only copy the prefix of the partition before the split, and
> > you
> > > > > send
> > > > > > it
> > > > > > > once to the producer and then once to the new generation
> > partition.
> > > > > Plus,
> > > > > > > assuming we're splitting the partition for the benefit of
> > > consumers,
> > > > > > > there's no reason we can't co-locate the post-split partitions
> on
> > > the
> > > > > > same
> > > > > > > host as the pre-split partition, making the second copy a local
> > > > > > filesystem
> > > > > > > operation.
> > > > > > >
> > > > > > > Even if you follow these two copies up with bootstrapping a new
> > > > > consumer,
> > > > > > > it's still rare for this to occur, so you get to amortize these
> > > > copies
> > > > > > over
> > > > > > > the lifetime of the topic, whereas a reshuffle just keeps
> making
> > > > copies
> > > > > > for
> > > > > > > every new event.
> > > > > > >
> > > > > > > And finally, I really do think that regardless of any
> performance
> > > > > > concerns
> > > > > > > about this operation, if it preserves loose organizational
> > > coupling,
> > > > it
> > > > > > is
> > > > > > > certainly worth it.
> > > > > > >
> > > > > > >
> > > > > > > In conclusion:
> > > > > > > It might actually be a good idea for us to clarify the scope of
> > > > > KIP-253.
> > > > > > If
> > > > > > > we're all agreed that it's a good algorithm for allowing
> in-order
> > > > > message
> > > > > > > delivery during partition expansion, then we can continue this
> > > > > discussion
> > > > > > > as a new KIP, something like "backfill with partition
> expansion".
> > > > This
> > > > > > > would let Dong proceed with KIP-253. On the other hand, if it
> > seems
> > > > > like
> > > > > > > this conversation may alter the design of KIP-253, then maybe
> we
> > > > > *should*
> > > > > > > just finish working it out.
> > > > > > >
> > > > > > > For my part, my only concern about KIP-253 is the one I raised
> > > > earlier.
> > > > > > >
> > > > > > > Thanks again, all, for considering these points,
> > > > > > > -John
> > > > > > >
> > > > > > >
> > > > > > > On Tue, Mar 27, 2018 at 2:10 AM, Dong Lin <lindong28@gmail.com
> >
> > > > wrote:
> > > > > > >
> > > > > > > > On Tue, Mar 27, 2018 at 12:04 AM, Dong Lin <
> > lindong28@gmail.com>
> > > > > > wrote:
> > > > > > > >
> > > > > > > > > Hey Jan,
> > > > > > > > >
> > > > > > > > > Thanks for the enthusiasm in improving Kafka's design. Now
> > > that I
> > > > > > have
> > > > > > > > > read through your discussion with Jun, here are my
> thoughts:
> > > > > > > > >
> > > > > > > > > - The latest proposal should with log compacted topics by
> > > > properly
> > > > > > > > > deleting old messages after a new message with the same key
> > is
> > > > > > > produced.
> > > > > > > > So
> > > > > > > > > it is probably not a concern anymore. Could you comment if
> > > there
> > > > is
> > > > > > > still
> > > > > > > > > issue?
> > > > > > > > >
> > > > > > > > > - I wrote the SEP-5 and I am pretty familiar with the
> > > motivation
> > > > > and
> > > > > > > the
> > > > > > > > > design of SEP-5. SEP-5 is probably orthornal to the
> > motivation
> > > of
> > > > > > this
> > > > > > > > KIP.
> > > > > > > > > The goal of SEP-5 is to allow user to increase task number
> of
> > > an
> > > > > > > existing
> > > > > > > > > Samza job. But if we increase the partition number of input
> > > > topics,
> > > > > > > > > messages may still be consumed out-of-order by tasks in
> Samza
> > > > which
> > > > > > > cause
> > > > > > > > > incorrect result. Similarly, the approach you proposed does
> > not
> > > > > seem
> > > > > > to
> > > > > > > > > ensure that the messages can be delivered in order, even if
> > we
> > > > can
> > > > > > make
> > > > > > > > > sure that each consumer instance is assigned the set of new
> > > > > > partitions
> > > > > > > > > covering the same set of keys.
> > > > > > > > >
> > > > > > > >
> > > > > > > > Let me correct this comment. The approach of copying data to
> a
> > > new
> > > > > > topic
> > > > > > > > can ensure in-order message delivery suppose we properly
> > migrate
> > > > > > offsets
> > > > > > > > from old topic to new topic.
> > > > > > > >
> > > > > > > >
> > > > > > > > > - I am trying to understand why it is better to copy the
> data
> > > > > instead
> > > > > > > of
> > > > > > > > > copying the change log topic for streaming use-case. For
> core
> > > > Kafka
> > > > > > > > > use-case, and for the stream use-case that does not need to
> > > > > increase
> > > > > > > > > consumers, the current KIP already supports in-order
> delivery
> > > > > without
> > > > > > > the
> > > > > > > > > overhead of copying the data. For stream use-case that
> needs
> > to
> > > > > > > increase
> > > > > > > > > consumer number, the existing consumer can backfill the
> > > existing
> > > > > data
> > > > > > > in
> > > > > > > > > the change log topic to the same change log topic with the
> > new
> > > > > > > partition
> > > > > > > > > number, before the new set of consumers bootstrap state
> from
> > > the
> > > > > new
> > > > > > > > > partitions of the change log topic. If this solution works,
> > > then
> > > > > > could
> > > > > > > > you
> > > > > > > > > summarize the advantage of copying the data of input topic
> as
> > > > > > compared
> > > > > > > to
> > > > > > > > > copying the change log topic? For example, does it enable
> > more
> > > > > > > use-case,
> > > > > > > > > simplify the implementation of Kafka library, or reduce the
> > > > > operation
> > > > > > > > > overhead etc?
> > > > > > > > >
> > > > > > > > > Thanks,
> > > > > > > > > Dong
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > On Wed, Mar 21, 2018 at 6:57 AM, Jan Filipiak <
> > > > > > > Jan.Filipiak@trivago.com>
> > > > > > > > > wrote:
> > > > > > > > >
> > > > > > > > >> Hi Jun,
> > > > > > > > >>
> > > > > > > > >> I was really seeing progress in our conversation but your
> > > latest
> > > > > > reply
> > > > > > > > is
> > > > > > > > >> just devastating.
> > > > > > > > >> I though we were getting close being on the same page now
> it
> > > > feels
> > > > > > > like
> > > > > > > > >> we are in different libraries.
> > > > > > > > >>
> > > > > > > > >> I just quickly slam my answers in here. If they are to
> > brief I
> > > > am
> > > > > > > sorry
> > > > > > > > >> give me a ping and try to go into details more.
> > > > > > > > >> Just want to show that your pro/cons listing is broken.
> > > > > > > > >>
> > > > > > > > >> Best Jan
> > > > > > > > >>
> > > > > > > > >> and want to get rid of this horrible compromise
> > > > > > > > >>
> > > > > > > > >>
> > > > > > > > >> On 19.03.2018 05:48, Jun Rao wrote:
> > > > > > > > >>
> > > > > > > > >>> Hi, Jan,
> > > > > > > > >>>
> > > > > > > > >>> Thanks for the discussion. Great points.
> > > > > > > > >>>
> > > > > > > > >>> Let me try to summarize the approach that you are
> > proposing.
> > > On
> > > > > the
> > > > > > > > >>> broker
> > > > > > > > >>> side, we reshuffle the existing data in a topic from
> > current
> > > > > > > partitions
> > > > > > > > >>> to
> > > > > > > > >>> the new partitions. Once the reshuffle fully catches up,
> > > switch
> > > > > the
> > > > > > > > >>> consumers to start consuming from the new partitions. If
> a
> > > > > consumer
> > > > > > > > needs
> > > > > > > > >>> to rebuild its local state (due to partition changes),
> let
> > > the
> > > > > > > consumer
> > > > > > > > >>> rebuild its state by reading all existing data from the
> new
> > > > > > > partitions.
> > > > > > > > >>> Once all consumers have switches over, cut over the
> > producer
> > > to
> > > > > the
> > > > > > > new
> > > > > > > > >>> partitions.
> > > > > > > > >>>
> > > > > > > > >>> The pros for this approach are that :
> > > > > > > > >>> 1. There is just one way to rebuild the local state,
> which
> > is
> > > > > > > simpler.
> > > > > > > > >>>
> > > > > > > > >> true thanks
> > > > > > > > >>
> > > > > > > > >>>
> > > > > > > > >>> The cons for this approach are:
> > > > > > > > >>> 1. Need to copy existing data.
> > > > > > > > >>>
> > > > > > > > >> Very unfair and not correct. It does not require you to
> copy
> > > > over
> > > > > > > > >> existing data. It _allows_ you to copy all existing data.
> > > > > > > > >>
> > > > > > > > >> 2. The cutover of the producer is a bit complicated since
> it
> > > > needs
> > > > > > to
> > > > > > > > >>> coordinate with all consumer groups.
> > > > > > > > >>>
> > > > > > > > >> Also not true. I explicitly tried to make clear that there
> > is
> > > > only
> > > > > > one
> > > > > > > > >> special consumer (in the case of actually copying data)
> > > > > coordination
> > > > > > > is
> > > > > > > > >> required.
> > > > > > > > >>
> > > > > > > > >>> 3. The rebuilding of the state in the consumer is from
> the
> > > > input
> > > > > > > topic,
> > > > > > > > >>> which can be more expensive than rebuilding from the
> > existing
> > > > > > state.
> > > > > > > > >>>
> > > > > > > > >> true, but rebuilding state is only required if you want to
> > > > > increase
> > > > > > > > >> processing power, so we assume this is at hand.
> > > > > > > > >>
> > > > > > > > >>> 4. The broker potentially has to know the partitioning
> > > > function.
> > > > > If
> > > > > > > > this
> > > > > > > > >>> needs to be customized at the topic level, it can be a
> bit
> > > > messy.
> > > > > > > > >>>
> > > > > > > > >> I would argue against having the operation being performed
> > by
> > > > the
> > > > > > > > broker.
> > > > > > > > >> This was not discussed yet but if you see my original
> email
> > i
> > > > > > > suggested
> > > > > > > > >> otherwise from the beginning.
> > > > > > > > >>
> > > > > > > > >>>
> > > > > > > > >>> Here is an alternative approach by applying your idea not
> > in
> > > > the
> > > > > > > > broker,
> > > > > > > > >>> but in the consumer. When new partitions are added, we
> > don't
> > > > move
> > > > > > > > >>> existing
> > > > > > > > >>> data. In KStreams, we first reshuffle the new input data
> > to a
> > > > new
> > > > > > > topic
> > > > > > > > >>> T1
> > > > > > > > >>> with the old number of partitions and feed T1's data to
> the
> > > > rest
> > > > > of
> > > > > > > the
> > > > > > > > >>> pipeline. In the meantime, KStreams reshuffles all
> existing
> > > > data
> > > > > of
> > > > > > > the
> > > > > > > > >>> change capture topic to another topic C1 with the new
> > number
> > > of
> > > > > > > > >>> partitions.
> > > > > > > > >>> We can then build the state of the new tasks from C1.
> Once
> > > the
> > > > > new
> > > > > > > > states
> > > > > > > > >>> have been fully built, we can cut over the consumption to
> > the
> > > > > input
> > > > > > > > topic
> > > > > > > > >>> and delete T1. This approach works with compacted topic
> > too.
> > > If
> > > > > an
> > > > > > > > >>> application reads from the beginning of a compacted
> topic,
> > > the
> > > > > > > consumer
> > > > > > > > >>> will reshuffle the portion of the input when the number
> of
> > > > > > partitions
> > > > > > > > >>> doesn't match the number of tasks.
> > > > > > > > >>>
> > > > > > > > >> We all wipe this idea from our heads instantly. Mixing
> Ideas
> > > > from
> > > > > an
> > > > > > > > >> argument is not a resolution strategy
> > > > > > > > >> just leads to horrible horrible software.
> > > > > > > > >>
> > > > > > > > >>
> > > > > > > > >>> The pros of this approach are:
> > > > > > > > >>> 1. No need to copy existing data.
> > > > > > > > >>> 2. Each consumer group can cut over to the new partitions
> > > > > > > > independently.
> > > > > > > > >>> 3. The state is rebuilt from the change capture topic,
> > which
> > > is
> > > > > > > cheaper
> > > > > > > > >>> than rebuilding from the input topic.
> > > > > > > > >>> 4. Only the KStreams job needs to know the partitioning
> > > > function.
> > > > > > > > >>>
> > > > > > > > >>> The cons of this approach are:
> > > > > > > > >>> 1. Potentially the same input topic needs to be
> reshuffled
> > > more
> > > > > > than
> > > > > > > > once
> > > > > > > > >>> in different consumer groups during the transition phase.
> > > > > > > > >>>
> > > > > > > > >>> What do you think?
> > > > > > > > >>>
> > > > > > > > >>> Thanks,
> > > > > > > > >>>
> > > > > > > > >>> Jun
> > > > > > > > >>>
> > > > > > > > >>>
> > > > > > > > >>>
> > > > > > > > >>> On Thu, Mar 15, 2018 at 1:04 AM, Jan Filipiak <
> > > > > > > > Jan.Filipiak@trivago.com>
> > > > > > > > >>> wrote:
> > > > > > > > >>>
> > > > > > > > >>> Hi Jun,
> > > > > > > > >>>>
> > > > > > > > >>>> thank you for following me on these thoughts. It was
> > > important
> > > > > to
> > > > > > me
> > > > > > > > to
> > > > > > > > >>>> feel that kind of understanding for my arguments.
> > > > > > > > >>>>
> > > > > > > > >>>> What I was hoping for (I mentioned this earlier) is that
> > we
> > > > can
> > > > > > > model
> > > > > > > > >>>> the
> > > > > > > > >>>> case where we do not want to copy the data the exact
> same
> > > way
> > > > as
> > > > > > the
> > > > > > > > >>>> case
> > > > > > > > >>>> when we do copy the data. Maybe you can peek into the
> > mails
> > > > > before
> > > > > > > to
> > > > > > > > >>>> see
> > > > > > > > >>>> more details for this.
> > > > > > > > >>>>
> > > > > > > > >>>> This means we have the same mechanism to transfer
> consumer
> > > > > groups
> > > > > > to
> > > > > > > > >>>> switch topic. The offset mapping that would be generated
> > > would
> > > > > > even
> > > > > > > be
> > > > > > > > >>>> simpler End Offset of the Old topic => offset 0 off all
> > the
> > > > > > > partitions
> > > > > > > > >>>> of
> > > > > > > > >>>> the new topic. Then we could model the transition of a
> > > > non-copy
> > > > > > > > >>>> expansion
> > > > > > > > >>>> the exact same way as a copy-expansion.
> > > > > > > > >>>>
> > > > > > > > >>>> I know this only works when topic growth by a factor.
> But
> > > the
> > > > > > > benefits
> > > > > > > > >>>> of
> > > > > > > > >>>> only growing by a factor are to strong anyways. See
> > > Clemens's
> > > > > hint
> > > > > > > and
> > > > > > > > >>>> remember that state reshuffling is entirely not needed
> if
> > > one
> > > > > > > doesn't
> > > > > > > > >>>> want
> > > > > > > > >>>> to grow processing power.
> > > > > > > > >>>>
> > > > > > > > >>>> I think these benefits should be clear, and that there
> is
> > > > > > basically
> > > > > > > no
> > > > > > > > >>>> downside to what is currently at hand but just makes
> > > > everything
> > > > > > > easy.
> > > > > > > > >>>>
> > > > > > > > >>>> One thing you need to know is. that if you do not offer
> > > > > > rebuilding a
> > > > > > > > log
> > > > > > > > >>>> compacted topic like i suggest that even if you have
> > > consumer
> > > > > > state
> > > > > > > > >>>> reshuffling. The topic is broken and can not be used to
> > > > > bootstrap
> > > > > > > new
> > > > > > > > >>>> consumers. They don't know if they need to apply a key
> > from
> > > > and
> > > > > > old
> > > > > > > > >>>> partition or not. This is a horrible downside I haven't
> > > seen a
> > > > > > > > solution
> > > > > > > > >>>> for
> > > > > > > > >>>> in the email conversation.
> > > > > > > > >>>>
> > > > > > > > >>>> I argue to:
> > > > > > > > >>>>
> > > > > > > > >>>> Only grow topic by a factor always.
> > > > > > > > >>>> Have the "no copy consumer" transition as the trivial
> case
> > > of
> > > > > the
> > > > > > > > "copy
> > > > > > > > >>>> consumer transition".
> > > > > > > > >>>> If processors needs to be scaled, let them rebuild from
> > the
> > > > new
> > > > > > > topic
> > > > > > > > >>>> and
> > > > > > > > >>>> leave the old running in the mean time.
> > > > > > > > >>>> Do not implement key shuffling in streams.
> > > > > > > > >>>>
> > > > > > > > >>>> I hope I can convince you especially with the fact how I
> > > want
> > > > to
> > > > > > > > handle
> > > > > > > > >>>> consumer transition. I think
> > > > > > > > >>>> you didn't quite understood me there before. I think the
> > > term
> > > > > "new
> > > > > > > > >>>> topic"
> > > > > > > > >>>> intimidated you a little.
> > > > > > > > >>>> How we solve this on disc doesn't really matter, If the
> > data
> > > > > goes
> > > > > > > into
> > > > > > > > >>>> the
> > > > > > > > >>>> same Dir or a different Dir or anything. I do think that
> > it
> > > > > needs
> > > > > > to
> > > > > > > > >>>> involve at least rolling a new segment for the existing
> > > > > > partitions.
> > > > > > > > >>>> But most of the transitions should work without
> restarting
> > > > > > > consumers.
> > > > > > > > >>>> (newer consumers with support for this). But with new
> > topic
> > > i
> > > > > just
> > > > > > > > meant
> > > > > > > > >>>> the topic that now has a different partition count.
> Plenty
> > > of
> > > > > ways
> > > > > > > to
> > > > > > > > >>>> handle that (versions, aliases)
> > > > > > > > >>>>
> > > > > > > > >>>> Hope I can further get my idea across.
> > > > > > > > >>>>
> > > > > > > > >>>> Best Jan
> > > > > > > > >>>>
> > > > > > > > >>>>
> > > > > > > > >>>>
> > > > > > > > >>>>
> > > > > > > > >>>>
> > > > > > > > >>>>
> > > > > > > > >>>> On 14.03.2018 02:45, Jun Rao wrote:
> > > > > > > > >>>>
> > > > > > > > >>>> Hi, Jan,
> > > > > > > > >>>>>
> > > > > > > > >>>>> Thanks for sharing your view.
> > > > > > > > >>>>>
> > > > > > > > >>>>> I agree with you that recopying the data potentially
> > makes
> > > > the
> > > > > > > state
> > > > > > > > >>>>> management easier since the consumer can just rebuild
> its
> > > > state
> > > > > > > from
> > > > > > > > >>>>> scratch (i.e., no need for state reshuffling).
> > > > > > > > >>>>>
> > > > > > > > >>>>> On the flip slide, I saw a few disadvantages of the
> > > approach
> > > > > that
> > > > > > > you
> > > > > > > > >>>>> suggested. (1) Building the state from the input topic
> > from
> > > > > > scratch
> > > > > > > > is
> > > > > > > > >>>>> in
> > > > > > > > >>>>> general less efficient than state reshuffling. Let's
> say
> > > one
> > > > > > > > computes a
> > > > > > > > >>>>> count per key from an input topic. The former requires
> > > > reading
> > > > > > all
> > > > > > > > >>>>> existing
> > > > > > > > >>>>> records in the input topic whereas the latter only
> > requires
> > > > > > reading
> > > > > > > > >>>>> data
> > > > > > > > >>>>> proportional to the number of unique keys. (2) The
> > > switching
> > > > of
> > > > > > the
> > > > > > > > >>>>> topic
> > > > > > > > >>>>> needs modification to the application. If there are
> many
> > > > > > > applications
> > > > > > > > >>>>> on a
> > > > > > > > >>>>> topic, coordinating such an effort may not be easy.
> Also,
> > > > it's
> > > > > > not
> > > > > > > > >>>>> clear
> > > > > > > > >>>>> how to enforce exactly-once semantic during the switch.
> > (3)
> > > > If
> > > > > a
> > > > > > > > topic
> > > > > > > > >>>>> doesn't need any state management, recopying the data
> > seems
> > > > > > > wasteful.
> > > > > > > > >>>>> In
> > > > > > > > >>>>> that case, in place partition expansion seems more
> > > desirable.
> > > > > > > > >>>>>
> > > > > > > > >>>>> I understand your concern about adding complexity in
> > > > KStreams.
> > > > > > But,
> > > > > > > > >>>>> perhaps
> > > > > > > > >>>>> we could iterate on that a bit more to see if it can be
> > > > > > simplified.
> > > > > > > > >>>>>
> > > > > > > > >>>>> Jun
> > > > > > > > >>>>>
> > > > > > > > >>>>>
> > > > > > > > >>>>> On Mon, Mar 12, 2018 at 11:21 PM, Jan Filipiak <
> > > > > > > > >>>>> Jan.Filipiak@trivago.com>
> > > > > > > > >>>>> wrote:
> > > > > > > > >>>>>
> > > > > > > > >>>>> Hi Jun,
> > > > > > > > >>>>>
> > > > > > > > >>>>>> I will focus on point 61 as I think its _the_
> > fundamental
> > > > part
> > > > > > > that
> > > > > > > > I
> > > > > > > > >>>>>> cant
> > > > > > > > >>>>>> get across at the moment.
> > > > > > > > >>>>>>
> > > > > > > > >>>>>> Kafka is the platform to have state materialized
> > multiple
> > > > > times
> > > > > > > from
> > > > > > > > >>>>>> one
> > > > > > > > >>>>>> input. I emphasize this: It is the building block in
> > > > > > architectures
> > > > > > > > >>>>>> that
> > > > > > > > >>>>>> allow you to
> > > > > > > > >>>>>> have your state maintained multiple times. You put a
> > > message
> > > > > in
> > > > > > > > once,
> > > > > > > > >>>>>> and
> > > > > > > > >>>>>> you have it pop out as often as you like. I believe
> you
> > > > > > understand
> > > > > > > > >>>>>> this.
> > > > > > > > >>>>>>
> > > > > > > > >>>>>> Now! The path of thinking goes the following: I am
> using
> > > > > apache
> > > > > > > > kafka
> > > > > > > > >>>>>> and
> > > > > > > > >>>>>> I _want_ my state multiple times. What am I going
> todo?
> > > > > > > > >>>>>>
> > > > > > > > >>>>>> A) Am I going to take my state that I build up, plunge
> > > some
> > > > > sort
> > > > > > > of
> > > > > > > > >>>>>> RPC
> > > > > > > > >>>>>> layer ontop of it, use that RPC layer to throw my
> > records
> > > > > across
> > > > > > > > >>>>>> instances?
> > > > > > > > >>>>>> B) Am I just going to read the damn message twice?
> > > > > > > > >>>>>>
> > > > > > > > >>>>>> Approach A is fundamentally flawed and a violation of
> > all
> > > > that
> > > > > > is
> > > > > > > > good
> > > > > > > > >>>>>> and
> > > > > > > > >>>>>> holy in kafka deployments. I can not understand how
> this
> > > > Idea
> > > > > > can
> > > > > > > > >>>>>> come in
> > > > > > > > >>>>>> the first place.
> > > > > > > > >>>>>> (I do understand: IQ in streams, they polluted the
> kafka
> > > > > streams
> > > > > > > > >>>>>> codebase
> > > > > > > > >>>>>> really bad already. It is not funny! I think they are
> > > > equally
> > > > > > > flawed
> > > > > > > > >>>>>> as
> > > > > > > > >>>>>> A)
> > > > > > > > >>>>>>
> > > > > > > > >>>>>> I say, we do what Kafka is good at. We repartition the
> > > topic
> > > > > > once.
> > > > > > > > We
> > > > > > > > >>>>>> switch the consumers.
> > > > > > > > >>>>>> (Those that need more partitions are going to rebuild
> > > their
> > > > > > state
> > > > > > > in
> > > > > > > > >>>>>> multiple partitions by reading the new topic, those
> that
> > > > don't
> > > > > > > just
> > > > > > > > >>>>>> assign
> > > > > > > > >>>>>> the new partitions properly)
> > > > > > > > >>>>>> We switch producers. Done!
> > > > > > > > >>>>>>
> > > > > > > > >>>>>> The best thing! It is trivial, hipster stream
> processor
> > > will
> > > > > > have
> > > > > > > an
> > > > > > > > >>>>>> easy
> > > > > > > > >>>>>> time with that aswell. Its so super simple. And simple
> > IS
> > > > > good!
> > > > > > > > >>>>>> It is what kafka was build todo. It is how we do it
> > today.
> > > > > All I
> > > > > > > am
> > > > > > > > >>>>>> saying
> > > > > > > > >>>>>> is that a little broker help doing the producer swap
> is
> > > > super
> > > > > > > > useful.
> > > > > > > > >>>>>>
> > > > > > > > >>>>>> For everyone interested in why kafka is so powerful
> with
> > > > > > approach
> > > > > > > B,
> > > > > > > > >>>>>> please watch https://youtu.be/bEbeZPVo98c?t=1633
> > > > > > > > >>>>>> I already looked up a good point in time, I think
> after
> > 5
> > > > > > minutes
> > > > > > > > the
> > > > > > > > >>>>>> "state" topic is handled and you should be able to
> > > > understand
> > > > > me
> > > > > > > > >>>>>> and inch better.
> > > > > > > > >>>>>>
> > > > > > > > >>>>>> Please do not do A to the project, it deserves better!
> > > > > > > > >>>>>>
> > > > > > > > >>>>>> Best Jan
> > > > > > > > >>>>>>
> > > > > > > > >>>>>>
> > > > > > > > >>>>>>
> > > > > > > > >>>>>> On 13.03.2018 02:40, Jun Rao wrote:
> > > > > > > > >>>>>>
> > > > > > > > >>>>>> Hi, Jan,
> > > > > > > > >>>>>>
> > > > > > > > >>>>>>> Thanks for the reply. A few more comments below.
> > > > > > > > >>>>>>>
> > > > > > > > >>>>>>> 50. Ok, we can think a bit harder for supporting
> > > compacted
> > > > > > > topics.
> > > > > > > > >>>>>>>
> > > > > > > > >>>>>>> 51. This is a fundamental design question. In the
> more
> > > > common
> > > > > > > case,
> > > > > > > > >>>>>>> the
> > > > > > > > >>>>>>> reason why someone wants to increase the number of
> > > > partitions
> > > > > > is
> > > > > > > > that
> > > > > > > > >>>>>>> the
> > > > > > > > >>>>>>> consumer application is slow and one wants to run
> more
> > > > > consumer
> > > > > > > > >>>>>>> instances
> > > > > > > > >>>>>>> to increase the degree of parallelism. So, fixing the
> > > > number
> > > > > of
> > > > > > > > >>>>>>> running
> > > > > > > > >>>>>>> consumer instances when expanding the partitions
> won't
> > > help
> > > > > > this
> > > > > > > > >>>>>>> case.
> > > > > > > > >>>>>>> If
> > > > > > > > >>>>>>> we do need to increase the number of consumer
> > instances,
> > > we
> > > > > > need
> > > > > > > to
> > > > > > > > >>>>>>> somehow
> > > > > > > > >>>>>>> reshuffle the state of the consumer across instances.
> > > What
> > > > we
> > > > > > > have
> > > > > > > > >>>>>>> been
> > > > > > > > >>>>>>> discussing in this KIP is whether we can do this more
> > > > > > effectively
> > > > > > > > >>>>>>> through
> > > > > > > > >>>>>>> the KStream library (e.g. through a 2-phase partition
> > > > > > expansion).
> > > > > > > > >>>>>>> This
> > > > > > > > >>>>>>> will
> > > > > > > > >>>>>>> add some complexity, but it's probably better than
> > > everyone
> > > > > > doing
> > > > > > > > >>>>>>> this
> > > > > > > > >>>>>>> in
> > > > > > > > >>>>>>> the application space. The recopying approach that
> you
> > > > > > mentioned
> > > > > > > > >>>>>>> doesn't
> > > > > > > > >>>>>>> seem to address the consumer state management issue
> > when
> > > > the
> > > > > > > > consumer
> > > > > > > > >>>>>>> switches from an old to a new topic.
> > > > > > > > >>>>>>>
> > > > > > > > >>>>>>> 52. As for your example, it depends on whether the
> join
> > > key
> > > > > is
> > > > > > > the
> > > > > > > > >>>>>>> same
> > > > > > > > >>>>>>> between (A,B) and (B,C). If the join key is the same,
> > we
> > > > can
> > > > > > do a
> > > > > > > > >>>>>>> 2-phase
> > > > > > > > >>>>>>> partition expansion of A, B, and C together. If the
> > join
> > > > keys
> > > > > > are
> > > > > > > > >>>>>>> different, one would need to repartition the data on
> a
> > > > > > different
> > > > > > > > key
> > > > > > > > >>>>>>> for
> > > > > > > > >>>>>>> the second join, then the partition expansion can be
> > done
> > > > > > > > >>>>>>> independently
> > > > > > > > >>>>>>> between (A,B) and (B,C).
> > > > > > > > >>>>>>>
> > > > > > > > >>>>>>> 53. If you always fix the number of consumer
> instances,
> > > we
> > > > > you
> > > > > > > > >>>>>>> described
> > > > > > > > >>>>>>> works. However, as I mentioned in #51, I am not sure
> > how
> > > > your
> > > > > > > > >>>>>>> proposal
> > > > > > > > >>>>>>> deals with consumer states when the number of
> consumer
> > > > > > instances
> > > > > > > > >>>>>>> grows.
> > > > > > > > >>>>>>> Also, it just seems that it's better to avoid
> > re-copying
> > > > the
> > > > > > > > existing
> > > > > > > > >>>>>>> data.
> > > > > > > > >>>>>>>
> > > > > > > > >>>>>>> 60. "just want to throw in my question from the
> longer
> > > > email
> > > > > in
> > > > > > > the
> > > > > > > > >>>>>>> other
> > > > > > > > >>>>>>> Thread here. How will the bloom filter help a new
> > > consumer
> > > > to
> > > > > > > > decide
> > > > > > > > >>>>>>> to
> > > > > > > > >>>>>>> apply the key or not?" Not sure that I fully
> understood
> > > > your
> > > > > > > > >>>>>>> question.
> > > > > > > > >>>>>>> The
> > > > > > > > >>>>>>> consumer just reads whatever key is in the log. The
> > bloom
> > > > > > filter
> > > > > > > > just
> > > > > > > > >>>>>>> helps
> > > > > > > > >>>>>>> clean up the old keys.
> > > > > > > > >>>>>>>
> > > > > > > > >>>>>>> 61. "Why can we afford having a topic where its
> > > apparently
> > > > > not
> > > > > > > > >>>>>>> possible
> > > > > > > > >>>>>>> to
> > > > > > > > >>>>>>> start a new application on? I think this is an
> overall
> > > flaw
> > > > > of
> > > > > > > the
> > > > > > > > >>>>>>> discussed idea here. Not playing attention to the
> > overall
> > > > > > > > >>>>>>> architecture."
> > > > > > > > >>>>>>> Could you explain a bit more when one can't start a
> new
> > > > > > > > application?
> > > > > > > > >>>>>>>
> > > > > > > > >>>>>>> Jun
> > > > > > > > >>>>>>>
> > > > > > > > >>>>>>>
> > > > > > > > >>>>>>>
> > > > > > > > >>>>>>> On Sat, Mar 10, 2018 at 1:40 AM, Jan Filipiak <
> > > > > > > > >>>>>>> Jan.Filipiak@trivago.com
> > > > > > > > >>>>>>> wrote:
> > > > > > > > >>>>>>>
> > > > > > > > >>>>>>> Hi Jun, thanks for your mail.
> > > > > > > > >>>>>>>
> > > > > > > > >>>>>>> Thank you for your questions!
> > > > > > > > >>>>>>>> I think they are really good and tackle the core of
> > the
> > > > > > problem
> > > > > > > I
> > > > > > > > >>>>>>>> see.
> > > > > > > > >>>>>>>>
> > > > > > > > >>>>>>>> I will answer inline, mostly but still want to set
> the
> > > > tone
> > > > > > > here.
> > > > > > > > >>>>>>>>
> > > > > > > > >>>>>>>> The core strength of kafka is what Martin once
> called
> > > the
> > > > > > > > >>>>>>>> kappa-Architecture. How does this work?
> > > > > > > > >>>>>>>> You have everything as a log as in kafka. When you
> > need
> > > to
> > > > > > > change
> > > > > > > > >>>>>>>> something.
> > > > > > > > >>>>>>>> You create the new version of your application and
> > leave
> > > > it
> > > > > > > > running
> > > > > > > > >>>>>>>> in
> > > > > > > > >>>>>>>> parallel.
> > > > > > > > >>>>>>>> Once the new version is good you switch your users
> to
> > > use
> > > > > the
> > > > > > > new
> > > > > > > > >>>>>>>> application.
> > > > > > > > >>>>>>>>
> > > > > > > > >>>>>>>> The online reshuffling effectively breaks this
> > > > architecture
> > > > > > and
> > > > > > > I
> > > > > > > > >>>>>>>> think
> > > > > > > > >>>>>>>> the switch in thinking here is more harmful
> > > > > > > > >>>>>>>> than any details about the partitioning function to
> > > allow
> > > > > > such a
> > > > > > > > >>>>>>>> change.
> > > > > > > > >>>>>>>> I
> > > > > > > > >>>>>>>> feel with my suggestion we are the closest to
> > > > > > > > >>>>>>>> the original and battle proven architecture and I
> can
> > > only
> > > > > > warn
> > > > > > > to
> > > > > > > > >>>>>>>> move
> > > > > > > > >>>>>>>> away from it.
> > > > > > > > >>>>>>>>
> > > > > > > > >>>>>>>> I might have forgotten something, sometimes its hard
> > for
> > > > me
> > > > > to
> > > > > > > > >>>>>>>> getting
> > > > > > > > >>>>>>>> all
> > > > > > > > >>>>>>>> the thoughts captured in a mail, but I hope the
> > comments
> > > > > > inline
> > > > > > > > will
> > > > > > > > >>>>>>>> further make my concern clear, and put some emphasis
> > on
> > > > why
> > > > > I
> > > > > > > > >>>>>>>> prefer my
> > > > > > > > >>>>>>>> solution ;)
> > > > > > > > >>>>>>>>
> > > > > > > > >>>>>>>> One thing we should all be aware of when discussing
> > > this,
> > > > > and
> > > > > > I
> > > > > > > > >>>>>>>> think
> > > > > > > > >>>>>>>> Dong
> > > > > > > > >>>>>>>> should have mentioned it (maybe he did).
> > > > > > > > >>>>>>>> We are not discussing all of this out of thin air
> but
> > > > there
> > > > > is
> > > > > > > an
> > > > > > > > >>>>>>>> effort
> > > > > > > > >>>>>>>> in the Samza project.
> > > > > > > > >>>>>>>>
> > > > > > > > >>>>>>>> https://cwiki.apache.org/confl
> > uence/display/SAMZA/SEP-
> > > > 5%3A+
> > > > > > > > >>>>>>>> Enable+partition+expansion+of+input+streams
> > > > > > > > >>>>>>>> https://issues.apache.org/jira/browse/SAMZA-1293
> > > > > > > > >>>>>>>>
> > > > > > > > >>>>>>>> To be clear. I think SEP-5 (state of last week, dont
> > > know
> > > > if
> > > > > > it
> > > > > > > > >>>>>>>> adapted
> > > > > > > > >>>>>>>> to
> > > > > > > > >>>>>>>> this discussion) is on a way better path than
> KIP-253,
> > > > and I
> > > > > > > can't
> > > > > > > > >>>>>>>> really
> > > > > > > > >>>>>>>> explain why.
> > > > > > > > >>>>>>>>
> > > > > > > > >>>>>>>> Best Jan,
> > > > > > > > >>>>>>>>
> > > > > > > > >>>>>>>> nice weekend everyone
> > > > > > > > >>>>>>>>
> > > > > > > > >>>>>>>>
> > > > > > > > >>>>>>>> On 09.03.2018 03:36, Jun Rao wrote:
> > > > > > > > >>>>>>>>
> > > > > > > > >>>>>>>> Hi, Jan,
> > > > > > > > >>>>>>>>
> > > > > > > > >>>>>>>> Thanks for the feedback. Just some comments on the
> > > earlier
> > > > > > > points
> > > > > > > > >>>>>>>>> that
> > > > > > > > >>>>>>>>> you
> > > > > > > > >>>>>>>>> mentioned.
> > > > > > > > >>>>>>>>>
> > > > > > > > >>>>>>>>> 50. You brought up the question of whether existing
> > > data
> > > > > > needs
> > > > > > > to
> > > > > > > > >>>>>>>>> be
> > > > > > > > >>>>>>>>> copied
> > > > > > > > >>>>>>>>> during partition expansion. My understand of your
> > view
> > > is
> > > > > > that
> > > > > > > > >>>>>>>>> avoid
> > > > > > > > >>>>>>>>> copying existing data will be more efficient, but
> it
> > > > > doesn't
> > > > > > > work
> > > > > > > > >>>>>>>>> well
> > > > > > > > >>>>>>>>> with
> > > > > > > > >>>>>>>>> compacted topics since some keys in the original
> > > > partitions
> > > > > > > will
> > > > > > > > >>>>>>>>> never
> > > > > > > > >>>>>>>>> be
> > > > > > > > >>>>>>>>> cleaned. It would be useful to understand your use
> > case
> > > > of
> > > > > > > > >>>>>>>>> compacted
> > > > > > > > >>>>>>>>> topics
> > > > > > > > >>>>>>>>> a bit more. In the common use case, the data volume
> > in
> > > a
> > > > > > > > compacted
> > > > > > > > >>>>>>>>> topic
> > > > > > > > >>>>>>>>> may not be large. So, I am not sure if there is a
> > > strong
> > > > > need
> > > > > > > to
> > > > > > > > >>>>>>>>> expand
> > > > > > > > >>>>>>>>> partitions in a compacted topic, at least
> initially.
> > > > > > > > >>>>>>>>>
> > > > > > > > >>>>>>>>> I do agree. State is usually smaller. Update rates
> > > might
> > > > be
> > > > > > > also
> > > > > > > > >>>>>>>>>
> > > > > > > > >>>>>>>>> competitively high.
> > > > > > > > >>>>>>>> Doing Log-compaction (even beeing very efficient and
> > > > > > > configurable)
> > > > > > > > >>>>>>>> is
> > > > > > > > >>>>>>>> also
> > > > > > > > >>>>>>>> a more expensive operation than
> > > > > > > > >>>>>>>> just discarding old segments. Further if you want to
> > use
> > > > > more
> > > > > > > > >>>>>>>> consumers
> > > > > > > > >>>>>>>> processing the events
> > > > > > > > >>>>>>>> you also have to grow the number of partitions.
> > > Especially
> > > > > for
> > > > > > > > >>>>>>>> use-cases
> > > > > > > > >>>>>>>> we do (KIP-213) a tiny state full
> > > > > > > > >>>>>>>> table might be very expensive to process if it joins
> > > > > against a
> > > > > > > > huge
> > > > > > > > >>>>>>>> table.
> > > > > > > > >>>>>>>>
> > > > > > > > >>>>>>>> I can just say we have been in the spot of needing
> to
> > > grow
> > > > > log
> > > > > > > > >>>>>>>> compacted
> > > > > > > > >>>>>>>> topics. Mainly for processing power we can bring to
> > the
> > > > > table.
> > > > > > > > >>>>>>>>
> > > > > > > > >>>>>>>> Further i am not at all concerned about the extra
> > spaced
> > > > > used
> > > > > > by
> > > > > > > > >>>>>>>> "garbage
> > > > > > > > >>>>>>>> keys". I am more concerned about the correctness of
> > > > innocent
> > > > > > > > >>>>>>>> consumers.
> > > > > > > > >>>>>>>> The
> > > > > > > > >>>>>>>> logic becomes complicated. Say for streams one would
> > > need
> > > > to
> > > > > > > load
> > > > > > > > >>>>>>>> the
> > > > > > > > >>>>>>>> record into state but not forward it the topology (
> to
> > > > have
> > > > > it
> > > > > > > > >>>>>>>> available
> > > > > > > > >>>>>>>> for shuffeling). I rather have it simple and a topic
> > > clean
> > > > > > > > >>>>>>>> regardless
> > > > > > > > >>>>>>>> if
> > > > > > > > >>>>>>>> it
> > > > > > > > >>>>>>>> still has its old partition count. Especially with
> > > > multiple
> > > > > > > > >>>>>>>> partitions
> > > > > > > > >>>>>>>> growth's I think it becomes insanely hard to to this
> > > > shuffle
> > > > > > > > >>>>>>>> correct.
> > > > > > > > >>>>>>>> Maybe
> > > > > > > > >>>>>>>> Streams and Samza can do it. Especially if you do
> > > "hipster
> > > > > > > stream
> > > > > > > > >>>>>>>> processing" <https://www.confluent.io/blog
> > > > > > > > >>>>>>>> /introducing-kafka-streams-
> > > > > > > > >>>>>>>> stream-processing-made-simple/>. This makes kafka
> way
> > > to
> > > > > > > > >>>>>>>> complicated.
> > > > > > > > >>>>>>>> With my approach I think its way simpler because the
> > > topic
> > > > > has
> > > > > > > no
> > > > > > > > >>>>>>>> "history"
> > > > > > > > >>>>>>>> in terms of partitioning but is always clean.
> > > > > > > > >>>>>>>>
> > > > > > > > >>>>>>>>
> > > > > > > > >>>>>>>> 51. "Growing the topic by an integer factor does not
> > > > require
> > > > > > any
> > > > > > > > >>>>>>>> state
> > > > > > > > >>>>>>>>
> > > > > > > > >>>>>>>> redistribution at all." Could you clarify this a bit
> > > more?
> > > > > > Let's
> > > > > > > > say
> > > > > > > > >>>>>>>>> you
> > > > > > > > >>>>>>>>> have a consumer app that computes the windowed
> count
> > > per
> > > > > key.
> > > > > > > If
> > > > > > > > >>>>>>>>> you
> > > > > > > > >>>>>>>>> double
> > > > > > > > >>>>>>>>> the number of partitions from 1 to 2 and grow the
> > > > consumer
> > > > > > > > >>>>>>>>> instances
> > > > > > > > >>>>>>>>> from
> > > > > > > > >>>>>>>>> 1
> > > > > > > > >>>>>>>>> to 2, we would need to redistribute some of the
> > counts
> > > to
> > > > > the
> > > > > > > new
> > > > > > > > >>>>>>>>> consumer
> > > > > > > > >>>>>>>>> instance. Regarding to linear hashing, it's true
> that
> > > it
> > > > > > won't
> > > > > > > > >>>>>>>>> solve
> > > > > > > > >>>>>>>>> the
> > > > > > > > >>>>>>>>> problem with compacted topics. The main benefit is
> > that
> > > > it
> > > > > > > > >>>>>>>>> redistributes
> > > > > > > > >>>>>>>>> the keys in one partition to no more than two
> > > partitions,
> > > > > > which
> > > > > > > > >>>>>>>>> could
> > > > > > > > >>>>>>>>> help
> > > > > > > > >>>>>>>>> redistribute the state.
> > > > > > > > >>>>>>>>>
> > > > > > > > >>>>>>>>> You don't need to spin up a new consumer in this
> > case.
> > > > > every
> > > > > > > > >>>>>>>>> consumer
> > > > > > > > >>>>>>>>>
> > > > > > > > >>>>>>>>> would just read every partition with the
> (partition %
> > > > > > num_task)
> > > > > > > > >>>>>>>> task.
> > > > > > > > >>>>>>>> it
> > > > > > > > >>>>>>>> will still have the previous data right there and
> can
> > go
> > > > on.
> > > > > > > > >>>>>>>>
> > > > > > > > >>>>>>>> This sounds contradictory to what I said before, but
> > > > please
> > > > > > bear
> > > > > > > > >>>>>>>> with
> > > > > > > > >>>>>>>> me.
> > > > > > > > >>>>>>>>
> > > > > > > > >>>>>>>> 52. Good point on coordinating the expansion of 2
> > topics
> > > > > that
> > > > > > > need
> > > > > > > > >>>>>>>> to
> > > > > > > > >>>>>>>> be
> > > > > > > > >>>>>>>>
> > > > > > > > >>>>>>>> joined together. This is where the 2-phase partition
> > > > > expansion
> > > > > > > > could
> > > > > > > > >>>>>>>>> potentially help. In the first phase, we could add
> > new
> > > > > > > partitions
> > > > > > > > >>>>>>>>> to
> > > > > > > > >>>>>>>>> the 2
> > > > > > > > >>>>>>>>> topics one at a time but without publishing to the
> > new
> > > > > > > patitions.
> > > > > > > > >>>>>>>>> Then,
> > > > > > > > >>>>>>>>> we
> > > > > > > > >>>>>>>>> can add new consumer instances to pick up the new
> > > > > partitions.
> > > > > > > In
> > > > > > > > >>>>>>>>> this
> > > > > > > > >>>>>>>>> transition phase, no reshuffling is needed since no
> > > data
> > > > is
> > > > > > > > coming
> > > > > > > > >>>>>>>>> from
> > > > > > > > >>>>>>>>> the
> > > > > > > > >>>>>>>>> new partitions. Finally, we can enable the
> publishing
> > > to
> > > > > the
> > > > > > > new
> > > > > > > > >>>>>>>>> partitions.
> > > > > > > > >>>>>>>>>
> > > > > > > > >>>>>>>>> I think its even worse than you think. I would like
> > to
> > > > > > > introduce
> > > > > > > > >>>>>>>>> the
> > > > > > > > >>>>>>>>>
> > > > > > > > >>>>>>>>> Term
> > > > > > > > >>>>>>>> transitive copartitioning. Imagine
> > > > > > > > >>>>>>>> 2 streams application. One joins (A,B) the other
> (B,C)
> > > > then
> > > > > > > there
> > > > > > > > >>>>>>>> is a
> > > > > > > > >>>>>>>> transitive copartition requirement for
> > > > > > > > >>>>>>>> (A,C) to be copartitioned aswell. This can spread
> > > > > > significantly
> > > > > > > > and
> > > > > > > > >>>>>>>> require many consumers to adapt at the same time.
> > > > > > > > >>>>>>>>
> > > > > > > > >>>>>>>> It is also not entirely clear to me how you not need
> > > > > > reshuffling
> > > > > > > > in
> > > > > > > > >>>>>>>> this
> > > > > > > > >>>>>>>> case. If A has a record that never gets updated
> after
> > > the
> > > > > > > > expansion
> > > > > > > > >>>>>>>> and
> > > > > > > > >>>>>>>> the
> > > > > > > > >>>>>>>> coresponding B record moves to a new partition. How
> > > shall
> > > > > they
> > > > > > > > meet
> > > > > > > > >>>>>>>> w/o
> > > > > > > > >>>>>>>> shuffle?
> > > > > > > > >>>>>>>>
> > > > > > > > >>>>>>>> 53. "Migrating consumer is a step that might be made
> > > > > completly
> > > > > > > > >>>>>>>>
> > > > > > > > >>>>>>>> unnecessary
> > > > > > > > >>>>>>>>> if - for example streams - takes the gcd as
> > > partitioning
> > > > > > scheme
> > > > > > > > >>>>>>>>> instead
> > > > > > > > >>>>>>>>> of
> > > > > > > > >>>>>>>>> enforcing 1 to 1." Not sure that I fully understand
> > > > this. I
> > > > > > > think
> > > > > > > > >>>>>>>>> you
> > > > > > > > >>>>>>>>> mean
> > > > > > > > >>>>>>>>> that a consumer application can run more instances
> > than
> > > > the
> > > > > > > > number
> > > > > > > > >>>>>>>>> of
> > > > > > > > >>>>>>>>> partitions. In that case, the consumer can just
> > > > > > repartitioning
> > > > > > > > the
> > > > > > > > >>>>>>>>> input
> > > > > > > > >>>>>>>>> data according to the number of instances. This is
> > > > > possible,
> > > > > > > but
> > > > > > > > >>>>>>>>> just
> > > > > > > > >>>>>>>>> has
> > > > > > > > >>>>>>>>> the overhead of reshuffling the data.
> > > > > > > > >>>>>>>>>
> > > > > > > > >>>>>>>>> No what I meant is ( that is also your question i
> > think
> > > > > > > Mathias)
> > > > > > > > >>>>>>>>> that
> > > > > > > > >>>>>>>>> if
> > > > > > > > >>>>>>>>>
> > > > > > > > >>>>>>>>> you grow a topic by a factor.
> > > > > > > > >>>>>>>> Even if your processor is statefull you can can just
> > > > assign
> > > > > > all
> > > > > > > > the
> > > > > > > > >>>>>>>> multiples of the previous partition to
> > > > > > > > >>>>>>>> this consumer and the state to keep processing
> > correctly
> > > > > will
> > > > > > be
> > > > > > > > >>>>>>>> present
> > > > > > > > >>>>>>>> w/o any shuffling.
> > > > > > > > >>>>>>>>
> > > > > > > > >>>>>>>> Say you have an assignment
> > > > > > > > >>>>>>>> Statefull consumer => partition
> > > > > > > > >>>>>>>> 0 => 0
> > > > > > > > >>>>>>>> 1 => 1
> > > > > > > > >>>>>>>> 2 => 2
> > > > > > > > >>>>>>>>
> > > > > > > > >>>>>>>> and you grow you topic by 4 you get,
> > > > > > > > >>>>>>>>
> > > > > > > > >>>>>>>> 0 => 0,3,6,9
> > > > > > > > >>>>>>>> 1 => 1,4,7,10
> > > > > > > > >>>>>>>> 2 => 2,5,8,11
> > > > > > > > >>>>>>>>
> > > > > > > > >>>>>>>> Say your hashcode is 8. 8%3 => 2  before so consumer
> > for
> > > > > > > > partition 2
> > > > > > > > >>>>>>>> has
> > > > > > > > >>>>>>>> it.
> > > > > > > > >>>>>>>> Now you you have 12 partitions so 8%12 => 8, so it
> > goes
> > > > into
> > > > > > > > >>>>>>>> partition
> > > > > > > > >>>>>>>> 8
> > > > > > > > >>>>>>>> which is assigned to the same consumer
> > > > > > > > >>>>>>>> who had 2 before and therefore knows the key.
> > > > > > > > >>>>>>>>
> > > > > > > > >>>>>>>> Userland reshuffeling is there as an options. And it
> > > does
> > > > > > > exactly
> > > > > > > > >>>>>>>> what
> > > > > > > > >>>>>>>> I
> > > > > > > > >>>>>>>> suggest. And I think its the perfect strategie. All
> I
> > am
> > > > > > > > suggestion
> > > > > > > > >>>>>>>> is
> > > > > > > > >>>>>>>> broker side support to switch the producers to the
> > newly
> > > > > > > > partitioned
> > > > > > > > >>>>>>>> topic.
> > > > > > > > >>>>>>>> Then the old (to few partition topic) can go away.
> > > > Remember
> > > > > > the
> > > > > > > > >>>>>>>> list
> > > > > > > > >>>>>>>> of
> > > > > > > > >>>>>>>> steps in the beginning of this thread. If one has
> > broker
> > > > > > support
> > > > > > > > for
> > > > > > > > >>>>>>>> all
> > > > > > > > >>>>>>>> where its required and streams support for those
> that
> > > > aren’t
> > > > > > > > >>>>>>>> necessarily.
> > > > > > > > >>>>>>>> Then one has solved the problem.
> > > > > > > > >>>>>>>> I repeat it because I think its important. I am
> really
> > > > happy
> > > > > > > that
> > > > > > > > >>>>>>>> you
> > > > > > > > >>>>>>>> brought that up! because its 100% what I want just
> > with
> > > > the
> > > > > > > > >>>>>>>> differences
> > > > > > > > >>>>>>>> to
> > > > > > > > >>>>>>>> have an option to discard the to small topic later
> > > (after
> > > > > all
> > > > > > > > >>>>>>>> consumers
> > > > > > > > >>>>>>>> adapted). And to have order correct there. I need
> > broker
> > > > > > support
> > > > > > > > >>>>>>>> managing
> > > > > > > > >>>>>>>> the copy process + the produces and fence them
> against
> > > > each
> > > > > > > > other. I
> > > > > > > > >>>>>>>> also
> > > > > > > > >>>>>>>> repeat. the copy process can run for weeks in the
> > worst
> > > > > case.
> > > > > > > > >>>>>>>> Copying
> > > > > > > > >>>>>>>> the
> > > > > > > > >>>>>>>> data is not the longest task migrating consumers
> might
> > > > very
> > > > > > well
> > > > > > > > be.
> > > > > > > > >>>>>>>> Once all consumers switched and copying is really up
> > to
> > > > date
> > > > > > > > (think
> > > > > > > > >>>>>>>> ISR
> > > > > > > > >>>>>>>> like up to date) only then we stop the producer,
> wait
> > > for
> > > > > the
> > > > > > > copy
> > > > > > > > >>>>>>>> to
> > > > > > > > >>>>>>>> finish and use the new topic for producing.
> > > > > > > > >>>>>>>>
> > > > > > > > >>>>>>>> After this the topic is perfect in shape. and no one
> > > needs
> > > > > to
> > > > > > > > worry
> > > > > > > > >>>>>>>> about
> > > > > > > > >>>>>>>> complicated stuff. (old keys hanging around might
> > arrive
> > > > in
> > > > > > some
> > > > > > > > >>>>>>>> other
> > > > > > > > >>>>>>>> topic later.....). can only imagine how many tricky
> > bugs
> > > > > gonna
> > > > > > > > >>>>>>>> arrive
> > > > > > > > >>>>>>>> after
> > > > > > > > >>>>>>>> someone had grown and shrunken is topic 10 times.
> > > > > > > > >>>>>>>>
> > > > > > > > >>>>>>>>
> > > > > > > > >>>>>>>>
> > > > > > > > >>>>>>>>
> > > > > > > > >>>>>>>>
> > > > > > > > >>>>>>>>
> > > > > > > > >>>>>>>> 54. "The other thing I wanted to mention is that I
> > > believe
> > > > > the
> > > > > > > > >>>>>>>> current
> > > > > > > > >>>>>>>>
> > > > > > > > >>>>>>>> suggestion (without copying data over) can be
> > > implemented
> > > > in
> > > > > > > pure
> > > > > > > > >>>>>>>>> userland
> > > > > > > > >>>>>>>>> with a custom partitioner and a small feedbackloop
> > from
> > > > > > > > >>>>>>>>> ProduceResponse
> > > > > > > > >>>>>>>>> =>
> > > > > > > > >>>>>>>>> Partitionier in coorporation with a change
> management
> > > > > > system."
> > > > > > > I
> > > > > > > > am
> > > > > > > > >>>>>>>>> not
> > > > > > > > >>>>>>>>> sure a customized partitioner itself solves the
> > > problem.
> > > > We
> > > > > > > > >>>>>>>>> probably
> > > > > > > > >>>>>>>>> need
> > > > > > > > >>>>>>>>> some broker side support to enforce when the new
> > > > partitions
> > > > > > can
> > > > > > > > be
> > > > > > > > >>>>>>>>> used.
> > > > > > > > >>>>>>>>> We
> > > > > > > > >>>>>>>>> also need some support on the consumer/kstream side
> > to
> > > > > > preserve
> > > > > > > > the
> > > > > > > > >>>>>>>>> per
> > > > > > > > >>>>>>>>> key
> > > > > > > > >>>>>>>>> ordering and potentially migrate the processing
> > state.
> > > > This
> > > > > > is
> > > > > > > > not
> > > > > > > > >>>>>>>>> trivial
> > > > > > > > >>>>>>>>> and I am not sure if it's ideal to fully push to
> the
> > > > > > > application
> > > > > > > > >>>>>>>>> space.
> > > > > > > > >>>>>>>>>
> > > > > > > > >>>>>>>>> Broker support is defenitly the preferred way
> here. I
> > > > have
> > > > > > > > nothing
> > > > > > > > >>>>>>>>>
> > > > > > > > >>>>>>>>> against
> > > > > > > > >>>>>>>> broker support.
> > > > > > > > >>>>>>>> I tried to say that for what I would preffer -
> copying
> > > the
> > > > > > data
> > > > > > > > >>>>>>>> over,
> > > > > > > > >>>>>>>> at
> > > > > > > > >>>>>>>> least for log compacted topics -
> > > > > > > > >>>>>>>> I would require more broker support than the KIP
> > > currently
> > > > > > > offers.
> > > > > > > > >>>>>>>>
> > > > > > > > >>>>>>>>
> > > > > > > > >>>>>>>>
> > > > > > > > >>>>>>>> Jun
> > > > > > > > >>>>>>>>
> > > > > > > > >>>>>>>> On Tue, Mar 6, 2018 at 10:33 PM, Jan Filipiak <
> > > > > > > > >>>>>>>>> Jan.Filipiak@trivago.com
> > > > > > > > >>>>>>>>> wrote:
> > > > > > > > >>>>>>>>>
> > > > > > > > >>>>>>>>> Hi Dong,
> > > > > > > > >>>>>>>>>
> > > > > > > > >>>>>>>>> are you actually reading my emails, or are you just
> > > using
> > > > > the
> > > > > > > > >>>>>>>>> thread I
> > > > > > > > >>>>>>>>>
> > > > > > > > >>>>>>>>>> started for general announcements regarding the
> KIP?
> > > > > > > > >>>>>>>>>>
> > > > > > > > >>>>>>>>>> I tried to argue really hard against linear
> hashing.
> > > > > Growing
> > > > > > > the
> > > > > > > > >>>>>>>>>> topic
> > > > > > > > >>>>>>>>>> by
> > > > > > > > >>>>>>>>>> an integer factor does not require any state
> > > > > redistribution
> > > > > > at
> > > > > > > > >>>>>>>>>> all. I
> > > > > > > > >>>>>>>>>> fail
> > > > > > > > >>>>>>>>>> to see completely where linear hashing helps on
> log
> > > > > > compacted
> > > > > > > > >>>>>>>>>> topics.
> > > > > > > > >>>>>>>>>>
> > > > > > > > >>>>>>>>>> If you are not willing to explain to me what I
> might
> > > be
> > > > > > > > >>>>>>>>>> overlooking:
> > > > > > > > >>>>>>>>>> that
> > > > > > > > >>>>>>>>>> is fine.
> > > > > > > > >>>>>>>>>> But I ask you to not reply to my emails then.
> Please
> > > > > > > understand
> > > > > > > > my
> > > > > > > > >>>>>>>>>> frustration with this.
> > > > > > > > >>>>>>>>>>
> > > > > > > > >>>>>>>>>> Best Jan
> > > > > > > > >>>>>>>>>>
> > > > > > > > >>>>>>>>>>
> > > > > > > > >>>>>>>>>>
> > > > > > > > >>>>>>>>>> On 06.03.2018 19:38, Dong Lin wrote:
> > > > > > > > >>>>>>>>>>
> > > > > > > > >>>>>>>>>> Hi everyone,
> > > > > > > > >>>>>>>>>>
> > > > > > > > >>>>>>>>>> Thanks for all the comments! It appears that
> > everyone
> > > > > > prefers
> > > > > > > > >>>>>>>>>> linear
> > > > > > > > >>>>>>>>>>
> > > > > > > > >>>>>>>>>>> hashing because it reduces the amount of state
> that
> > > > needs
> > > > > > to
> > > > > > > be
> > > > > > > > >>>>>>>>>>> moved
> > > > > > > > >>>>>>>>>>> between consumers (for stream processing). The
> KIP
> > > has
> > > > > been
> > > > > > > > >>>>>>>>>>> updated
> > > > > > > > >>>>>>>>>>> to
> > > > > > > > >>>>>>>>>>> use
> > > > > > > > >>>>>>>>>>> linear hashing.
> > > > > > > > >>>>>>>>>>>
> > > > > > > > >>>>>>>>>>> Regarding the migration endeavor: it seems that
> > > > migrating
> > > > > > > > >>>>>>>>>>> producer
> > > > > > > > >>>>>>>>>>> library
> > > > > > > > >>>>>>>>>>> to use linear hashing should be pretty
> > > straightforward
> > > > > > > without
> > > > > > > > >>>>>>>>>>> much operational endeavor. If we don't upgrade
> > client
> > > > > > library
> > > > > > > > to
> > > > > > > > >>>>>>>>>>> use
> > > > > > > > >>>>>>>>>>> this
> > > > > > > > >>>>>>>>>>> KIP, we can not support in-order delivery after
> > > > partition
> > > > > > is
> > > > > > > > >>>>>>>>>>> changed
> > > > > > > > >>>>>>>>>>> anyway. Suppose we upgrade client library to use
> > this
> > > > > KIP,
> > > > > > if
> > > > > > > > >>>>>>>>>>> partition
> > > > > > > > >>>>>>>>>>> number is not changed, the key -> partition
> mapping
> > > > will
> > > > > be
> > > > > > > > >>>>>>>>>>> exactly
> > > > > > > > >>>>>>>>>>> the
> > > > > > > > >>>>>>>>>>> same as it is now because it is still determined
> > > using
> > > > > > > > >>>>>>>>>>> murmur_hash(key)
> > > > > > > > >>>>>>>>>>> %
> > > > > > > > >>>>>>>>>>> original_partition_num. In other words, this
> change
> > > is
> > > > > > > backward
> > > > > > > > >>>>>>>>>>> compatible.
> > > > > > > > >>>>>>>>>>>
> > > > > > > > >>>>>>>>>>> Regarding the load distribution: if we use linear
> > > > > hashing,
> > > > > > > the
> > > > > > > > >>>>>>>>>>> load
> > > > > > > > >>>>>>>>>>> may
> > > > > > > > >>>>>>>>>>> be
> > > > > > > > >>>>>>>>>>> unevenly distributed because those partitions
> which
> > > are
> > > > > not
> > > > > > > > split
> > > > > > > > >>>>>>>>>>> may
> > > > > > > > >>>>>>>>>>> receive twice as much traffic as other partitions
> > > that
> > > > > are
> > > > > > > > split.
> > > > > > > > >>>>>>>>>>> This
> > > > > > > > >>>>>>>>>>> issue can be mitigated by creating topic with
> > > > partitions
> > > > > > that
> > > > > > > > are
> > > > > > > > >>>>>>>>>>> several
> > > > > > > > >>>>>>>>>>> times the number of consumers. And there will be
> no
> > > > > > imbalance
> > > > > > > > if
> > > > > > > > >>>>>>>>>>> the
> > > > > > > > >>>>>>>>>>> partition number is always doubled. So this
> > imbalance
> > > > > seems
> > > > > > > > >>>>>>>>>>> acceptable.
> > > > > > > > >>>>>>>>>>>
> > > > > > > > >>>>>>>>>>> Regarding storing the partition strategy as
> > per-topic
> > > > > > config:
> > > > > > > > It
> > > > > > > > >>>>>>>>>>> seems
> > > > > > > > >>>>>>>>>>> not
> > > > > > > > >>>>>>>>>>> necessary since we can still use murmur_hash as
> the
> > > > > default
> > > > > > > > hash
> > > > > > > > >>>>>>>>>>> function
> > > > > > > > >>>>>>>>>>> and additionally apply the linear hashing
> algorithm
> > > if
> > > > > the
> > > > > > > > >>>>>>>>>>> partition
> > > > > > > > >>>>>>>>>>> number
> > > > > > > > >>>>>>>>>>> has increased. Not sure if there is any use-case
> > for
> > > > > > producer
> > > > > > > > to
> > > > > > > > >>>>>>>>>>> use a
> > > > > > > > >>>>>>>>>>> different hash function. Jason, can you check if
> > > there
> > > > is
> > > > > > > some
> > > > > > > > >>>>>>>>>>> use-case
> > > > > > > > >>>>>>>>>>> that I missed for using the per-topic partition
> > > > strategy?
> > > > > > > > >>>>>>>>>>>
> > > > > > > > >>>>>>>>>>> Regarding how to reduce latency (due to state
> > > > store/load)
> > > > > > in
> > > > > > > > >>>>>>>>>>> stream
> > > > > > > > >>>>>>>>>>> processing consumer when partition number
> changes:
> > I
> > > > need
> > > > > > to
> > > > > > > > read
> > > > > > > > >>>>>>>>>>> the
> > > > > > > > >>>>>>>>>>> Kafka
> > > > > > > > >>>>>>>>>>> Stream code to understand how Kafka Stream
> > currently
> > > > > > migrate
> > > > > > > > >>>>>>>>>>> state
> > > > > > > > >>>>>>>>>>> between
> > > > > > > > >>>>>>>>>>> consumers when the application is added/removed
> > for a
> > > > > given
> > > > > > > > job.
> > > > > > > > >>>>>>>>>>> I
> > > > > > > > >>>>>>>>>>> will
> > > > > > > > >>>>>>>>>>> reply after I finish reading the documentation
> and
> > > > code.
> > > > > > > > >>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>
> > > > > > > > >>>>>>>>>>> Thanks,
> > > > > > > > >>>>>>>>>>> Dong
> > > > > > > > >>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>
> > > > > > > > >>>>>>>>>>> On Mon, Mar 5, 2018 at 10:43 AM, Jason Gustafson
> <
> > > > > > > > >>>>>>>>>>> jason@confluent.io>
> > > > > > > > >>>>>>>>>>> wrote:
> > > > > > > > >>>>>>>>>>>
> > > > > > > > >>>>>>>>>>> Great discussion. I think I'm wondering whether
> we
> > > can
> > > > > > > continue
> > > > > > > > >>>>>>>>>>> to
> > > > > > > > >>>>>>>>>>> leave
> > > > > > > > >>>>>>>>>>>
> > > > > > > > >>>>>>>>>>> Kafka agnostic to the partitioning strategy. The
> > > > > challenge
> > > > > > is
> > > > > > > > >>>>>>>>>>>
> > > > > > > > >>>>>>>>>>> communicating
> > > > > > > > >>>>>>>>>>>> the partitioning logic from producers to
> consumers
> > > so
> > > > > that
> > > > > > > the
> > > > > > > > >>>>>>>>>>>> dependencies
> > > > > > > > >>>>>>>>>>>> between each epoch can be determined. For the
> sake
> > > of
> > > > > > > > >>>>>>>>>>>> discussion,
> > > > > > > > >>>>>>>>>>>> imagine
> > > > > > > > >>>>>>>>>>>> you did something like the following:
> > > > > > > > >>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>> 1. The name (and perhaps version) of a
> > partitioning
> > > > > > strategy
> > > > > > > > is
> > > > > > > > >>>>>>>>>>>> stored
> > > > > > > > >>>>>>>>>>>> in
> > > > > > > > >>>>>>>>>>>> topic configuration when a topic is created.
> > > > > > > > >>>>>>>>>>>> 2. The producer looks up the partitioning
> strategy
> > > > > before
> > > > > > > > >>>>>>>>>>>> writing
> > > > > > > > >>>>>>>>>>>> to
> > > > > > > > >>>>>>>>>>>> a
> > > > > > > > >>>>>>>>>>>> topic and includes it in the produce request
> (for
> > > > > > fencing).
> > > > > > > If
> > > > > > > > >>>>>>>>>>>> it
> > > > > > > > >>>>>>>>>>>> doesn't
> > > > > > > > >>>>>>>>>>>> have an implementation for the configured
> > strategy,
> > > it
> > > > > > > fails.
> > > > > > > > >>>>>>>>>>>> 3. The consumer also looks up the partitioning
> > > > strategy
> > > > > > and
> > > > > > > > >>>>>>>>>>>> uses it
> > > > > > > > >>>>>>>>>>>> to
> > > > > > > > >>>>>>>>>>>> determine dependencies when reading a new epoch.
> > It
> > > > > could
> > > > > > > > either
> > > > > > > > >>>>>>>>>>>> fail
> > > > > > > > >>>>>>>>>>>> or
> > > > > > > > >>>>>>>>>>>> make the most conservative dependency
> assumptions
> > if
> > > > it
> > > > > > > > doesn't
> > > > > > > > >>>>>>>>>>>> know
> > > > > > > > >>>>>>>>>>>> how
> > > > > > > > >>>>>>>>>>>> to
> > > > > > > > >>>>>>>>>>>> implement the partitioning strategy. For the
> > > consumer,
> > > > > the
> > > > > > > new
> > > > > > > > >>>>>>>>>>>> interface
> > > > > > > > >>>>>>>>>>>> might look something like this:
> > > > > > > > >>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>> // Return the partition dependencies following
> an
> > > > epoch
> > > > > > bump
> > > > > > > > >>>>>>>>>>>> Map<Integer, List<Integer>> dependencies(int
> > > > > > > > >>>>>>>>>>>> numPartitionsBeforeEpochBump,
> > > > > > > > >>>>>>>>>>>> int numPartitionsAfterEpochBump)
> > > > > > > > >>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>> The unordered case then is just a particular
> > > > > > implementation
> > > > > > > > >>>>>>>>>>>> which
> > > > > > > > >>>>>>>>>>>> never
> > > > > > > > >>>>>>>>>>>> has
> > > > > > > > >>>>>>>>>>>> any epoch dependencies. To implement this, we
> > would
> > > > need
> > > > > > > some
> > > > > > > > >>>>>>>>>>>> way
> > > > > > > > >>>>>>>>>>>> for
> > > > > > > > >>>>>>>>>>>> the
> > > > > > > > >>>>>>>>>>>> consumer to find out how many partitions there
> > were
> > > in
> > > > > > each
> > > > > > > > >>>>>>>>>>>> epoch,
> > > > > > > > >>>>>>>>>>>> but
> > > > > > > > >>>>>>>>>>>> maybe that's not too unreasonable.
> > > > > > > > >>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>> Thanks,
> > > > > > > > >>>>>>>>>>>> Jason
> > > > > > > > >>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>> On Mon, Mar 5, 2018 at 4:51 AM, Jan Filipiak <
> > > > > > > > >>>>>>>>>>>> Jan.Filipiak@trivago.com
> > > > > > > > >>>>>>>>>>>> wrote:
> > > > > > > > >>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>> Hi Dong
> > > > > > > > >>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>> thank you very much for your questions.
> > > > > > > > >>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>> regarding the time spend copying data across:
> > > > > > > > >>>>>>>>>>>>> It is correct that copying data from a topic
> with
> > > one
> > > > > > > > partition
> > > > > > > > >>>>>>>>>>>>> mapping
> > > > > > > > >>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>> to
> > > > > > > > >>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>> a topic with a different partition mapping
> takes
> > > way
> > > > > > longer
> > > > > > > > >>>>>>>>>>>>> than
> > > > > > > > >>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>> we
> > > > > > > > >>>>>>>>>>>> can
> > > > > > > > >>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>> stop producers. Tens of minutes is a very
> > optimistic
> > > > > > > estimate
> > > > > > > > >>>>>>>>>>>> here.
> > > > > > > > >>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>> Many
> > > > > > > > >>>>>>>>>>>>> people can not afford copy full steam and
> > therefore
> > > > > will
> > > > > > > have
> > > > > > > > >>>>>>>>>>>>> some
> > > > > > > > >>>>>>>>>>>>> rate
> > > > > > > > >>>>>>>>>>>>> limiting in place, this can bump the timespan
> > into
> > > > the
> > > > > > > day's.
> > > > > > > > >>>>>>>>>>>>> The
> > > > > > > > >>>>>>>>>>>>> good
> > > > > > > > >>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>> part
> > > > > > > > >>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>> is that the vast majority of the data can be
> > copied
> > > > > while
> > > > > > > the
> > > > > > > > >>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>> producers
> > > > > > > > >>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>> are
> > > > > > > > >>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>> still going. One can then, piggyback the
> > consumers
> > > > > ontop
> > > > > > of
> > > > > > > > >>>>>>>>>>>>> this
> > > > > > > > >>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>> timeframe,
> > > > > > > > >>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>> by the method mentioned (provide them an
> mapping
> > > from
> > > > > > their
> > > > > > > > old
> > > > > > > > >>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>> offsets
> > > > > > > > >>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>> to
> > > > > > > > >>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>> new offsets in their repartitioned topics. In
> > that
> > > > way
> > > > > we
> > > > > > > > >>>>>>>>>>>>> separate
> > > > > > > > >>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>> migration of consumers from migration of
> producers
> > > > > > > (decoupling
> > > > > > > > >>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>> these
> > > > > > > > >>>>>>>>>>>>> is
> > > > > > > > >>>>>>>>>>>>> what kafka is strongest at). The time to
> actually
> > > > swap
> > > > > > over
> > > > > > > > the
> > > > > > > > >>>>>>>>>>>>> producers
> > > > > > > > >>>>>>>>>>>>> should be kept minimal by ensuring that when a
> > swap
> > > > > > attempt
> > > > > > > > is
> > > > > > > > >>>>>>>>>>>>> started
> > > > > > > > >>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>> the
> > > > > > > > >>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>> consumer copying over should be very close to
> the
> > > log
> > > > > end
> > > > > > > and
> > > > > > > > >>>>>>>>>>>>> is
> > > > > > > > >>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>> expected
> > > > > > > > >>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>> to finish within the next fetch. The operation
> > > should
> > > > > > have
> > > > > > > a
> > > > > > > > >>>>>>>>>>>>> time-out
> > > > > > > > >>>>>>>>>>>>> and
> > > > > > > > >>>>>>>>>>>>> should be "reattemtable".
> > > > > > > > >>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>> Importance of logcompaction:
> > > > > > > > >>>>>>>>>>>>> If a producer produces key A, to partiton 0,
> its
> > > > > forever
> > > > > > > > gonna
> > > > > > > > >>>>>>>>>>>>> be
> > > > > > > > >>>>>>>>>>>>> there,
> > > > > > > > >>>>>>>>>>>>> unless it gets deleted. The record might sit in
> > > there
> > > > > for
> > > > > > > > >>>>>>>>>>>>> years. A
> > > > > > > > >>>>>>>>>>>>> new
> > > > > > > > >>>>>>>>>>>>> producer started with the new partitions will
> > fail
> > > to
> > > > > > > delete
> > > > > > > > >>>>>>>>>>>>> the
> > > > > > > > >>>>>>>>>>>>> record
> > > > > > > > >>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>> in
> > > > > > > > >>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>> the correct partition. Th record will be there
> > > > forever
> > > > > > and
> > > > > > > > one
> > > > > > > > >>>>>>>>>>>>> can
> > > > > > > > >>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>> not
> > > > > > > > >>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>> reliable bootstrap new consumers. I cannot see
> how
> > > > > linear
> > > > > > > > >>>>>>>>>>>> hashing
> > > > > > > > >>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>> can
> > > > > > > > >>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>> solve
> > > > > > > > >>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>> this.
> > > > > > > > >>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>> Regarding your skipping of userland copying:
> > > > > > > > >>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>> 100%, copying the data across in userland is,
> as
> > > far
> > > > > as i
> > > > > > > can
> > > > > > > > >>>>>>>>>>>>> see,
> > > > > > > > >>>>>>>>>>>>> only
> > > > > > > > >>>>>>>>>>>>> a
> > > > > > > > >>>>>>>>>>>>> usecase for log compacted topics. Even for
> > > > > logcompaction
> > > > > > +
> > > > > > > > >>>>>>>>>>>>> retentions
> > > > > > > > >>>>>>>>>>>>> it
> > > > > > > > >>>>>>>>>>>>> should only be opt-in. Why did I bring it up? I
> > > think
> > > > > log
> > > > > > > > >>>>>>>>>>>>> compaction
> > > > > > > > >>>>>>>>>>>>> is
> > > > > > > > >>>>>>>>>>>>> a
> > > > > > > > >>>>>>>>>>>>> very important feature to really embrace kafka
> > as a
> > > > > "data
> > > > > > > > >>>>>>>>>>>>> plattform".
> > > > > > > > >>>>>>>>>>>>> The
> > > > > > > > >>>>>>>>>>>>> point I also want to make is that copying data
> > this
> > > > way
> > > > > > is
> > > > > > > > >>>>>>>>>>>>> completely
> > > > > > > > >>>>>>>>>>>>> inline with the kafka architecture. it only
> > > consists
> > > > of
> > > > > > > > reading
> > > > > > > > >>>>>>>>>>>>> and
> > > > > > > > >>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>> writing
> > > > > > > > >>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>> to topics.
> > > > > > > > >>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>> I hope it clarifies more why I think we should
> aim
> > > for
> > > > > > more
> > > > > > > > than
> > > > > > > > >>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>> the
> > > > > > > > >>>>>>>>>>>>> current KIP. I fear that once the KIP is done
> not
> > > > much
> > > > > > more
> > > > > > > > >>>>>>>>>>>>> effort
> > > > > > > > >>>>>>>>>>>>> will
> > > > > > > > >>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>> be
> > > > > > > > >>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>> taken.
> > > > > > > > >>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>> On 04.03.2018 02:28, Dong Lin wrote:
> > > > > > > > >>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>> Hey Jan,
> > > > > > > > >>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>> In the current proposal, the consumer will be
> > > blocked
> > > > > on
> > > > > > > > >>>>>>>>>>>>> waiting
> > > > > > > > >>>>>>>>>>>>> for
> > > > > > > > >>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>> other
> > > > > > > > >>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>> consumers of the group to consume up to a
> given
> > > > > offset.
> > > > > > In
> > > > > > > > >>>>>>>>>>>>>> most
> > > > > > > > >>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>> cases,
> > > > > > > > >>>>>>>>>>>>> all
> > > > > > > > >>>>>>>>>>>>> consumers should be close to the LEO of the
> > > > partitions
> > > > > > when
> > > > > > > > the
> > > > > > > > >>>>>>>>>>>>> partition
> > > > > > > > >>>>>>>>>>>>> expansion happens. Thus the time waiting should
> > not
> > > > be
> > > > > > long
> > > > > > > > >>>>>>>>>>>>> e.g.
> > > > > > > > >>>>>>>>>>>>> on
> > > > > > > > >>>>>>>>>>>>> the
> > > > > > > > >>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>> order of seconds. On the other hand, it may
> take
> > a
> > > > long
> > > > > > > time
> > > > > > > > to
> > > > > > > > >>>>>>>>>>>>> wait
> > > > > > > > >>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>> for
> > > > > > > > >>>>>>>>>>>>>> the entire partition to be copied -- the
> amount
> > of
> > > > > time
> > > > > > is
> > > > > > > > >>>>>>>>>>>>>> proportional
> > > > > > > > >>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>> to
> > > > > > > > >>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>> the amount of existing data in the partition,
> > > which
> > > > > can
> > > > > > > take
> > > > > > > > >>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>> tens of
> > > > > > > > >>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>> minutes. So the amount of time that we stop
> > > consumers
> > > > > may
> > > > > > > not
> > > > > > > > >>>>>>>>>>>>> be
> > > > > > > > >>>>>>>>>>>>> on
> > > > > > > > >>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>> the
> > > > > > > > >>>>>>>>>>>>>> same order of magnitude.
> > > > > > > > >>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>> If we can implement this suggestion without
> > > copying
> > > > > data
> > > > > > > > over
> > > > > > > > >>>>>>>>>>>>>> in
> > > > > > > > >>>>>>>>>>>>>> purse
> > > > > > > > >>>>>>>>>>>>>> userland, it will be much more valuable. Do
> you
> > > have
> > > > > > ideas
> > > > > > > > on
> > > > > > > > >>>>>>>>>>>>>> how
> > > > > > > > >>>>>>>>>>>>>> this
> > > > > > > > >>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>> can
> > > > > > > > >>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>> be done?
> > > > > > > > >>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>> Not sure why the current KIP not help people
> who
> > > > depend
> > > > > > on
> > > > > > > > log
> > > > > > > > >>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>> compaction.
> > > > > > > > >>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>> Could you elaborate more on this point?
> > > > > > > > >>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>> Thanks,
> > > > > > > > >>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>> Dong
> > > > > > > > >>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>> On Wed, Feb 28, 2018 at 10:55 PM, Jan
> > > > > > > > >>>>>>>>>>>>>> Filipiak<Jan.Filipiak@trivago.
> > > > > > > > >>>>>>>>>>>>>> com
> > > > > > > > >>>>>>>>>>>>>> wrote:
> > > > > > > > >>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>> Hi Dong,
> > > > > > > > >>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>> I tried to focus on what the steps are one can
> > > > > currently
> > > > > > > > >>>>>>>>>>>>>> perform
> > > > > > > > >>>>>>>>>>>>>> to
> > > > > > > > >>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>> expand
> > > > > > > > >>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>>> or shrink a keyed topic while maintaining a
> top
> > > > notch
> > > > > > > > >>>>>>>>>>>>>>> semantics.
> > > > > > > > >>>>>>>>>>>>>>> I can understand that there might be
> confusion
> > > > about
> > > > > > > > >>>>>>>>>>>>>>> "stopping
> > > > > > > > >>>>>>>>>>>>>>> the
> > > > > > > > >>>>>>>>>>>>>>> consumer". It is exactly the same as proposed
> > in
> > > > the
> > > > > > KIP.
> > > > > > > > >>>>>>>>>>>>>>> there
> > > > > > > > >>>>>>>>>>>>>>> needs
> > > > > > > > >>>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>>> to
> > > > > > > > >>>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>>> be
> > > > > > > > >>>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>> a time the producers agree on the new
> > > partitioning.
> > > > > The
> > > > > > > > extra
> > > > > > > > >>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>> semantics I
> > > > > > > > >>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>>> want to put in there is that we have a
> > > possibility
> > > > to
> > > > > > > wait
> > > > > > > > >>>>>>>>>>>>>>> until
> > > > > > > > >>>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>> all
> > > > > > > > >>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>> the
> > > > > > > > >>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>> existing data
> > > > > > > > >>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>> is copied over into the new partitioning
> scheme.
> > > > When
> > > > > I
> > > > > > > say
> > > > > > > > >>>>>>>>>>>>> stopping
> > > > > > > > >>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>> I
> > > > > > > > >>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>>> think more of having a memory barrier that
> > > ensures
> > > > > the
> > > > > > > > >>>>>>>>>>>>>>> ordering. I
> > > > > > > > >>>>>>>>>>>>>>> am
> > > > > > > > >>>>>>>>>>>>>>> still
> > > > > > > > >>>>>>>>>>>>>>> aming for latencies  on the scale of leader
> > > > > failovers.
> > > > > > > > >>>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>>> Consumers have to explicitly adapt the new
> > > > > partitioning
> > > > > > > > >>>>>>>>>>>>>>> scheme
> > > > > > > > >>>>>>>>>>>>>>> in
> > > > > > > > >>>>>>>>>>>>>>> the
> > > > > > > > >>>>>>>>>>>>>>> above scenario. The reason is that in these
> > cases
> > > > > where
> > > > > > > you
> > > > > > > > >>>>>>>>>>>>>>> are
> > > > > > > > >>>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>>> dependent
> > > > > > > > >>>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>>> on a particular partitioning scheme, you also
> > > have
> > > > > > other
> > > > > > > > >>>>>>>>>>>>>>> topics
> > > > > > > > >>>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>> that
> > > > > > > > >>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>> have
> > > > > > > > >>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>> co-partition enforcements or the kind
> > -frequently.
> > > > > > > Therefore
> > > > > > > > >>>>>>>>>>>>>> all
> > > > > > > > >>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>> your
> > > > > > > > >>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>> other
> > > > > > > > >>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>> input topics might need to grow accordingly.
> > > > > > > > >>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>>> What I was suggesting was to streamline all
> > these
> > > > > > > > operations
> > > > > > > > >>>>>>>>>>>>>>> as
> > > > > > > > >>>>>>>>>>>>>>> best
> > > > > > > > >>>>>>>>>>>>>>> as
> > > > > > > > >>>>>>>>>>>>>>> possible to have "real" partition grow and
> > > > shrinkage
> > > > > > > going
> > > > > > > > >>>>>>>>>>>>>>> on.
> > > > > > > > >>>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>>> Migrating
> > > > > > > > >>>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>>> the producers to a new partitioning scheme
> can
> > be
> > > > > much
> > > > > > > more
> > > > > > > > >>>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>> streamlined
> > > > > > > > >>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>> with proper broker support for this. Migrating
> > > > consumer
> > > > > > is
> > > > > > > a
> > > > > > > > >>>>>>>>>>>>> step
> > > > > > > > >>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>> that
> > > > > > > > >>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>>> might be made completly unnecessary if - for
> > > > example
> > > > > > > > streams
> > > > > > > > >>>>>>>>>>>>>>> -
> > > > > > > > >>>>>>>>>>>>>>> takes
> > > > > > > > >>>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>>> the
> > > > > > > > >>>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>>> gcd as partitioning scheme instead of
> > enforcing 1
> > > > to
> > > > > 1.
> > > > > > > > >>>>>>>>>>>>>>> Connect
> > > > > > > > >>>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>> consumers
> > > > > > > > >>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>> and other consumers should be fine anyways.
> > > > > > > > >>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>> I hope this makes more clear where I was
> aiming
> > > at.
> > > > > The
> > > > > > > rest
> > > > > > > > >>>>>>>>>>>>> needs
> > > > > > > > >>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>> to
> > > > > > > > >>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>> be
> > > > > > > > >>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>>> figured out. The only danger i see is that
> when
> > > we
> > > > > are
> > > > > > > > >>>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>> introducing
> > > > > > > > >>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>> this
> > > > > > > > >>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>> feature as supposed in the KIP, it wont help
> any
> > > > people
> > > > > > > > >>>>>>>>>>>>> depending
> > > > > > > > >>>>>>>>>>>>> on
> > > > > > > > >>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>> log
> > > > > > > > >>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>>> compaction.
> > > > > > > > >>>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>> The other thing I wanted to mention is that I
> > > > believe
> > > > > > the
> > > > > > > > >>>>>>>>>>>>> current
> > > > > > > > >>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>> suggestion (without copying data over) can be
> > > > > implemented
> > > > > > > in
> > > > > > > > >>>>>>>>>>>>>> pure
> > > > > > > > >>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>>> userland
> > > > > > > > >>>>>>>>>>>>>>> with a custom partitioner and a small
> > > feedbackloop
> > > > > from
> > > > > > > > >>>>>>>>>>>>>>> ProduceResponse
> > > > > > > > >>>>>>>>>>>>>>> =>
> > > > > > > > >>>>>>>>>>>>>>> Partitionier in coorporation with a change
> > > > management
> > > > > > > > system.
> > > > > > > > >>>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>>> Best Jan
> > > > > > > > >>>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>>> On 28.02.2018 07:13, Dong Lin wrote:
> > > > > > > > >>>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>>> Hey Jan,
> > > > > > > > >>>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>>> I am not sure if it is acceptable for
> producer
> > to
> > > > be
> > > > > > > > stopped
> > > > > > > > >>>>>>>>>>>>>>> for a
> > > > > > > > >>>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>>> while,
> > > > > > > > >>>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>>>> particularly for online application which
> > > requires
> > > > > low
> > > > > > > > >>>>>>>>>>>>>>>> latency. I
> > > > > > > > >>>>>>>>>>>>>>>> am
> > > > > > > > >>>>>>>>>>>>>>>> also
> > > > > > > > >>>>>>>>>>>>>>>> not sure how consumers can switch to a new
> > > topic.
> > > > > Does
> > > > > > > > user
> > > > > > > > >>>>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>>>> application
> > > > > > > > >>>>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>>>> needs to explicitly specify a different
> topic
> > > for
> > > > > > > > >>>>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>>> producer/consumer
> > > > > > > > >>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>> to
> > > > > > > > >>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>> subscribe to? It will be helpful for discussion
> > if
> > > > you
> > > > > > can
> > > > > > > > >>>>>>>>>>>>> provide
> > > > > > > > >>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>> more
> > > > > > > > >>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>>> detail on the interface change for this
> > solution.
> > > > > > > > >>>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>>> Thanks,
> > > > > > > > >>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>> Dong
> > > > > > > > >>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>>> On Mon, Feb 26, 2018 at 12:48 AM, Jan
> > > > > > > > >>>>>>>>>>>>>>>> Filipiak<Jan.Filipiak@trivago.
> > > > > > > > >>>>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>>>> com
> > > > > > > > >>>>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>>>> wrote:
> > > > > > > > >>>>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>>> Hi,
> > > > > > > > >>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>> just want to throw my though in. In general
> the
> > > > > > > > functionality
> > > > > > > > >>>>>>>>>>>>>> is
> > > > > > > > >>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>>> very
> > > > > > > > >>>>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>>>> usefull, we should though not try to find
> the
> > > > > > > architecture
> > > > > > > > >>>>>>>>>>>>>>>> to
> > > > > > > > >>>>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>>>> hard
> > > > > > > > >>>>>>>>>>>>>>>>> while
> > > > > > > > >>>>>>>>>>>>>>>>> implementing.
> > > > > > > > >>>>>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>>>>> The manual steps would be to
> > > > > > > > >>>>>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>>>>> create a new topic
> > > > > > > > >>>>>>>>>>>>>>>>> the mirrormake from the new old topic to
> the
> > > new
> > > > > > topic
> > > > > > > > >>>>>>>>>>>>>>>>> wait for mirror making to catch up.
> > > > > > > > >>>>>>>>>>>>>>>>> then put the consumers onto the new topic
> > > > > > > > >>>>>>>>>>>>>>>>>            (having mirrormaker spit out a
> > > mapping
> > > > > > from
> > > > > > > > old
> > > > > > > > >>>>>>>>>>>>>>>>> offsets to
> > > > > > > > >>>>>>>>>>>>>>>>> new
> > > > > > > > >>>>>>>>>>>>>>>>> offsets:
> > > > > > > > >>>>>>>>>>>>>>>>>                if topic is increased by
> > factor
> > > X
> > > > > > there
> > > > > > > is
> > > > > > > > >>>>>>>>>>>>>>>>> gonna
> > > > > > > > >>>>>>>>>>>>>>>>> be a
> > > > > > > > >>>>>>>>>>>>>>>>> clean
> > > > > > > > >>>>>>>>>>>>>>>>> mapping from 1 offset in the old topic to X
> > > > offsets
> > > > > > in
> > > > > > > > the
> > > > > > > > >>>>>>>>>>>>>>>>> new
> > > > > > > > >>>>>>>>>>>>>>>>> topic,
> > > > > > > > >>>>>>>>>>>>>>>>>                if there is no factor then
> > there
> > > > is
> > > > > no
> > > > > > > > >>>>>>>>>>>>>>>>> chance to
> > > > > > > > >>>>>>>>>>>>>>>>> generate a
> > > > > > > > >>>>>>>>>>>>>>>>> mapping that can be reasonable used for
> > > > continuing)
> > > > > > > > >>>>>>>>>>>>>>>>>            make consumers stop at
> appropriate
> > > > > points
> > > > > > > and
> > > > > > > > >>>>>>>>>>>>>>>>> continue
> > > > > > > > >>>>>>>>>>>>>>>>> consumption
> > > > > > > > >>>>>>>>>>>>>>>>> with offsets from the mapping.
> > > > > > > > >>>>>>>>>>>>>>>>> have the producers stop for a minimal time.
> > > > > > > > >>>>>>>>>>>>>>>>> wait for mirrormaker to finish
> > > > > > > > >>>>>>>>>>>>>>>>> let producer produce with the new metadata.
> > > > > > > > >>>>>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>>>>> Instead of implementing the approach
> suggest
> > in
> > > > the
> > > > > > KIP
> > > > > > > > >>>>>>>>>>>>>>>>> which
> > > > > > > > >>>>>>>>>>>>>>>>> will
> > > > > > > > >>>>>>>>>>>>>>>>> leave
> > > > > > > > >>>>>>>>>>>>>>>>> log compacted topic completely crumbled and
> > > > > unusable.
> > > > > > > > >>>>>>>>>>>>>>>>> I would much rather try to build
> > infrastructure
> > > > to
> > > > > > > > support
> > > > > > > > >>>>>>>>>>>>>>>>> the
> > > > > > > > >>>>>>>>>>>>>>>>> mentioned
> > > > > > > > >>>>>>>>>>>>>>>>> above operations more smoothly.
> > > > > > > > >>>>>>>>>>>>>>>>> Especially having producers stop and use
> > > another
> > > > > > topic
> > > > > > > is
> > > > > > > > >>>>>>>>>>>>>>>>> difficult
> > > > > > > > >>>>>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>>>>> and
> > > > > > > > >>>>>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>>>>> it would be nice if one can trigger
> "invalid
> > > > > > metadata"
> > > > > > > > >>>>>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>>>> exceptions
> > > > > > > > >>>>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>>>> for
> > > > > > > > >>>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>> them
> > > > > > > > >>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>> and
> > > > > > > > >>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>>> if one could give topics aliases so that
> their
> > > > > produces
> > > > > > > > with
> > > > > > > > >>>>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>>>>> the
> > > > > > > > >>>>>>>>>>>>>>>>> old
> > > > > > > > >>>>>>>>>>>>>>>>> topic
> > > > > > > > >>>>>>>>>>>>>>>>> will arrive in the new topic.
> > > > > > > > >>>>>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>>>>> The downsides are obvious I guess ( having
> > the
> > > > same
> > > > > > > data
> > > > > > > > >>>>>>>>>>>>>>>>> twice
> > > > > > > > >>>>>>>>>>>>>>>>> for
> > > > > > > > >>>>>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>>>>> the
> > > > > > > > >>>>>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>>>>> transition period, but kafka tends to scale
> > > well
> > > > > with
> > > > > > > > >>>>>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>>>> datasize).
> > > > > > > > >>>>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>>>> So
> > > > > > > > >>>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>>> its a
> > > > > > > > >>>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>> nicer fit into the architecture.
> > > > > > > > >>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>>> I further want to argument that the
> > functionality
> > > > by
> > > > > > the
> > > > > > > > KIP
> > > > > > > > >>>>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>>>>> can
> > > > > > > > >>>>>>>>>>>>>>>>> completely be implementing in "userland"
> > with a
> > > > > > custom
> > > > > > > > >>>>>>>>>>>>>>>>> partitioner
> > > > > > > > >>>>>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>>>>> that
> > > > > > > > >>>>>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>>>>> handles the transition as needed. I would
> > > > > appreciate
> > > > > > if
> > > > > > > > >>>>>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>>>> someone
> > > > > > > > >>>>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>>>> could
> > > > > > > > >>>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>> point
> > > > > > > > >>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>> out what a custom partitioner couldn't handle
> in
> > > this
> > > > > > case?
> > > > > > > > >>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>>> With the above approach, shrinking a topic
> > > becomes
> > > > > the
> > > > > > > same
> > > > > > > > >>>>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>>>>> steps.
> > > > > > > > >>>>>>>>>>>>>>>>> Without
> > > > > > > > >>>>>>>>>>>>>>>>> loosing keys in the discontinued
> partitions.
> > > > > > > > >>>>>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>>>>> Would love to hear what everyone thinks.
> > > > > > > > >>>>>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>>>>> Best Jan
> > > > > > > > >>>>>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>>>>> On 11.02.2018 00:35, Dong Lin wrote:
> > > > > > > > >>>>>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>>>>> Hi all,
> > > > > > > > >>>>>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>>>>> I have created KIP-253: Support in-order
> > > message
> > > > > > > delivery
> > > > > > > > >>>>>>>>>>>>>>>>> with
> > > > > > > > >>>>>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>>>>> partition
> > > > > > > > >>>>>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>>>>> expansion. See
> > > > > > > > >>>>>>>>>>>>>>>>>> https://cwiki.apache.org/confl
> > > > > > > > >>>>>>>>>>>>>>>>>> uence/display/KAFKA/KIP-253%
> > > > > > > > >>>>>>>>>>>>>>>>>> 3A+Support+in-order+message+de
> > > > > > > > >>>>>>>>>>>>>>>>>> livery+with+partition+expansio
> > > > > > > > >>>>>>>>>>>>>>>>>> n
> > > > > > > > >>>>>>>>>>>>>>>>>> .
> > > > > > > > >>>>>>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>>>>>> This KIP provides a way to allow messages
> of
> > > the
> > > > > > same
> > > > > > > > key
> > > > > > > > >>>>>>>>>>>>>>>>>> from
> > > > > > > > >>>>>>>>>>>>>>>>>> the
> > > > > > > > >>>>>>>>>>>>>>>>>> same
> > > > > > > > >>>>>>>>>>>>>>>>>> producer to be consumed in the same order
> > they
> > > > are
> > > > > > > > >>>>>>>>>>>>>>>>>> produced
> > > > > > > > >>>>>>>>>>>>>>>>>> even
> > > > > > > > >>>>>>>>>>>>>>>>>> if
> > > > > > > > >>>>>>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>>>>>> we
> > > > > > > > >>>>>>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>>>>>> expand partition of the topic.
> > > > > > > > >>>>>>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>>>>> Thanks,
> > > > > > > > >>>>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>>> Dong
> > > > > > > > >>>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>>>>>>
> > > > > > > > >>>>>>>>>>>>>>>>>>
> > > > > > > > >>>>
> > > > > > > > >>
> > > > > > > > >>
> > > > > > > > >
> > > > > > > >
> > > > > > >
> > > > > >
> > > > >
> > > >
> > >
> >
> >
> >
> > --
> > -- Guozhang
> >
>

Re: [DISCUSS] KIP-253: Support in-order message delivery with partition expansion

Posted by Dong Lin <li...@gmail.com>.
Hey John,

Thanks much for your comments!!

I have yet to go through the emails of John/Jun/Guozhang in detail. But let
me present my idea for how to minimize the delay for state loading for
stream use-case.

For ease of understanding, let's assume that the initial partition number
of input topics and change log topic are both 10. And initial number of
stream processor is also 10. If we only increase initial partition number
of input topics to 15 without changing number of stream processor, the
current KIP already guarantees in-order delivery and no state needs to be
moved between consumers for stream use-case. Next, let's say we want to
increase the number of processor to expand the processing capacity for
stream use-case. This requires us to move state between processors which
will take time. Our goal is to minimize the impact (i.e. delay) for
processing while we increase the number of processors.

Note that stream processor generally includes both consumer and producer.
In addition to consume from the input topic, consumer may also need to
consume from change log topic on startup for recovery. And producer may
produce state to the change log topic.

The solution will include the following steps:

1) Increase partition number of the input topic from 10 to 15. Since the
messages with the same key will still go to the same consume before and
after the partition expansion, this step can be done without having to move
state between processors.

2) Increase partition number of the change log topic from 10 to 15. Note
that this step can also be done without impacting existing workflow. After
we increase partition number of the change log topic, key space may split
and some key will be produced to the newly-added partition. But the same
key will still go to the same processor (i.e. consumer) before and after
the partition. Thus this step can also be done without having to move state
between processors.

3) Now, let's add 5 new consumers whose groupId is different from the
existing processor's groupId. Thus these new consumers will not impact
existing workflow. Each of these new consumers should consume two
partitions from the earliest offset, where these two partitions are the
same partitions that will be consumed if the consumers have the same
groupId as the existing processor's groupId. For example, the first of the
five consumers will consume partition 0 and partition 10. The purpose of
these consumers is to rebuild the state (e.g. RocksDB) for the processors
in advance. Also note that, by design of the current KIP, each consume will
consume the existing partition of the change log topic up to the offset
before the partition expansion. Then they will only need to consume the
state of the new partition of the change log topic.

4) After consumers have caught up in step 3), we should stop these
consumers and add 5 new processors to the stream processing job. These 5
new processors should run in the same location as the previous 5 consumers
to re-use the state (e.g. RocksDB). And these processors' consumers should
consume partitions of the change log topic from the committed offset the
previous 5 consumers so that no state is missed.

One important trick to note here is that, the mapping from partition to
consumer should also use linear hashing. And we need to remember the
initial number of processors in the job, 10 in this example, and use this
number in the linear hashing algorithm. This is pretty much the same as how
we use linear hashing to map key to partition. In this case, we get an
identity map from partition -> processor, for both input topic and the
change log topic. For example, processor 12 will consume partition 12 of
the input topic and produce state to the partition 12 of the change log
topic.

There are a few important properties of this solution to note:

- We can increase the number of partitions for input topic and the change
log topic in any order asynchronously.
- The expansion of the processors in a given job in step 4) only requires
the step 3) for the same job. It does not require coordination across
different jobs for step 3) and 4). Thus different jobs can independently
expand there capacity without waiting for each other.
- The logic for 1) and 2) is already supported in the current KIP. The
logic for 3) and 4) appears to be independent of the core Kafka logic and
can be implemented separately outside core Kafka. Thus the current KIP is
probably sufficient after we agree on the efficiency and the correctness of
the solution. We can have a separate KIP for Kafka Stream to support 3) and
4).


Cheers,
Dong


On Mon, Apr 2, 2018 at 3:25 PM, Guozhang Wang <wa...@gmail.com> wrote:

> Hey guys, just sharing my two cents here (I promise it will be shorter than
> John's article :).
>
> 0. Just to quickly recap, the main discussion point now is how to support
> "key partitioning preservation" (John's #4 in topic characteristics above)
> beyond the "single-key ordering preservation" that KIP-253 was originally
> proposed to maintain (John's #6 above).
>
> 1. From the streams project, we are actively working on improving the
> elastic scalability of the library. One of the key features is to decouple
> the input topics from the parallelism model of Streams: i.e. not enforcing
> the topic to be partitioned by the key, not enforcing joining topics to be
> co-partitioned, not relying the number of parallel tasks on the input topic
> partitions. This can be achieved by re-shuffling on the input topics to
> make sure key-partitioning / co-partitioning on the internal topics. Note
> the re-shuffling task is purely stateless and hence does not require "key
> partitioning preservation". Operational-wise it is similar to the "creating
> a new topic with new number of partitions, pipe the data to the new topic
> and cut over consumers from old topics" idea, just that users can
> optionally let Streams to handle such rather than doing it manually
> themselves. There are a few more details on that regard but I will skip
> since they are not directly related to this discussion.
>
> 2. Assuming that 1) above is done, then the only topics involved in the
> scaling events are all input topics. For these topics the only producers /
> consumers of these topics are controlled by Streams clients themselves, and
> hence achieving "key partitioning preservation" is simpler than non-Streams
> scenarios: consumers know the partitioning scheme that producers are using,
> so that for their stateful operations it is doable to split the local state
> stores accordingly or execute backfilling on its own. Of course, if we
> decide to do server-side backfilling, it can still help Streams to directly
> rely on that functionality.
>
> 3. As John mentioned, another way inside Streams is to do over-partitioning
> on all internal topics; then with 1) Streams would not rely on KIP-253 at
> all. But personally I'd like to avoid it if possible to reduce Kafka side
> footprint: say we overpartition each input topic up to 1k, with a
> reasonable sized stateful topology it can still contribute to tens of
> thousands of topics to the topic partition capacity of a single cluster.
>
> 4. Summing up 1/2/3, I think we should focus more on non-Streams users
> writing their stateful computations with local states, and think whether /
> how we could enable "key partitioning preservation" for them easily, than
> to think heavily for Streams library. People may have different opinion on
> how common of a usage pattern it is (I think Jun might be suggesting that
> for DIY apps people may more likely use remote states so that it is not a
> problem for them). My opinion is that for non-Streams users such usage
> pattern could still be large (think: if you are piping data from Kafka to
> an external data storage which has single-writer requirements for each
> single shard, even though it is not a stateful computational application it
> may still require "key partitioning preservation"), so I prefer to have
> backfilling in our KIP than only exposing the API for expansion and
> requires consumers to have pre-knowledge of the producer's partitioning
> scheme.
>
>
>
> Guozhang
>
>
>
> On Thu, Mar 29, 2018 at 2:33 PM, John Roesler <jo...@confluent.io> wrote:
>
> > Hey Dong,
> >
> > Congrats on becoming a committer!!!
> >
> > Since I just sent a novel-length email, I'll try and keep this one brief
> ;)
> >
> > Regarding producer coordination, I'll grant that in that case, producers
> > may coordinate among themselves to produce into the same topic or to
> > produce co-partitioned topics. Nothing in KStreams or the Kafka ecosystem
> > in general requires such coordination for correctness or in fact for any
> > optional features, though, so I would not say that we require producer
> > coordination of partition logic. If producers currently coordinate, it's
> > completely optional and their own choice.
> >
> > Regarding the portability of partition algorithms, my observation is that
> > systems requiring independent implementations of the same algorithm with
> > 100% correctness are a large source of risk and also a burden on those
> who
> > have to maintain them. If people could flawlessly implement algorithms in
> > actual software, the world would be a wonderful place indeed! For a
> system
> > as important and widespread as Kafka, I would recommend restricting
> > limiting such requirements as aggressively as possible.
> >
> > I'd agree that we can always revisit decisions like allowing arbitrary
> > partition functions, but of course, we shouldn't do that in a vacuum.
> That
> > feels like the kind of thing we'd need to proactively seek guidance from
> > the users list about. I do think that the general approach of saying that
> > "if you use a custom partitioner, you cannot do partition expansion" is
> > very reasonable (but I don't think we need to go that far with the
> current
> > proposal). It's similar to my statement in my email to Jun that in
> > principle KStreams doesn't *need* backfill, we only need it if we want to
> > employ partition expansion.
> >
> > I reckon that the main motivation for backfill is to support KStreams use
> > cases and also any other use cases involving stateful consumers.
> >
> > Thanks for your response, and congrats again!
> > -John
> >
> >
> > On Wed, Mar 28, 2018 at 1:34 AM, Dong Lin <li...@gmail.com> wrote:
> >
> > > Hey John,
> > >
> > > Great! Thanks for all the comment. It seems that we agree that the
> > current
> > > KIP is in good shape for core Kafka. IMO, what we have been discussing
> in
> > > the recent email exchanges is mostly about the second step, i.e. how to
> > > address problem for the stream use-case (or stateful processing in
> > > general).
> > >
> > > I will comment inline.
> > >
> > >
> > >
> > >
> > > On Tue, Mar 27, 2018 at 4:38 PM, John Roesler <jo...@confluent.io>
> wrote:
> > >
> > > > Thanks for the response, Dong.
> > > >
> > > > Here are my answers to your questions:
> > > >
> > > > - "Asking producers and consumers, or even two different producers,
> to
> > > > > share code like the partition function is a pretty huge ask. What
> if
> > > they
> > > > > are using different languages?". It seems that today we already
> > require
> > > > > different producer's to use the same hash function -- otherwise
> > > messages
> > > > > with the same key will go to different partitions of the same topic
> > > which
> > > > > may cause problem for downstream consumption. So not sure if it
> adds
> > > any
> > > > > more constraint by assuming consumers know the hash function of
> > > producer.
> > > > > Could you explain more why user would want to use a cusmtom
> partition
> > > > > function? Maybe we can check if this is something that can be
> > supported
> > > > in
> > > > > the default Kafka hash function. Also, can you explain more why it
> is
> > > > > difficuilt to implement the same hash function in different
> > languages?
> > > >
> > > >
> > > > Sorry, I meant two different producers as in producers to two
> different
> > > > topics. This was in response to the suggestion that we already
> require
> > > > coordination among producers to different topics in order to achieve
> > > > co-partitioning. I was saying that we do not (and should not).
> > >
> > >
> > > It is probably common for producers of different team to produce
> message
> > to
> > > the same topic. In order to ensure that messages with the same key go
> to
> > > same partition, we need producers of different team to share the same
> > > partition algorithm, which by definition requires coordination among
> > > producers of different teams in an organization. Even for producers of
> > > different topics, it may be common to require producers to use the same
> > > partition algorithm in order to join two topics for stream processing.
> > Does
> > > this make it reasonable to say we already require coordination across
> > > producers?
> > >
> > >
> > > > By design, consumers are currently ignorant of the partitioning
> scheme.
> > > It
> > > > suffices to trust that the producer has partitioned the topic by key,
> > if
> > > > they claim to have done so. If you don't trust that, or even if you
> > just
> > > > need some other partitioning scheme, then you must re-partition it
> > > > yourself. Nothing we're discussing can or should change that. The
> value
> > > of
> > > > backfill is that it preserves the ability for consumers to avoid
> > > > re-partitioning before consuming, in the case where they don't need
> to
> > > > today.
> > >
> > >
> > > > Regarding shared "hash functions", note that it's a bit inaccurate to
> > > talk
> > > > about the "hash function" of the producer. Properly speaking, the
> > > producer
> > > > has only a "partition function". We do not know that it is a hash.
> The
> > > > producer can use any method at their disposal to assign a partition
> to
> > a
> > > > record. The partition function obviously may we written in any
> > > programming
> > > > language, so in general it's not something that can be shared around
> > > > without a formal spec or the ability to execute arbitrary executables
> > in
> > > > arbitrary runtime environments.
> > > >
> > >
> > > Yeah it is probably better to say partition algorithm. I guess it
> should
> > > not be difficult to implement same partition algorithms in different
> > > languages, right? Yes we would need a formal specification of the
> default
> > > partition algorithm in the producer. I think that can be documented as
> > part
> > > of the producer interface.
> > >
> > >
> > > >
> > > > Why would a producer want a custom partition function? I don't
> know...
> > > why
> > > > did we design the interface so that our users can provide one? In
> > > general,
> > > > such systems provide custom partitioners because some data sets may
> be
> > > > unbalanced under the default or because they can provide some
> > interesting
> > > > functionality built on top of the partitioning scheme, etc. Having
> > > provided
> > > > this ability, I don't know why we would remove it.
> > > >
> > >
> > > Yeah it is reasonable to assume that there was reason to support custom
> > > partition function in producer. On the other hand it may also be
> > reasonable
> > > to revisit this interface and discuss whether we actually need to
> support
> > > custom partition function. If we don't have a good reason, we can
> choose
> > > not to support custom partition function in this KIP in a backward
> > > compatible manner, i.e. user can still use custom partition function
> but
> > > they would not get the benefit of in-order delivery when there is
> > partition
> > > expansion. What do you think?
> > >
> > >
> > > >
> > > > - Besides the assumption that consumer needs to share the hash
> function
> > > of
> > > > > producer, is there other organization overhead of the proposal in
> the
> > > > > current KIP?
> > > > >
> > > >
> > > > It wasn't clear to me that KIP-253 currently required the producer
> and
> > > > consumer to share the partition function, or in fact that it had a
> hard
> > > > requirement to abandon the general partition function and use a
> linear
> > > hash
> > > > function instead.
> > >
> > >
> > > > In my reading, there is a requirement to track the metadata about
> what
> > > > partitions split into what other partitions during an expansion
> > > operation.
> > > > If the partition function is linear, this is easy. If not, you can
> > always
> > > > just record that all old partitions split into all new partitions.
> This
> > > has
> > > > the effect of forcing all consumers to wait until the old epoch is
> > > > completely consumed before starting on the new epoch. But this may
> be a
> > > > reasonable tradeoff, and it doesn't otherwise alter your design.
> > > >
> > > > You only mention the consumer needing to know that the partition
> > function
> > > > is linear, not what the actual function is, so I don't think your
> > design
> > > > actually calls for sharing the function. Plus, really all the
> consumer
> > > > needs is the metadata about what old-epoch partitions to wait for
> > before
> > > > consuming a new-epoch partition. This information is directly
> captured
> > in
> > > > metadata, so I don't think it actually even cares whether the
> partition
> > > > function is linear or not.
> > > >
> > >
> > > You are right that the current KIP does not mention it. My comment
> > related
> > > to the partition function coordination was related to support the
> > > stream-use case which we have been discussing so far.
> > >
> > >
> > > > So, no, I really think KIP-253 is in good shape. I was really more
> > > talking
> > > > about the part of this thread that's outside of KIP-253's scope,
> > namely,
> > > > creating the possibility of backfilling partitions after expansion.
> > > >
> > >
> > > Great! Can you also confirm that the main motivation for backfilling
> > > partitions after expansion is to support the stream use-case?
> > >
> > >
> > > > - Currently producer can forget about the message that has been
> > > > > acknowledged by the broker. Thus the producer probably does not
> know
> > > most
> > > > > of the exiting messages in topic, including those messages produced
> > by
> > > > > other producers. We can have the owner of the producer to
> > > split+backfill.
> > > > > In my opion it will be a new program that wraps around the existing
> > > > > producer and consumer classes.
> > > > >
> > > >
> > > > This sounds fine by me!
> > > >
> > > > Really, I was just emphasizing that the part of the organization that
> > > > produces a topic shouldn't have to export their partition function to
> > the
> > > > part(s) of the organization (or other organizations) that consume the
> > > > topic. Whether the backfill operation goes into the Producer
> interface
> > is
> > > > secondary, I think.
> > > >
> > > > - Regarding point 5. The argument is in favor of the split+backfill
> but
> > > for
> > > > > changelog topic. And it intends to address the problem for stream
> > > > use-case
> > > > > in general. In this KIP we will provide interface (i.e.
> > > > > PartitionKeyRebalanceListener in the KIP) to be used by sream
> > use-case
> > > > and
> > > > > the goal is that user can flush/re-consume the state as part of the
> > > > > interface implementation regardless of whether there is change log
> > > topic.
> > > > >
> > > > > Maybe you are suggesting that the main reason to do split+backfill
> of
> > > > input
> > > > > topic is to support log compacted topics? You mentioned in Point 1
> > that
> > > > log
> > > > > compacted topics is out of the scope of this KIP. Maybe I could
> > > > understand
> > > > > your position better. Regarding Jan's proposal to split partitions
> > with
> > > > > backfill, do you think this should replace the proposal in the
> > existing
> > > > > KIP, or do you think this is something that we should do in
> addition
> > to
> > > > the
> > > > > existing KIP?
> > > > >
> > > >
> > > > I think that interface is a good/necessary component of KIP-253.
> > > >
> > > > I personally (FWIW) feel that KIP-253 is appropriately scoped, but I
> do
> > > > think its utility will be limited unless there is a later KIP
> offering
> > > > backfill. But, maybe unlike Jan, I think it makes sense to try and
> > tackle
> > > > the ordering problem independently of backfill, so I'm in support of
> > the
> > > > current KIP.
> > > >
> > > > - Regarding point 6. I guess we can agree that it is better not to
> have
> > > the
> > > > > performance overhread of copying the input data. Before we discuss
> > more
> > > > on
> > > > > whether the performance overhead is acceptable or not, I am trying
> to
> > > > > figure out what is the benefit of introducing this overhread. You
> > > > mentioned
> > > > > that the benefit is the loose organizational coupling. By
> > > "organizational
> > > > > coupling", are you referring to the requirement that consumer needs
> > to
> > > > know
> > > > > the hash function of producer? If so, maybe we can discuss the
> > use-case
> > > > of
> > > > > custom partiton function and see whether we can find a way to
> support
> > > > such
> > > > > use-case without having to copy the input data.
> > > > >
> > > >
> > > > I'm not too sure about what an "input" is in this sense, since we are
> > > just
> > > > talking about topics. Actually the point I was making there is that
> > > AKAICT
> > > > the performance overhead of a backfill is less than any other option,
> > > > assuming you split partitions rarely.
> > > >
> > >
> > > By "input" I was referring to source Kafka topic of a stream processing
> > > job.
> > >
> > >
> > > > Separately, yes, "organizational coupling" increases if producers and
> > > > consumers have to share code, such as the partition function. This
> > would
> > > > not be the case if producers could only pick from a menu of a few
> > > > well-known partition functions, but I think this is a poor tradeoff.
> > > >
> > >
> > > Maybe we can revisit the custom partition function and see whether we
> > > actually need it? Otherwise, I am concerned that every user will pay
> the
> > > overhead of data movement to support something that was not really
> needed
> > > for most users.
> > >
> > >
> > > >
> > > > To me, this is two strong arguments in favor of backfill being less
> > > > expensive than no backfill, but again, I think that particular debate
> > > comes
> > > > after KIP-253, so I don't want to create the impression of opposition
> > to
> > > > your proposal.
> > > >
> > > >
> > > > Finally, to respond to a new email I just noticed:
> > > >
> > > > > BTW, here is my understanding of the scope of this KIP. We want to
> > > allow
> > > > > consumers to always consume messages with the same key from the
> same
> > > > > producer in the order they are produced. And we need to provide a
> way
> > > for
> > > > > stream use-case to be able to flush/load state when messages with
> the
> > > > same
> > > > > key are migrated between consumers. In addition to ensuring that
> this
> > > > goal
> > > > > is correctly supported, we should do our best to keep the
> performance
> > > and
> > > > > organization overhead of this KIP as low as possible.
> > > > >
> > > >
> > > > I think we're on the same page there! In fact, I would generalize a
> > > little
> > > > more and say that the mechanism you've designed provides *all
> > consumers*
> > > > the ability "to flush/load state when messages with the same key are
> > > > migrated between consumers", not just Streams.
> > > >
> > >
> > > Thanks for all the comment!
> > >
> > >
> > > >
> > > > Thanks for the discussion,
> > > > -John
> > > >
> > > >
> > > >
> > > > On Tue, Mar 27, 2018 at 3:14 PM, Dong Lin <li...@gmail.com>
> wrote:
> > > >
> > > > > Hey John,
> > > > >
> > > > > Thanks much for the detailed comments. Here are my thoughts:
> > > > >
> > > > > - The need to delete messages from log compacted topics is mainly
> for
> > > > > performance (e.g. storage space) optimization than for correctness
> > for
> > > > this
> > > > > KIP. I agree that we probably don't need to focus on this in our
> > > > discussion
> > > > > since it is mostly for performance optimization.
> > > > >
> > > > > - "Asking producers and consumers, or even two different producers,
> > to
> > > > > share code like the partition function is a pretty huge ask. What
> if
> > > they
> > > > > are using different languages?". It seems that today we already
> > require
> > > > > different producer's to use the same hash function -- otherwise
> > > messages
> > > > > with the same key will go to different partitions of the same topic
> > > which
> > > > > may cause problem for downstream consumption. So not sure if it
> adds
> > > any
> > > > > more constraint by assuming consumers know the hash function of
> > > producer.
> > > > > Could you explain more why user would want to use a cusmtom
> partition
> > > > > function? Maybe we can check if this is something that can be
> > supported
> > > > in
> > > > > the default Kafka hash function. Also, can you explain more why it
> is
> > > > > difficuilt to implement the same hash function in different
> > languages?
> > > > >
> > > > > - Besides the assumption that consumer needs to share the hash
> > function
> > > > of
> > > > > producer, is there other organization overhead of the proposal in
> the
> > > > > current KIP?
> > > > >
> > > > > - Currently producer can forget about the message that has been
> > > > > acknowledged by the broker. Thus the producer probably does not
> know
> > > most
> > > > > of the exiting messages in topic, including those messages produced
> > by
> > > > > other producers. We can have the owner of the producer to
> > > split+backfill.
> > > > > In my opion it will be a new program that wraps around the existing
> > > > > producer and consumer classes.
> > > > >
> > > > > - Regarding point 5. The argument is in favor of the split+backfill
> > but
> > > > for
> > > > > changelog topic. And it intends to address the problem for stream
> > > > use-case
> > > > > in general. In this KIP we will provide interface (i.e.
> > > > > PartitionKeyRebalanceListener in the KIP) to be used by sream
> > use-case
> > > > and
> > > > > the goal is that user can flush/re-consume the state as part of the
> > > > > interface implementation regardless of whether there is change log
> > > topic.
> > > > >
> > > > > Maybe you are suggesting that the main reason to do split+backfill
> of
> > > > input
> > > > > topic is to support log compacted topics? You mentioned in Point 1
> > that
> > > > log
> > > > > compacted topics is out of the scope of this KIP. Maybe I could
> > > > understand
> > > > > your position better. Regarding Jan's proposal to split partitions
> > with
> > > > > backfill, do you think this should replace the proposal in the
> > existing
> > > > > KIP, or do you think this is something that we should do in
> addition
> > to
> > > > the
> > > > > existing KIP?
> > > > >
> > > > > - Regarding point 6. I guess we can agree that it is better not to
> > have
> > > > the
> > > > > performance overhread of copying the input data. Before we discuss
> > more
> > > > on
> > > > > whether the performance overhead is acceptable or not, I am trying
> to
> > > > > figure out what is the benefit of introducing this overhread. You
> > > > mentioned
> > > > > that the benefit is the loose organizational coupling. By
> > > "organizational
> > > > > coupling", are you referring to the requirement that consumer needs
> > to
> > > > know
> > > > > the hash function of producer? If so, maybe we can discuss the
> > use-case
> > > > of
> > > > > custom partiton function and see whether we can find a way to
> support
> > > > such
> > > > > use-case without having to copy the input data.
> > > > >
> > > > > Thanks,
> > > > > Dong
> > > > >
> > > > >
> > > > > On Tue, Mar 27, 2018 at 11:34 AM, John Roesler <jo...@confluent.io>
> > > > wrote:
> > > > >
> > > > > > Hey Dong and Jun,
> > > > > >
> > > > > > Thanks for the thoughtful responses. If you don't mind, I'll mix
> my
> > > > > replies
> > > > > > together to try for a coherent response. I'm not too familiar
> with
> > > > > > mailing-list etiquette, though.
> > > > > >
> > > > > > I'm going to keep numbering my points because it makes it easy
> for
> > > you
> > > > > all
> > > > > > to respond.
> > > > > >
> > > > > > Point 1:
> > > > > > As I read it, KIP-253 is *just* about properly fencing the
> > producers
> > > > and
> > > > > > consumers so that you preserve the correct ordering of records
> > during
> > > > > > partition expansion. This is clearly necessary regardless of
> > anything
> > > > > else
> > > > > > we discuss. I think this whole discussion about backfill,
> > consumers,
> > > > > > streams, etc., is beyond the scope of KIP-253. But it would be
> > > > cumbersome
> > > > > > to start a new thread at this point.
> > > > > >
> > > > > > I had missed KIP-253's Proposed Change #9 among all the
> details...
> > I
> > > > > think
> > > > > > this is a nice addition to the proposal. One thought is that it's
> > > > > actually
> > > > > > irrelevant whether the hash function is linear. This is simply an
> > > > > algorithm
> > > > > > for moving a key from one partition to another, so the type of
> hash
> > > > > > function need not be a precondition. In fact, it also doesn't
> > matter
> > > > > > whether the topic is compacted or not, the algorithm works
> > > regardless.
> > > > > >
> > > > > > I think this is a good algorithm to keep in mind, as it might
> > solve a
> > > > > > variety of problems, but it does have a downside: that the
> producer
> > > > won't
> > > > > > know whether or not K1 was actually in P1, it just knows that K1
> > was
> > > in
> > > > > > P1's keyspace before the new epoch. Therefore, it will have to
> > > > > > pessimistically send (K1,null) to P1 just in case. But the next
> > time
> > > K1
> > > > > > comes along, the producer *also* won't remember that it already
> > > > retracted
> > > > > > K1 from P1, so it will have to send (K1,null) *again*. By
> > extension,
> > > > > every
> > > > > > time the producer sends to P2, it will also have to send a
> > tombstone
> > > to
> > > > > P1,
> > > > > > which is a pretty big burden. To make the situation worse, if
> there
> > > is
> > > > a
> > > > > > second split, say P2 becomes P2 and P3, then any key Kx belonging
> > to
> > > P3
> > > > > > will also have to be retracted from P2 *and* P1, since the
> producer
> > > > can't
> > > > > > know whether Kx had been last written to P2 or P1. Over a long
> > period
> > > > of
> > > > > > time, this clearly becomes a issue, as the producer must send an
> > > > > arbitrary
> > > > > > number of retractions along with every update.
> > > > > >
> > > > > > In contrast, the proposed backfill operation has an end, and
> after
> > it
> > > > > ends,
> > > > > > everyone can afford to forget that there ever was a different
> > > partition
> > > > > > layout.
> > > > > >
> > > > > > Really, though, figuring out how to split compacted topics is
> > beyond
> > > > the
> > > > > > scope of KIP-253, so I'm not sure #9 really even needs to be in
> > this
> > > > > KIP...
> > > > > > We do need in-order delivery during partition expansion. It would
> > be
> > > > fine
> > > > > > by me to say that you *cannot* expand partitions of a
> log-compacted
> > > > topic
> > > > > > and call it a day. I think it would be better to tackle that in
> > > another
> > > > > > KIP.
> > > > > >
> > > > > >
> > > > > > Point 2:
> > > > > > Regarding whether the consumer re-shuffles its inputs, this is
> > always
> > > > on
> > > > > > the table; any consumer who wants to re-shuffle its input is free
> > to
> > > do
> > > > > so.
> > > > > > But this is currently not required. It's just that the current
> > > > high-level
> > > > > > story with Kafka encourages the use of partitions as a unit of
> > > > > concurrency.
> > > > > > As long as consumers are single-threaded, they can happily
> consume
> > a
> > > > > single
> > > > > > partition without concurrency control of any kind. This is a key
> > > aspect
> > > > > to
> > > > > > this system that lets folks design high-throughput systems on top
> > of
> > > it
> > > > > > surprisingly easily. If all consumers were instead
> > > encouraged/required
> > > > to
> > > > > > implement a repartition of their own, then the consumer becomes
> > > > > > significantly more complex, requiring either the consumer to
> first
> > > > > produce
> > > > > > to its own intermediate repartition topic or to ensure that
> > consumer
> > > > > > threads have a reliable, high-bandwith channel of communication
> > with
> > > > > every
> > > > > > other consumer thread.
> > > > > >
> > > > > > Either of those tradeoffs may be reasonable for a particular user
> > of
> > > > > Kafka,
> > > > > > but I don't know if we're in a position to say that they are
> > > reasonable
> > > > > for
> > > > > > *every* user of Kafka.
> > > > > >
> > > > > >
> > > > > > Point 3:
> > > > > > Regarding Jun's point about this use case, "(3) stateful and
> > > > maintaining
> > > > > > the
> > > > > > states in a local store", I agree that they may use a framework
> > > *like*
> > > > > > Kafka Streams, but that is not the same as using Kafka Streams.
> > This
> > > is
> > > > > why
> > > > > > I think it's better to solve it in Core: because it is then
> solved
> > > for
> > > > > > KStreams and also for everything else that facilitates local
> state
> > > > > > maintenance. To me, Streams is a member of the category of
> "stream
> > > > > > processing frameworks", which is itself a subcategory of "things
> > > > > requiring
> > > > > > local state maintenence". I'm not sure if it makes sense to
> assert
> > > that
> > > > > > Streams is a sufficient and practical replacement for everything
> in
> > > > > "things
> > > > > > requiring local state maintenence".
> > > > > >
> > > > > > But, yes, I do agree that per-key ordering is an absolute
> > > requirement,
> > > > > > therefore I think that KIP-253 itself is a necessary step.
> > Regarding
> > > > the
> > > > > > coupling of the state store partitioning to the topic
> partitioning,
> > > > yes,
> > > > > > this is an issue we are discussing solutions to right now. We may
> > go
> > > > > ahead
> > > > > > and introduce an overpartition layer on our inputs to solve it,
> but
> > > > then
> > > > > > again, if we get the ability to split partitions with backfill,
> we
> > > may
> > > > > not
> > > > > > need to!
> > > > > >
> > > > > >
> > > > > > Point 4:
> > > > > > On this:
> > > > > >
> > > > > > > Regarding thought 2: If we don't care about the stream
> use-case,
> > > then
> > > > > the
> > > > > > > current KIP probably has already addressed problem without
> > > requiring
> > > > > > > consumer to know the partition function. If we care about the
> > > stream
> > > > > > > use-case, we already need coordination across producers of
> > > different
> > > > > > > topics, i.e. the same partition function needs to be used by
> > > > producers
> > > > > of
> > > > > > > topics A and B in order to join topics A and B. Thus, it might
> be
> > > > > > > reasonable to extend coordination a bit and say we need
> > > coordination
> > > > > > across
> > > > > > > clients (i.e. producer and consumer), such that consumer knows
> > the
> > > > > > > partition function used by producer. If we do so, then we can
> let
> > > > > > consumer
> > > > > > > re-copy data for the change log topic using the same partition
> > > > function
> > > > > > as
> > > > > > > producer. This approach has lower overhead as compared to
> having
> > > > > producer
> > > > > > > re-copy data of the input topic.
> > > > > > > Also, producer currently does not need to know the data already
> > > > > produced
> > > > > > to
> > > > > > > the topic. If we let producer split/merge partition, it would
> > > require
> > > > > > > producer to consume the existing data, which intuitively is the
> > > task
> > > > of
> > > > > > > consumer.
> > > > > >
> > > > > >
> > > > > > I think we do care about use cases *like* Streams, I just don't
> > think
> > > > we
> > > > > > should rely on Streams to implement a feature of Core like
> > partition
> > > > > > expansion.
> > > > > >
> > > > > > Note, though, that we (Streams) do not require coordination
> across
> > > > > > producers. If two topics are certified to be co-partitioned, then
> > > > Streams
> > > > > > apps can make use of that knowledge to optimize their topology
> > > > (skipping
> > > > > a
> > > > > > repartition). But if they don't know whether they are
> > co-partitioned,
> > > > > then
> > > > > > they'd better go ahead and repartition within the topology. This
> is
> > > the
> > > > > > current state.
> > > > > >
> > > > > > A huge selling point of Kafka is enabling different parts of
> > loosely
> > > > > > coupled organizations to produce and consume data independently.
> > Some
> > > > > > coordination between producers and consumers is necessary, like
> > > > > > coordinating on the names of topics and their schemas. But
> Kafka's
> > > > value
> > > > > > proposition w.r.t. ESBs, etc. is inversely proportional to the
> > amount
> > > > of
> > > > > > coordination required. I think it behooves us to be extremely
> > > skeptical
> > > > > > about introducing any coordination beyond correctness protocols.
> > > > > >
> > > > > > Asking producers and consumers, or even two different producers,
> to
> > > > share
> > > > > > code like the partition function is a pretty huge ask. What if
> they
> > > are
> > > > > > using different languages?
> > > > > >
> > > > > > Comparing organizational overhead vs computational overhead,
> there
> > > are
> > > > > > maybe two orders of magnitude difference between them. In other
> > > words,
> > > > I
> > > > > > would happily take on the (linear) overhead of having the
> producer
> > > > > re-copy
> > > > > > the data once during a re-partition in order to save the
> > > organizational
> > > > > > overhead of tying all the producers and consumers together across
> > > > > multiple
> > > > > > boundaries.
> > > > > >
> > > > > > On that last paragraph: note that the producer *did* know the
> data
> > it
> > > > > > already produced. It handled it the first time around. Asking it
> to
> > > > > > re-produce it into a new partition layout is squarely within its
> > > scope
> > > > of
> > > > > > capabilities. Contrast this with the alternative, asking the
> > consumer
> > > > to
> > > > > > re-partition the data. I think this is even less intuitive, when
> > the
> > > > > > partition function belongs to the producer.
> > > > > >
> > > > > >
> > > > > > Point 5:
> > > > > > Dong asked this:
> > > > > >
> > > > > > > For stream use-case that needs to increase consumer number, the
> > > > > > > existing consumer can backfill the existing data in the change
> > log
> > > > > topic
> > > > > > to
> > > > > > > the same change log topic with the new partition number, before
> > the
> > > > new
> > > > > > set
> > > > > > > of consumers bootstrap state from the new partitions of the
> > change
> > > > log
> > > > > > > topic, right?
> > > > > >
> > > > > >
> > > > > > In this sense, the "consumer" is actually the producer of the
> > > changelog
> > > > > > topic, so if we support partition expansion + backfill as a
> > > > > producer/broker
> > > > > > operation, then it would be very straightforward for Streams to
> > > split a
> > > > > > state store. As you say, they would simply instruct the broker to
> > > split
> > > > > the
> > > > > > changelog topic's partitions, then backfill. Once the backfill is
> > > > ready,
> > > > > > they can create a new crop of StandbyTasks to bootstrap the more
> > > > granular
> > > > > > state stores and finally switch over to them when they are ready.
> > > > > >
> > > > > > But this actually seems to be an argument in favor of
> > split+backfill,
> > > > so
> > > > > > maybe I missed the point.
> > > > > >
> > > > > > You also asked me to explain why copying the "input" topic is
> > better
> > > > than
> > > > > > copying the "changelog" topic. I think they are totally
> > independent,
> > > > > > actually. For one thing, you can't depend on the existence of a
> > > > > "changelog"
> > > > > > topic in general, only within Streams, but Kafka's user base
> > clearly
> > > > > > exceeds Streams's user base. Plus, you actually also can't depend
> > on
> > > > the
> > > > > > existence of a changelog topic within Streams, since that is an
> > > > optional
> > > > > > feature of *some* state store implementations. Even in the
> > situation
> > > > > where
> > > > > > you do have a changelog topic in Streams, there may be use cases
> > > where
> > > > it
> > > > > > makes sense to expand the partitions of just the input, or just
> the
> > > > > > changelog.
> > > > > >
> > > > > > The ask for a Core feature of split+backfill is really about
> > > supporting
> > > > > the
> > > > > > use case of splitting partitions in log-compacted topics,
> > regardless
> > > of
> > > > > > whether that topic is an "input" or a "changelog" or anything
> else
> > > for
> > > > > that
> > > > > > matter.
> > > > > >
> > > > > >
> > > > > > Point 6:
> > > > > > On the concern about the performance overhead of copying data
> > between
> > > > the
> > > > > > brokers, I think it's actually a bit overestimated. Splitting a
> > > topic's
> > > > > > partition is probably rare, certainly rarer in general than
> > > > bootstrapping
> > > > > > new consumers on that topic. If "bootstrapping new consumers"
> means
> > > > that
> > > > > > they have to re-shuffle the data before they consume it, then you
> > > wind
> > > > up
> > > > > > copying the same record multiple times:
> > > > > >
> > > > > > (broker: input topic) -> (initial consumer) -> (broker:
> repartition
> > > > > topic)
> > > > > > -> (real consumer)
> > > > > >
> > > > > > That's 3x, and it's also 3x for every new record after the split
> as
> > > > well,
> > > > > > since you don't get to stop repartitioning/reshuffling once you
> > > start.
> > > > > >
> > > > > > Whereas if you do a backfill in something like the procedure I
> > > > outlined,
> > > > > > you only copy the prefix of the partition before the split, and
> you
> > > > send
> > > > > it
> > > > > > once to the producer and then once to the new generation
> partition.
> > > > Plus,
> > > > > > assuming we're splitting the partition for the benefit of
> > consumers,
> > > > > > there's no reason we can't co-locate the post-split partitions on
> > the
> > > > > same
> > > > > > host as the pre-split partition, making the second copy a local
> > > > > filesystem
> > > > > > operation.
> > > > > >
> > > > > > Even if you follow these two copies up with bootstrapping a new
> > > > consumer,
> > > > > > it's still rare for this to occur, so you get to amortize these
> > > copies
> > > > > over
> > > > > > the lifetime of the topic, whereas a reshuffle just keeps making
> > > copies
> > > > > for
> > > > > > every new event.
> > > > > >
> > > > > > And finally, I really do think that regardless of any performance
> > > > > concerns
> > > > > > about this operation, if it preserves loose organizational
> > coupling,
> > > it
> > > > > is
> > > > > > certainly worth it.
> > > > > >
> > > > > >
> > > > > > In conclusion:
> > > > > > It might actually be a good idea for us to clarify the scope of
> > > > KIP-253.
> > > > > If
> > > > > > we're all agreed that it's a good algorithm for allowing in-order
> > > > message
> > > > > > delivery during partition expansion, then we can continue this
> > > > discussion
> > > > > > as a new KIP, something like "backfill with partition expansion".
> > > This
> > > > > > would let Dong proceed with KIP-253. On the other hand, if it
> seems
> > > > like
> > > > > > this conversation may alter the design of KIP-253, then maybe we
> > > > *should*
> > > > > > just finish working it out.
> > > > > >
> > > > > > For my part, my only concern about KIP-253 is the one I raised
> > > earlier.
> > > > > >
> > > > > > Thanks again, all, for considering these points,
> > > > > > -John
> > > > > >
> > > > > >
> > > > > > On Tue, Mar 27, 2018 at 2:10 AM, Dong Lin <li...@gmail.com>
> > > wrote:
> > > > > >
> > > > > > > On Tue, Mar 27, 2018 at 12:04 AM, Dong Lin <
> lindong28@gmail.com>
> > > > > wrote:
> > > > > > >
> > > > > > > > Hey Jan,
> > > > > > > >
> > > > > > > > Thanks for the enthusiasm in improving Kafka's design. Now
> > that I
> > > > > have
> > > > > > > > read through your discussion with Jun, here are my thoughts:
> > > > > > > >
> > > > > > > > - The latest proposal should with log compacted topics by
> > > properly
> > > > > > > > deleting old messages after a new message with the same key
> is
> > > > > > produced.
> > > > > > > So
> > > > > > > > it is probably not a concern anymore. Could you comment if
> > there
> > > is
> > > > > > still
> > > > > > > > issue?
> > > > > > > >
> > > > > > > > - I wrote the SEP-5 and I am pretty familiar with the
> > motivation
> > > > and
> > > > > > the
> > > > > > > > design of SEP-5. SEP-5 is probably orthornal to the
> motivation
> > of
> > > > > this
> > > > > > > KIP.
> > > > > > > > The goal of SEP-5 is to allow user to increase task number of
> > an
> > > > > > existing
> > > > > > > > Samza job. But if we increase the partition number of input
> > > topics,
> > > > > > > > messages may still be consumed out-of-order by tasks in Samza
> > > which
> > > > > > cause
> > > > > > > > incorrect result. Similarly, the approach you proposed does
> not
> > > > seem
> > > > > to
> > > > > > > > ensure that the messages can be delivered in order, even if
> we
> > > can
> > > > > make
> > > > > > > > sure that each consumer instance is assigned the set of new
> > > > > partitions
> > > > > > > > covering the same set of keys.
> > > > > > > >
> > > > > > >
> > > > > > > Let me correct this comment. The approach of copying data to a
> > new
> > > > > topic
> > > > > > > can ensure in-order message delivery suppose we properly
> migrate
> > > > > offsets
> > > > > > > from old topic to new topic.
> > > > > > >
> > > > > > >
> > > > > > > > - I am trying to understand why it is better to copy the data
> > > > instead
> > > > > > of
> > > > > > > > copying the change log topic for streaming use-case. For core
> > > Kafka
> > > > > > > > use-case, and for the stream use-case that does not need to
> > > > increase
> > > > > > > > consumers, the current KIP already supports in-order delivery
> > > > without
> > > > > > the
> > > > > > > > overhead of copying the data. For stream use-case that needs
> to
> > > > > > increase
> > > > > > > > consumer number, the existing consumer can backfill the
> > existing
> > > > data
> > > > > > in
> > > > > > > > the change log topic to the same change log topic with the
> new
> > > > > > partition
> > > > > > > > number, before the new set of consumers bootstrap state from
> > the
> > > > new
> > > > > > > > partitions of the change log topic. If this solution works,
> > then
> > > > > could
> > > > > > > you
> > > > > > > > summarize the advantage of copying the data of input topic as
> > > > > compared
> > > > > > to
> > > > > > > > copying the change log topic? For example, does it enable
> more
> > > > > > use-case,
> > > > > > > > simplify the implementation of Kafka library, or reduce the
> > > > operation
> > > > > > > > overhead etc?
> > > > > > > >
> > > > > > > > Thanks,
> > > > > > > > Dong
> > > > > > > >
> > > > > > > >
> > > > > > > > On Wed, Mar 21, 2018 at 6:57 AM, Jan Filipiak <
> > > > > > Jan.Filipiak@trivago.com>
> > > > > > > > wrote:
> > > > > > > >
> > > > > > > >> Hi Jun,
> > > > > > > >>
> > > > > > > >> I was really seeing progress in our conversation but your
> > latest
> > > > > reply
> > > > > > > is
> > > > > > > >> just devastating.
> > > > > > > >> I though we were getting close being on the same page now it
> > > feels
> > > > > > like
> > > > > > > >> we are in different libraries.
> > > > > > > >>
> > > > > > > >> I just quickly slam my answers in here. If they are to
> brief I
> > > am
> > > > > > sorry
> > > > > > > >> give me a ping and try to go into details more.
> > > > > > > >> Just want to show that your pro/cons listing is broken.
> > > > > > > >>
> > > > > > > >> Best Jan
> > > > > > > >>
> > > > > > > >> and want to get rid of this horrible compromise
> > > > > > > >>
> > > > > > > >>
> > > > > > > >> On 19.03.2018 05:48, Jun Rao wrote:
> > > > > > > >>
> > > > > > > >>> Hi, Jan,
> > > > > > > >>>
> > > > > > > >>> Thanks for the discussion. Great points.
> > > > > > > >>>
> > > > > > > >>> Let me try to summarize the approach that you are
> proposing.
> > On
> > > > the
> > > > > > > >>> broker
> > > > > > > >>> side, we reshuffle the existing data in a topic from
> current
> > > > > > partitions
> > > > > > > >>> to
> > > > > > > >>> the new partitions. Once the reshuffle fully catches up,
> > switch
> > > > the
> > > > > > > >>> consumers to start consuming from the new partitions. If a
> > > > consumer
> > > > > > > needs
> > > > > > > >>> to rebuild its local state (due to partition changes), let
> > the
> > > > > > consumer
> > > > > > > >>> rebuild its state by reading all existing data from the new
> > > > > > partitions.
> > > > > > > >>> Once all consumers have switches over, cut over the
> producer
> > to
> > > > the
> > > > > > new
> > > > > > > >>> partitions.
> > > > > > > >>>
> > > > > > > >>> The pros for this approach are that :
> > > > > > > >>> 1. There is just one way to rebuild the local state, which
> is
> > > > > > simpler.
> > > > > > > >>>
> > > > > > > >> true thanks
> > > > > > > >>
> > > > > > > >>>
> > > > > > > >>> The cons for this approach are:
> > > > > > > >>> 1. Need to copy existing data.
> > > > > > > >>>
> > > > > > > >> Very unfair and not correct. It does not require you to copy
> > > over
> > > > > > > >> existing data. It _allows_ you to copy all existing data.
> > > > > > > >>
> > > > > > > >> 2. The cutover of the producer is a bit complicated since it
> > > needs
> > > > > to
> > > > > > > >>> coordinate with all consumer groups.
> > > > > > > >>>
> > > > > > > >> Also not true. I explicitly tried to make clear that there
> is
> > > only
> > > > > one
> > > > > > > >> special consumer (in the case of actually copying data)
> > > > coordination
> > > > > > is
> > > > > > > >> required.
> > > > > > > >>
> > > > > > > >>> 3. The rebuilding of the state in the consumer is from the
> > > input
> > > > > > topic,
> > > > > > > >>> which can be more expensive than rebuilding from the
> existing
> > > > > state.
> > > > > > > >>>
> > > > > > > >> true, but rebuilding state is only required if you want to
> > > > increase
> > > > > > > >> processing power, so we assume this is at hand.
> > > > > > > >>
> > > > > > > >>> 4. The broker potentially has to know the partitioning
> > > function.
> > > > If
> > > > > > > this
> > > > > > > >>> needs to be customized at the topic level, it can be a bit
> > > messy.
> > > > > > > >>>
> > > > > > > >> I would argue against having the operation being performed
> by
> > > the
> > > > > > > broker.
> > > > > > > >> This was not discussed yet but if you see my original email
> i
> > > > > > suggested
> > > > > > > >> otherwise from the beginning.
> > > > > > > >>
> > > > > > > >>>
> > > > > > > >>> Here is an alternative approach by applying your idea not
> in
> > > the
> > > > > > > broker,
> > > > > > > >>> but in the consumer. When new partitions are added, we
> don't
> > > move
> > > > > > > >>> existing
> > > > > > > >>> data. In KStreams, we first reshuffle the new input data
> to a
> > > new
> > > > > > topic
> > > > > > > >>> T1
> > > > > > > >>> with the old number of partitions and feed T1's data to the
> > > rest
> > > > of
> > > > > > the
> > > > > > > >>> pipeline. In the meantime, KStreams reshuffles all existing
> > > data
> > > > of
> > > > > > the
> > > > > > > >>> change capture topic to another topic C1 with the new
> number
> > of
> > > > > > > >>> partitions.
> > > > > > > >>> We can then build the state of the new tasks from C1. Once
> > the
> > > > new
> > > > > > > states
> > > > > > > >>> have been fully built, we can cut over the consumption to
> the
> > > > input
> > > > > > > topic
> > > > > > > >>> and delete T1. This approach works with compacted topic
> too.
> > If
> > > > an
> > > > > > > >>> application reads from the beginning of a compacted topic,
> > the
> > > > > > consumer
> > > > > > > >>> will reshuffle the portion of the input when the number of
> > > > > partitions
> > > > > > > >>> doesn't match the number of tasks.
> > > > > > > >>>
> > > > > > > >> We all wipe this idea from our heads instantly. Mixing Ideas
> > > from
> > > > an
> > > > > > > >> argument is not a resolution strategy
> > > > > > > >> just leads to horrible horrible software.
> > > > > > > >>
> > > > > > > >>
> > > > > > > >>> The pros of this approach are:
> > > > > > > >>> 1. No need to copy existing data.
> > > > > > > >>> 2. Each consumer group can cut over to the new partitions
> > > > > > > independently.
> > > > > > > >>> 3. The state is rebuilt from the change capture topic,
> which
> > is
> > > > > > cheaper
> > > > > > > >>> than rebuilding from the input topic.
> > > > > > > >>> 4. Only the KStreams job needs to know the partitioning
> > > function.
> > > > > > > >>>
> > > > > > > >>> The cons of this approach are:
> > > > > > > >>> 1. Potentially the same input topic needs to be reshuffled
> > more
> > > > > than
> > > > > > > once
> > > > > > > >>> in different consumer groups during the transition phase.
> > > > > > > >>>
> > > > > > > >>> What do you think?
> > > > > > > >>>
> > > > > > > >>> Thanks,
> > > > > > > >>>
> > > > > > > >>> Jun
> > > > > > > >>>
> > > > > > > >>>
> > > > > > > >>>
> > > > > > > >>> On Thu, Mar 15, 2018 at 1:04 AM, Jan Filipiak <
> > > > > > > Jan.Filipiak@trivago.com>
> > > > > > > >>> wrote:
> > > > > > > >>>
> > > > > > > >>> Hi Jun,
> > > > > > > >>>>
> > > > > > > >>>> thank you for following me on these thoughts. It was
> > important
> > > > to
> > > > > me
> > > > > > > to
> > > > > > > >>>> feel that kind of understanding for my arguments.
> > > > > > > >>>>
> > > > > > > >>>> What I was hoping for (I mentioned this earlier) is that
> we
> > > can
> > > > > > model
> > > > > > > >>>> the
> > > > > > > >>>> case where we do not want to copy the data the exact same
> > way
> > > as
> > > > > the
> > > > > > > >>>> case
> > > > > > > >>>> when we do copy the data. Maybe you can peek into the
> mails
> > > > before
> > > > > > to
> > > > > > > >>>> see
> > > > > > > >>>> more details for this.
> > > > > > > >>>>
> > > > > > > >>>> This means we have the same mechanism to transfer consumer
> > > > groups
> > > > > to
> > > > > > > >>>> switch topic. The offset mapping that would be generated
> > would
> > > > > even
> > > > > > be
> > > > > > > >>>> simpler End Offset of the Old topic => offset 0 off all
> the
> > > > > > partitions
> > > > > > > >>>> of
> > > > > > > >>>> the new topic. Then we could model the transition of a
> > > non-copy
> > > > > > > >>>> expansion
> > > > > > > >>>> the exact same way as a copy-expansion.
> > > > > > > >>>>
> > > > > > > >>>> I know this only works when topic growth by a factor. But
> > the
> > > > > > benefits
> > > > > > > >>>> of
> > > > > > > >>>> only growing by a factor are to strong anyways. See
> > Clemens's
> > > > hint
> > > > > > and
> > > > > > > >>>> remember that state reshuffling is entirely not needed if
> > one
> > > > > > doesn't
> > > > > > > >>>> want
> > > > > > > >>>> to grow processing power.
> > > > > > > >>>>
> > > > > > > >>>> I think these benefits should be clear, and that there is
> > > > > basically
> > > > > > no
> > > > > > > >>>> downside to what is currently at hand but just makes
> > > everything
> > > > > > easy.
> > > > > > > >>>>
> > > > > > > >>>> One thing you need to know is. that if you do not offer
> > > > > rebuilding a
> > > > > > > log
> > > > > > > >>>> compacted topic like i suggest that even if you have
> > consumer
> > > > > state
> > > > > > > >>>> reshuffling. The topic is broken and can not be used to
> > > > bootstrap
> > > > > > new
> > > > > > > >>>> consumers. They don't know if they need to apply a key
> from
> > > and
> > > > > old
> > > > > > > >>>> partition or not. This is a horrible downside I haven't
> > seen a
> > > > > > > solution
> > > > > > > >>>> for
> > > > > > > >>>> in the email conversation.
> > > > > > > >>>>
> > > > > > > >>>> I argue to:
> > > > > > > >>>>
> > > > > > > >>>> Only grow topic by a factor always.
> > > > > > > >>>> Have the "no copy consumer" transition as the trivial case
> > of
> > > > the
> > > > > > > "copy
> > > > > > > >>>> consumer transition".
> > > > > > > >>>> If processors needs to be scaled, let them rebuild from
> the
> > > new
> > > > > > topic
> > > > > > > >>>> and
> > > > > > > >>>> leave the old running in the mean time.
> > > > > > > >>>> Do not implement key shuffling in streams.
> > > > > > > >>>>
> > > > > > > >>>> I hope I can convince you especially with the fact how I
> > want
> > > to
> > > > > > > handle
> > > > > > > >>>> consumer transition. I think
> > > > > > > >>>> you didn't quite understood me there before. I think the
> > term
> > > > "new
> > > > > > > >>>> topic"
> > > > > > > >>>> intimidated you a little.
> > > > > > > >>>> How we solve this on disc doesn't really matter, If the
> data
> > > > goes
> > > > > > into
> > > > > > > >>>> the
> > > > > > > >>>> same Dir or a different Dir or anything. I do think that
> it
> > > > needs
> > > > > to
> > > > > > > >>>> involve at least rolling a new segment for the existing
> > > > > partitions.
> > > > > > > >>>> But most of the transitions should work without restarting
> > > > > > consumers.
> > > > > > > >>>> (newer consumers with support for this). But with new
> topic
> > i
> > > > just
> > > > > > > meant
> > > > > > > >>>> the topic that now has a different partition count. Plenty
> > of
> > > > ways
> > > > > > to
> > > > > > > >>>> handle that (versions, aliases)
> > > > > > > >>>>
> > > > > > > >>>> Hope I can further get my idea across.
> > > > > > > >>>>
> > > > > > > >>>> Best Jan
> > > > > > > >>>>
> > > > > > > >>>>
> > > > > > > >>>>
> > > > > > > >>>>
> > > > > > > >>>>
> > > > > > > >>>>
> > > > > > > >>>> On 14.03.2018 02:45, Jun Rao wrote:
> > > > > > > >>>>
> > > > > > > >>>> Hi, Jan,
> > > > > > > >>>>>
> > > > > > > >>>>> Thanks for sharing your view.
> > > > > > > >>>>>
> > > > > > > >>>>> I agree with you that recopying the data potentially
> makes
> > > the
> > > > > > state
> > > > > > > >>>>> management easier since the consumer can just rebuild its
> > > state
> > > > > > from
> > > > > > > >>>>> scratch (i.e., no need for state reshuffling).
> > > > > > > >>>>>
> > > > > > > >>>>> On the flip slide, I saw a few disadvantages of the
> > approach
> > > > that
> > > > > > you
> > > > > > > >>>>> suggested. (1) Building the state from the input topic
> from
> > > > > scratch
> > > > > > > is
> > > > > > > >>>>> in
> > > > > > > >>>>> general less efficient than state reshuffling. Let's say
> > one
> > > > > > > computes a
> > > > > > > >>>>> count per key from an input topic. The former requires
> > > reading
> > > > > all
> > > > > > > >>>>> existing
> > > > > > > >>>>> records in the input topic whereas the latter only
> requires
> > > > > reading
> > > > > > > >>>>> data
> > > > > > > >>>>> proportional to the number of unique keys. (2) The
> > switching
> > > of
> > > > > the
> > > > > > > >>>>> topic
> > > > > > > >>>>> needs modification to the application. If there are many
> > > > > > applications
> > > > > > > >>>>> on a
> > > > > > > >>>>> topic, coordinating such an effort may not be easy. Also,
> > > it's
> > > > > not
> > > > > > > >>>>> clear
> > > > > > > >>>>> how to enforce exactly-once semantic during the switch.
> (3)
> > > If
> > > > a
> > > > > > > topic
> > > > > > > >>>>> doesn't need any state management, recopying the data
> seems
> > > > > > wasteful.
> > > > > > > >>>>> In
> > > > > > > >>>>> that case, in place partition expansion seems more
> > desirable.
> > > > > > > >>>>>
> > > > > > > >>>>> I understand your concern about adding complexity in
> > > KStreams.
> > > > > But,
> > > > > > > >>>>> perhaps
> > > > > > > >>>>> we could iterate on that a bit more to see if it can be
> > > > > simplified.
> > > > > > > >>>>>
> > > > > > > >>>>> Jun
> > > > > > > >>>>>
> > > > > > > >>>>>
> > > > > > > >>>>> On Mon, Mar 12, 2018 at 11:21 PM, Jan Filipiak <
> > > > > > > >>>>> Jan.Filipiak@trivago.com>
> > > > > > > >>>>> wrote:
> > > > > > > >>>>>
> > > > > > > >>>>> Hi Jun,
> > > > > > > >>>>>
> > > > > > > >>>>>> I will focus on point 61 as I think its _the_
> fundamental
> > > part
> > > > > > that
> > > > > > > I
> > > > > > > >>>>>> cant
> > > > > > > >>>>>> get across at the moment.
> > > > > > > >>>>>>
> > > > > > > >>>>>> Kafka is the platform to have state materialized
> multiple
> > > > times
> > > > > > from
> > > > > > > >>>>>> one
> > > > > > > >>>>>> input. I emphasize this: It is the building block in
> > > > > architectures
> > > > > > > >>>>>> that
> > > > > > > >>>>>> allow you to
> > > > > > > >>>>>> have your state maintained multiple times. You put a
> > message
> > > > in
> > > > > > > once,
> > > > > > > >>>>>> and
> > > > > > > >>>>>> you have it pop out as often as you like. I believe you
> > > > > understand
> > > > > > > >>>>>> this.
> > > > > > > >>>>>>
> > > > > > > >>>>>> Now! The path of thinking goes the following: I am using
> > > > apache
> > > > > > > kafka
> > > > > > > >>>>>> and
> > > > > > > >>>>>> I _want_ my state multiple times. What am I going todo?
> > > > > > > >>>>>>
> > > > > > > >>>>>> A) Am I going to take my state that I build up, plunge
> > some
> > > > sort
> > > > > > of
> > > > > > > >>>>>> RPC
> > > > > > > >>>>>> layer ontop of it, use that RPC layer to throw my
> records
> > > > across
> > > > > > > >>>>>> instances?
> > > > > > > >>>>>> B) Am I just going to read the damn message twice?
> > > > > > > >>>>>>
> > > > > > > >>>>>> Approach A is fundamentally flawed and a violation of
> all
> > > that
> > > > > is
> > > > > > > good
> > > > > > > >>>>>> and
> > > > > > > >>>>>> holy in kafka deployments. I can not understand how this
> > > Idea
> > > > > can
> > > > > > > >>>>>> come in
> > > > > > > >>>>>> the first place.
> > > > > > > >>>>>> (I do understand: IQ in streams, they polluted the kafka
> > > > streams
> > > > > > > >>>>>> codebase
> > > > > > > >>>>>> really bad already. It is not funny! I think they are
> > > equally
> > > > > > flawed
> > > > > > > >>>>>> as
> > > > > > > >>>>>> A)
> > > > > > > >>>>>>
> > > > > > > >>>>>> I say, we do what Kafka is good at. We repartition the
> > topic
> > > > > once.
> > > > > > > We
> > > > > > > >>>>>> switch the consumers.
> > > > > > > >>>>>> (Those that need more partitions are going to rebuild
> > their
> > > > > state
> > > > > > in
> > > > > > > >>>>>> multiple partitions by reading the new topic, those that
> > > don't
> > > > > > just
> > > > > > > >>>>>> assign
> > > > > > > >>>>>> the new partitions properly)
> > > > > > > >>>>>> We switch producers. Done!
> > > > > > > >>>>>>
> > > > > > > >>>>>> The best thing! It is trivial, hipster stream processor
> > will
> > > > > have
> > > > > > an
> > > > > > > >>>>>> easy
> > > > > > > >>>>>> time with that aswell. Its so super simple. And simple
> IS
> > > > good!
> > > > > > > >>>>>> It is what kafka was build todo. It is how we do it
> today.
> > > > All I
> > > > > > am
> > > > > > > >>>>>> saying
> > > > > > > >>>>>> is that a little broker help doing the producer swap is
> > > super
> > > > > > > useful.
> > > > > > > >>>>>>
> > > > > > > >>>>>> For everyone interested in why kafka is so powerful with
> > > > > approach
> > > > > > B,
> > > > > > > >>>>>> please watch https://youtu.be/bEbeZPVo98c?t=1633
> > > > > > > >>>>>> I already looked up a good point in time, I think after
> 5
> > > > > minutes
> > > > > > > the
> > > > > > > >>>>>> "state" topic is handled and you should be able to
> > > understand
> > > > me
> > > > > > > >>>>>> and inch better.
> > > > > > > >>>>>>
> > > > > > > >>>>>> Please do not do A to the project, it deserves better!
> > > > > > > >>>>>>
> > > > > > > >>>>>> Best Jan
> > > > > > > >>>>>>
> > > > > > > >>>>>>
> > > > > > > >>>>>>
> > > > > > > >>>>>> On 13.03.2018 02:40, Jun Rao wrote:
> > > > > > > >>>>>>
> > > > > > > >>>>>> Hi, Jan,
> > > > > > > >>>>>>
> > > > > > > >>>>>>> Thanks for the reply. A few more comments below.
> > > > > > > >>>>>>>
> > > > > > > >>>>>>> 50. Ok, we can think a bit harder for supporting
> > compacted
> > > > > > topics.
> > > > > > > >>>>>>>
> > > > > > > >>>>>>> 51. This is a fundamental design question. In the more
> > > common
> > > > > > case,
> > > > > > > >>>>>>> the
> > > > > > > >>>>>>> reason why someone wants to increase the number of
> > > partitions
> > > > > is
> > > > > > > that
> > > > > > > >>>>>>> the
> > > > > > > >>>>>>> consumer application is slow and one wants to run more
> > > > consumer
> > > > > > > >>>>>>> instances
> > > > > > > >>>>>>> to increase the degree of parallelism. So, fixing the
> > > number
> > > > of
> > > > > > > >>>>>>> running
> > > > > > > >>>>>>> consumer instances when expanding the partitions won't
> > help
> > > > > this
> > > > > > > >>>>>>> case.
> > > > > > > >>>>>>> If
> > > > > > > >>>>>>> we do need to increase the number of consumer
> instances,
> > we
> > > > > need
> > > > > > to
> > > > > > > >>>>>>> somehow
> > > > > > > >>>>>>> reshuffle the state of the consumer across instances.
> > What
> > > we
> > > > > > have
> > > > > > > >>>>>>> been
> > > > > > > >>>>>>> discussing in this KIP is whether we can do this more
> > > > > effectively
> > > > > > > >>>>>>> through
> > > > > > > >>>>>>> the KStream library (e.g. through a 2-phase partition
> > > > > expansion).
> > > > > > > >>>>>>> This
> > > > > > > >>>>>>> will
> > > > > > > >>>>>>> add some complexity, but it's probably better than
> > everyone
> > > > > doing
> > > > > > > >>>>>>> this
> > > > > > > >>>>>>> in
> > > > > > > >>>>>>> the application space. The recopying approach that you
> > > > > mentioned
> > > > > > > >>>>>>> doesn't
> > > > > > > >>>>>>> seem to address the consumer state management issue
> when
> > > the
> > > > > > > consumer
> > > > > > > >>>>>>> switches from an old to a new topic.
> > > > > > > >>>>>>>
> > > > > > > >>>>>>> 52. As for your example, it depends on whether the join
> > key
> > > > is
> > > > > > the
> > > > > > > >>>>>>> same
> > > > > > > >>>>>>> between (A,B) and (B,C). If the join key is the same,
> we
> > > can
> > > > > do a
> > > > > > > >>>>>>> 2-phase
> > > > > > > >>>>>>> partition expansion of A, B, and C together. If the
> join
> > > keys
> > > > > are
> > > > > > > >>>>>>> different, one would need to repartition the data on a
> > > > > different
> > > > > > > key
> > > > > > > >>>>>>> for
> > > > > > > >>>>>>> the second join, then the partition expansion can be
> done
> > > > > > > >>>>>>> independently
> > > > > > > >>>>>>> between (A,B) and (B,C).
> > > > > > > >>>>>>>
> > > > > > > >>>>>>> 53. If you always fix the number of consumer instances,
> > we
> > > > you
> > > > > > > >>>>>>> described
> > > > > > > >>>>>>> works. However, as I mentioned in #51, I am not sure
> how
> > > your
> > > > > > > >>>>>>> proposal
> > > > > > > >>>>>>> deals with consumer states when the number of consumer
> > > > > instances
> > > > > > > >>>>>>> grows.
> > > > > > > >>>>>>> Also, it just seems that it's better to avoid
> re-copying
> > > the
> > > > > > > existing
> > > > > > > >>>>>>> data.
> > > > > > > >>>>>>>
> > > > > > > >>>>>>> 60. "just want to throw in my question from the longer
> > > email
> > > > in
> > > > > > the
> > > > > > > >>>>>>> other
> > > > > > > >>>>>>> Thread here. How will the bloom filter help a new
> > consumer
> > > to
> > > > > > > decide
> > > > > > > >>>>>>> to
> > > > > > > >>>>>>> apply the key or not?" Not sure that I fully understood
> > > your
> > > > > > > >>>>>>> question.
> > > > > > > >>>>>>> The
> > > > > > > >>>>>>> consumer just reads whatever key is in the log. The
> bloom
> > > > > filter
> > > > > > > just
> > > > > > > >>>>>>> helps
> > > > > > > >>>>>>> clean up the old keys.
> > > > > > > >>>>>>>
> > > > > > > >>>>>>> 61. "Why can we afford having a topic where its
> > apparently
> > > > not
> > > > > > > >>>>>>> possible
> > > > > > > >>>>>>> to
> > > > > > > >>>>>>> start a new application on? I think this is an overall
> > flaw
> > > > of
> > > > > > the
> > > > > > > >>>>>>> discussed idea here. Not playing attention to the
> overall
> > > > > > > >>>>>>> architecture."
> > > > > > > >>>>>>> Could you explain a bit more when one can't start a new
> > > > > > > application?
> > > > > > > >>>>>>>
> > > > > > > >>>>>>> Jun
> > > > > > > >>>>>>>
> > > > > > > >>>>>>>
> > > > > > > >>>>>>>
> > > > > > > >>>>>>> On Sat, Mar 10, 2018 at 1:40 AM, Jan Filipiak <
> > > > > > > >>>>>>> Jan.Filipiak@trivago.com
> > > > > > > >>>>>>> wrote:
> > > > > > > >>>>>>>
> > > > > > > >>>>>>> Hi Jun, thanks for your mail.
> > > > > > > >>>>>>>
> > > > > > > >>>>>>> Thank you for your questions!
> > > > > > > >>>>>>>> I think they are really good and tackle the core of
> the
> > > > > problem
> > > > > > I
> > > > > > > >>>>>>>> see.
> > > > > > > >>>>>>>>
> > > > > > > >>>>>>>> I will answer inline, mostly but still want to set the
> > > tone
> > > > > > here.
> > > > > > > >>>>>>>>
> > > > > > > >>>>>>>> The core strength of kafka is what Martin once called
> > the
> > > > > > > >>>>>>>> kappa-Architecture. How does this work?
> > > > > > > >>>>>>>> You have everything as a log as in kafka. When you
> need
> > to
> > > > > > change
> > > > > > > >>>>>>>> something.
> > > > > > > >>>>>>>> You create the new version of your application and
> leave
> > > it
> > > > > > > running
> > > > > > > >>>>>>>> in
> > > > > > > >>>>>>>> parallel.
> > > > > > > >>>>>>>> Once the new version is good you switch your users to
> > use
> > > > the
> > > > > > new
> > > > > > > >>>>>>>> application.
> > > > > > > >>>>>>>>
> > > > > > > >>>>>>>> The online reshuffling effectively breaks this
> > > architecture
> > > > > and
> > > > > > I
> > > > > > > >>>>>>>> think
> > > > > > > >>>>>>>> the switch in thinking here is more harmful
> > > > > > > >>>>>>>> than any details about the partitioning function to
> > allow
> > > > > such a
> > > > > > > >>>>>>>> change.
> > > > > > > >>>>>>>> I
> > > > > > > >>>>>>>> feel with my suggestion we are the closest to
> > > > > > > >>>>>>>> the original and battle proven architecture and I can
> > only
> > > > > warn
> > > > > > to
> > > > > > > >>>>>>>> move
> > > > > > > >>>>>>>> away from it.
> > > > > > > >>>>>>>>
> > > > > > > >>>>>>>> I might have forgotten something, sometimes its hard
> for
> > > me
> > > > to
> > > > > > > >>>>>>>> getting
> > > > > > > >>>>>>>> all
> > > > > > > >>>>>>>> the thoughts captured in a mail, but I hope the
> comments
> > > > > inline
> > > > > > > will
> > > > > > > >>>>>>>> further make my concern clear, and put some emphasis
> on
> > > why
> > > > I
> > > > > > > >>>>>>>> prefer my
> > > > > > > >>>>>>>> solution ;)
> > > > > > > >>>>>>>>
> > > > > > > >>>>>>>> One thing we should all be aware of when discussing
> > this,
> > > > and
> > > > > I
> > > > > > > >>>>>>>> think
> > > > > > > >>>>>>>> Dong
> > > > > > > >>>>>>>> should have mentioned it (maybe he did).
> > > > > > > >>>>>>>> We are not discussing all of this out of thin air but
> > > there
> > > > is
> > > > > > an
> > > > > > > >>>>>>>> effort
> > > > > > > >>>>>>>> in the Samza project.
> > > > > > > >>>>>>>>
> > > > > > > >>>>>>>> https://cwiki.apache.org/confl
> uence/display/SAMZA/SEP-
> > > 5%3A+
> > > > > > > >>>>>>>> Enable+partition+expansion+of+input+streams
> > > > > > > >>>>>>>> https://issues.apache.org/jira/browse/SAMZA-1293
> > > > > > > >>>>>>>>
> > > > > > > >>>>>>>> To be clear. I think SEP-5 (state of last week, dont
> > know
> > > if
> > > > > it
> > > > > > > >>>>>>>> adapted
> > > > > > > >>>>>>>> to
> > > > > > > >>>>>>>> this discussion) is on a way better path than KIP-253,
> > > and I
> > > > > > can't
> > > > > > > >>>>>>>> really
> > > > > > > >>>>>>>> explain why.
> > > > > > > >>>>>>>>
> > > > > > > >>>>>>>> Best Jan,
> > > > > > > >>>>>>>>
> > > > > > > >>>>>>>> nice weekend everyone
> > > > > > > >>>>>>>>
> > > > > > > >>>>>>>>
> > > > > > > >>>>>>>> On 09.03.2018 03:36, Jun Rao wrote:
> > > > > > > >>>>>>>>
> > > > > > > >>>>>>>> Hi, Jan,
> > > > > > > >>>>>>>>
> > > > > > > >>>>>>>> Thanks for the feedback. Just some comments on the
> > earlier
> > > > > > points
> > > > > > > >>>>>>>>> that
> > > > > > > >>>>>>>>> you
> > > > > > > >>>>>>>>> mentioned.
> > > > > > > >>>>>>>>>
> > > > > > > >>>>>>>>> 50. You brought up the question of whether existing
> > data
> > > > > needs
> > > > > > to
> > > > > > > >>>>>>>>> be
> > > > > > > >>>>>>>>> copied
> > > > > > > >>>>>>>>> during partition expansion. My understand of your
> view
> > is
> > > > > that
> > > > > > > >>>>>>>>> avoid
> > > > > > > >>>>>>>>> copying existing data will be more efficient, but it
> > > > doesn't
> > > > > > work
> > > > > > > >>>>>>>>> well
> > > > > > > >>>>>>>>> with
> > > > > > > >>>>>>>>> compacted topics since some keys in the original
> > > partitions
> > > > > > will
> > > > > > > >>>>>>>>> never
> > > > > > > >>>>>>>>> be
> > > > > > > >>>>>>>>> cleaned. It would be useful to understand your use
> case
> > > of
> > > > > > > >>>>>>>>> compacted
> > > > > > > >>>>>>>>> topics
> > > > > > > >>>>>>>>> a bit more. In the common use case, the data volume
> in
> > a
> > > > > > > compacted
> > > > > > > >>>>>>>>> topic
> > > > > > > >>>>>>>>> may not be large. So, I am not sure if there is a
> > strong
> > > > need
> > > > > > to
> > > > > > > >>>>>>>>> expand
> > > > > > > >>>>>>>>> partitions in a compacted topic, at least initially.
> > > > > > > >>>>>>>>>
> > > > > > > >>>>>>>>> I do agree. State is usually smaller. Update rates
> > might
> > > be
> > > > > > also
> > > > > > > >>>>>>>>>
> > > > > > > >>>>>>>>> competitively high.
> > > > > > > >>>>>>>> Doing Log-compaction (even beeing very efficient and
> > > > > > configurable)
> > > > > > > >>>>>>>> is
> > > > > > > >>>>>>>> also
> > > > > > > >>>>>>>> a more expensive operation than
> > > > > > > >>>>>>>> just discarding old segments. Further if you want to
> use
> > > > more
> > > > > > > >>>>>>>> consumers
> > > > > > > >>>>>>>> processing the events
> > > > > > > >>>>>>>> you also have to grow the number of partitions.
> > Especially
> > > > for
> > > > > > > >>>>>>>> use-cases
> > > > > > > >>>>>>>> we do (KIP-213) a tiny state full
> > > > > > > >>>>>>>> table might be very expensive to process if it joins
> > > > against a
> > > > > > > huge
> > > > > > > >>>>>>>> table.
> > > > > > > >>>>>>>>
> > > > > > > >>>>>>>> I can just say we have been in the spot of needing to
> > grow
> > > > log
> > > > > > > >>>>>>>> compacted
> > > > > > > >>>>>>>> topics. Mainly for processing power we can bring to
> the
> > > > table.
> > > > > > > >>>>>>>>
> > > > > > > >>>>>>>> Further i am not at all concerned about the extra
> spaced
> > > > used
> > > > > by
> > > > > > > >>>>>>>> "garbage
> > > > > > > >>>>>>>> keys". I am more concerned about the correctness of
> > > innocent
> > > > > > > >>>>>>>> consumers.
> > > > > > > >>>>>>>> The
> > > > > > > >>>>>>>> logic becomes complicated. Say for streams one would
> > need
> > > to
> > > > > > load
> > > > > > > >>>>>>>> the
> > > > > > > >>>>>>>> record into state but not forward it the topology ( to
> > > have
> > > > it
> > > > > > > >>>>>>>> available
> > > > > > > >>>>>>>> for shuffeling). I rather have it simple and a topic
> > clean
> > > > > > > >>>>>>>> regardless
> > > > > > > >>>>>>>> if
> > > > > > > >>>>>>>> it
> > > > > > > >>>>>>>> still has its old partition count. Especially with
> > > multiple
> > > > > > > >>>>>>>> partitions
> > > > > > > >>>>>>>> growth's I think it becomes insanely hard to to this
> > > shuffle
> > > > > > > >>>>>>>> correct.
> > > > > > > >>>>>>>> Maybe
> > > > > > > >>>>>>>> Streams and Samza can do it. Especially if you do
> > "hipster
> > > > > > stream
> > > > > > > >>>>>>>> processing" <https://www.confluent.io/blog
> > > > > > > >>>>>>>> /introducing-kafka-streams-
> > > > > > > >>>>>>>> stream-processing-made-simple/>. This makes kafka way
> > to
> > > > > > > >>>>>>>> complicated.
> > > > > > > >>>>>>>> With my approach I think its way simpler because the
> > topic
> > > > has
> > > > > > no
> > > > > > > >>>>>>>> "history"
> > > > > > > >>>>>>>> in terms of partitioning but is always clean.
> > > > > > > >>>>>>>>
> > > > > > > >>>>>>>>
> > > > > > > >>>>>>>> 51. "Growing the topic by an integer factor does not
> > > require
> > > > > any
> > > > > > > >>>>>>>> state
> > > > > > > >>>>>>>>
> > > > > > > >>>>>>>> redistribution at all." Could you clarify this a bit
> > more?
> > > > > Let's
> > > > > > > say
> > > > > > > >>>>>>>>> you
> > > > > > > >>>>>>>>> have a consumer app that computes the windowed count
> > per
> > > > key.
> > > > > > If
> > > > > > > >>>>>>>>> you
> > > > > > > >>>>>>>>> double
> > > > > > > >>>>>>>>> the number of partitions from 1 to 2 and grow the
> > > consumer
> > > > > > > >>>>>>>>> instances
> > > > > > > >>>>>>>>> from
> > > > > > > >>>>>>>>> 1
> > > > > > > >>>>>>>>> to 2, we would need to redistribute some of the
> counts
> > to
> > > > the
> > > > > > new
> > > > > > > >>>>>>>>> consumer
> > > > > > > >>>>>>>>> instance. Regarding to linear hashing, it's true that
> > it
> > > > > won't
> > > > > > > >>>>>>>>> solve
> > > > > > > >>>>>>>>> the
> > > > > > > >>>>>>>>> problem with compacted topics. The main benefit is
> that
> > > it
> > > > > > > >>>>>>>>> redistributes
> > > > > > > >>>>>>>>> the keys in one partition to no more than two
> > partitions,
> > > > > which
> > > > > > > >>>>>>>>> could
> > > > > > > >>>>>>>>> help
> > > > > > > >>>>>>>>> redistribute the state.
> > > > > > > >>>>>>>>>
> > > > > > > >>>>>>>>> You don't need to spin up a new consumer in this
> case.
> > > > every
> > > > > > > >>>>>>>>> consumer
> > > > > > > >>>>>>>>>
> > > > > > > >>>>>>>>> would just read every partition with the (partition %
> > > > > num_task)
> > > > > > > >>>>>>>> task.
> > > > > > > >>>>>>>> it
> > > > > > > >>>>>>>> will still have the previous data right there and can
> go
> > > on.
> > > > > > > >>>>>>>>
> > > > > > > >>>>>>>> This sounds contradictory to what I said before, but
> > > please
> > > > > bear
> > > > > > > >>>>>>>> with
> > > > > > > >>>>>>>> me.
> > > > > > > >>>>>>>>
> > > > > > > >>>>>>>> 52. Good point on coordinating the expansion of 2
> topics
> > > > that
> > > > > > need
> > > > > > > >>>>>>>> to
> > > > > > > >>>>>>>> be
> > > > > > > >>>>>>>>
> > > > > > > >>>>>>>> joined together. This is where the 2-phase partition
> > > > expansion
> > > > > > > could
> > > > > > > >>>>>>>>> potentially help. In the first phase, we could add
> new
> > > > > > partitions
> > > > > > > >>>>>>>>> to
> > > > > > > >>>>>>>>> the 2
> > > > > > > >>>>>>>>> topics one at a time but without publishing to the
> new
> > > > > > patitions.
> > > > > > > >>>>>>>>> Then,
> > > > > > > >>>>>>>>> we
> > > > > > > >>>>>>>>> can add new consumer instances to pick up the new
> > > > partitions.
> > > > > > In
> > > > > > > >>>>>>>>> this
> > > > > > > >>>>>>>>> transition phase, no reshuffling is needed since no
> > data
> > > is
> > > > > > > coming
> > > > > > > >>>>>>>>> from
> > > > > > > >>>>>>>>> the
> > > > > > > >>>>>>>>> new partitions. Finally, we can enable the publishing
> > to
> > > > the
> > > > > > new
> > > > > > > >>>>>>>>> partitions.
> > > > > > > >>>>>>>>>
> > > > > > > >>>>>>>>> I think its even worse than you think. I would like
> to
> > > > > > introduce
> > > > > > > >>>>>>>>> the
> > > > > > > >>>>>>>>>
> > > > > > > >>>>>>>>> Term
> > > > > > > >>>>>>>> transitive copartitioning. Imagine
> > > > > > > >>>>>>>> 2 streams application. One joins (A,B) the other (B,C)
> > > then
> > > > > > there
> > > > > > > >>>>>>>> is a
> > > > > > > >>>>>>>> transitive copartition requirement for
> > > > > > > >>>>>>>> (A,C) to be copartitioned aswell. This can spread
> > > > > significantly
> > > > > > > and
> > > > > > > >>>>>>>> require many consumers to adapt at the same time.
> > > > > > > >>>>>>>>
> > > > > > > >>>>>>>> It is also not entirely clear to me how you not need
> > > > > reshuffling
> > > > > > > in
> > > > > > > >>>>>>>> this
> > > > > > > >>>>>>>> case. If A has a record that never gets updated after
> > the
> > > > > > > expansion
> > > > > > > >>>>>>>> and
> > > > > > > >>>>>>>> the
> > > > > > > >>>>>>>> coresponding B record moves to a new partition. How
> > shall
> > > > they
> > > > > > > meet
> > > > > > > >>>>>>>> w/o
> > > > > > > >>>>>>>> shuffle?
> > > > > > > >>>>>>>>
> > > > > > > >>>>>>>> 53. "Migrating consumer is a step that might be made
> > > > completly
> > > > > > > >>>>>>>>
> > > > > > > >>>>>>>> unnecessary
> > > > > > > >>>>>>>>> if - for example streams - takes the gcd as
> > partitioning
> > > > > scheme
> > > > > > > >>>>>>>>> instead
> > > > > > > >>>>>>>>> of
> > > > > > > >>>>>>>>> enforcing 1 to 1." Not sure that I fully understand
> > > this. I
> > > > > > think
> > > > > > > >>>>>>>>> you
> > > > > > > >>>>>>>>> mean
> > > > > > > >>>>>>>>> that a consumer application can run more instances
> than
> > > the
> > > > > > > number
> > > > > > > >>>>>>>>> of
> > > > > > > >>>>>>>>> partitions. In that case, the consumer can just
> > > > > repartitioning
> > > > > > > the
> > > > > > > >>>>>>>>> input
> > > > > > > >>>>>>>>> data according to the number of instances. This is
> > > > possible,
> > > > > > but
> > > > > > > >>>>>>>>> just
> > > > > > > >>>>>>>>> has
> > > > > > > >>>>>>>>> the overhead of reshuffling the data.
> > > > > > > >>>>>>>>>
> > > > > > > >>>>>>>>> No what I meant is ( that is also your question i
> think
> > > > > > Mathias)
> > > > > > > >>>>>>>>> that
> > > > > > > >>>>>>>>> if
> > > > > > > >>>>>>>>>
> > > > > > > >>>>>>>>> you grow a topic by a factor.
> > > > > > > >>>>>>>> Even if your processor is statefull you can can just
> > > assign
> > > > > all
> > > > > > > the
> > > > > > > >>>>>>>> multiples of the previous partition to
> > > > > > > >>>>>>>> this consumer and the state to keep processing
> correctly
> > > > will
> > > > > be
> > > > > > > >>>>>>>> present
> > > > > > > >>>>>>>> w/o any shuffling.
> > > > > > > >>>>>>>>
> > > > > > > >>>>>>>> Say you have an assignment
> > > > > > > >>>>>>>> Statefull consumer => partition
> > > > > > > >>>>>>>> 0 => 0
> > > > > > > >>>>>>>> 1 => 1
> > > > > > > >>>>>>>> 2 => 2
> > > > > > > >>>>>>>>
> > > > > > > >>>>>>>> and you grow you topic by 4 you get,
> > > > > > > >>>>>>>>
> > > > > > > >>>>>>>> 0 => 0,3,6,9
> > > > > > > >>>>>>>> 1 => 1,4,7,10
> > > > > > > >>>>>>>> 2 => 2,5,8,11
> > > > > > > >>>>>>>>
> > > > > > > >>>>>>>> Say your hashcode is 8. 8%3 => 2  before so consumer
> for
> > > > > > > partition 2
> > > > > > > >>>>>>>> has
> > > > > > > >>>>>>>> it.
> > > > > > > >>>>>>>> Now you you have 12 partitions so 8%12 => 8, so it
> goes
> > > into
> > > > > > > >>>>>>>> partition
> > > > > > > >>>>>>>> 8
> > > > > > > >>>>>>>> which is assigned to the same consumer
> > > > > > > >>>>>>>> who had 2 before and therefore knows the key.
> > > > > > > >>>>>>>>
> > > > > > > >>>>>>>> Userland reshuffeling is there as an options. And it
> > does
> > > > > > exactly
> > > > > > > >>>>>>>> what
> > > > > > > >>>>>>>> I
> > > > > > > >>>>>>>> suggest. And I think its the perfect strategie. All I
> am
> > > > > > > suggestion
> > > > > > > >>>>>>>> is
> > > > > > > >>>>>>>> broker side support to switch the producers to the
> newly
> > > > > > > partitioned
> > > > > > > >>>>>>>> topic.
> > > > > > > >>>>>>>> Then the old (to few partition topic) can go away.
> > > Remember
> > > > > the
> > > > > > > >>>>>>>> list
> > > > > > > >>>>>>>> of
> > > > > > > >>>>>>>> steps in the beginning of this thread. If one has
> broker
> > > > > support
> > > > > > > for
> > > > > > > >>>>>>>> all
> > > > > > > >>>>>>>> where its required and streams support for those that
> > > aren’t
> > > > > > > >>>>>>>> necessarily.
> > > > > > > >>>>>>>> Then one has solved the problem.
> > > > > > > >>>>>>>> I repeat it because I think its important. I am really
> > > happy
> > > > > > that
> > > > > > > >>>>>>>> you
> > > > > > > >>>>>>>> brought that up! because its 100% what I want just
> with
> > > the
> > > > > > > >>>>>>>> differences
> > > > > > > >>>>>>>> to
> > > > > > > >>>>>>>> have an option to discard the to small topic later
> > (after
> > > > all
> > > > > > > >>>>>>>> consumers
> > > > > > > >>>>>>>> adapted). And to have order correct there. I need
> broker
> > > > > support
> > > > > > > >>>>>>>> managing
> > > > > > > >>>>>>>> the copy process + the produces and fence them against
> > > each
> > > > > > > other. I
> > > > > > > >>>>>>>> also
> > > > > > > >>>>>>>> repeat. the copy process can run for weeks in the
> worst
> > > > case.
> > > > > > > >>>>>>>> Copying
> > > > > > > >>>>>>>> the
> > > > > > > >>>>>>>> data is not the longest task migrating consumers might
> > > very
> > > > > well
> > > > > > > be.
> > > > > > > >>>>>>>> Once all consumers switched and copying is really up
> to
> > > date
> > > > > > > (think
> > > > > > > >>>>>>>> ISR
> > > > > > > >>>>>>>> like up to date) only then we stop the producer, wait
> > for
> > > > the
> > > > > > copy
> > > > > > > >>>>>>>> to
> > > > > > > >>>>>>>> finish and use the new topic for producing.
> > > > > > > >>>>>>>>
> > > > > > > >>>>>>>> After this the topic is perfect in shape. and no one
> > needs
> > > > to
> > > > > > > worry
> > > > > > > >>>>>>>> about
> > > > > > > >>>>>>>> complicated stuff. (old keys hanging around might
> arrive
> > > in
> > > > > some
> > > > > > > >>>>>>>> other
> > > > > > > >>>>>>>> topic later.....). can only imagine how many tricky
> bugs
> > > > gonna
> > > > > > > >>>>>>>> arrive
> > > > > > > >>>>>>>> after
> > > > > > > >>>>>>>> someone had grown and shrunken is topic 10 times.
> > > > > > > >>>>>>>>
> > > > > > > >>>>>>>>
> > > > > > > >>>>>>>>
> > > > > > > >>>>>>>>
> > > > > > > >>>>>>>>
> > > > > > > >>>>>>>>
> > > > > > > >>>>>>>> 54. "The other thing I wanted to mention is that I
> > believe
> > > > the
> > > > > > > >>>>>>>> current
> > > > > > > >>>>>>>>
> > > > > > > >>>>>>>> suggestion (without copying data over) can be
> > implemented
> > > in
> > > > > > pure
> > > > > > > >>>>>>>>> userland
> > > > > > > >>>>>>>>> with a custom partitioner and a small feedbackloop
> from
> > > > > > > >>>>>>>>> ProduceResponse
> > > > > > > >>>>>>>>> =>
> > > > > > > >>>>>>>>> Partitionier in coorporation with a change management
> > > > > system."
> > > > > > I
> > > > > > > am
> > > > > > > >>>>>>>>> not
> > > > > > > >>>>>>>>> sure a customized partitioner itself solves the
> > problem.
> > > We
> > > > > > > >>>>>>>>> probably
> > > > > > > >>>>>>>>> need
> > > > > > > >>>>>>>>> some broker side support to enforce when the new
> > > partitions
> > > > > can
> > > > > > > be
> > > > > > > >>>>>>>>> used.
> > > > > > > >>>>>>>>> We
> > > > > > > >>>>>>>>> also need some support on the consumer/kstream side
> to
> > > > > preserve
> > > > > > > the
> > > > > > > >>>>>>>>> per
> > > > > > > >>>>>>>>> key
> > > > > > > >>>>>>>>> ordering and potentially migrate the processing
> state.
> > > This
> > > > > is
> > > > > > > not
> > > > > > > >>>>>>>>> trivial
> > > > > > > >>>>>>>>> and I am not sure if it's ideal to fully push to the
> > > > > > application
> > > > > > > >>>>>>>>> space.
> > > > > > > >>>>>>>>>
> > > > > > > >>>>>>>>> Broker support is defenitly the preferred way here. I
> > > have
> > > > > > > nothing
> > > > > > > >>>>>>>>>
> > > > > > > >>>>>>>>> against
> > > > > > > >>>>>>>> broker support.
> > > > > > > >>>>>>>> I tried to say that for what I would preffer - copying
> > the
> > > > > data
> > > > > > > >>>>>>>> over,
> > > > > > > >>>>>>>> at
> > > > > > > >>>>>>>> least for log compacted topics -
> > > > > > > >>>>>>>> I would require more broker support than the KIP
> > currently
> > > > > > offers.
> > > > > > > >>>>>>>>
> > > > > > > >>>>>>>>
> > > > > > > >>>>>>>>
> > > > > > > >>>>>>>> Jun
> > > > > > > >>>>>>>>
> > > > > > > >>>>>>>> On Tue, Mar 6, 2018 at 10:33 PM, Jan Filipiak <
> > > > > > > >>>>>>>>> Jan.Filipiak@trivago.com
> > > > > > > >>>>>>>>> wrote:
> > > > > > > >>>>>>>>>
> > > > > > > >>>>>>>>> Hi Dong,
> > > > > > > >>>>>>>>>
> > > > > > > >>>>>>>>> are you actually reading my emails, or are you just
> > using
> > > > the
> > > > > > > >>>>>>>>> thread I
> > > > > > > >>>>>>>>>
> > > > > > > >>>>>>>>>> started for general announcements regarding the KIP?
> > > > > > > >>>>>>>>>>
> > > > > > > >>>>>>>>>> I tried to argue really hard against linear hashing.
> > > > Growing
> > > > > > the
> > > > > > > >>>>>>>>>> topic
> > > > > > > >>>>>>>>>> by
> > > > > > > >>>>>>>>>> an integer factor does not require any state
> > > > redistribution
> > > > > at
> > > > > > > >>>>>>>>>> all. I
> > > > > > > >>>>>>>>>> fail
> > > > > > > >>>>>>>>>> to see completely where linear hashing helps on log
> > > > > compacted
> > > > > > > >>>>>>>>>> topics.
> > > > > > > >>>>>>>>>>
> > > > > > > >>>>>>>>>> If you are not willing to explain to me what I might
> > be
> > > > > > > >>>>>>>>>> overlooking:
> > > > > > > >>>>>>>>>> that
> > > > > > > >>>>>>>>>> is fine.
> > > > > > > >>>>>>>>>> But I ask you to not reply to my emails then. Please
> > > > > > understand
> > > > > > > my
> > > > > > > >>>>>>>>>> frustration with this.
> > > > > > > >>>>>>>>>>
> > > > > > > >>>>>>>>>> Best Jan
> > > > > > > >>>>>>>>>>
> > > > > > > >>>>>>>>>>
> > > > > > > >>>>>>>>>>
> > > > > > > >>>>>>>>>> On 06.03.2018 19:38, Dong Lin wrote:
> > > > > > > >>>>>>>>>>
> > > > > > > >>>>>>>>>> Hi everyone,
> > > > > > > >>>>>>>>>>
> > > > > > > >>>>>>>>>> Thanks for all the comments! It appears that
> everyone
> > > > > prefers
> > > > > > > >>>>>>>>>> linear
> > > > > > > >>>>>>>>>>
> > > > > > > >>>>>>>>>>> hashing because it reduces the amount of state that
> > > needs
> > > > > to
> > > > > > be
> > > > > > > >>>>>>>>>>> moved
> > > > > > > >>>>>>>>>>> between consumers (for stream processing). The KIP
> > has
> > > > been
> > > > > > > >>>>>>>>>>> updated
> > > > > > > >>>>>>>>>>> to
> > > > > > > >>>>>>>>>>> use
> > > > > > > >>>>>>>>>>> linear hashing.
> > > > > > > >>>>>>>>>>>
> > > > > > > >>>>>>>>>>> Regarding the migration endeavor: it seems that
> > > migrating
> > > > > > > >>>>>>>>>>> producer
> > > > > > > >>>>>>>>>>> library
> > > > > > > >>>>>>>>>>> to use linear hashing should be pretty
> > straightforward
> > > > > > without
> > > > > > > >>>>>>>>>>> much operational endeavor. If we don't upgrade
> client
> > > > > library
> > > > > > > to
> > > > > > > >>>>>>>>>>> use
> > > > > > > >>>>>>>>>>> this
> > > > > > > >>>>>>>>>>> KIP, we can not support in-order delivery after
> > > partition
> > > > > is
> > > > > > > >>>>>>>>>>> changed
> > > > > > > >>>>>>>>>>> anyway. Suppose we upgrade client library to use
> this
> > > > KIP,
> > > > > if
> > > > > > > >>>>>>>>>>> partition
> > > > > > > >>>>>>>>>>> number is not changed, the key -> partition mapping
> > > will
> > > > be
> > > > > > > >>>>>>>>>>> exactly
> > > > > > > >>>>>>>>>>> the
> > > > > > > >>>>>>>>>>> same as it is now because it is still determined
> > using
> > > > > > > >>>>>>>>>>> murmur_hash(key)
> > > > > > > >>>>>>>>>>> %
> > > > > > > >>>>>>>>>>> original_partition_num. In other words, this change
> > is
> > > > > > backward
> > > > > > > >>>>>>>>>>> compatible.
> > > > > > > >>>>>>>>>>>
> > > > > > > >>>>>>>>>>> Regarding the load distribution: if we use linear
> > > > hashing,
> > > > > > the
> > > > > > > >>>>>>>>>>> load
> > > > > > > >>>>>>>>>>> may
> > > > > > > >>>>>>>>>>> be
> > > > > > > >>>>>>>>>>> unevenly distributed because those partitions which
> > are
> > > > not
> > > > > > > split
> > > > > > > >>>>>>>>>>> may
> > > > > > > >>>>>>>>>>> receive twice as much traffic as other partitions
> > that
> > > > are
> > > > > > > split.
> > > > > > > >>>>>>>>>>> This
> > > > > > > >>>>>>>>>>> issue can be mitigated by creating topic with
> > > partitions
> > > > > that
> > > > > > > are
> > > > > > > >>>>>>>>>>> several
> > > > > > > >>>>>>>>>>> times the number of consumers. And there will be no
> > > > > imbalance
> > > > > > > if
> > > > > > > >>>>>>>>>>> the
> > > > > > > >>>>>>>>>>> partition number is always doubled. So this
> imbalance
> > > > seems
> > > > > > > >>>>>>>>>>> acceptable.
> > > > > > > >>>>>>>>>>>
> > > > > > > >>>>>>>>>>> Regarding storing the partition strategy as
> per-topic
> > > > > config:
> > > > > > > It
> > > > > > > >>>>>>>>>>> seems
> > > > > > > >>>>>>>>>>> not
> > > > > > > >>>>>>>>>>> necessary since we can still use murmur_hash as the
> > > > default
> > > > > > > hash
> > > > > > > >>>>>>>>>>> function
> > > > > > > >>>>>>>>>>> and additionally apply the linear hashing algorithm
> > if
> > > > the
> > > > > > > >>>>>>>>>>> partition
> > > > > > > >>>>>>>>>>> number
> > > > > > > >>>>>>>>>>> has increased. Not sure if there is any use-case
> for
> > > > > producer
> > > > > > > to
> > > > > > > >>>>>>>>>>> use a
> > > > > > > >>>>>>>>>>> different hash function. Jason, can you check if
> > there
> > > is
> > > > > > some
> > > > > > > >>>>>>>>>>> use-case
> > > > > > > >>>>>>>>>>> that I missed for using the per-topic partition
> > > strategy?
> > > > > > > >>>>>>>>>>>
> > > > > > > >>>>>>>>>>> Regarding how to reduce latency (due to state
> > > store/load)
> > > > > in
> > > > > > > >>>>>>>>>>> stream
> > > > > > > >>>>>>>>>>> processing consumer when partition number changes:
> I
> > > need
> > > > > to
> > > > > > > read
> > > > > > > >>>>>>>>>>> the
> > > > > > > >>>>>>>>>>> Kafka
> > > > > > > >>>>>>>>>>> Stream code to understand how Kafka Stream
> currently
> > > > > migrate
> > > > > > > >>>>>>>>>>> state
> > > > > > > >>>>>>>>>>> between
> > > > > > > >>>>>>>>>>> consumers when the application is added/removed
> for a
> > > > given
> > > > > > > job.
> > > > > > > >>>>>>>>>>> I
> > > > > > > >>>>>>>>>>> will
> > > > > > > >>>>>>>>>>> reply after I finish reading the documentation and
> > > code.
> > > > > > > >>>>>>>>>>>
> > > > > > > >>>>>>>>>>>
> > > > > > > >>>>>>>>>>> Thanks,
> > > > > > > >>>>>>>>>>> Dong
> > > > > > > >>>>>>>>>>>
> > > > > > > >>>>>>>>>>>
> > > > > > > >>>>>>>>>>> On Mon, Mar 5, 2018 at 10:43 AM, Jason Gustafson <
> > > > > > > >>>>>>>>>>> jason@confluent.io>
> > > > > > > >>>>>>>>>>> wrote:
> > > > > > > >>>>>>>>>>>
> > > > > > > >>>>>>>>>>> Great discussion. I think I'm wondering whether we
> > can
> > > > > > continue
> > > > > > > >>>>>>>>>>> to
> > > > > > > >>>>>>>>>>> leave
> > > > > > > >>>>>>>>>>>
> > > > > > > >>>>>>>>>>> Kafka agnostic to the partitioning strategy. The
> > > > challenge
> > > > > is
> > > > > > > >>>>>>>>>>>
> > > > > > > >>>>>>>>>>> communicating
> > > > > > > >>>>>>>>>>>> the partitioning logic from producers to consumers
> > so
> > > > that
> > > > > > the
> > > > > > > >>>>>>>>>>>> dependencies
> > > > > > > >>>>>>>>>>>> between each epoch can be determined. For the sake
> > of
> > > > > > > >>>>>>>>>>>> discussion,
> > > > > > > >>>>>>>>>>>> imagine
> > > > > > > >>>>>>>>>>>> you did something like the following:
> > > > > > > >>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>> 1. The name (and perhaps version) of a
> partitioning
> > > > > strategy
> > > > > > > is
> > > > > > > >>>>>>>>>>>> stored
> > > > > > > >>>>>>>>>>>> in
> > > > > > > >>>>>>>>>>>> topic configuration when a topic is created.
> > > > > > > >>>>>>>>>>>> 2. The producer looks up the partitioning strategy
> > > > before
> > > > > > > >>>>>>>>>>>> writing
> > > > > > > >>>>>>>>>>>> to
> > > > > > > >>>>>>>>>>>> a
> > > > > > > >>>>>>>>>>>> topic and includes it in the produce request (for
> > > > > fencing).
> > > > > > If
> > > > > > > >>>>>>>>>>>> it
> > > > > > > >>>>>>>>>>>> doesn't
> > > > > > > >>>>>>>>>>>> have an implementation for the configured
> strategy,
> > it
> > > > > > fails.
> > > > > > > >>>>>>>>>>>> 3. The consumer also looks up the partitioning
> > > strategy
> > > > > and
> > > > > > > >>>>>>>>>>>> uses it
> > > > > > > >>>>>>>>>>>> to
> > > > > > > >>>>>>>>>>>> determine dependencies when reading a new epoch.
> It
> > > > could
> > > > > > > either
> > > > > > > >>>>>>>>>>>> fail
> > > > > > > >>>>>>>>>>>> or
> > > > > > > >>>>>>>>>>>> make the most conservative dependency assumptions
> if
> > > it
> > > > > > > doesn't
> > > > > > > >>>>>>>>>>>> know
> > > > > > > >>>>>>>>>>>> how
> > > > > > > >>>>>>>>>>>> to
> > > > > > > >>>>>>>>>>>> implement the partitioning strategy. For the
> > consumer,
> > > > the
> > > > > > new
> > > > > > > >>>>>>>>>>>> interface
> > > > > > > >>>>>>>>>>>> might look something like this:
> > > > > > > >>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>> // Return the partition dependencies following an
> > > epoch
> > > > > bump
> > > > > > > >>>>>>>>>>>> Map<Integer, List<Integer>> dependencies(int
> > > > > > > >>>>>>>>>>>> numPartitionsBeforeEpochBump,
> > > > > > > >>>>>>>>>>>> int numPartitionsAfterEpochBump)
> > > > > > > >>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>> The unordered case then is just a particular
> > > > > implementation
> > > > > > > >>>>>>>>>>>> which
> > > > > > > >>>>>>>>>>>> never
> > > > > > > >>>>>>>>>>>> has
> > > > > > > >>>>>>>>>>>> any epoch dependencies. To implement this, we
> would
> > > need
> > > > > > some
> > > > > > > >>>>>>>>>>>> way
> > > > > > > >>>>>>>>>>>> for
> > > > > > > >>>>>>>>>>>> the
> > > > > > > >>>>>>>>>>>> consumer to find out how many partitions there
> were
> > in
> > > > > each
> > > > > > > >>>>>>>>>>>> epoch,
> > > > > > > >>>>>>>>>>>> but
> > > > > > > >>>>>>>>>>>> maybe that's not too unreasonable.
> > > > > > > >>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>> Thanks,
> > > > > > > >>>>>>>>>>>> Jason
> > > > > > > >>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>> On Mon, Mar 5, 2018 at 4:51 AM, Jan Filipiak <
> > > > > > > >>>>>>>>>>>> Jan.Filipiak@trivago.com
> > > > > > > >>>>>>>>>>>> wrote:
> > > > > > > >>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>> Hi Dong
> > > > > > > >>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>> thank you very much for your questions.
> > > > > > > >>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>> regarding the time spend copying data across:
> > > > > > > >>>>>>>>>>>>> It is correct that copying data from a topic with
> > one
> > > > > > > partition
> > > > > > > >>>>>>>>>>>>> mapping
> > > > > > > >>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>> to
> > > > > > > >>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>> a topic with a different partition mapping takes
> > way
> > > > > longer
> > > > > > > >>>>>>>>>>>>> than
> > > > > > > >>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>> we
> > > > > > > >>>>>>>>>>>> can
> > > > > > > >>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>> stop producers. Tens of minutes is a very
> optimistic
> > > > > > estimate
> > > > > > > >>>>>>>>>>>> here.
> > > > > > > >>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>> Many
> > > > > > > >>>>>>>>>>>>> people can not afford copy full steam and
> therefore
> > > > will
> > > > > > have
> > > > > > > >>>>>>>>>>>>> some
> > > > > > > >>>>>>>>>>>>> rate
> > > > > > > >>>>>>>>>>>>> limiting in place, this can bump the timespan
> into
> > > the
> > > > > > day's.
> > > > > > > >>>>>>>>>>>>> The
> > > > > > > >>>>>>>>>>>>> good
> > > > > > > >>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>> part
> > > > > > > >>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>> is that the vast majority of the data can be
> copied
> > > > while
> > > > > > the
> > > > > > > >>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>> producers
> > > > > > > >>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>> are
> > > > > > > >>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>> still going. One can then, piggyback the
> consumers
> > > > ontop
> > > > > of
> > > > > > > >>>>>>>>>>>>> this
> > > > > > > >>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>> timeframe,
> > > > > > > >>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>> by the method mentioned (provide them an mapping
> > from
> > > > > their
> > > > > > > old
> > > > > > > >>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>> offsets
> > > > > > > >>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>> to
> > > > > > > >>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>> new offsets in their repartitioned topics. In
> that
> > > way
> > > > we
> > > > > > > >>>>>>>>>>>>> separate
> > > > > > > >>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>> migration of consumers from migration of producers
> > > > > > (decoupling
> > > > > > > >>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>> these
> > > > > > > >>>>>>>>>>>>> is
> > > > > > > >>>>>>>>>>>>> what kafka is strongest at). The time to actually
> > > swap
> > > > > over
> > > > > > > the
> > > > > > > >>>>>>>>>>>>> producers
> > > > > > > >>>>>>>>>>>>> should be kept minimal by ensuring that when a
> swap
> > > > > attempt
> > > > > > > is
> > > > > > > >>>>>>>>>>>>> started
> > > > > > > >>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>> the
> > > > > > > >>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>> consumer copying over should be very close to the
> > log
> > > > end
> > > > > > and
> > > > > > > >>>>>>>>>>>>> is
> > > > > > > >>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>> expected
> > > > > > > >>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>> to finish within the next fetch. The operation
> > should
> > > > > have
> > > > > > a
> > > > > > > >>>>>>>>>>>>> time-out
> > > > > > > >>>>>>>>>>>>> and
> > > > > > > >>>>>>>>>>>>> should be "reattemtable".
> > > > > > > >>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>> Importance of logcompaction:
> > > > > > > >>>>>>>>>>>>> If a producer produces key A, to partiton 0, its
> > > > forever
> > > > > > > gonna
> > > > > > > >>>>>>>>>>>>> be
> > > > > > > >>>>>>>>>>>>> there,
> > > > > > > >>>>>>>>>>>>> unless it gets deleted. The record might sit in
> > there
> > > > for
> > > > > > > >>>>>>>>>>>>> years. A
> > > > > > > >>>>>>>>>>>>> new
> > > > > > > >>>>>>>>>>>>> producer started with the new partitions will
> fail
> > to
> > > > > > delete
> > > > > > > >>>>>>>>>>>>> the
> > > > > > > >>>>>>>>>>>>> record
> > > > > > > >>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>> in
> > > > > > > >>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>> the correct partition. Th record will be there
> > > forever
> > > > > and
> > > > > > > one
> > > > > > > >>>>>>>>>>>>> can
> > > > > > > >>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>> not
> > > > > > > >>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>> reliable bootstrap new consumers. I cannot see how
> > > > linear
> > > > > > > >>>>>>>>>>>> hashing
> > > > > > > >>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>> can
> > > > > > > >>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>> solve
> > > > > > > >>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>> this.
> > > > > > > >>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>> Regarding your skipping of userland copying:
> > > > > > > >>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>> 100%, copying the data across in userland is, as
> > far
> > > > as i
> > > > > > can
> > > > > > > >>>>>>>>>>>>> see,
> > > > > > > >>>>>>>>>>>>> only
> > > > > > > >>>>>>>>>>>>> a
> > > > > > > >>>>>>>>>>>>> usecase for log compacted topics. Even for
> > > > logcompaction
> > > > > +
> > > > > > > >>>>>>>>>>>>> retentions
> > > > > > > >>>>>>>>>>>>> it
> > > > > > > >>>>>>>>>>>>> should only be opt-in. Why did I bring it up? I
> > think
> > > > log
> > > > > > > >>>>>>>>>>>>> compaction
> > > > > > > >>>>>>>>>>>>> is
> > > > > > > >>>>>>>>>>>>> a
> > > > > > > >>>>>>>>>>>>> very important feature to really embrace kafka
> as a
> > > > "data
> > > > > > > >>>>>>>>>>>>> plattform".
> > > > > > > >>>>>>>>>>>>> The
> > > > > > > >>>>>>>>>>>>> point I also want to make is that copying data
> this
> > > way
> > > > > is
> > > > > > > >>>>>>>>>>>>> completely
> > > > > > > >>>>>>>>>>>>> inline with the kafka architecture. it only
> > consists
> > > of
> > > > > > > reading
> > > > > > > >>>>>>>>>>>>> and
> > > > > > > >>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>> writing
> > > > > > > >>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>> to topics.
> > > > > > > >>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>> I hope it clarifies more why I think we should aim
> > for
> > > > > more
> > > > > > > than
> > > > > > > >>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>> the
> > > > > > > >>>>>>>>>>>>> current KIP. I fear that once the KIP is done not
> > > much
> > > > > more
> > > > > > > >>>>>>>>>>>>> effort
> > > > > > > >>>>>>>>>>>>> will
> > > > > > > >>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>> be
> > > > > > > >>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>> taken.
> > > > > > > >>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>> On 04.03.2018 02:28, Dong Lin wrote:
> > > > > > > >>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>> Hey Jan,
> > > > > > > >>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>> In the current proposal, the consumer will be
> > blocked
> > > > on
> > > > > > > >>>>>>>>>>>>> waiting
> > > > > > > >>>>>>>>>>>>> for
> > > > > > > >>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>> other
> > > > > > > >>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>> consumers of the group to consume up to a given
> > > > offset.
> > > > > In
> > > > > > > >>>>>>>>>>>>>> most
> > > > > > > >>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>> cases,
> > > > > > > >>>>>>>>>>>>> all
> > > > > > > >>>>>>>>>>>>> consumers should be close to the LEO of the
> > > partitions
> > > > > when
> > > > > > > the
> > > > > > > >>>>>>>>>>>>> partition
> > > > > > > >>>>>>>>>>>>> expansion happens. Thus the time waiting should
> not
> > > be
> > > > > long
> > > > > > > >>>>>>>>>>>>> e.g.
> > > > > > > >>>>>>>>>>>>> on
> > > > > > > >>>>>>>>>>>>> the
> > > > > > > >>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>> order of seconds. On the other hand, it may take
> a
> > > long
> > > > > > time
> > > > > > > to
> > > > > > > >>>>>>>>>>>>> wait
> > > > > > > >>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>> for
> > > > > > > >>>>>>>>>>>>>> the entire partition to be copied -- the amount
> of
> > > > time
> > > > > is
> > > > > > > >>>>>>>>>>>>>> proportional
> > > > > > > >>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>> to
> > > > > > > >>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>> the amount of existing data in the partition,
> > which
> > > > can
> > > > > > take
> > > > > > > >>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>> tens of
> > > > > > > >>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>> minutes. So the amount of time that we stop
> > consumers
> > > > may
> > > > > > not
> > > > > > > >>>>>>>>>>>>> be
> > > > > > > >>>>>>>>>>>>> on
> > > > > > > >>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>> the
> > > > > > > >>>>>>>>>>>>>> same order of magnitude.
> > > > > > > >>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>> If we can implement this suggestion without
> > copying
> > > > data
> > > > > > > over
> > > > > > > >>>>>>>>>>>>>> in
> > > > > > > >>>>>>>>>>>>>> purse
> > > > > > > >>>>>>>>>>>>>> userland, it will be much more valuable. Do you
> > have
> > > > > ideas
> > > > > > > on
> > > > > > > >>>>>>>>>>>>>> how
> > > > > > > >>>>>>>>>>>>>> this
> > > > > > > >>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>> can
> > > > > > > >>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>> be done?
> > > > > > > >>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>> Not sure why the current KIP not help people who
> > > depend
> > > > > on
> > > > > > > log
> > > > > > > >>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>> compaction.
> > > > > > > >>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>> Could you elaborate more on this point?
> > > > > > > >>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>> Thanks,
> > > > > > > >>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>> Dong
> > > > > > > >>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>> On Wed, Feb 28, 2018 at 10:55 PM, Jan
> > > > > > > >>>>>>>>>>>>>> Filipiak<Jan.Filipiak@trivago.
> > > > > > > >>>>>>>>>>>>>> com
> > > > > > > >>>>>>>>>>>>>> wrote:
> > > > > > > >>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>> Hi Dong,
> > > > > > > >>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>> I tried to focus on what the steps are one can
> > > > currently
> > > > > > > >>>>>>>>>>>>>> perform
> > > > > > > >>>>>>>>>>>>>> to
> > > > > > > >>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>> expand
> > > > > > > >>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>>> or shrink a keyed topic while maintaining a top
> > > notch
> > > > > > > >>>>>>>>>>>>>>> semantics.
> > > > > > > >>>>>>>>>>>>>>> I can understand that there might be confusion
> > > about
> > > > > > > >>>>>>>>>>>>>>> "stopping
> > > > > > > >>>>>>>>>>>>>>> the
> > > > > > > >>>>>>>>>>>>>>> consumer". It is exactly the same as proposed
> in
> > > the
> > > > > KIP.
> > > > > > > >>>>>>>>>>>>>>> there
> > > > > > > >>>>>>>>>>>>>>> needs
> > > > > > > >>>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>>> to
> > > > > > > >>>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>>> be
> > > > > > > >>>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>> a time the producers agree on the new
> > partitioning.
> > > > The
> > > > > > > extra
> > > > > > > >>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>> semantics I
> > > > > > > >>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>>> want to put in there is that we have a
> > possibility
> > > to
> > > > > > wait
> > > > > > > >>>>>>>>>>>>>>> until
> > > > > > > >>>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>> all
> > > > > > > >>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>> the
> > > > > > > >>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>> existing data
> > > > > > > >>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>> is copied over into the new partitioning scheme.
> > > When
> > > > I
> > > > > > say
> > > > > > > >>>>>>>>>>>>> stopping
> > > > > > > >>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>> I
> > > > > > > >>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>>> think more of having a memory barrier that
> > ensures
> > > > the
> > > > > > > >>>>>>>>>>>>>>> ordering. I
> > > > > > > >>>>>>>>>>>>>>> am
> > > > > > > >>>>>>>>>>>>>>> still
> > > > > > > >>>>>>>>>>>>>>> aming for latencies  on the scale of leader
> > > > failovers.
> > > > > > > >>>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>>> Consumers have to explicitly adapt the new
> > > > partitioning
> > > > > > > >>>>>>>>>>>>>>> scheme
> > > > > > > >>>>>>>>>>>>>>> in
> > > > > > > >>>>>>>>>>>>>>> the
> > > > > > > >>>>>>>>>>>>>>> above scenario. The reason is that in these
> cases
> > > > where
> > > > > > you
> > > > > > > >>>>>>>>>>>>>>> are
> > > > > > > >>>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>>> dependent
> > > > > > > >>>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>>> on a particular partitioning scheme, you also
> > have
> > > > > other
> > > > > > > >>>>>>>>>>>>>>> topics
> > > > > > > >>>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>> that
> > > > > > > >>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>> have
> > > > > > > >>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>> co-partition enforcements or the kind
> -frequently.
> > > > > > Therefore
> > > > > > > >>>>>>>>>>>>>> all
> > > > > > > >>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>> your
> > > > > > > >>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>> other
> > > > > > > >>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>> input topics might need to grow accordingly.
> > > > > > > >>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>>> What I was suggesting was to streamline all
> these
> > > > > > > operations
> > > > > > > >>>>>>>>>>>>>>> as
> > > > > > > >>>>>>>>>>>>>>> best
> > > > > > > >>>>>>>>>>>>>>> as
> > > > > > > >>>>>>>>>>>>>>> possible to have "real" partition grow and
> > > shrinkage
> > > > > > going
> > > > > > > >>>>>>>>>>>>>>> on.
> > > > > > > >>>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>>> Migrating
> > > > > > > >>>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>>> the producers to a new partitioning scheme can
> be
> > > > much
> > > > > > more
> > > > > > > >>>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>> streamlined
> > > > > > > >>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>> with proper broker support for this. Migrating
> > > consumer
> > > > > is
> > > > > > a
> > > > > > > >>>>>>>>>>>>> step
> > > > > > > >>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>> that
> > > > > > > >>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>>> might be made completly unnecessary if - for
> > > example
> > > > > > > streams
> > > > > > > >>>>>>>>>>>>>>> -
> > > > > > > >>>>>>>>>>>>>>> takes
> > > > > > > >>>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>>> the
> > > > > > > >>>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>>> gcd as partitioning scheme instead of
> enforcing 1
> > > to
> > > > 1.
> > > > > > > >>>>>>>>>>>>>>> Connect
> > > > > > > >>>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>> consumers
> > > > > > > >>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>> and other consumers should be fine anyways.
> > > > > > > >>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>> I hope this makes more clear where I was aiming
> > at.
> > > > The
> > > > > > rest
> > > > > > > >>>>>>>>>>>>> needs
> > > > > > > >>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>> to
> > > > > > > >>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>> be
> > > > > > > >>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>>> figured out. The only danger i see is that when
> > we
> > > > are
> > > > > > > >>>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>> introducing
> > > > > > > >>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>> this
> > > > > > > >>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>> feature as supposed in the KIP, it wont help any
> > > people
> > > > > > > >>>>>>>>>>>>> depending
> > > > > > > >>>>>>>>>>>>> on
> > > > > > > >>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>> log
> > > > > > > >>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>>> compaction.
> > > > > > > >>>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>> The other thing I wanted to mention is that I
> > > believe
> > > > > the
> > > > > > > >>>>>>>>>>>>> current
> > > > > > > >>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>> suggestion (without copying data over) can be
> > > > implemented
> > > > > > in
> > > > > > > >>>>>>>>>>>>>> pure
> > > > > > > >>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>>> userland
> > > > > > > >>>>>>>>>>>>>>> with a custom partitioner and a small
> > feedbackloop
> > > > from
> > > > > > > >>>>>>>>>>>>>>> ProduceResponse
> > > > > > > >>>>>>>>>>>>>>> =>
> > > > > > > >>>>>>>>>>>>>>> Partitionier in coorporation with a change
> > > management
> > > > > > > system.
> > > > > > > >>>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>>> Best Jan
> > > > > > > >>>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>>> On 28.02.2018 07:13, Dong Lin wrote:
> > > > > > > >>>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>>> Hey Jan,
> > > > > > > >>>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>>> I am not sure if it is acceptable for producer
> to
> > > be
> > > > > > > stopped
> > > > > > > >>>>>>>>>>>>>>> for a
> > > > > > > >>>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>>> while,
> > > > > > > >>>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>>>> particularly for online application which
> > requires
> > > > low
> > > > > > > >>>>>>>>>>>>>>>> latency. I
> > > > > > > >>>>>>>>>>>>>>>> am
> > > > > > > >>>>>>>>>>>>>>>> also
> > > > > > > >>>>>>>>>>>>>>>> not sure how consumers can switch to a new
> > topic.
> > > > Does
> > > > > > > user
> > > > > > > >>>>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>>>> application
> > > > > > > >>>>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>>>> needs to explicitly specify a different topic
> > for
> > > > > > > >>>>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>>> producer/consumer
> > > > > > > >>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>> to
> > > > > > > >>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>> subscribe to? It will be helpful for discussion
> if
> > > you
> > > > > can
> > > > > > > >>>>>>>>>>>>> provide
> > > > > > > >>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>> more
> > > > > > > >>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>>> detail on the interface change for this
> solution.
> > > > > > > >>>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>>> Thanks,
> > > > > > > >>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>> Dong
> > > > > > > >>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>>> On Mon, Feb 26, 2018 at 12:48 AM, Jan
> > > > > > > >>>>>>>>>>>>>>>> Filipiak<Jan.Filipiak@trivago.
> > > > > > > >>>>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>>>> com
> > > > > > > >>>>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>>>> wrote:
> > > > > > > >>>>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>>> Hi,
> > > > > > > >>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>> just want to throw my though in. In general the
> > > > > > > functionality
> > > > > > > >>>>>>>>>>>>>> is
> > > > > > > >>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>>> very
> > > > > > > >>>>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>>>> usefull, we should though not try to find the
> > > > > > architecture
> > > > > > > >>>>>>>>>>>>>>>> to
> > > > > > > >>>>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>>>> hard
> > > > > > > >>>>>>>>>>>>>>>>> while
> > > > > > > >>>>>>>>>>>>>>>>> implementing.
> > > > > > > >>>>>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>>>>> The manual steps would be to
> > > > > > > >>>>>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>>>>> create a new topic
> > > > > > > >>>>>>>>>>>>>>>>> the mirrormake from the new old topic to the
> > new
> > > > > topic
> > > > > > > >>>>>>>>>>>>>>>>> wait for mirror making to catch up.
> > > > > > > >>>>>>>>>>>>>>>>> then put the consumers onto the new topic
> > > > > > > >>>>>>>>>>>>>>>>>            (having mirrormaker spit out a
> > mapping
> > > > > from
> > > > > > > old
> > > > > > > >>>>>>>>>>>>>>>>> offsets to
> > > > > > > >>>>>>>>>>>>>>>>> new
> > > > > > > >>>>>>>>>>>>>>>>> offsets:
> > > > > > > >>>>>>>>>>>>>>>>>                if topic is increased by
> factor
> > X
> > > > > there
> > > > > > is
> > > > > > > >>>>>>>>>>>>>>>>> gonna
> > > > > > > >>>>>>>>>>>>>>>>> be a
> > > > > > > >>>>>>>>>>>>>>>>> clean
> > > > > > > >>>>>>>>>>>>>>>>> mapping from 1 offset in the old topic to X
> > > offsets
> > > > > in
> > > > > > > the
> > > > > > > >>>>>>>>>>>>>>>>> new
> > > > > > > >>>>>>>>>>>>>>>>> topic,
> > > > > > > >>>>>>>>>>>>>>>>>                if there is no factor then
> there
> > > is
> > > > no
> > > > > > > >>>>>>>>>>>>>>>>> chance to
> > > > > > > >>>>>>>>>>>>>>>>> generate a
> > > > > > > >>>>>>>>>>>>>>>>> mapping that can be reasonable used for
> > > continuing)
> > > > > > > >>>>>>>>>>>>>>>>>            make consumers stop at appropriate
> > > > points
> > > > > > and
> > > > > > > >>>>>>>>>>>>>>>>> continue
> > > > > > > >>>>>>>>>>>>>>>>> consumption
> > > > > > > >>>>>>>>>>>>>>>>> with offsets from the mapping.
> > > > > > > >>>>>>>>>>>>>>>>> have the producers stop for a minimal time.
> > > > > > > >>>>>>>>>>>>>>>>> wait for mirrormaker to finish
> > > > > > > >>>>>>>>>>>>>>>>> let producer produce with the new metadata.
> > > > > > > >>>>>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>>>>> Instead of implementing the approach suggest
> in
> > > the
> > > > > KIP
> > > > > > > >>>>>>>>>>>>>>>>> which
> > > > > > > >>>>>>>>>>>>>>>>> will
> > > > > > > >>>>>>>>>>>>>>>>> leave
> > > > > > > >>>>>>>>>>>>>>>>> log compacted topic completely crumbled and
> > > > unusable.
> > > > > > > >>>>>>>>>>>>>>>>> I would much rather try to build
> infrastructure
> > > to
> > > > > > > support
> > > > > > > >>>>>>>>>>>>>>>>> the
> > > > > > > >>>>>>>>>>>>>>>>> mentioned
> > > > > > > >>>>>>>>>>>>>>>>> above operations more smoothly.
> > > > > > > >>>>>>>>>>>>>>>>> Especially having producers stop and use
> > another
> > > > > topic
> > > > > > is
> > > > > > > >>>>>>>>>>>>>>>>> difficult
> > > > > > > >>>>>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>>>>> and
> > > > > > > >>>>>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>>>>> it would be nice if one can trigger "invalid
> > > > > metadata"
> > > > > > > >>>>>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>>>> exceptions
> > > > > > > >>>>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>>>> for
> > > > > > > >>>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>> them
> > > > > > > >>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>> and
> > > > > > > >>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>>> if one could give topics aliases so that their
> > > > produces
> > > > > > > with
> > > > > > > >>>>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>>>>> the
> > > > > > > >>>>>>>>>>>>>>>>> old
> > > > > > > >>>>>>>>>>>>>>>>> topic
> > > > > > > >>>>>>>>>>>>>>>>> will arrive in the new topic.
> > > > > > > >>>>>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>>>>> The downsides are obvious I guess ( having
> the
> > > same
> > > > > > data
> > > > > > > >>>>>>>>>>>>>>>>> twice
> > > > > > > >>>>>>>>>>>>>>>>> for
> > > > > > > >>>>>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>>>>> the
> > > > > > > >>>>>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>>>>> transition period, but kafka tends to scale
> > well
> > > > with
> > > > > > > >>>>>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>>>> datasize).
> > > > > > > >>>>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>>>> So
> > > > > > > >>>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>>> its a
> > > > > > > >>>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>> nicer fit into the architecture.
> > > > > > > >>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>>> I further want to argument that the
> functionality
> > > by
> > > > > the
> > > > > > > KIP
> > > > > > > >>>>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>>>>> can
> > > > > > > >>>>>>>>>>>>>>>>> completely be implementing in "userland"
> with a
> > > > > custom
> > > > > > > >>>>>>>>>>>>>>>>> partitioner
> > > > > > > >>>>>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>>>>> that
> > > > > > > >>>>>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>>>>> handles the transition as needed. I would
> > > > appreciate
> > > > > if
> > > > > > > >>>>>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>>>> someone
> > > > > > > >>>>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>>>> could
> > > > > > > >>>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>> point
> > > > > > > >>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>> out what a custom partitioner couldn't handle in
> > this
> > > > > case?
> > > > > > > >>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>>> With the above approach, shrinking a topic
> > becomes
> > > > the
> > > > > > same
> > > > > > > >>>>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>>>>> steps.
> > > > > > > >>>>>>>>>>>>>>>>> Without
> > > > > > > >>>>>>>>>>>>>>>>> loosing keys in the discontinued partitions.
> > > > > > > >>>>>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>>>>> Would love to hear what everyone thinks.
> > > > > > > >>>>>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>>>>> Best Jan
> > > > > > > >>>>>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>>>>> On 11.02.2018 00:35, Dong Lin wrote:
> > > > > > > >>>>>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>>>>> Hi all,
> > > > > > > >>>>>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>>>>> I have created KIP-253: Support in-order
> > message
> > > > > > delivery
> > > > > > > >>>>>>>>>>>>>>>>> with
> > > > > > > >>>>>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>>>>> partition
> > > > > > > >>>>>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>>>>> expansion. See
> > > > > > > >>>>>>>>>>>>>>>>>> https://cwiki.apache.org/confl
> > > > > > > >>>>>>>>>>>>>>>>>> uence/display/KAFKA/KIP-253%
> > > > > > > >>>>>>>>>>>>>>>>>> 3A+Support+in-order+message+de
> > > > > > > >>>>>>>>>>>>>>>>>> livery+with+partition+expansio
> > > > > > > >>>>>>>>>>>>>>>>>> n
> > > > > > > >>>>>>>>>>>>>>>>>> .
> > > > > > > >>>>>>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>>>>>> This KIP provides a way to allow messages of
> > the
> > > > > same
> > > > > > > key
> > > > > > > >>>>>>>>>>>>>>>>>> from
> > > > > > > >>>>>>>>>>>>>>>>>> the
> > > > > > > >>>>>>>>>>>>>>>>>> same
> > > > > > > >>>>>>>>>>>>>>>>>> producer to be consumed in the same order
> they
> > > are
> > > > > > > >>>>>>>>>>>>>>>>>> produced
> > > > > > > >>>>>>>>>>>>>>>>>> even
> > > > > > > >>>>>>>>>>>>>>>>>> if
> > > > > > > >>>>>>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>>>>>> we
> > > > > > > >>>>>>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>>>>>> expand partition of the topic.
> > > > > > > >>>>>>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>>>>> Thanks,
> > > > > > > >>>>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>>> Dong
> > > > > > > >>>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>>>>>>
> > > > > > > >>>>>>>>>>>>>>>>>>
> > > > > > > >>>>
> > > > > > > >>
> > > > > > > >>
> > > > > > > >
> > > > > > >
> > > > > >
> > > > >
> > > >
> > >
> >
>
>
>
> --
> -- Guozhang
>

Re: [DISCUSS] KIP-253: Support in-order message delivery with partition expansion

Posted by Guozhang Wang <wa...@gmail.com>.
Hey guys, just sharing my two cents here (I promise it will be shorter than
John's article :).

0. Just to quickly recap, the main discussion point now is how to support
"key partitioning preservation" (John's #4 in topic characteristics above)
beyond the "single-key ordering preservation" that KIP-253 was originally
proposed to maintain (John's #6 above).

1. From the streams project, we are actively working on improving the
elastic scalability of the library. One of the key features is to decouple
the input topics from the parallelism model of Streams: i.e. not enforcing
the topic to be partitioned by the key, not enforcing joining topics to be
co-partitioned, not relying the number of parallel tasks on the input topic
partitions. This can be achieved by re-shuffling on the input topics to
make sure key-partitioning / co-partitioning on the internal topics. Note
the re-shuffling task is purely stateless and hence does not require "key
partitioning preservation". Operational-wise it is similar to the "creating
a new topic with new number of partitions, pipe the data to the new topic
and cut over consumers from old topics" idea, just that users can
optionally let Streams to handle such rather than doing it manually
themselves. There are a few more details on that regard but I will skip
since they are not directly related to this discussion.

2. Assuming that 1) above is done, then the only topics involved in the
scaling events are all input topics. For these topics the only producers /
consumers of these topics are controlled by Streams clients themselves, and
hence achieving "key partitioning preservation" is simpler than non-Streams
scenarios: consumers know the partitioning scheme that producers are using,
so that for their stateful operations it is doable to split the local state
stores accordingly or execute backfilling on its own. Of course, if we
decide to do server-side backfilling, it can still help Streams to directly
rely on that functionality.

3. As John mentioned, another way inside Streams is to do over-partitioning
on all internal topics; then with 1) Streams would not rely on KIP-253 at
all. But personally I'd like to avoid it if possible to reduce Kafka side
footprint: say we overpartition each input topic up to 1k, with a
reasonable sized stateful topology it can still contribute to tens of
thousands of topics to the topic partition capacity of a single cluster.

4. Summing up 1/2/3, I think we should focus more on non-Streams users
writing their stateful computations with local states, and think whether /
how we could enable "key partitioning preservation" for them easily, than
to think heavily for Streams library. People may have different opinion on
how common of a usage pattern it is (I think Jun might be suggesting that
for DIY apps people may more likely use remote states so that it is not a
problem for them). My opinion is that for non-Streams users such usage
pattern could still be large (think: if you are piping data from Kafka to
an external data storage which has single-writer requirements for each
single shard, even though it is not a stateful computational application it
may still require "key partitioning preservation"), so I prefer to have
backfilling in our KIP than only exposing the API for expansion and
requires consumers to have pre-knowledge of the producer's partitioning
scheme.



Guozhang



On Thu, Mar 29, 2018 at 2:33 PM, John Roesler <jo...@confluent.io> wrote:

> Hey Dong,
>
> Congrats on becoming a committer!!!
>
> Since I just sent a novel-length email, I'll try and keep this one brief ;)
>
> Regarding producer coordination, I'll grant that in that case, producers
> may coordinate among themselves to produce into the same topic or to
> produce co-partitioned topics. Nothing in KStreams or the Kafka ecosystem
> in general requires such coordination for correctness or in fact for any
> optional features, though, so I would not say that we require producer
> coordination of partition logic. If producers currently coordinate, it's
> completely optional and their own choice.
>
> Regarding the portability of partition algorithms, my observation is that
> systems requiring independent implementations of the same algorithm with
> 100% correctness are a large source of risk and also a burden on those who
> have to maintain them. If people could flawlessly implement algorithms in
> actual software, the world would be a wonderful place indeed! For a system
> as important and widespread as Kafka, I would recommend restricting
> limiting such requirements as aggressively as possible.
>
> I'd agree that we can always revisit decisions like allowing arbitrary
> partition functions, but of course, we shouldn't do that in a vacuum. That
> feels like the kind of thing we'd need to proactively seek guidance from
> the users list about. I do think that the general approach of saying that
> "if you use a custom partitioner, you cannot do partition expansion" is
> very reasonable (but I don't think we need to go that far with the current
> proposal). It's similar to my statement in my email to Jun that in
> principle KStreams doesn't *need* backfill, we only need it if we want to
> employ partition expansion.
>
> I reckon that the main motivation for backfill is to support KStreams use
> cases and also any other use cases involving stateful consumers.
>
> Thanks for your response, and congrats again!
> -John
>
>
> On Wed, Mar 28, 2018 at 1:34 AM, Dong Lin <li...@gmail.com> wrote:
>
> > Hey John,
> >
> > Great! Thanks for all the comment. It seems that we agree that the
> current
> > KIP is in good shape for core Kafka. IMO, what we have been discussing in
> > the recent email exchanges is mostly about the second step, i.e. how to
> > address problem for the stream use-case (or stateful processing in
> > general).
> >
> > I will comment inline.
> >
> >
> >
> >
> > On Tue, Mar 27, 2018 at 4:38 PM, John Roesler <jo...@confluent.io> wrote:
> >
> > > Thanks for the response, Dong.
> > >
> > > Here are my answers to your questions:
> > >
> > > - "Asking producers and consumers, or even two different producers, to
> > > > share code like the partition function is a pretty huge ask. What if
> > they
> > > > are using different languages?". It seems that today we already
> require
> > > > different producer's to use the same hash function -- otherwise
> > messages
> > > > with the same key will go to different partitions of the same topic
> > which
> > > > may cause problem for downstream consumption. So not sure if it adds
> > any
> > > > more constraint by assuming consumers know the hash function of
> > producer.
> > > > Could you explain more why user would want to use a cusmtom partition
> > > > function? Maybe we can check if this is something that can be
> supported
> > > in
> > > > the default Kafka hash function. Also, can you explain more why it is
> > > > difficuilt to implement the same hash function in different
> languages?
> > >
> > >
> > > Sorry, I meant two different producers as in producers to two different
> > > topics. This was in response to the suggestion that we already require
> > > coordination among producers to different topics in order to achieve
> > > co-partitioning. I was saying that we do not (and should not).
> >
> >
> > It is probably common for producers of different team to produce message
> to
> > the same topic. In order to ensure that messages with the same key go to
> > same partition, we need producers of different team to share the same
> > partition algorithm, which by definition requires coordination among
> > producers of different teams in an organization. Even for producers of
> > different topics, it may be common to require producers to use the same
> > partition algorithm in order to join two topics for stream processing.
> Does
> > this make it reasonable to say we already require coordination across
> > producers?
> >
> >
> > > By design, consumers are currently ignorant of the partitioning scheme.
> > It
> > > suffices to trust that the producer has partitioned the topic by key,
> if
> > > they claim to have done so. If you don't trust that, or even if you
> just
> > > need some other partitioning scheme, then you must re-partition it
> > > yourself. Nothing we're discussing can or should change that. The value
> > of
> > > backfill is that it preserves the ability for consumers to avoid
> > > re-partitioning before consuming, in the case where they don't need to
> > > today.
> >
> >
> > > Regarding shared "hash functions", note that it's a bit inaccurate to
> > talk
> > > about the "hash function" of the producer. Properly speaking, the
> > producer
> > > has only a "partition function". We do not know that it is a hash. The
> > > producer can use any method at their disposal to assign a partition to
> a
> > > record. The partition function obviously may we written in any
> > programming
> > > language, so in general it's not something that can be shared around
> > > without a formal spec or the ability to execute arbitrary executables
> in
> > > arbitrary runtime environments.
> > >
> >
> > Yeah it is probably better to say partition algorithm. I guess it should
> > not be difficult to implement same partition algorithms in different
> > languages, right? Yes we would need a formal specification of the default
> > partition algorithm in the producer. I think that can be documented as
> part
> > of the producer interface.
> >
> >
> > >
> > > Why would a producer want a custom partition function? I don't know...
> > why
> > > did we design the interface so that our users can provide one? In
> > general,
> > > such systems provide custom partitioners because some data sets may be
> > > unbalanced under the default or because they can provide some
> interesting
> > > functionality built on top of the partitioning scheme, etc. Having
> > provided
> > > this ability, I don't know why we would remove it.
> > >
> >
> > Yeah it is reasonable to assume that there was reason to support custom
> > partition function in producer. On the other hand it may also be
> reasonable
> > to revisit this interface and discuss whether we actually need to support
> > custom partition function. If we don't have a good reason, we can choose
> > not to support custom partition function in this KIP in a backward
> > compatible manner, i.e. user can still use custom partition function but
> > they would not get the benefit of in-order delivery when there is
> partition
> > expansion. What do you think?
> >
> >
> > >
> > > - Besides the assumption that consumer needs to share the hash function
> > of
> > > > producer, is there other organization overhead of the proposal in the
> > > > current KIP?
> > > >
> > >
> > > It wasn't clear to me that KIP-253 currently required the producer and
> > > consumer to share the partition function, or in fact that it had a hard
> > > requirement to abandon the general partition function and use a linear
> > hash
> > > function instead.
> >
> >
> > > In my reading, there is a requirement to track the metadata about what
> > > partitions split into what other partitions during an expansion
> > operation.
> > > If the partition function is linear, this is easy. If not, you can
> always
> > > just record that all old partitions split into all new partitions. This
> > has
> > > the effect of forcing all consumers to wait until the old epoch is
> > > completely consumed before starting on the new epoch. But this may be a
> > > reasonable tradeoff, and it doesn't otherwise alter your design.
> > >
> > > You only mention the consumer needing to know that the partition
> function
> > > is linear, not what the actual function is, so I don't think your
> design
> > > actually calls for sharing the function. Plus, really all the consumer
> > > needs is the metadata about what old-epoch partitions to wait for
> before
> > > consuming a new-epoch partition. This information is directly captured
> in
> > > metadata, so I don't think it actually even cares whether the partition
> > > function is linear or not.
> > >
> >
> > You are right that the current KIP does not mention it. My comment
> related
> > to the partition function coordination was related to support the
> > stream-use case which we have been discussing so far.
> >
> >
> > > So, no, I really think KIP-253 is in good shape. I was really more
> > talking
> > > about the part of this thread that's outside of KIP-253's scope,
> namely,
> > > creating the possibility of backfilling partitions after expansion.
> > >
> >
> > Great! Can you also confirm that the main motivation for backfilling
> > partitions after expansion is to support the stream use-case?
> >
> >
> > > - Currently producer can forget about the message that has been
> > > > acknowledged by the broker. Thus the producer probably does not know
> > most
> > > > of the exiting messages in topic, including those messages produced
> by
> > > > other producers. We can have the owner of the producer to
> > split+backfill.
> > > > In my opion it will be a new program that wraps around the existing
> > > > producer and consumer classes.
> > > >
> > >
> > > This sounds fine by me!
> > >
> > > Really, I was just emphasizing that the part of the organization that
> > > produces a topic shouldn't have to export their partition function to
> the
> > > part(s) of the organization (or other organizations) that consume the
> > > topic. Whether the backfill operation goes into the Producer interface
> is
> > > secondary, I think.
> > >
> > > - Regarding point 5. The argument is in favor of the split+backfill but
> > for
> > > > changelog topic. And it intends to address the problem for stream
> > > use-case
> > > > in general. In this KIP we will provide interface (i.e.
> > > > PartitionKeyRebalanceListener in the KIP) to be used by sream
> use-case
> > > and
> > > > the goal is that user can flush/re-consume the state as part of the
> > > > interface implementation regardless of whether there is change log
> > topic.
> > > >
> > > > Maybe you are suggesting that the main reason to do split+backfill of
> > > input
> > > > topic is to support log compacted topics? You mentioned in Point 1
> that
> > > log
> > > > compacted topics is out of the scope of this KIP. Maybe I could
> > > understand
> > > > your position better. Regarding Jan's proposal to split partitions
> with
> > > > backfill, do you think this should replace the proposal in the
> existing
> > > > KIP, or do you think this is something that we should do in addition
> to
> > > the
> > > > existing KIP?
> > > >
> > >
> > > I think that interface is a good/necessary component of KIP-253.
> > >
> > > I personally (FWIW) feel that KIP-253 is appropriately scoped, but I do
> > > think its utility will be limited unless there is a later KIP offering
> > > backfill. But, maybe unlike Jan, I think it makes sense to try and
> tackle
> > > the ordering problem independently of backfill, so I'm in support of
> the
> > > current KIP.
> > >
> > > - Regarding point 6. I guess we can agree that it is better not to have
> > the
> > > > performance overhread of copying the input data. Before we discuss
> more
> > > on
> > > > whether the performance overhead is acceptable or not, I am trying to
> > > > figure out what is the benefit of introducing this overhread. You
> > > mentioned
> > > > that the benefit is the loose organizational coupling. By
> > "organizational
> > > > coupling", are you referring to the requirement that consumer needs
> to
> > > know
> > > > the hash function of producer? If so, maybe we can discuss the
> use-case
> > > of
> > > > custom partiton function and see whether we can find a way to support
> > > such
> > > > use-case without having to copy the input data.
> > > >
> > >
> > > I'm not too sure about what an "input" is in this sense, since we are
> > just
> > > talking about topics. Actually the point I was making there is that
> > AKAICT
> > > the performance overhead of a backfill is less than any other option,
> > > assuming you split partitions rarely.
> > >
> >
> > By "input" I was referring to source Kafka topic of a stream processing
> > job.
> >
> >
> > > Separately, yes, "organizational coupling" increases if producers and
> > > consumers have to share code, such as the partition function. This
> would
> > > not be the case if producers could only pick from a menu of a few
> > > well-known partition functions, but I think this is a poor tradeoff.
> > >
> >
> > Maybe we can revisit the custom partition function and see whether we
> > actually need it? Otherwise, I am concerned that every user will pay the
> > overhead of data movement to support something that was not really needed
> > for most users.
> >
> >
> > >
> > > To me, this is two strong arguments in favor of backfill being less
> > > expensive than no backfill, but again, I think that particular debate
> > comes
> > > after KIP-253, so I don't want to create the impression of opposition
> to
> > > your proposal.
> > >
> > >
> > > Finally, to respond to a new email I just noticed:
> > >
> > > > BTW, here is my understanding of the scope of this KIP. We want to
> > allow
> > > > consumers to always consume messages with the same key from the same
> > > > producer in the order they are produced. And we need to provide a way
> > for
> > > > stream use-case to be able to flush/load state when messages with the
> > > same
> > > > key are migrated between consumers. In addition to ensuring that this
> > > goal
> > > > is correctly supported, we should do our best to keep the performance
> > and
> > > > organization overhead of this KIP as low as possible.
> > > >
> > >
> > > I think we're on the same page there! In fact, I would generalize a
> > little
> > > more and say that the mechanism you've designed provides *all
> consumers*
> > > the ability "to flush/load state when messages with the same key are
> > > migrated between consumers", not just Streams.
> > >
> >
> > Thanks for all the comment!
> >
> >
> > >
> > > Thanks for the discussion,
> > > -John
> > >
> > >
> > >
> > > On Tue, Mar 27, 2018 at 3:14 PM, Dong Lin <li...@gmail.com> wrote:
> > >
> > > > Hey John,
> > > >
> > > > Thanks much for the detailed comments. Here are my thoughts:
> > > >
> > > > - The need to delete messages from log compacted topics is mainly for
> > > > performance (e.g. storage space) optimization than for correctness
> for
> > > this
> > > > KIP. I agree that we probably don't need to focus on this in our
> > > discussion
> > > > since it is mostly for performance optimization.
> > > >
> > > > - "Asking producers and consumers, or even two different producers,
> to
> > > > share code like the partition function is a pretty huge ask. What if
> > they
> > > > are using different languages?". It seems that today we already
> require
> > > > different producer's to use the same hash function -- otherwise
> > messages
> > > > with the same key will go to different partitions of the same topic
> > which
> > > > may cause problem for downstream consumption. So not sure if it adds
> > any
> > > > more constraint by assuming consumers know the hash function of
> > producer.
> > > > Could you explain more why user would want to use a cusmtom partition
> > > > function? Maybe we can check if this is something that can be
> supported
> > > in
> > > > the default Kafka hash function. Also, can you explain more why it is
> > > > difficuilt to implement the same hash function in different
> languages?
> > > >
> > > > - Besides the assumption that consumer needs to share the hash
> function
> > > of
> > > > producer, is there other organization overhead of the proposal in the
> > > > current KIP?
> > > >
> > > > - Currently producer can forget about the message that has been
> > > > acknowledged by the broker. Thus the producer probably does not know
> > most
> > > > of the exiting messages in topic, including those messages produced
> by
> > > > other producers. We can have the owner of the producer to
> > split+backfill.
> > > > In my opion it will be a new program that wraps around the existing
> > > > producer and consumer classes.
> > > >
> > > > - Regarding point 5. The argument is in favor of the split+backfill
> but
> > > for
> > > > changelog topic. And it intends to address the problem for stream
> > > use-case
> > > > in general. In this KIP we will provide interface (i.e.
> > > > PartitionKeyRebalanceListener in the KIP) to be used by sream
> use-case
> > > and
> > > > the goal is that user can flush/re-consume the state as part of the
> > > > interface implementation regardless of whether there is change log
> > topic.
> > > >
> > > > Maybe you are suggesting that the main reason to do split+backfill of
> > > input
> > > > topic is to support log compacted topics? You mentioned in Point 1
> that
> > > log
> > > > compacted topics is out of the scope of this KIP. Maybe I could
> > > understand
> > > > your position better. Regarding Jan's proposal to split partitions
> with
> > > > backfill, do you think this should replace the proposal in the
> existing
> > > > KIP, or do you think this is something that we should do in addition
> to
> > > the
> > > > existing KIP?
> > > >
> > > > - Regarding point 6. I guess we can agree that it is better not to
> have
> > > the
> > > > performance overhread of copying the input data. Before we discuss
> more
> > > on
> > > > whether the performance overhead is acceptable or not, I am trying to
> > > > figure out what is the benefit of introducing this overhread. You
> > > mentioned
> > > > that the benefit is the loose organizational coupling. By
> > "organizational
> > > > coupling", are you referring to the requirement that consumer needs
> to
> > > know
> > > > the hash function of producer? If so, maybe we can discuss the
> use-case
> > > of
> > > > custom partiton function and see whether we can find a way to support
> > > such
> > > > use-case without having to copy the input data.
> > > >
> > > > Thanks,
> > > > Dong
> > > >
> > > >
> > > > On Tue, Mar 27, 2018 at 11:34 AM, John Roesler <jo...@confluent.io>
> > > wrote:
> > > >
> > > > > Hey Dong and Jun,
> > > > >
> > > > > Thanks for the thoughtful responses. If you don't mind, I'll mix my
> > > > replies
> > > > > together to try for a coherent response. I'm not too familiar with
> > > > > mailing-list etiquette, though.
> > > > >
> > > > > I'm going to keep numbering my points because it makes it easy for
> > you
> > > > all
> > > > > to respond.
> > > > >
> > > > > Point 1:
> > > > > As I read it, KIP-253 is *just* about properly fencing the
> producers
> > > and
> > > > > consumers so that you preserve the correct ordering of records
> during
> > > > > partition expansion. This is clearly necessary regardless of
> anything
> > > > else
> > > > > we discuss. I think this whole discussion about backfill,
> consumers,
> > > > > streams, etc., is beyond the scope of KIP-253. But it would be
> > > cumbersome
> > > > > to start a new thread at this point.
> > > > >
> > > > > I had missed KIP-253's Proposed Change #9 among all the details...
> I
> > > > think
> > > > > this is a nice addition to the proposal. One thought is that it's
> > > > actually
> > > > > irrelevant whether the hash function is linear. This is simply an
> > > > algorithm
> > > > > for moving a key from one partition to another, so the type of hash
> > > > > function need not be a precondition. In fact, it also doesn't
> matter
> > > > > whether the topic is compacted or not, the algorithm works
> > regardless.
> > > > >
> > > > > I think this is a good algorithm to keep in mind, as it might
> solve a
> > > > > variety of problems, but it does have a downside: that the producer
> > > won't
> > > > > know whether or not K1 was actually in P1, it just knows that K1
> was
> > in
> > > > > P1's keyspace before the new epoch. Therefore, it will have to
> > > > > pessimistically send (K1,null) to P1 just in case. But the next
> time
> > K1
> > > > > comes along, the producer *also* won't remember that it already
> > > retracted
> > > > > K1 from P1, so it will have to send (K1,null) *again*. By
> extension,
> > > > every
> > > > > time the producer sends to P2, it will also have to send a
> tombstone
> > to
> > > > P1,
> > > > > which is a pretty big burden. To make the situation worse, if there
> > is
> > > a
> > > > > second split, say P2 becomes P2 and P3, then any key Kx belonging
> to
> > P3
> > > > > will also have to be retracted from P2 *and* P1, since the producer
> > > can't
> > > > > know whether Kx had been last written to P2 or P1. Over a long
> period
> > > of
> > > > > time, this clearly becomes a issue, as the producer must send an
> > > > arbitrary
> > > > > number of retractions along with every update.
> > > > >
> > > > > In contrast, the proposed backfill operation has an end, and after
> it
> > > > ends,
> > > > > everyone can afford to forget that there ever was a different
> > partition
> > > > > layout.
> > > > >
> > > > > Really, though, figuring out how to split compacted topics is
> beyond
> > > the
> > > > > scope of KIP-253, so I'm not sure #9 really even needs to be in
> this
> > > > KIP...
> > > > > We do need in-order delivery during partition expansion. It would
> be
> > > fine
> > > > > by me to say that you *cannot* expand partitions of a log-compacted
> > > topic
> > > > > and call it a day. I think it would be better to tackle that in
> > another
> > > > > KIP.
> > > > >
> > > > >
> > > > > Point 2:
> > > > > Regarding whether the consumer re-shuffles its inputs, this is
> always
> > > on
> > > > > the table; any consumer who wants to re-shuffle its input is free
> to
> > do
> > > > so.
> > > > > But this is currently not required. It's just that the current
> > > high-level
> > > > > story with Kafka encourages the use of partitions as a unit of
> > > > concurrency.
> > > > > As long as consumers are single-threaded, they can happily consume
> a
> > > > single
> > > > > partition without concurrency control of any kind. This is a key
> > aspect
> > > > to
> > > > > this system that lets folks design high-throughput systems on top
> of
> > it
> > > > > surprisingly easily. If all consumers were instead
> > encouraged/required
> > > to
> > > > > implement a repartition of their own, then the consumer becomes
> > > > > significantly more complex, requiring either the consumer to first
> > > > produce
> > > > > to its own intermediate repartition topic or to ensure that
> consumer
> > > > > threads have a reliable, high-bandwith channel of communication
> with
> > > > every
> > > > > other consumer thread.
> > > > >
> > > > > Either of those tradeoffs may be reasonable for a particular user
> of
> > > > Kafka,
> > > > > but I don't know if we're in a position to say that they are
> > reasonable
> > > > for
> > > > > *every* user of Kafka.
> > > > >
> > > > >
> > > > > Point 3:
> > > > > Regarding Jun's point about this use case, "(3) stateful and
> > > maintaining
> > > > > the
> > > > > states in a local store", I agree that they may use a framework
> > *like*
> > > > > Kafka Streams, but that is not the same as using Kafka Streams.
> This
> > is
> > > > why
> > > > > I think it's better to solve it in Core: because it is then solved
> > for
> > > > > KStreams and also for everything else that facilitates local state
> > > > > maintenance. To me, Streams is a member of the category of "stream
> > > > > processing frameworks", which is itself a subcategory of "things
> > > > requiring
> > > > > local state maintenence". I'm not sure if it makes sense to assert
> > that
> > > > > Streams is a sufficient and practical replacement for everything in
> > > > "things
> > > > > requiring local state maintenence".
> > > > >
> > > > > But, yes, I do agree that per-key ordering is an absolute
> > requirement,
> > > > > therefore I think that KIP-253 itself is a necessary step.
> Regarding
> > > the
> > > > > coupling of the state store partitioning to the topic partitioning,
> > > yes,
> > > > > this is an issue we are discussing solutions to right now. We may
> go
> > > > ahead
> > > > > and introduce an overpartition layer on our inputs to solve it, but
> > > then
> > > > > again, if we get the ability to split partitions with backfill, we
> > may
> > > > not
> > > > > need to!
> > > > >
> > > > >
> > > > > Point 4:
> > > > > On this:
> > > > >
> > > > > > Regarding thought 2: If we don't care about the stream use-case,
> > then
> > > > the
> > > > > > current KIP probably has already addressed problem without
> > requiring
> > > > > > consumer to know the partition function. If we care about the
> > stream
> > > > > > use-case, we already need coordination across producers of
> > different
> > > > > > topics, i.e. the same partition function needs to be used by
> > > producers
> > > > of
> > > > > > topics A and B in order to join topics A and B. Thus, it might be
> > > > > > reasonable to extend coordination a bit and say we need
> > coordination
> > > > > across
> > > > > > clients (i.e. producer and consumer), such that consumer knows
> the
> > > > > > partition function used by producer. If we do so, then we can let
> > > > > consumer
> > > > > > re-copy data for the change log topic using the same partition
> > > function
> > > > > as
> > > > > > producer. This approach has lower overhead as compared to having
> > > > producer
> > > > > > re-copy data of the input topic.
> > > > > > Also, producer currently does not need to know the data already
> > > > produced
> > > > > to
> > > > > > the topic. If we let producer split/merge partition, it would
> > require
> > > > > > producer to consume the existing data, which intuitively is the
> > task
> > > of
> > > > > > consumer.
> > > > >
> > > > >
> > > > > I think we do care about use cases *like* Streams, I just don't
> think
> > > we
> > > > > should rely on Streams to implement a feature of Core like
> partition
> > > > > expansion.
> > > > >
> > > > > Note, though, that we (Streams) do not require coordination across
> > > > > producers. If two topics are certified to be co-partitioned, then
> > > Streams
> > > > > apps can make use of that knowledge to optimize their topology
> > > (skipping
> > > > a
> > > > > repartition). But if they don't know whether they are
> co-partitioned,
> > > > then
> > > > > they'd better go ahead and repartition within the topology. This is
> > the
> > > > > current state.
> > > > >
> > > > > A huge selling point of Kafka is enabling different parts of
> loosely
> > > > > coupled organizations to produce and consume data independently.
> Some
> > > > > coordination between producers and consumers is necessary, like
> > > > > coordinating on the names of topics and their schemas. But Kafka's
> > > value
> > > > > proposition w.r.t. ESBs, etc. is inversely proportional to the
> amount
> > > of
> > > > > coordination required. I think it behooves us to be extremely
> > skeptical
> > > > > about introducing any coordination beyond correctness protocols.
> > > > >
> > > > > Asking producers and consumers, or even two different producers, to
> > > share
> > > > > code like the partition function is a pretty huge ask. What if they
> > are
> > > > > using different languages?
> > > > >
> > > > > Comparing organizational overhead vs computational overhead, there
> > are
> > > > > maybe two orders of magnitude difference between them. In other
> > words,
> > > I
> > > > > would happily take on the (linear) overhead of having the producer
> > > > re-copy
> > > > > the data once during a re-partition in order to save the
> > organizational
> > > > > overhead of tying all the producers and consumers together across
> > > > multiple
> > > > > boundaries.
> > > > >
> > > > > On that last paragraph: note that the producer *did* know the data
> it
> > > > > already produced. It handled it the first time around. Asking it to
> > > > > re-produce it into a new partition layout is squarely within its
> > scope
> > > of
> > > > > capabilities. Contrast this with the alternative, asking the
> consumer
> > > to
> > > > > re-partition the data. I think this is even less intuitive, when
> the
> > > > > partition function belongs to the producer.
> > > > >
> > > > >
> > > > > Point 5:
> > > > > Dong asked this:
> > > > >
> > > > > > For stream use-case that needs to increase consumer number, the
> > > > > > existing consumer can backfill the existing data in the change
> log
> > > > topic
> > > > > to
> > > > > > the same change log topic with the new partition number, before
> the
> > > new
> > > > > set
> > > > > > of consumers bootstrap state from the new partitions of the
> change
> > > log
> > > > > > topic, right?
> > > > >
> > > > >
> > > > > In this sense, the "consumer" is actually the producer of the
> > changelog
> > > > > topic, so if we support partition expansion + backfill as a
> > > > producer/broker
> > > > > operation, then it would be very straightforward for Streams to
> > split a
> > > > > state store. As you say, they would simply instruct the broker to
> > split
> > > > the
> > > > > changelog topic's partitions, then backfill. Once the backfill is
> > > ready,
> > > > > they can create a new crop of StandbyTasks to bootstrap the more
> > > granular
> > > > > state stores and finally switch over to them when they are ready.
> > > > >
> > > > > But this actually seems to be an argument in favor of
> split+backfill,
> > > so
> > > > > maybe I missed the point.
> > > > >
> > > > > You also asked me to explain why copying the "input" topic is
> better
> > > than
> > > > > copying the "changelog" topic. I think they are totally
> independent,
> > > > > actually. For one thing, you can't depend on the existence of a
> > > > "changelog"
> > > > > topic in general, only within Streams, but Kafka's user base
> clearly
> > > > > exceeds Streams's user base. Plus, you actually also can't depend
> on
> > > the
> > > > > existence of a changelog topic within Streams, since that is an
> > > optional
> > > > > feature of *some* state store implementations. Even in the
> situation
> > > > where
> > > > > you do have a changelog topic in Streams, there may be use cases
> > where
> > > it
> > > > > makes sense to expand the partitions of just the input, or just the
> > > > > changelog.
> > > > >
> > > > > The ask for a Core feature of split+backfill is really about
> > supporting
> > > > the
> > > > > use case of splitting partitions in log-compacted topics,
> regardless
> > of
> > > > > whether that topic is an "input" or a "changelog" or anything else
> > for
> > > > that
> > > > > matter.
> > > > >
> > > > >
> > > > > Point 6:
> > > > > On the concern about the performance overhead of copying data
> between
> > > the
> > > > > brokers, I think it's actually a bit overestimated. Splitting a
> > topic's
> > > > > partition is probably rare, certainly rarer in general than
> > > bootstrapping
> > > > > new consumers on that topic. If "bootstrapping new consumers" means
> > > that
> > > > > they have to re-shuffle the data before they consume it, then you
> > wind
> > > up
> > > > > copying the same record multiple times:
> > > > >
> > > > > (broker: input topic) -> (initial consumer) -> (broker: repartition
> > > > topic)
> > > > > -> (real consumer)
> > > > >
> > > > > That's 3x, and it's also 3x for every new record after the split as
> > > well,
> > > > > since you don't get to stop repartitioning/reshuffling once you
> > start.
> > > > >
> > > > > Whereas if you do a backfill in something like the procedure I
> > > outlined,
> > > > > you only copy the prefix of the partition before the split, and you
> > > send
> > > > it
> > > > > once to the producer and then once to the new generation partition.
> > > Plus,
> > > > > assuming we're splitting the partition for the benefit of
> consumers,
> > > > > there's no reason we can't co-locate the post-split partitions on
> the
> > > > same
> > > > > host as the pre-split partition, making the second copy a local
> > > > filesystem
> > > > > operation.
> > > > >
> > > > > Even if you follow these two copies up with bootstrapping a new
> > > consumer,
> > > > > it's still rare for this to occur, so you get to amortize these
> > copies
> > > > over
> > > > > the lifetime of the topic, whereas a reshuffle just keeps making
> > copies
> > > > for
> > > > > every new event.
> > > > >
> > > > > And finally, I really do think that regardless of any performance
> > > > concerns
> > > > > about this operation, if it preserves loose organizational
> coupling,
> > it
> > > > is
> > > > > certainly worth it.
> > > > >
> > > > >
> > > > > In conclusion:
> > > > > It might actually be a good idea for us to clarify the scope of
> > > KIP-253.
> > > > If
> > > > > we're all agreed that it's a good algorithm for allowing in-order
> > > message
> > > > > delivery during partition expansion, then we can continue this
> > > discussion
> > > > > as a new KIP, something like "backfill with partition expansion".
> > This
> > > > > would let Dong proceed with KIP-253. On the other hand, if it seems
> > > like
> > > > > this conversation may alter the design of KIP-253, then maybe we
> > > *should*
> > > > > just finish working it out.
> > > > >
> > > > > For my part, my only concern about KIP-253 is the one I raised
> > earlier.
> > > > >
> > > > > Thanks again, all, for considering these points,
> > > > > -John
> > > > >
> > > > >
> > > > > On Tue, Mar 27, 2018 at 2:10 AM, Dong Lin <li...@gmail.com>
> > wrote:
> > > > >
> > > > > > On Tue, Mar 27, 2018 at 12:04 AM, Dong Lin <li...@gmail.com>
> > > > wrote:
> > > > > >
> > > > > > > Hey Jan,
> > > > > > >
> > > > > > > Thanks for the enthusiasm in improving Kafka's design. Now
> that I
> > > > have
> > > > > > > read through your discussion with Jun, here are my thoughts:
> > > > > > >
> > > > > > > - The latest proposal should with log compacted topics by
> > properly
> > > > > > > deleting old messages after a new message with the same key is
> > > > > produced.
> > > > > > So
> > > > > > > it is probably not a concern anymore. Could you comment if
> there
> > is
> > > > > still
> > > > > > > issue?
> > > > > > >
> > > > > > > - I wrote the SEP-5 and I am pretty familiar with the
> motivation
> > > and
> > > > > the
> > > > > > > design of SEP-5. SEP-5 is probably orthornal to the motivation
> of
> > > > this
> > > > > > KIP.
> > > > > > > The goal of SEP-5 is to allow user to increase task number of
> an
> > > > > existing
> > > > > > > Samza job. But if we increase the partition number of input
> > topics,
> > > > > > > messages may still be consumed out-of-order by tasks in Samza
> > which
> > > > > cause
> > > > > > > incorrect result. Similarly, the approach you proposed does not
> > > seem
> > > > to
> > > > > > > ensure that the messages can be delivered in order, even if we
> > can
> > > > make
> > > > > > > sure that each consumer instance is assigned the set of new
> > > > partitions
> > > > > > > covering the same set of keys.
> > > > > > >
> > > > > >
> > > > > > Let me correct this comment. The approach of copying data to a
> new
> > > > topic
> > > > > > can ensure in-order message delivery suppose we properly migrate
> > > > offsets
> > > > > > from old topic to new topic.
> > > > > >
> > > > > >
> > > > > > > - I am trying to understand why it is better to copy the data
> > > instead
> > > > > of
> > > > > > > copying the change log topic for streaming use-case. For core
> > Kafka
> > > > > > > use-case, and for the stream use-case that does not need to
> > > increase
> > > > > > > consumers, the current KIP already supports in-order delivery
> > > without
> > > > > the
> > > > > > > overhead of copying the data. For stream use-case that needs to
> > > > > increase
> > > > > > > consumer number, the existing consumer can backfill the
> existing
> > > data
> > > > > in
> > > > > > > the change log topic to the same change log topic with the new
> > > > > partition
> > > > > > > number, before the new set of consumers bootstrap state from
> the
> > > new
> > > > > > > partitions of the change log topic. If this solution works,
> then
> > > > could
> > > > > > you
> > > > > > > summarize the advantage of copying the data of input topic as
> > > > compared
> > > > > to
> > > > > > > copying the change log topic? For example, does it enable more
> > > > > use-case,
> > > > > > > simplify the implementation of Kafka library, or reduce the
> > > operation
> > > > > > > overhead etc?
> > > > > > >
> > > > > > > Thanks,
> > > > > > > Dong
> > > > > > >
> > > > > > >
> > > > > > > On Wed, Mar 21, 2018 at 6:57 AM, Jan Filipiak <
> > > > > Jan.Filipiak@trivago.com>
> > > > > > > wrote:
> > > > > > >
> > > > > > >> Hi Jun,
> > > > > > >>
> > > > > > >> I was really seeing progress in our conversation but your
> latest
> > > > reply
> > > > > > is
> > > > > > >> just devastating.
> > > > > > >> I though we were getting close being on the same page now it
> > feels
> > > > > like
> > > > > > >> we are in different libraries.
> > > > > > >>
> > > > > > >> I just quickly slam my answers in here. If they are to brief I
> > am
> > > > > sorry
> > > > > > >> give me a ping and try to go into details more.
> > > > > > >> Just want to show that your pro/cons listing is broken.
> > > > > > >>
> > > > > > >> Best Jan
> > > > > > >>
> > > > > > >> and want to get rid of this horrible compromise
> > > > > > >>
> > > > > > >>
> > > > > > >> On 19.03.2018 05:48, Jun Rao wrote:
> > > > > > >>
> > > > > > >>> Hi, Jan,
> > > > > > >>>
> > > > > > >>> Thanks for the discussion. Great points.
> > > > > > >>>
> > > > > > >>> Let me try to summarize the approach that you are proposing.
> On
> > > the
> > > > > > >>> broker
> > > > > > >>> side, we reshuffle the existing data in a topic from current
> > > > > partitions
> > > > > > >>> to
> > > > > > >>> the new partitions. Once the reshuffle fully catches up,
> switch
> > > the
> > > > > > >>> consumers to start consuming from the new partitions. If a
> > > consumer
> > > > > > needs
> > > > > > >>> to rebuild its local state (due to partition changes), let
> the
> > > > > consumer
> > > > > > >>> rebuild its state by reading all existing data from the new
> > > > > partitions.
> > > > > > >>> Once all consumers have switches over, cut over the producer
> to
> > > the
> > > > > new
> > > > > > >>> partitions.
> > > > > > >>>
> > > > > > >>> The pros for this approach are that :
> > > > > > >>> 1. There is just one way to rebuild the local state, which is
> > > > > simpler.
> > > > > > >>>
> > > > > > >> true thanks
> > > > > > >>
> > > > > > >>>
> > > > > > >>> The cons for this approach are:
> > > > > > >>> 1. Need to copy existing data.
> > > > > > >>>
> > > > > > >> Very unfair and not correct. It does not require you to copy
> > over
> > > > > > >> existing data. It _allows_ you to copy all existing data.
> > > > > > >>
> > > > > > >> 2. The cutover of the producer is a bit complicated since it
> > needs
> > > > to
> > > > > > >>> coordinate with all consumer groups.
> > > > > > >>>
> > > > > > >> Also not true. I explicitly tried to make clear that there is
> > only
> > > > one
> > > > > > >> special consumer (in the case of actually copying data)
> > > coordination
> > > > > is
> > > > > > >> required.
> > > > > > >>
> > > > > > >>> 3. The rebuilding of the state in the consumer is from the
> > input
> > > > > topic,
> > > > > > >>> which can be more expensive than rebuilding from the existing
> > > > state.
> > > > > > >>>
> > > > > > >> true, but rebuilding state is only required if you want to
> > > increase
> > > > > > >> processing power, so we assume this is at hand.
> > > > > > >>
> > > > > > >>> 4. The broker potentially has to know the partitioning
> > function.
> > > If
> > > > > > this
> > > > > > >>> needs to be customized at the topic level, it can be a bit
> > messy.
> > > > > > >>>
> > > > > > >> I would argue against having the operation being performed by
> > the
> > > > > > broker.
> > > > > > >> This was not discussed yet but if you see my original email i
> > > > > suggested
> > > > > > >> otherwise from the beginning.
> > > > > > >>
> > > > > > >>>
> > > > > > >>> Here is an alternative approach by applying your idea not in
> > the
> > > > > > broker,
> > > > > > >>> but in the consumer. When new partitions are added, we don't
> > move
> > > > > > >>> existing
> > > > > > >>> data. In KStreams, we first reshuffle the new input data to a
> > new
> > > > > topic
> > > > > > >>> T1
> > > > > > >>> with the old number of partitions and feed T1's data to the
> > rest
> > > of
> > > > > the
> > > > > > >>> pipeline. In the meantime, KStreams reshuffles all existing
> > data
> > > of
> > > > > the
> > > > > > >>> change capture topic to another topic C1 with the new number
> of
> > > > > > >>> partitions.
> > > > > > >>> We can then build the state of the new tasks from C1. Once
> the
> > > new
> > > > > > states
> > > > > > >>> have been fully built, we can cut over the consumption to the
> > > input
> > > > > > topic
> > > > > > >>> and delete T1. This approach works with compacted topic too.
> If
> > > an
> > > > > > >>> application reads from the beginning of a compacted topic,
> the
> > > > > consumer
> > > > > > >>> will reshuffle the portion of the input when the number of
> > > > partitions
> > > > > > >>> doesn't match the number of tasks.
> > > > > > >>>
> > > > > > >> We all wipe this idea from our heads instantly. Mixing Ideas
> > from
> > > an
> > > > > > >> argument is not a resolution strategy
> > > > > > >> just leads to horrible horrible software.
> > > > > > >>
> > > > > > >>
> > > > > > >>> The pros of this approach are:
> > > > > > >>> 1. No need to copy existing data.
> > > > > > >>> 2. Each consumer group can cut over to the new partitions
> > > > > > independently.
> > > > > > >>> 3. The state is rebuilt from the change capture topic, which
> is
> > > > > cheaper
> > > > > > >>> than rebuilding from the input topic.
> > > > > > >>> 4. Only the KStreams job needs to know the partitioning
> > function.
> > > > > > >>>
> > > > > > >>> The cons of this approach are:
> > > > > > >>> 1. Potentially the same input topic needs to be reshuffled
> more
> > > > than
> > > > > > once
> > > > > > >>> in different consumer groups during the transition phase.
> > > > > > >>>
> > > > > > >>> What do you think?
> > > > > > >>>
> > > > > > >>> Thanks,
> > > > > > >>>
> > > > > > >>> Jun
> > > > > > >>>
> > > > > > >>>
> > > > > > >>>
> > > > > > >>> On Thu, Mar 15, 2018 at 1:04 AM, Jan Filipiak <
> > > > > > Jan.Filipiak@trivago.com>
> > > > > > >>> wrote:
> > > > > > >>>
> > > > > > >>> Hi Jun,
> > > > > > >>>>
> > > > > > >>>> thank you for following me on these thoughts. It was
> important
> > > to
> > > > me
> > > > > > to
> > > > > > >>>> feel that kind of understanding for my arguments.
> > > > > > >>>>
> > > > > > >>>> What I was hoping for (I mentioned this earlier) is that we
> > can
> > > > > model
> > > > > > >>>> the
> > > > > > >>>> case where we do not want to copy the data the exact same
> way
> > as
> > > > the
> > > > > > >>>> case
> > > > > > >>>> when we do copy the data. Maybe you can peek into the mails
> > > before
> > > > > to
> > > > > > >>>> see
> > > > > > >>>> more details for this.
> > > > > > >>>>
> > > > > > >>>> This means we have the same mechanism to transfer consumer
> > > groups
> > > > to
> > > > > > >>>> switch topic. The offset mapping that would be generated
> would
> > > > even
> > > > > be
> > > > > > >>>> simpler End Offset of the Old topic => offset 0 off all the
> > > > > partitions
> > > > > > >>>> of
> > > > > > >>>> the new topic. Then we could model the transition of a
> > non-copy
> > > > > > >>>> expansion
> > > > > > >>>> the exact same way as a copy-expansion.
> > > > > > >>>>
> > > > > > >>>> I know this only works when topic growth by a factor. But
> the
> > > > > benefits
> > > > > > >>>> of
> > > > > > >>>> only growing by a factor are to strong anyways. See
> Clemens's
> > > hint
> > > > > and
> > > > > > >>>> remember that state reshuffling is entirely not needed if
> one
> > > > > doesn't
> > > > > > >>>> want
> > > > > > >>>> to grow processing power.
> > > > > > >>>>
> > > > > > >>>> I think these benefits should be clear, and that there is
> > > > basically
> > > > > no
> > > > > > >>>> downside to what is currently at hand but just makes
> > everything
> > > > > easy.
> > > > > > >>>>
> > > > > > >>>> One thing you need to know is. that if you do not offer
> > > > rebuilding a
> > > > > > log
> > > > > > >>>> compacted topic like i suggest that even if you have
> consumer
> > > > state
> > > > > > >>>> reshuffling. The topic is broken and can not be used to
> > > bootstrap
> > > > > new
> > > > > > >>>> consumers. They don't know if they need to apply a key from
> > and
> > > > old
> > > > > > >>>> partition or not. This is a horrible downside I haven't
> seen a
> > > > > > solution
> > > > > > >>>> for
> > > > > > >>>> in the email conversation.
> > > > > > >>>>
> > > > > > >>>> I argue to:
> > > > > > >>>>
> > > > > > >>>> Only grow topic by a factor always.
> > > > > > >>>> Have the "no copy consumer" transition as the trivial case
> of
> > > the
> > > > > > "copy
> > > > > > >>>> consumer transition".
> > > > > > >>>> If processors needs to be scaled, let them rebuild from the
> > new
> > > > > topic
> > > > > > >>>> and
> > > > > > >>>> leave the old running in the mean time.
> > > > > > >>>> Do not implement key shuffling in streams.
> > > > > > >>>>
> > > > > > >>>> I hope I can convince you especially with the fact how I
> want
> > to
> > > > > > handle
> > > > > > >>>> consumer transition. I think
> > > > > > >>>> you didn't quite understood me there before. I think the
> term
> > > "new
> > > > > > >>>> topic"
> > > > > > >>>> intimidated you a little.
> > > > > > >>>> How we solve this on disc doesn't really matter, If the data
> > > goes
> > > > > into
> > > > > > >>>> the
> > > > > > >>>> same Dir or a different Dir or anything. I do think that it
> > > needs
> > > > to
> > > > > > >>>> involve at least rolling a new segment for the existing
> > > > partitions.
> > > > > > >>>> But most of the transitions should work without restarting
> > > > > consumers.
> > > > > > >>>> (newer consumers with support for this). But with new topic
> i
> > > just
> > > > > > meant
> > > > > > >>>> the topic that now has a different partition count. Plenty
> of
> > > ways
> > > > > to
> > > > > > >>>> handle that (versions, aliases)
> > > > > > >>>>
> > > > > > >>>> Hope I can further get my idea across.
> > > > > > >>>>
> > > > > > >>>> Best Jan
> > > > > > >>>>
> > > > > > >>>>
> > > > > > >>>>
> > > > > > >>>>
> > > > > > >>>>
> > > > > > >>>>
> > > > > > >>>> On 14.03.2018 02:45, Jun Rao wrote:
> > > > > > >>>>
> > > > > > >>>> Hi, Jan,
> > > > > > >>>>>
> > > > > > >>>>> Thanks for sharing your view.
> > > > > > >>>>>
> > > > > > >>>>> I agree with you that recopying the data potentially makes
> > the
> > > > > state
> > > > > > >>>>> management easier since the consumer can just rebuild its
> > state
> > > > > from
> > > > > > >>>>> scratch (i.e., no need for state reshuffling).
> > > > > > >>>>>
> > > > > > >>>>> On the flip slide, I saw a few disadvantages of the
> approach
> > > that
> > > > > you
> > > > > > >>>>> suggested. (1) Building the state from the input topic from
> > > > scratch
> > > > > > is
> > > > > > >>>>> in
> > > > > > >>>>> general less efficient than state reshuffling. Let's say
> one
> > > > > > computes a
> > > > > > >>>>> count per key from an input topic. The former requires
> > reading
> > > > all
> > > > > > >>>>> existing
> > > > > > >>>>> records in the input topic whereas the latter only requires
> > > > reading
> > > > > > >>>>> data
> > > > > > >>>>> proportional to the number of unique keys. (2) The
> switching
> > of
> > > > the
> > > > > > >>>>> topic
> > > > > > >>>>> needs modification to the application. If there are many
> > > > > applications
> > > > > > >>>>> on a
> > > > > > >>>>> topic, coordinating such an effort may not be easy. Also,
> > it's
> > > > not
> > > > > > >>>>> clear
> > > > > > >>>>> how to enforce exactly-once semantic during the switch. (3)
> > If
> > > a
> > > > > > topic
> > > > > > >>>>> doesn't need any state management, recopying the data seems
> > > > > wasteful.
> > > > > > >>>>> In
> > > > > > >>>>> that case, in place partition expansion seems more
> desirable.
> > > > > > >>>>>
> > > > > > >>>>> I understand your concern about adding complexity in
> > KStreams.
> > > > But,
> > > > > > >>>>> perhaps
> > > > > > >>>>> we could iterate on that a bit more to see if it can be
> > > > simplified.
> > > > > > >>>>>
> > > > > > >>>>> Jun
> > > > > > >>>>>
> > > > > > >>>>>
> > > > > > >>>>> On Mon, Mar 12, 2018 at 11:21 PM, Jan Filipiak <
> > > > > > >>>>> Jan.Filipiak@trivago.com>
> > > > > > >>>>> wrote:
> > > > > > >>>>>
> > > > > > >>>>> Hi Jun,
> > > > > > >>>>>
> > > > > > >>>>>> I will focus on point 61 as I think its _the_ fundamental
> > part
> > > > > that
> > > > > > I
> > > > > > >>>>>> cant
> > > > > > >>>>>> get across at the moment.
> > > > > > >>>>>>
> > > > > > >>>>>> Kafka is the platform to have state materialized multiple
> > > times
> > > > > from
> > > > > > >>>>>> one
> > > > > > >>>>>> input. I emphasize this: It is the building block in
> > > > architectures
> > > > > > >>>>>> that
> > > > > > >>>>>> allow you to
> > > > > > >>>>>> have your state maintained multiple times. You put a
> message
> > > in
> > > > > > once,
> > > > > > >>>>>> and
> > > > > > >>>>>> you have it pop out as often as you like. I believe you
> > > > understand
> > > > > > >>>>>> this.
> > > > > > >>>>>>
> > > > > > >>>>>> Now! The path of thinking goes the following: I am using
> > > apache
> > > > > > kafka
> > > > > > >>>>>> and
> > > > > > >>>>>> I _want_ my state multiple times. What am I going todo?
> > > > > > >>>>>>
> > > > > > >>>>>> A) Am I going to take my state that I build up, plunge
> some
> > > sort
> > > > > of
> > > > > > >>>>>> RPC
> > > > > > >>>>>> layer ontop of it, use that RPC layer to throw my records
> > > across
> > > > > > >>>>>> instances?
> > > > > > >>>>>> B) Am I just going to read the damn message twice?
> > > > > > >>>>>>
> > > > > > >>>>>> Approach A is fundamentally flawed and a violation of all
> > that
> > > > is
> > > > > > good
> > > > > > >>>>>> and
> > > > > > >>>>>> holy in kafka deployments. I can not understand how this
> > Idea
> > > > can
> > > > > > >>>>>> come in
> > > > > > >>>>>> the first place.
> > > > > > >>>>>> (I do understand: IQ in streams, they polluted the kafka
> > > streams
> > > > > > >>>>>> codebase
> > > > > > >>>>>> really bad already. It is not funny! I think they are
> > equally
> > > > > flawed
> > > > > > >>>>>> as
> > > > > > >>>>>> A)
> > > > > > >>>>>>
> > > > > > >>>>>> I say, we do what Kafka is good at. We repartition the
> topic
> > > > once.
> > > > > > We
> > > > > > >>>>>> switch the consumers.
> > > > > > >>>>>> (Those that need more partitions are going to rebuild
> their
> > > > state
> > > > > in
> > > > > > >>>>>> multiple partitions by reading the new topic, those that
> > don't
> > > > > just
> > > > > > >>>>>> assign
> > > > > > >>>>>> the new partitions properly)
> > > > > > >>>>>> We switch producers. Done!
> > > > > > >>>>>>
> > > > > > >>>>>> The best thing! It is trivial, hipster stream processor
> will
> > > > have
> > > > > an
> > > > > > >>>>>> easy
> > > > > > >>>>>> time with that aswell. Its so super simple. And simple IS
> > > good!
> > > > > > >>>>>> It is what kafka was build todo. It is how we do it today.
> > > All I
> > > > > am
> > > > > > >>>>>> saying
> > > > > > >>>>>> is that a little broker help doing the producer swap is
> > super
> > > > > > useful.
> > > > > > >>>>>>
> > > > > > >>>>>> For everyone interested in why kafka is so powerful with
> > > > approach
> > > > > B,
> > > > > > >>>>>> please watch https://youtu.be/bEbeZPVo98c?t=1633
> > > > > > >>>>>> I already looked up a good point in time, I think after 5
> > > > minutes
> > > > > > the
> > > > > > >>>>>> "state" topic is handled and you should be able to
> > understand
> > > me
> > > > > > >>>>>> and inch better.
> > > > > > >>>>>>
> > > > > > >>>>>> Please do not do A to the project, it deserves better!
> > > > > > >>>>>>
> > > > > > >>>>>> Best Jan
> > > > > > >>>>>>
> > > > > > >>>>>>
> > > > > > >>>>>>
> > > > > > >>>>>> On 13.03.2018 02:40, Jun Rao wrote:
> > > > > > >>>>>>
> > > > > > >>>>>> Hi, Jan,
> > > > > > >>>>>>
> > > > > > >>>>>>> Thanks for the reply. A few more comments below.
> > > > > > >>>>>>>
> > > > > > >>>>>>> 50. Ok, we can think a bit harder for supporting
> compacted
> > > > > topics.
> > > > > > >>>>>>>
> > > > > > >>>>>>> 51. This is a fundamental design question. In the more
> > common
> > > > > case,
> > > > > > >>>>>>> the
> > > > > > >>>>>>> reason why someone wants to increase the number of
> > partitions
> > > > is
> > > > > > that
> > > > > > >>>>>>> the
> > > > > > >>>>>>> consumer application is slow and one wants to run more
> > > consumer
> > > > > > >>>>>>> instances
> > > > > > >>>>>>> to increase the degree of parallelism. So, fixing the
> > number
> > > of
> > > > > > >>>>>>> running
> > > > > > >>>>>>> consumer instances when expanding the partitions won't
> help
> > > > this
> > > > > > >>>>>>> case.
> > > > > > >>>>>>> If
> > > > > > >>>>>>> we do need to increase the number of consumer instances,
> we
> > > > need
> > > > > to
> > > > > > >>>>>>> somehow
> > > > > > >>>>>>> reshuffle the state of the consumer across instances.
> What
> > we
> > > > > have
> > > > > > >>>>>>> been
> > > > > > >>>>>>> discussing in this KIP is whether we can do this more
> > > > effectively
> > > > > > >>>>>>> through
> > > > > > >>>>>>> the KStream library (e.g. through a 2-phase partition
> > > > expansion).
> > > > > > >>>>>>> This
> > > > > > >>>>>>> will
> > > > > > >>>>>>> add some complexity, but it's probably better than
> everyone
> > > > doing
> > > > > > >>>>>>> this
> > > > > > >>>>>>> in
> > > > > > >>>>>>> the application space. The recopying approach that you
> > > > mentioned
> > > > > > >>>>>>> doesn't
> > > > > > >>>>>>> seem to address the consumer state management issue when
> > the
> > > > > > consumer
> > > > > > >>>>>>> switches from an old to a new topic.
> > > > > > >>>>>>>
> > > > > > >>>>>>> 52. As for your example, it depends on whether the join
> key
> > > is
> > > > > the
> > > > > > >>>>>>> same
> > > > > > >>>>>>> between (A,B) and (B,C). If the join key is the same, we
> > can
> > > > do a
> > > > > > >>>>>>> 2-phase
> > > > > > >>>>>>> partition expansion of A, B, and C together. If the join
> > keys
> > > > are
> > > > > > >>>>>>> different, one would need to repartition the data on a
> > > > different
> > > > > > key
> > > > > > >>>>>>> for
> > > > > > >>>>>>> the second join, then the partition expansion can be done
> > > > > > >>>>>>> independently
> > > > > > >>>>>>> between (A,B) and (B,C).
> > > > > > >>>>>>>
> > > > > > >>>>>>> 53. If you always fix the number of consumer instances,
> we
> > > you
> > > > > > >>>>>>> described
> > > > > > >>>>>>> works. However, as I mentioned in #51, I am not sure how
> > your
> > > > > > >>>>>>> proposal
> > > > > > >>>>>>> deals with consumer states when the number of consumer
> > > > instances
> > > > > > >>>>>>> grows.
> > > > > > >>>>>>> Also, it just seems that it's better to avoid re-copying
> > the
> > > > > > existing
> > > > > > >>>>>>> data.
> > > > > > >>>>>>>
> > > > > > >>>>>>> 60. "just want to throw in my question from the longer
> > email
> > > in
> > > > > the
> > > > > > >>>>>>> other
> > > > > > >>>>>>> Thread here. How will the bloom filter help a new
> consumer
> > to
> > > > > > decide
> > > > > > >>>>>>> to
> > > > > > >>>>>>> apply the key or not?" Not sure that I fully understood
> > your
> > > > > > >>>>>>> question.
> > > > > > >>>>>>> The
> > > > > > >>>>>>> consumer just reads whatever key is in the log. The bloom
> > > > filter
> > > > > > just
> > > > > > >>>>>>> helps
> > > > > > >>>>>>> clean up the old keys.
> > > > > > >>>>>>>
> > > > > > >>>>>>> 61. "Why can we afford having a topic where its
> apparently
> > > not
> > > > > > >>>>>>> possible
> > > > > > >>>>>>> to
> > > > > > >>>>>>> start a new application on? I think this is an overall
> flaw
> > > of
> > > > > the
> > > > > > >>>>>>> discussed idea here. Not playing attention to the overall
> > > > > > >>>>>>> architecture."
> > > > > > >>>>>>> Could you explain a bit more when one can't start a new
> > > > > > application?
> > > > > > >>>>>>>
> > > > > > >>>>>>> Jun
> > > > > > >>>>>>>
> > > > > > >>>>>>>
> > > > > > >>>>>>>
> > > > > > >>>>>>> On Sat, Mar 10, 2018 at 1:40 AM, Jan Filipiak <
> > > > > > >>>>>>> Jan.Filipiak@trivago.com
> > > > > > >>>>>>> wrote:
> > > > > > >>>>>>>
> > > > > > >>>>>>> Hi Jun, thanks for your mail.
> > > > > > >>>>>>>
> > > > > > >>>>>>> Thank you for your questions!
> > > > > > >>>>>>>> I think they are really good and tackle the core of the
> > > > problem
> > > > > I
> > > > > > >>>>>>>> see.
> > > > > > >>>>>>>>
> > > > > > >>>>>>>> I will answer inline, mostly but still want to set the
> > tone
> > > > > here.
> > > > > > >>>>>>>>
> > > > > > >>>>>>>> The core strength of kafka is what Martin once called
> the
> > > > > > >>>>>>>> kappa-Architecture. How does this work?
> > > > > > >>>>>>>> You have everything as a log as in kafka. When you need
> to
> > > > > change
> > > > > > >>>>>>>> something.
> > > > > > >>>>>>>> You create the new version of your application and leave
> > it
> > > > > > running
> > > > > > >>>>>>>> in
> > > > > > >>>>>>>> parallel.
> > > > > > >>>>>>>> Once the new version is good you switch your users to
> use
> > > the
> > > > > new
> > > > > > >>>>>>>> application.
> > > > > > >>>>>>>>
> > > > > > >>>>>>>> The online reshuffling effectively breaks this
> > architecture
> > > > and
> > > > > I
> > > > > > >>>>>>>> think
> > > > > > >>>>>>>> the switch in thinking here is more harmful
> > > > > > >>>>>>>> than any details about the partitioning function to
> allow
> > > > such a
> > > > > > >>>>>>>> change.
> > > > > > >>>>>>>> I
> > > > > > >>>>>>>> feel with my suggestion we are the closest to
> > > > > > >>>>>>>> the original and battle proven architecture and I can
> only
> > > > warn
> > > > > to
> > > > > > >>>>>>>> move
> > > > > > >>>>>>>> away from it.
> > > > > > >>>>>>>>
> > > > > > >>>>>>>> I might have forgotten something, sometimes its hard for
> > me
> > > to
> > > > > > >>>>>>>> getting
> > > > > > >>>>>>>> all
> > > > > > >>>>>>>> the thoughts captured in a mail, but I hope the comments
> > > > inline
> > > > > > will
> > > > > > >>>>>>>> further make my concern clear, and put some emphasis on
> > why
> > > I
> > > > > > >>>>>>>> prefer my
> > > > > > >>>>>>>> solution ;)
> > > > > > >>>>>>>>
> > > > > > >>>>>>>> One thing we should all be aware of when discussing
> this,
> > > and
> > > > I
> > > > > > >>>>>>>> think
> > > > > > >>>>>>>> Dong
> > > > > > >>>>>>>> should have mentioned it (maybe he did).
> > > > > > >>>>>>>> We are not discussing all of this out of thin air but
> > there
> > > is
> > > > > an
> > > > > > >>>>>>>> effort
> > > > > > >>>>>>>> in the Samza project.
> > > > > > >>>>>>>>
> > > > > > >>>>>>>> https://cwiki.apache.org/confluence/display/SAMZA/SEP-
> > 5%3A+
> > > > > > >>>>>>>> Enable+partition+expansion+of+input+streams
> > > > > > >>>>>>>> https://issues.apache.org/jira/browse/SAMZA-1293
> > > > > > >>>>>>>>
> > > > > > >>>>>>>> To be clear. I think SEP-5 (state of last week, dont
> know
> > if
> > > > it
> > > > > > >>>>>>>> adapted
> > > > > > >>>>>>>> to
> > > > > > >>>>>>>> this discussion) is on a way better path than KIP-253,
> > and I
> > > > > can't
> > > > > > >>>>>>>> really
> > > > > > >>>>>>>> explain why.
> > > > > > >>>>>>>>
> > > > > > >>>>>>>> Best Jan,
> > > > > > >>>>>>>>
> > > > > > >>>>>>>> nice weekend everyone
> > > > > > >>>>>>>>
> > > > > > >>>>>>>>
> > > > > > >>>>>>>> On 09.03.2018 03:36, Jun Rao wrote:
> > > > > > >>>>>>>>
> > > > > > >>>>>>>> Hi, Jan,
> > > > > > >>>>>>>>
> > > > > > >>>>>>>> Thanks for the feedback. Just some comments on the
> earlier
> > > > > points
> > > > > > >>>>>>>>> that
> > > > > > >>>>>>>>> you
> > > > > > >>>>>>>>> mentioned.
> > > > > > >>>>>>>>>
> > > > > > >>>>>>>>> 50. You brought up the question of whether existing
> data
> > > > needs
> > > > > to
> > > > > > >>>>>>>>> be
> > > > > > >>>>>>>>> copied
> > > > > > >>>>>>>>> during partition expansion. My understand of your view
> is
> > > > that
> > > > > > >>>>>>>>> avoid
> > > > > > >>>>>>>>> copying existing data will be more efficient, but it
> > > doesn't
> > > > > work
> > > > > > >>>>>>>>> well
> > > > > > >>>>>>>>> with
> > > > > > >>>>>>>>> compacted topics since some keys in the original
> > partitions
> > > > > will
> > > > > > >>>>>>>>> never
> > > > > > >>>>>>>>> be
> > > > > > >>>>>>>>> cleaned. It would be useful to understand your use case
> > of
> > > > > > >>>>>>>>> compacted
> > > > > > >>>>>>>>> topics
> > > > > > >>>>>>>>> a bit more. In the common use case, the data volume in
> a
> > > > > > compacted
> > > > > > >>>>>>>>> topic
> > > > > > >>>>>>>>> may not be large. So, I am not sure if there is a
> strong
> > > need
> > > > > to
> > > > > > >>>>>>>>> expand
> > > > > > >>>>>>>>> partitions in a compacted topic, at least initially.
> > > > > > >>>>>>>>>
> > > > > > >>>>>>>>> I do agree. State is usually smaller. Update rates
> might
> > be
> > > > > also
> > > > > > >>>>>>>>>
> > > > > > >>>>>>>>> competitively high.
> > > > > > >>>>>>>> Doing Log-compaction (even beeing very efficient and
> > > > > configurable)
> > > > > > >>>>>>>> is
> > > > > > >>>>>>>> also
> > > > > > >>>>>>>> a more expensive operation than
> > > > > > >>>>>>>> just discarding old segments. Further if you want to use
> > > more
> > > > > > >>>>>>>> consumers
> > > > > > >>>>>>>> processing the events
> > > > > > >>>>>>>> you also have to grow the number of partitions.
> Especially
> > > for
> > > > > > >>>>>>>> use-cases
> > > > > > >>>>>>>> we do (KIP-213) a tiny state full
> > > > > > >>>>>>>> table might be very expensive to process if it joins
> > > against a
> > > > > > huge
> > > > > > >>>>>>>> table.
> > > > > > >>>>>>>>
> > > > > > >>>>>>>> I can just say we have been in the spot of needing to
> grow
> > > log
> > > > > > >>>>>>>> compacted
> > > > > > >>>>>>>> topics. Mainly for processing power we can bring to the
> > > table.
> > > > > > >>>>>>>>
> > > > > > >>>>>>>> Further i am not at all concerned about the extra spaced
> > > used
> > > > by
> > > > > > >>>>>>>> "garbage
> > > > > > >>>>>>>> keys". I am more concerned about the correctness of
> > innocent
> > > > > > >>>>>>>> consumers.
> > > > > > >>>>>>>> The
> > > > > > >>>>>>>> logic becomes complicated. Say for streams one would
> need
> > to
> > > > > load
> > > > > > >>>>>>>> the
> > > > > > >>>>>>>> record into state but not forward it the topology ( to
> > have
> > > it
> > > > > > >>>>>>>> available
> > > > > > >>>>>>>> for shuffeling). I rather have it simple and a topic
> clean
> > > > > > >>>>>>>> regardless
> > > > > > >>>>>>>> if
> > > > > > >>>>>>>> it
> > > > > > >>>>>>>> still has its old partition count. Especially with
> > multiple
> > > > > > >>>>>>>> partitions
> > > > > > >>>>>>>> growth's I think it becomes insanely hard to to this
> > shuffle
> > > > > > >>>>>>>> correct.
> > > > > > >>>>>>>> Maybe
> > > > > > >>>>>>>> Streams and Samza can do it. Especially if you do
> "hipster
> > > > > stream
> > > > > > >>>>>>>> processing" <https://www.confluent.io/blog
> > > > > > >>>>>>>> /introducing-kafka-streams-
> > > > > > >>>>>>>> stream-processing-made-simple/>. This makes kafka way
> to
> > > > > > >>>>>>>> complicated.
> > > > > > >>>>>>>> With my approach I think its way simpler because the
> topic
> > > has
> > > > > no
> > > > > > >>>>>>>> "history"
> > > > > > >>>>>>>> in terms of partitioning but is always clean.
> > > > > > >>>>>>>>
> > > > > > >>>>>>>>
> > > > > > >>>>>>>> 51. "Growing the topic by an integer factor does not
> > require
> > > > any
> > > > > > >>>>>>>> state
> > > > > > >>>>>>>>
> > > > > > >>>>>>>> redistribution at all." Could you clarify this a bit
> more?
> > > > Let's
> > > > > > say
> > > > > > >>>>>>>>> you
> > > > > > >>>>>>>>> have a consumer app that computes the windowed count
> per
> > > key.
> > > > > If
> > > > > > >>>>>>>>> you
> > > > > > >>>>>>>>> double
> > > > > > >>>>>>>>> the number of partitions from 1 to 2 and grow the
> > consumer
> > > > > > >>>>>>>>> instances
> > > > > > >>>>>>>>> from
> > > > > > >>>>>>>>> 1
> > > > > > >>>>>>>>> to 2, we would need to redistribute some of the counts
> to
> > > the
> > > > > new
> > > > > > >>>>>>>>> consumer
> > > > > > >>>>>>>>> instance. Regarding to linear hashing, it's true that
> it
> > > > won't
> > > > > > >>>>>>>>> solve
> > > > > > >>>>>>>>> the
> > > > > > >>>>>>>>> problem with compacted topics. The main benefit is that
> > it
> > > > > > >>>>>>>>> redistributes
> > > > > > >>>>>>>>> the keys in one partition to no more than two
> partitions,
> > > > which
> > > > > > >>>>>>>>> could
> > > > > > >>>>>>>>> help
> > > > > > >>>>>>>>> redistribute the state.
> > > > > > >>>>>>>>>
> > > > > > >>>>>>>>> You don't need to spin up a new consumer in this case.
> > > every
> > > > > > >>>>>>>>> consumer
> > > > > > >>>>>>>>>
> > > > > > >>>>>>>>> would just read every partition with the (partition %
> > > > num_task)
> > > > > > >>>>>>>> task.
> > > > > > >>>>>>>> it
> > > > > > >>>>>>>> will still have the previous data right there and can go
> > on.
> > > > > > >>>>>>>>
> > > > > > >>>>>>>> This sounds contradictory to what I said before, but
> > please
> > > > bear
> > > > > > >>>>>>>> with
> > > > > > >>>>>>>> me.
> > > > > > >>>>>>>>
> > > > > > >>>>>>>> 52. Good point on coordinating the expansion of 2 topics
> > > that
> > > > > need
> > > > > > >>>>>>>> to
> > > > > > >>>>>>>> be
> > > > > > >>>>>>>>
> > > > > > >>>>>>>> joined together. This is where the 2-phase partition
> > > expansion
> > > > > > could
> > > > > > >>>>>>>>> potentially help. In the first phase, we could add new
> > > > > partitions
> > > > > > >>>>>>>>> to
> > > > > > >>>>>>>>> the 2
> > > > > > >>>>>>>>> topics one at a time but without publishing to the new
> > > > > patitions.
> > > > > > >>>>>>>>> Then,
> > > > > > >>>>>>>>> we
> > > > > > >>>>>>>>> can add new consumer instances to pick up the new
> > > partitions.
> > > > > In
> > > > > > >>>>>>>>> this
> > > > > > >>>>>>>>> transition phase, no reshuffling is needed since no
> data
> > is
> > > > > > coming
> > > > > > >>>>>>>>> from
> > > > > > >>>>>>>>> the
> > > > > > >>>>>>>>> new partitions. Finally, we can enable the publishing
> to
> > > the
> > > > > new
> > > > > > >>>>>>>>> partitions.
> > > > > > >>>>>>>>>
> > > > > > >>>>>>>>> I think its even worse than you think. I would like to
> > > > > introduce
> > > > > > >>>>>>>>> the
> > > > > > >>>>>>>>>
> > > > > > >>>>>>>>> Term
> > > > > > >>>>>>>> transitive copartitioning. Imagine
> > > > > > >>>>>>>> 2 streams application. One joins (A,B) the other (B,C)
> > then
> > > > > there
> > > > > > >>>>>>>> is a
> > > > > > >>>>>>>> transitive copartition requirement for
> > > > > > >>>>>>>> (A,C) to be copartitioned aswell. This can spread
> > > > significantly
> > > > > > and
> > > > > > >>>>>>>> require many consumers to adapt at the same time.
> > > > > > >>>>>>>>
> > > > > > >>>>>>>> It is also not entirely clear to me how you not need
> > > > reshuffling
> > > > > > in
> > > > > > >>>>>>>> this
> > > > > > >>>>>>>> case. If A has a record that never gets updated after
> the
> > > > > > expansion
> > > > > > >>>>>>>> and
> > > > > > >>>>>>>> the
> > > > > > >>>>>>>> coresponding B record moves to a new partition. How
> shall
> > > they
> > > > > > meet
> > > > > > >>>>>>>> w/o
> > > > > > >>>>>>>> shuffle?
> > > > > > >>>>>>>>
> > > > > > >>>>>>>> 53. "Migrating consumer is a step that might be made
> > > completly
> > > > > > >>>>>>>>
> > > > > > >>>>>>>> unnecessary
> > > > > > >>>>>>>>> if - for example streams - takes the gcd as
> partitioning
> > > > scheme
> > > > > > >>>>>>>>> instead
> > > > > > >>>>>>>>> of
> > > > > > >>>>>>>>> enforcing 1 to 1." Not sure that I fully understand
> > this. I
> > > > > think
> > > > > > >>>>>>>>> you
> > > > > > >>>>>>>>> mean
> > > > > > >>>>>>>>> that a consumer application can run more instances than
> > the
> > > > > > number
> > > > > > >>>>>>>>> of
> > > > > > >>>>>>>>> partitions. In that case, the consumer can just
> > > > repartitioning
> > > > > > the
> > > > > > >>>>>>>>> input
> > > > > > >>>>>>>>> data according to the number of instances. This is
> > > possible,
> > > > > but
> > > > > > >>>>>>>>> just
> > > > > > >>>>>>>>> has
> > > > > > >>>>>>>>> the overhead of reshuffling the data.
> > > > > > >>>>>>>>>
> > > > > > >>>>>>>>> No what I meant is ( that is also your question i think
> > > > > Mathias)
> > > > > > >>>>>>>>> that
> > > > > > >>>>>>>>> if
> > > > > > >>>>>>>>>
> > > > > > >>>>>>>>> you grow a topic by a factor.
> > > > > > >>>>>>>> Even if your processor is statefull you can can just
> > assign
> > > > all
> > > > > > the
> > > > > > >>>>>>>> multiples of the previous partition to
> > > > > > >>>>>>>> this consumer and the state to keep processing correctly
> > > will
> > > > be
> > > > > > >>>>>>>> present
> > > > > > >>>>>>>> w/o any shuffling.
> > > > > > >>>>>>>>
> > > > > > >>>>>>>> Say you have an assignment
> > > > > > >>>>>>>> Statefull consumer => partition
> > > > > > >>>>>>>> 0 => 0
> > > > > > >>>>>>>> 1 => 1
> > > > > > >>>>>>>> 2 => 2
> > > > > > >>>>>>>>
> > > > > > >>>>>>>> and you grow you topic by 4 you get,
> > > > > > >>>>>>>>
> > > > > > >>>>>>>> 0 => 0,3,6,9
> > > > > > >>>>>>>> 1 => 1,4,7,10
> > > > > > >>>>>>>> 2 => 2,5,8,11
> > > > > > >>>>>>>>
> > > > > > >>>>>>>> Say your hashcode is 8. 8%3 => 2  before so consumer for
> > > > > > partition 2
> > > > > > >>>>>>>> has
> > > > > > >>>>>>>> it.
> > > > > > >>>>>>>> Now you you have 12 partitions so 8%12 => 8, so it goes
> > into
> > > > > > >>>>>>>> partition
> > > > > > >>>>>>>> 8
> > > > > > >>>>>>>> which is assigned to the same consumer
> > > > > > >>>>>>>> who had 2 before and therefore knows the key.
> > > > > > >>>>>>>>
> > > > > > >>>>>>>> Userland reshuffeling is there as an options. And it
> does
> > > > > exactly
> > > > > > >>>>>>>> what
> > > > > > >>>>>>>> I
> > > > > > >>>>>>>> suggest. And I think its the perfect strategie. All I am
> > > > > > suggestion
> > > > > > >>>>>>>> is
> > > > > > >>>>>>>> broker side support to switch the producers to the newly
> > > > > > partitioned
> > > > > > >>>>>>>> topic.
> > > > > > >>>>>>>> Then the old (to few partition topic) can go away.
> > Remember
> > > > the
> > > > > > >>>>>>>> list
> > > > > > >>>>>>>> of
> > > > > > >>>>>>>> steps in the beginning of this thread. If one has broker
> > > > support
> > > > > > for
> > > > > > >>>>>>>> all
> > > > > > >>>>>>>> where its required and streams support for those that
> > aren’t
> > > > > > >>>>>>>> necessarily.
> > > > > > >>>>>>>> Then one has solved the problem.
> > > > > > >>>>>>>> I repeat it because I think its important. I am really
> > happy
> > > > > that
> > > > > > >>>>>>>> you
> > > > > > >>>>>>>> brought that up! because its 100% what I want just with
> > the
> > > > > > >>>>>>>> differences
> > > > > > >>>>>>>> to
> > > > > > >>>>>>>> have an option to discard the to small topic later
> (after
> > > all
> > > > > > >>>>>>>> consumers
> > > > > > >>>>>>>> adapted). And to have order correct there. I need broker
> > > > support
> > > > > > >>>>>>>> managing
> > > > > > >>>>>>>> the copy process + the produces and fence them against
> > each
> > > > > > other. I
> > > > > > >>>>>>>> also
> > > > > > >>>>>>>> repeat. the copy process can run for weeks in the worst
> > > case.
> > > > > > >>>>>>>> Copying
> > > > > > >>>>>>>> the
> > > > > > >>>>>>>> data is not the longest task migrating consumers might
> > very
> > > > well
> > > > > > be.
> > > > > > >>>>>>>> Once all consumers switched and copying is really up to
> > date
> > > > > > (think
> > > > > > >>>>>>>> ISR
> > > > > > >>>>>>>> like up to date) only then we stop the producer, wait
> for
> > > the
> > > > > copy
> > > > > > >>>>>>>> to
> > > > > > >>>>>>>> finish and use the new topic for producing.
> > > > > > >>>>>>>>
> > > > > > >>>>>>>> After this the topic is perfect in shape. and no one
> needs
> > > to
> > > > > > worry
> > > > > > >>>>>>>> about
> > > > > > >>>>>>>> complicated stuff. (old keys hanging around might arrive
> > in
> > > > some
> > > > > > >>>>>>>> other
> > > > > > >>>>>>>> topic later.....). can only imagine how many tricky bugs
> > > gonna
> > > > > > >>>>>>>> arrive
> > > > > > >>>>>>>> after
> > > > > > >>>>>>>> someone had grown and shrunken is topic 10 times.
> > > > > > >>>>>>>>
> > > > > > >>>>>>>>
> > > > > > >>>>>>>>
> > > > > > >>>>>>>>
> > > > > > >>>>>>>>
> > > > > > >>>>>>>>
> > > > > > >>>>>>>> 54. "The other thing I wanted to mention is that I
> believe
> > > the
> > > > > > >>>>>>>> current
> > > > > > >>>>>>>>
> > > > > > >>>>>>>> suggestion (without copying data over) can be
> implemented
> > in
> > > > > pure
> > > > > > >>>>>>>>> userland
> > > > > > >>>>>>>>> with a custom partitioner and a small feedbackloop from
> > > > > > >>>>>>>>> ProduceResponse
> > > > > > >>>>>>>>> =>
> > > > > > >>>>>>>>> Partitionier in coorporation with a change management
> > > > system."
> > > > > I
> > > > > > am
> > > > > > >>>>>>>>> not
> > > > > > >>>>>>>>> sure a customized partitioner itself solves the
> problem.
> > We
> > > > > > >>>>>>>>> probably
> > > > > > >>>>>>>>> need
> > > > > > >>>>>>>>> some broker side support to enforce when the new
> > partitions
> > > > can
> > > > > > be
> > > > > > >>>>>>>>> used.
> > > > > > >>>>>>>>> We
> > > > > > >>>>>>>>> also need some support on the consumer/kstream side to
> > > > preserve
> > > > > > the
> > > > > > >>>>>>>>> per
> > > > > > >>>>>>>>> key
> > > > > > >>>>>>>>> ordering and potentially migrate the processing state.
> > This
> > > > is
> > > > > > not
> > > > > > >>>>>>>>> trivial
> > > > > > >>>>>>>>> and I am not sure if it's ideal to fully push to the
> > > > > application
> > > > > > >>>>>>>>> space.
> > > > > > >>>>>>>>>
> > > > > > >>>>>>>>> Broker support is defenitly the preferred way here. I
> > have
> > > > > > nothing
> > > > > > >>>>>>>>>
> > > > > > >>>>>>>>> against
> > > > > > >>>>>>>> broker support.
> > > > > > >>>>>>>> I tried to say that for what I would preffer - copying
> the
> > > > data
> > > > > > >>>>>>>> over,
> > > > > > >>>>>>>> at
> > > > > > >>>>>>>> least for log compacted topics -
> > > > > > >>>>>>>> I would require more broker support than the KIP
> currently
> > > > > offers.
> > > > > > >>>>>>>>
> > > > > > >>>>>>>>
> > > > > > >>>>>>>>
> > > > > > >>>>>>>> Jun
> > > > > > >>>>>>>>
> > > > > > >>>>>>>> On Tue, Mar 6, 2018 at 10:33 PM, Jan Filipiak <
> > > > > > >>>>>>>>> Jan.Filipiak@trivago.com
> > > > > > >>>>>>>>> wrote:
> > > > > > >>>>>>>>>
> > > > > > >>>>>>>>> Hi Dong,
> > > > > > >>>>>>>>>
> > > > > > >>>>>>>>> are you actually reading my emails, or are you just
> using
> > > the
> > > > > > >>>>>>>>> thread I
> > > > > > >>>>>>>>>
> > > > > > >>>>>>>>>> started for general announcements regarding the KIP?
> > > > > > >>>>>>>>>>
> > > > > > >>>>>>>>>> I tried to argue really hard against linear hashing.
> > > Growing
> > > > > the
> > > > > > >>>>>>>>>> topic
> > > > > > >>>>>>>>>> by
> > > > > > >>>>>>>>>> an integer factor does not require any state
> > > redistribution
> > > > at
> > > > > > >>>>>>>>>> all. I
> > > > > > >>>>>>>>>> fail
> > > > > > >>>>>>>>>> to see completely where linear hashing helps on log
> > > > compacted
> > > > > > >>>>>>>>>> topics.
> > > > > > >>>>>>>>>>
> > > > > > >>>>>>>>>> If you are not willing to explain to me what I might
> be
> > > > > > >>>>>>>>>> overlooking:
> > > > > > >>>>>>>>>> that
> > > > > > >>>>>>>>>> is fine.
> > > > > > >>>>>>>>>> But I ask you to not reply to my emails then. Please
> > > > > understand
> > > > > > my
> > > > > > >>>>>>>>>> frustration with this.
> > > > > > >>>>>>>>>>
> > > > > > >>>>>>>>>> Best Jan
> > > > > > >>>>>>>>>>
> > > > > > >>>>>>>>>>
> > > > > > >>>>>>>>>>
> > > > > > >>>>>>>>>> On 06.03.2018 19:38, Dong Lin wrote:
> > > > > > >>>>>>>>>>
> > > > > > >>>>>>>>>> Hi everyone,
> > > > > > >>>>>>>>>>
> > > > > > >>>>>>>>>> Thanks for all the comments! It appears that everyone
> > > > prefers
> > > > > > >>>>>>>>>> linear
> > > > > > >>>>>>>>>>
> > > > > > >>>>>>>>>>> hashing because it reduces the amount of state that
> > needs
> > > > to
> > > > > be
> > > > > > >>>>>>>>>>> moved
> > > > > > >>>>>>>>>>> between consumers (for stream processing). The KIP
> has
> > > been
> > > > > > >>>>>>>>>>> updated
> > > > > > >>>>>>>>>>> to
> > > > > > >>>>>>>>>>> use
> > > > > > >>>>>>>>>>> linear hashing.
> > > > > > >>>>>>>>>>>
> > > > > > >>>>>>>>>>> Regarding the migration endeavor: it seems that
> > migrating
> > > > > > >>>>>>>>>>> producer
> > > > > > >>>>>>>>>>> library
> > > > > > >>>>>>>>>>> to use linear hashing should be pretty
> straightforward
> > > > > without
> > > > > > >>>>>>>>>>> much operational endeavor. If we don't upgrade client
> > > > library
> > > > > > to
> > > > > > >>>>>>>>>>> use
> > > > > > >>>>>>>>>>> this
> > > > > > >>>>>>>>>>> KIP, we can not support in-order delivery after
> > partition
> > > > is
> > > > > > >>>>>>>>>>> changed
> > > > > > >>>>>>>>>>> anyway. Suppose we upgrade client library to use this
> > > KIP,
> > > > if
> > > > > > >>>>>>>>>>> partition
> > > > > > >>>>>>>>>>> number is not changed, the key -> partition mapping
> > will
> > > be
> > > > > > >>>>>>>>>>> exactly
> > > > > > >>>>>>>>>>> the
> > > > > > >>>>>>>>>>> same as it is now because it is still determined
> using
> > > > > > >>>>>>>>>>> murmur_hash(key)
> > > > > > >>>>>>>>>>> %
> > > > > > >>>>>>>>>>> original_partition_num. In other words, this change
> is
> > > > > backward
> > > > > > >>>>>>>>>>> compatible.
> > > > > > >>>>>>>>>>>
> > > > > > >>>>>>>>>>> Regarding the load distribution: if we use linear
> > > hashing,
> > > > > the
> > > > > > >>>>>>>>>>> load
> > > > > > >>>>>>>>>>> may
> > > > > > >>>>>>>>>>> be
> > > > > > >>>>>>>>>>> unevenly distributed because those partitions which
> are
> > > not
> > > > > > split
> > > > > > >>>>>>>>>>> may
> > > > > > >>>>>>>>>>> receive twice as much traffic as other partitions
> that
> > > are
> > > > > > split.
> > > > > > >>>>>>>>>>> This
> > > > > > >>>>>>>>>>> issue can be mitigated by creating topic with
> > partitions
> > > > that
> > > > > > are
> > > > > > >>>>>>>>>>> several
> > > > > > >>>>>>>>>>> times the number of consumers. And there will be no
> > > > imbalance
> > > > > > if
> > > > > > >>>>>>>>>>> the
> > > > > > >>>>>>>>>>> partition number is always doubled. So this imbalance
> > > seems
> > > > > > >>>>>>>>>>> acceptable.
> > > > > > >>>>>>>>>>>
> > > > > > >>>>>>>>>>> Regarding storing the partition strategy as per-topic
> > > > config:
> > > > > > It
> > > > > > >>>>>>>>>>> seems
> > > > > > >>>>>>>>>>> not
> > > > > > >>>>>>>>>>> necessary since we can still use murmur_hash as the
> > > default
> > > > > > hash
> > > > > > >>>>>>>>>>> function
> > > > > > >>>>>>>>>>> and additionally apply the linear hashing algorithm
> if
> > > the
> > > > > > >>>>>>>>>>> partition
> > > > > > >>>>>>>>>>> number
> > > > > > >>>>>>>>>>> has increased. Not sure if there is any use-case for
> > > > producer
> > > > > > to
> > > > > > >>>>>>>>>>> use a
> > > > > > >>>>>>>>>>> different hash function. Jason, can you check if
> there
> > is
> > > > > some
> > > > > > >>>>>>>>>>> use-case
> > > > > > >>>>>>>>>>> that I missed for using the per-topic partition
> > strategy?
> > > > > > >>>>>>>>>>>
> > > > > > >>>>>>>>>>> Regarding how to reduce latency (due to state
> > store/load)
> > > > in
> > > > > > >>>>>>>>>>> stream
> > > > > > >>>>>>>>>>> processing consumer when partition number changes: I
> > need
> > > > to
> > > > > > read
> > > > > > >>>>>>>>>>> the
> > > > > > >>>>>>>>>>> Kafka
> > > > > > >>>>>>>>>>> Stream code to understand how Kafka Stream currently
> > > > migrate
> > > > > > >>>>>>>>>>> state
> > > > > > >>>>>>>>>>> between
> > > > > > >>>>>>>>>>> consumers when the application is added/removed for a
> > > given
> > > > > > job.
> > > > > > >>>>>>>>>>> I
> > > > > > >>>>>>>>>>> will
> > > > > > >>>>>>>>>>> reply after I finish reading the documentation and
> > code.
> > > > > > >>>>>>>>>>>
> > > > > > >>>>>>>>>>>
> > > > > > >>>>>>>>>>> Thanks,
> > > > > > >>>>>>>>>>> Dong
> > > > > > >>>>>>>>>>>
> > > > > > >>>>>>>>>>>
> > > > > > >>>>>>>>>>> On Mon, Mar 5, 2018 at 10:43 AM, Jason Gustafson <
> > > > > > >>>>>>>>>>> jason@confluent.io>
> > > > > > >>>>>>>>>>> wrote:
> > > > > > >>>>>>>>>>>
> > > > > > >>>>>>>>>>> Great discussion. I think I'm wondering whether we
> can
> > > > > continue
> > > > > > >>>>>>>>>>> to
> > > > > > >>>>>>>>>>> leave
> > > > > > >>>>>>>>>>>
> > > > > > >>>>>>>>>>> Kafka agnostic to the partitioning strategy. The
> > > challenge
> > > > is
> > > > > > >>>>>>>>>>>
> > > > > > >>>>>>>>>>> communicating
> > > > > > >>>>>>>>>>>> the partitioning logic from producers to consumers
> so
> > > that
> > > > > the
> > > > > > >>>>>>>>>>>> dependencies
> > > > > > >>>>>>>>>>>> between each epoch can be determined. For the sake
> of
> > > > > > >>>>>>>>>>>> discussion,
> > > > > > >>>>>>>>>>>> imagine
> > > > > > >>>>>>>>>>>> you did something like the following:
> > > > > > >>>>>>>>>>>>
> > > > > > >>>>>>>>>>>> 1. The name (and perhaps version) of a partitioning
> > > > strategy
> > > > > > is
> > > > > > >>>>>>>>>>>> stored
> > > > > > >>>>>>>>>>>> in
> > > > > > >>>>>>>>>>>> topic configuration when a topic is created.
> > > > > > >>>>>>>>>>>> 2. The producer looks up the partitioning strategy
> > > before
> > > > > > >>>>>>>>>>>> writing
> > > > > > >>>>>>>>>>>> to
> > > > > > >>>>>>>>>>>> a
> > > > > > >>>>>>>>>>>> topic and includes it in the produce request (for
> > > > fencing).
> > > > > If
> > > > > > >>>>>>>>>>>> it
> > > > > > >>>>>>>>>>>> doesn't
> > > > > > >>>>>>>>>>>> have an implementation for the configured strategy,
> it
> > > > > fails.
> > > > > > >>>>>>>>>>>> 3. The consumer also looks up the partitioning
> > strategy
> > > > and
> > > > > > >>>>>>>>>>>> uses it
> > > > > > >>>>>>>>>>>> to
> > > > > > >>>>>>>>>>>> determine dependencies when reading a new epoch. It
> > > could
> > > > > > either
> > > > > > >>>>>>>>>>>> fail
> > > > > > >>>>>>>>>>>> or
> > > > > > >>>>>>>>>>>> make the most conservative dependency assumptions if
> > it
> > > > > > doesn't
> > > > > > >>>>>>>>>>>> know
> > > > > > >>>>>>>>>>>> how
> > > > > > >>>>>>>>>>>> to
> > > > > > >>>>>>>>>>>> implement the partitioning strategy. For the
> consumer,
> > > the
> > > > > new
> > > > > > >>>>>>>>>>>> interface
> > > > > > >>>>>>>>>>>> might look something like this:
> > > > > > >>>>>>>>>>>>
> > > > > > >>>>>>>>>>>> // Return the partition dependencies following an
> > epoch
> > > > bump
> > > > > > >>>>>>>>>>>> Map<Integer, List<Integer>> dependencies(int
> > > > > > >>>>>>>>>>>> numPartitionsBeforeEpochBump,
> > > > > > >>>>>>>>>>>> int numPartitionsAfterEpochBump)
> > > > > > >>>>>>>>>>>>
> > > > > > >>>>>>>>>>>> The unordered case then is just a particular
> > > > implementation
> > > > > > >>>>>>>>>>>> which
> > > > > > >>>>>>>>>>>> never
> > > > > > >>>>>>>>>>>> has
> > > > > > >>>>>>>>>>>> any epoch dependencies. To implement this, we would
> > need
> > > > > some
> > > > > > >>>>>>>>>>>> way
> > > > > > >>>>>>>>>>>> for
> > > > > > >>>>>>>>>>>> the
> > > > > > >>>>>>>>>>>> consumer to find out how many partitions there were
> in
> > > > each
> > > > > > >>>>>>>>>>>> epoch,
> > > > > > >>>>>>>>>>>> but
> > > > > > >>>>>>>>>>>> maybe that's not too unreasonable.
> > > > > > >>>>>>>>>>>>
> > > > > > >>>>>>>>>>>> Thanks,
> > > > > > >>>>>>>>>>>> Jason
> > > > > > >>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>
> > > > > > >>>>>>>>>>>> On Mon, Mar 5, 2018 at 4:51 AM, Jan Filipiak <
> > > > > > >>>>>>>>>>>> Jan.Filipiak@trivago.com
> > > > > > >>>>>>>>>>>> wrote:
> > > > > > >>>>>>>>>>>>
> > > > > > >>>>>>>>>>>> Hi Dong
> > > > > > >>>>>>>>>>>>
> > > > > > >>>>>>>>>>>> thank you very much for your questions.
> > > > > > >>>>>>>>>>>>
> > > > > > >>>>>>>>>>>> regarding the time spend copying data across:
> > > > > > >>>>>>>>>>>>> It is correct that copying data from a topic with
> one
> > > > > > partition
> > > > > > >>>>>>>>>>>>> mapping
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> to
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> a topic with a different partition mapping takes
> way
> > > > longer
> > > > > > >>>>>>>>>>>>> than
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>> we
> > > > > > >>>>>>>>>>>> can
> > > > > > >>>>>>>>>>>>
> > > > > > >>>>>>>>>>>> stop producers. Tens of minutes is a very optimistic
> > > > > estimate
> > > > > > >>>>>>>>>>>> here.
> > > > > > >>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> Many
> > > > > > >>>>>>>>>>>>> people can not afford copy full steam and therefore
> > > will
> > > > > have
> > > > > > >>>>>>>>>>>>> some
> > > > > > >>>>>>>>>>>>> rate
> > > > > > >>>>>>>>>>>>> limiting in place, this can bump the timespan into
> > the
> > > > > day's.
> > > > > > >>>>>>>>>>>>> The
> > > > > > >>>>>>>>>>>>> good
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> part
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> is that the vast majority of the data can be copied
> > > while
> > > > > the
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>> producers
> > > > > > >>>>>>>>>>>>
> > > > > > >>>>>>>>>>>> are
> > > > > > >>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> still going. One can then, piggyback the consumers
> > > ontop
> > > > of
> > > > > > >>>>>>>>>>>>> this
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>> timeframe,
> > > > > > >>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> by the method mentioned (provide them an mapping
> from
> > > > their
> > > > > > old
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>> offsets
> > > > > > >>>>>>>>>>>>
> > > > > > >>>>>>>>>>>> to
> > > > > > >>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> new offsets in their repartitioned topics. In that
> > way
> > > we
> > > > > > >>>>>>>>>>>>> separate
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>> migration of consumers from migration of producers
> > > > > (decoupling
> > > > > > >>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> these
> > > > > > >>>>>>>>>>>>> is
> > > > > > >>>>>>>>>>>>> what kafka is strongest at). The time to actually
> > swap
> > > > over
> > > > > > the
> > > > > > >>>>>>>>>>>>> producers
> > > > > > >>>>>>>>>>>>> should be kept minimal by ensuring that when a swap
> > > > attempt
> > > > > > is
> > > > > > >>>>>>>>>>>>> started
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> the
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> consumer copying over should be very close to the
> log
> > > end
> > > > > and
> > > > > > >>>>>>>>>>>>> is
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>> expected
> > > > > > >>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> to finish within the next fetch. The operation
> should
> > > > have
> > > > > a
> > > > > > >>>>>>>>>>>>> time-out
> > > > > > >>>>>>>>>>>>> and
> > > > > > >>>>>>>>>>>>> should be "reattemtable".
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> Importance of logcompaction:
> > > > > > >>>>>>>>>>>>> If a producer produces key A, to partiton 0, its
> > > forever
> > > > > > gonna
> > > > > > >>>>>>>>>>>>> be
> > > > > > >>>>>>>>>>>>> there,
> > > > > > >>>>>>>>>>>>> unless it gets deleted. The record might sit in
> there
> > > for
> > > > > > >>>>>>>>>>>>> years. A
> > > > > > >>>>>>>>>>>>> new
> > > > > > >>>>>>>>>>>>> producer started with the new partitions will fail
> to
> > > > > delete
> > > > > > >>>>>>>>>>>>> the
> > > > > > >>>>>>>>>>>>> record
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> in
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> the correct partition. Th record will be there
> > forever
> > > > and
> > > > > > one
> > > > > > >>>>>>>>>>>>> can
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>> not
> > > > > > >>>>>>>>>>>>
> > > > > > >>>>>>>>>>>> reliable bootstrap new consumers. I cannot see how
> > > linear
> > > > > > >>>>>>>>>>>> hashing
> > > > > > >>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> can
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> solve
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> this.
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>> Regarding your skipping of userland copying:
> > > > > > >>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> 100%, copying the data across in userland is, as
> far
> > > as i
> > > > > can
> > > > > > >>>>>>>>>>>>> see,
> > > > > > >>>>>>>>>>>>> only
> > > > > > >>>>>>>>>>>>> a
> > > > > > >>>>>>>>>>>>> usecase for log compacted topics. Even for
> > > logcompaction
> > > > +
> > > > > > >>>>>>>>>>>>> retentions
> > > > > > >>>>>>>>>>>>> it
> > > > > > >>>>>>>>>>>>> should only be opt-in. Why did I bring it up? I
> think
> > > log
> > > > > > >>>>>>>>>>>>> compaction
> > > > > > >>>>>>>>>>>>> is
> > > > > > >>>>>>>>>>>>> a
> > > > > > >>>>>>>>>>>>> very important feature to really embrace kafka as a
> > > "data
> > > > > > >>>>>>>>>>>>> plattform".
> > > > > > >>>>>>>>>>>>> The
> > > > > > >>>>>>>>>>>>> point I also want to make is that copying data this
> > way
> > > > is
> > > > > > >>>>>>>>>>>>> completely
> > > > > > >>>>>>>>>>>>> inline with the kafka architecture. it only
> consists
> > of
> > > > > > reading
> > > > > > >>>>>>>>>>>>> and
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> writing
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> to topics.
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>> I hope it clarifies more why I think we should aim
> for
> > > > more
> > > > > > than
> > > > > > >>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> the
> > > > > > >>>>>>>>>>>>> current KIP. I fear that once the KIP is done not
> > much
> > > > more
> > > > > > >>>>>>>>>>>>> effort
> > > > > > >>>>>>>>>>>>> will
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> be
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> taken.
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>
> > > > > > >>>>>>>>>>>> On 04.03.2018 02:28, Dong Lin wrote:
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> Hey Jan,
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> In the current proposal, the consumer will be
> blocked
> > > on
> > > > > > >>>>>>>>>>>>> waiting
> > > > > > >>>>>>>>>>>>> for
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> other
> > > > > > >>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>> consumers of the group to consume up to a given
> > > offset.
> > > > In
> > > > > > >>>>>>>>>>>>>> most
> > > > > > >>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> cases,
> > > > > > >>>>>>>>>>>>> all
> > > > > > >>>>>>>>>>>>> consumers should be close to the LEO of the
> > partitions
> > > > when
> > > > > > the
> > > > > > >>>>>>>>>>>>> partition
> > > > > > >>>>>>>>>>>>> expansion happens. Thus the time waiting should not
> > be
> > > > long
> > > > > > >>>>>>>>>>>>> e.g.
> > > > > > >>>>>>>>>>>>> on
> > > > > > >>>>>>>>>>>>> the
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> order of seconds. On the other hand, it may take a
> > long
> > > > > time
> > > > > > to
> > > > > > >>>>>>>>>>>>> wait
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> for
> > > > > > >>>>>>>>>>>>>> the entire partition to be copied -- the amount of
> > > time
> > > > is
> > > > > > >>>>>>>>>>>>>> proportional
> > > > > > >>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>> to
> > > > > > >>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>> the amount of existing data in the partition,
> which
> > > can
> > > > > take
> > > > > > >>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> tens of
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> minutes. So the amount of time that we stop
> consumers
> > > may
> > > > > not
> > > > > > >>>>>>>>>>>>> be
> > > > > > >>>>>>>>>>>>> on
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> the
> > > > > > >>>>>>>>>>>>>> same order of magnitude.
> > > > > > >>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>> If we can implement this suggestion without
> copying
> > > data
> > > > > > over
> > > > > > >>>>>>>>>>>>>> in
> > > > > > >>>>>>>>>>>>>> purse
> > > > > > >>>>>>>>>>>>>> userland, it will be much more valuable. Do you
> have
> > > > ideas
> > > > > > on
> > > > > > >>>>>>>>>>>>>> how
> > > > > > >>>>>>>>>>>>>> this
> > > > > > >>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>> can
> > > > > > >>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>> be done?
> > > > > > >>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> Not sure why the current KIP not help people who
> > depend
> > > > on
> > > > > > log
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> compaction.
> > > > > > >>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>> Could you elaborate more on this point?
> > > > > > >>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> Thanks,
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> Dong
> > > > > > >>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>> On Wed, Feb 28, 2018 at 10:55 PM, Jan
> > > > > > >>>>>>>>>>>>>> Filipiak<Jan.Filipiak@trivago.
> > > > > > >>>>>>>>>>>>>> com
> > > > > > >>>>>>>>>>>>>> wrote:
> > > > > > >>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>> Hi Dong,
> > > > > > >>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>> I tried to focus on what the steps are one can
> > > currently
> > > > > > >>>>>>>>>>>>>> perform
> > > > > > >>>>>>>>>>>>>> to
> > > > > > >>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>> expand
> > > > > > >>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>> or shrink a keyed topic while maintaining a top
> > notch
> > > > > > >>>>>>>>>>>>>>> semantics.
> > > > > > >>>>>>>>>>>>>>> I can understand that there might be confusion
> > about
> > > > > > >>>>>>>>>>>>>>> "stopping
> > > > > > >>>>>>>>>>>>>>> the
> > > > > > >>>>>>>>>>>>>>> consumer". It is exactly the same as proposed in
> > the
> > > > KIP.
> > > > > > >>>>>>>>>>>>>>> there
> > > > > > >>>>>>>>>>>>>>> needs
> > > > > > >>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>> to
> > > > > > >>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>> be
> > > > > > >>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>> a time the producers agree on the new
> partitioning.
> > > The
> > > > > > extra
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> semantics I
> > > > > > >>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>> want to put in there is that we have a
> possibility
> > to
> > > > > wait
> > > > > > >>>>>>>>>>>>>>> until
> > > > > > >>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>> all
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> the
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> existing data
> > > > > > >>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>> is copied over into the new partitioning scheme.
> > When
> > > I
> > > > > say
> > > > > > >>>>>>>>>>>>> stopping
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> I
> > > > > > >>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>> think more of having a memory barrier that
> ensures
> > > the
> > > > > > >>>>>>>>>>>>>>> ordering. I
> > > > > > >>>>>>>>>>>>>>> am
> > > > > > >>>>>>>>>>>>>>> still
> > > > > > >>>>>>>>>>>>>>> aming for latencies  on the scale of leader
> > > failovers.
> > > > > > >>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>> Consumers have to explicitly adapt the new
> > > partitioning
> > > > > > >>>>>>>>>>>>>>> scheme
> > > > > > >>>>>>>>>>>>>>> in
> > > > > > >>>>>>>>>>>>>>> the
> > > > > > >>>>>>>>>>>>>>> above scenario. The reason is that in these cases
> > > where
> > > > > you
> > > > > > >>>>>>>>>>>>>>> are
> > > > > > >>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>> dependent
> > > > > > >>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>> on a particular partitioning scheme, you also
> have
> > > > other
> > > > > > >>>>>>>>>>>>>>> topics
> > > > > > >>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>> that
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> have
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> co-partition enforcements or the kind -frequently.
> > > > > Therefore
> > > > > > >>>>>>>>>>>>>> all
> > > > > > >>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>> your
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> other
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> input topics might need to grow accordingly.
> > > > > > >>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>> What I was suggesting was to streamline all these
> > > > > > operations
> > > > > > >>>>>>>>>>>>>>> as
> > > > > > >>>>>>>>>>>>>>> best
> > > > > > >>>>>>>>>>>>>>> as
> > > > > > >>>>>>>>>>>>>>> possible to have "real" partition grow and
> > shrinkage
> > > > > going
> > > > > > >>>>>>>>>>>>>>> on.
> > > > > > >>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>> Migrating
> > > > > > >>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>> the producers to a new partitioning scheme can be
> > > much
> > > > > more
> > > > > > >>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>> streamlined
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> with proper broker support for this. Migrating
> > consumer
> > > > is
> > > > > a
> > > > > > >>>>>>>>>>>>> step
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> that
> > > > > > >>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>> might be made completly unnecessary if - for
> > example
> > > > > > streams
> > > > > > >>>>>>>>>>>>>>> -
> > > > > > >>>>>>>>>>>>>>> takes
> > > > > > >>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>> the
> > > > > > >>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>> gcd as partitioning scheme instead of enforcing 1
> > to
> > > 1.
> > > > > > >>>>>>>>>>>>>>> Connect
> > > > > > >>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>> consumers
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> and other consumers should be fine anyways.
> > > > > > >>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>> I hope this makes more clear where I was aiming
> at.
> > > The
> > > > > rest
> > > > > > >>>>>>>>>>>>> needs
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> to
> > > > > > >>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>> be
> > > > > > >>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>> figured out. The only danger i see is that when
> we
> > > are
> > > > > > >>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>> introducing
> > > > > > >>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>> this
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> feature as supposed in the KIP, it wont help any
> > people
> > > > > > >>>>>>>>>>>>> depending
> > > > > > >>>>>>>>>>>>> on
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> log
> > > > > > >>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>> compaction.
> > > > > > >>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>> The other thing I wanted to mention is that I
> > believe
> > > > the
> > > > > > >>>>>>>>>>>>> current
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> suggestion (without copying data over) can be
> > > implemented
> > > > > in
> > > > > > >>>>>>>>>>>>>> pure
> > > > > > >>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>> userland
> > > > > > >>>>>>>>>>>>>>> with a custom partitioner and a small
> feedbackloop
> > > from
> > > > > > >>>>>>>>>>>>>>> ProduceResponse
> > > > > > >>>>>>>>>>>>>>> =>
> > > > > > >>>>>>>>>>>>>>> Partitionier in coorporation with a change
> > management
> > > > > > system.
> > > > > > >>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>> Best Jan
> > > > > > >>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>> On 28.02.2018 07:13, Dong Lin wrote:
> > > > > > >>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>> Hey Jan,
> > > > > > >>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>> I am not sure if it is acceptable for producer to
> > be
> > > > > > stopped
> > > > > > >>>>>>>>>>>>>>> for a
> > > > > > >>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>> while,
> > > > > > >>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>> particularly for online application which
> requires
> > > low
> > > > > > >>>>>>>>>>>>>>>> latency. I
> > > > > > >>>>>>>>>>>>>>>> am
> > > > > > >>>>>>>>>>>>>>>> also
> > > > > > >>>>>>>>>>>>>>>> not sure how consumers can switch to a new
> topic.
> > > Does
> > > > > > user
> > > > > > >>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>> application
> > > > > > >>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>> needs to explicitly specify a different topic
> for
> > > > > > >>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>> producer/consumer
> > > > > > >>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>> to
> > > > > > >>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> subscribe to? It will be helpful for discussion if
> > you
> > > > can
> > > > > > >>>>>>>>>>>>> provide
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> more
> > > > > > >>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>> detail on the interface change for this solution.
> > > > > > >>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>> Thanks,
> > > > > > >>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>> Dong
> > > > > > >>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>> On Mon, Feb 26, 2018 at 12:48 AM, Jan
> > > > > > >>>>>>>>>>>>>>>> Filipiak<Jan.Filipiak@trivago.
> > > > > > >>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>> com
> > > > > > >>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>> wrote:
> > > > > > >>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>> Hi,
> > > > > > >>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>> just want to throw my though in. In general the
> > > > > > functionality
> > > > > > >>>>>>>>>>>>>> is
> > > > > > >>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>> very
> > > > > > >>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>> usefull, we should though not try to find the
> > > > > architecture
> > > > > > >>>>>>>>>>>>>>>> to
> > > > > > >>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>> hard
> > > > > > >>>>>>>>>>>>>>>>> while
> > > > > > >>>>>>>>>>>>>>>>> implementing.
> > > > > > >>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>> The manual steps would be to
> > > > > > >>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>> create a new topic
> > > > > > >>>>>>>>>>>>>>>>> the mirrormake from the new old topic to the
> new
> > > > topic
> > > > > > >>>>>>>>>>>>>>>>> wait for mirror making to catch up.
> > > > > > >>>>>>>>>>>>>>>>> then put the consumers onto the new topic
> > > > > > >>>>>>>>>>>>>>>>>            (having mirrormaker spit out a
> mapping
> > > > from
> > > > > > old
> > > > > > >>>>>>>>>>>>>>>>> offsets to
> > > > > > >>>>>>>>>>>>>>>>> new
> > > > > > >>>>>>>>>>>>>>>>> offsets:
> > > > > > >>>>>>>>>>>>>>>>>                if topic is increased by factor
> X
> > > > there
> > > > > is
> > > > > > >>>>>>>>>>>>>>>>> gonna
> > > > > > >>>>>>>>>>>>>>>>> be a
> > > > > > >>>>>>>>>>>>>>>>> clean
> > > > > > >>>>>>>>>>>>>>>>> mapping from 1 offset in the old topic to X
> > offsets
> > > > in
> > > > > > the
> > > > > > >>>>>>>>>>>>>>>>> new
> > > > > > >>>>>>>>>>>>>>>>> topic,
> > > > > > >>>>>>>>>>>>>>>>>                if there is no factor then there
> > is
> > > no
> > > > > > >>>>>>>>>>>>>>>>> chance to
> > > > > > >>>>>>>>>>>>>>>>> generate a
> > > > > > >>>>>>>>>>>>>>>>> mapping that can be reasonable used for
> > continuing)
> > > > > > >>>>>>>>>>>>>>>>>            make consumers stop at appropriate
> > > points
> > > > > and
> > > > > > >>>>>>>>>>>>>>>>> continue
> > > > > > >>>>>>>>>>>>>>>>> consumption
> > > > > > >>>>>>>>>>>>>>>>> with offsets from the mapping.
> > > > > > >>>>>>>>>>>>>>>>> have the producers stop for a minimal time.
> > > > > > >>>>>>>>>>>>>>>>> wait for mirrormaker to finish
> > > > > > >>>>>>>>>>>>>>>>> let producer produce with the new metadata.
> > > > > > >>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>> Instead of implementing the approach suggest in
> > the
> > > > KIP
> > > > > > >>>>>>>>>>>>>>>>> which
> > > > > > >>>>>>>>>>>>>>>>> will
> > > > > > >>>>>>>>>>>>>>>>> leave
> > > > > > >>>>>>>>>>>>>>>>> log compacted topic completely crumbled and
> > > unusable.
> > > > > > >>>>>>>>>>>>>>>>> I would much rather try to build infrastructure
> > to
> > > > > > support
> > > > > > >>>>>>>>>>>>>>>>> the
> > > > > > >>>>>>>>>>>>>>>>> mentioned
> > > > > > >>>>>>>>>>>>>>>>> above operations more smoothly.
> > > > > > >>>>>>>>>>>>>>>>> Especially having producers stop and use
> another
> > > > topic
> > > > > is
> > > > > > >>>>>>>>>>>>>>>>> difficult
> > > > > > >>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>> and
> > > > > > >>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>> it would be nice if one can trigger "invalid
> > > > metadata"
> > > > > > >>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>> exceptions
> > > > > > >>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>> for
> > > > > > >>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>> them
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> and
> > > > > > >>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>> if one could give topics aliases so that their
> > > produces
> > > > > > with
> > > > > > >>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>> the
> > > > > > >>>>>>>>>>>>>>>>> old
> > > > > > >>>>>>>>>>>>>>>>> topic
> > > > > > >>>>>>>>>>>>>>>>> will arrive in the new topic.
> > > > > > >>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>> The downsides are obvious I guess ( having the
> > same
> > > > > data
> > > > > > >>>>>>>>>>>>>>>>> twice
> > > > > > >>>>>>>>>>>>>>>>> for
> > > > > > >>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>> the
> > > > > > >>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>> transition period, but kafka tends to scale
> well
> > > with
> > > > > > >>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>> datasize).
> > > > > > >>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>> So
> > > > > > >>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>> its a
> > > > > > >>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>> nicer fit into the architecture.
> > > > > > >>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>> I further want to argument that the functionality
> > by
> > > > the
> > > > > > KIP
> > > > > > >>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>> can
> > > > > > >>>>>>>>>>>>>>>>> completely be implementing in "userland" with a
> > > > custom
> > > > > > >>>>>>>>>>>>>>>>> partitioner
> > > > > > >>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>> that
> > > > > > >>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>> handles the transition as needed. I would
> > > appreciate
> > > > if
> > > > > > >>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>> someone
> > > > > > >>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>> could
> > > > > > >>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>> point
> > > > > > >>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>> out what a custom partitioner couldn't handle in
> this
> > > > case?
> > > > > > >>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>> With the above approach, shrinking a topic
> becomes
> > > the
> > > > > same
> > > > > > >>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>> steps.
> > > > > > >>>>>>>>>>>>>>>>> Without
> > > > > > >>>>>>>>>>>>>>>>> loosing keys in the discontinued partitions.
> > > > > > >>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>> Would love to hear what everyone thinks.
> > > > > > >>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>> Best Jan
> > > > > > >>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>> On 11.02.2018 00:35, Dong Lin wrote:
> > > > > > >>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>> Hi all,
> > > > > > >>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>> I have created KIP-253: Support in-order
> message
> > > > > delivery
> > > > > > >>>>>>>>>>>>>>>>> with
> > > > > > >>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>> partition
> > > > > > >>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>> expansion. See
> > > > > > >>>>>>>>>>>>>>>>>> https://cwiki.apache.org/confl
> > > > > > >>>>>>>>>>>>>>>>>> uence/display/KAFKA/KIP-253%
> > > > > > >>>>>>>>>>>>>>>>>> 3A+Support+in-order+message+de
> > > > > > >>>>>>>>>>>>>>>>>> livery+with+partition+expansio
> > > > > > >>>>>>>>>>>>>>>>>> n
> > > > > > >>>>>>>>>>>>>>>>>> .
> > > > > > >>>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>>> This KIP provides a way to allow messages of
> the
> > > > same
> > > > > > key
> > > > > > >>>>>>>>>>>>>>>>>> from
> > > > > > >>>>>>>>>>>>>>>>>> the
> > > > > > >>>>>>>>>>>>>>>>>> same
> > > > > > >>>>>>>>>>>>>>>>>> producer to be consumed in the same order they
> > are
> > > > > > >>>>>>>>>>>>>>>>>> produced
> > > > > > >>>>>>>>>>>>>>>>>> even
> > > > > > >>>>>>>>>>>>>>>>>> if
> > > > > > >>>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>>> we
> > > > > > >>>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>>> expand partition of the topic.
> > > > > > >>>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>> Thanks,
> > > > > > >>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>> Dong
> > > > > > >>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>>>
> > > > > > >>>>>>>>>>>>>>>>>>
> > > > > > >>>>
> > > > > > >>
> > > > > > >>
> > > > > > >
> > > > > >
> > > > >
> > > >
> > >
> >
>



-- 
-- Guozhang

Re: [DISCUSS] KIP-253: Support in-order message delivery with partition expansion

Posted by John Roesler <jo...@confluent.io>.
Hey Dong,

Congrats on becoming a committer!!!

Since I just sent a novel-length email, I'll try and keep this one brief ;)

Regarding producer coordination, I'll grant that in that case, producers
may coordinate among themselves to produce into the same topic or to
produce co-partitioned topics. Nothing in KStreams or the Kafka ecosystem
in general requires such coordination for correctness or in fact for any
optional features, though, so I would not say that we require producer
coordination of partition logic. If producers currently coordinate, it's
completely optional and their own choice.

Regarding the portability of partition algorithms, my observation is that
systems requiring independent implementations of the same algorithm with
100% correctness are a large source of risk and also a burden on those who
have to maintain them. If people could flawlessly implement algorithms in
actual software, the world would be a wonderful place indeed! For a system
as important and widespread as Kafka, I would recommend restricting
limiting such requirements as aggressively as possible.

I'd agree that we can always revisit decisions like allowing arbitrary
partition functions, but of course, we shouldn't do that in a vacuum. That
feels like the kind of thing we'd need to proactively seek guidance from
the users list about. I do think that the general approach of saying that
"if you use a custom partitioner, you cannot do partition expansion" is
very reasonable (but I don't think we need to go that far with the current
proposal). It's similar to my statement in my email to Jun that in
principle KStreams doesn't *need* backfill, we only need it if we want to
employ partition expansion.

I reckon that the main motivation for backfill is to support KStreams use
cases and also any other use cases involving stateful consumers.

Thanks for your response, and congrats again!
-John


On Wed, Mar 28, 2018 at 1:34 AM, Dong Lin <li...@gmail.com> wrote:

> Hey John,
>
> Great! Thanks for all the comment. It seems that we agree that the current
> KIP is in good shape for core Kafka. IMO, what we have been discussing in
> the recent email exchanges is mostly about the second step, i.e. how to
> address problem for the stream use-case (or stateful processing in
> general).
>
> I will comment inline.
>
>
>
>
> On Tue, Mar 27, 2018 at 4:38 PM, John Roesler <jo...@confluent.io> wrote:
>
> > Thanks for the response, Dong.
> >
> > Here are my answers to your questions:
> >
> > - "Asking producers and consumers, or even two different producers, to
> > > share code like the partition function is a pretty huge ask. What if
> they
> > > are using different languages?". It seems that today we already require
> > > different producer's to use the same hash function -- otherwise
> messages
> > > with the same key will go to different partitions of the same topic
> which
> > > may cause problem for downstream consumption. So not sure if it adds
> any
> > > more constraint by assuming consumers know the hash function of
> producer.
> > > Could you explain more why user would want to use a cusmtom partition
> > > function? Maybe we can check if this is something that can be supported
> > in
> > > the default Kafka hash function. Also, can you explain more why it is
> > > difficuilt to implement the same hash function in different languages?
> >
> >
> > Sorry, I meant two different producers as in producers to two different
> > topics. This was in response to the suggestion that we already require
> > coordination among producers to different topics in order to achieve
> > co-partitioning. I was saying that we do not (and should not).
>
>
> It is probably common for producers of different team to produce message to
> the same topic. In order to ensure that messages with the same key go to
> same partition, we need producers of different team to share the same
> partition algorithm, which by definition requires coordination among
> producers of different teams in an organization. Even for producers of
> different topics, it may be common to require producers to use the same
> partition algorithm in order to join two topics for stream processing. Does
> this make it reasonable to say we already require coordination across
> producers?
>
>
> > By design, consumers are currently ignorant of the partitioning scheme.
> It
> > suffices to trust that the producer has partitioned the topic by key, if
> > they claim to have done so. If you don't trust that, or even if you just
> > need some other partitioning scheme, then you must re-partition it
> > yourself. Nothing we're discussing can or should change that. The value
> of
> > backfill is that it preserves the ability for consumers to avoid
> > re-partitioning before consuming, in the case where they don't need to
> > today.
>
>
> > Regarding shared "hash functions", note that it's a bit inaccurate to
> talk
> > about the "hash function" of the producer. Properly speaking, the
> producer
> > has only a "partition function". We do not know that it is a hash. The
> > producer can use any method at their disposal to assign a partition to a
> > record. The partition function obviously may we written in any
> programming
> > language, so in general it's not something that can be shared around
> > without a formal spec or the ability to execute arbitrary executables in
> > arbitrary runtime environments.
> >
>
> Yeah it is probably better to say partition algorithm. I guess it should
> not be difficult to implement same partition algorithms in different
> languages, right? Yes we would need a formal specification of the default
> partition algorithm in the producer. I think that can be documented as part
> of the producer interface.
>
>
> >
> > Why would a producer want a custom partition function? I don't know...
> why
> > did we design the interface so that our users can provide one? In
> general,
> > such systems provide custom partitioners because some data sets may be
> > unbalanced under the default or because they can provide some interesting
> > functionality built on top of the partitioning scheme, etc. Having
> provided
> > this ability, I don't know why we would remove it.
> >
>
> Yeah it is reasonable to assume that there was reason to support custom
> partition function in producer. On the other hand it may also be reasonable
> to revisit this interface and discuss whether we actually need to support
> custom partition function. If we don't have a good reason, we can choose
> not to support custom partition function in this KIP in a backward
> compatible manner, i.e. user can still use custom partition function but
> they would not get the benefit of in-order delivery when there is partition
> expansion. What do you think?
>
>
> >
> > - Besides the assumption that consumer needs to share the hash function
> of
> > > producer, is there other organization overhead of the proposal in the
> > > current KIP?
> > >
> >
> > It wasn't clear to me that KIP-253 currently required the producer and
> > consumer to share the partition function, or in fact that it had a hard
> > requirement to abandon the general partition function and use a linear
> hash
> > function instead.
>
>
> > In my reading, there is a requirement to track the metadata about what
> > partitions split into what other partitions during an expansion
> operation.
> > If the partition function is linear, this is easy. If not, you can always
> > just record that all old partitions split into all new partitions. This
> has
> > the effect of forcing all consumers to wait until the old epoch is
> > completely consumed before starting on the new epoch. But this may be a
> > reasonable tradeoff, and it doesn't otherwise alter your design.
> >
> > You only mention the consumer needing to know that the partition function
> > is linear, not what the actual function is, so I don't think your design
> > actually calls for sharing the function. Plus, really all the consumer
> > needs is the metadata about what old-epoch partitions to wait for before
> > consuming a new-epoch partition. This information is directly captured in
> > metadata, so I don't think it actually even cares whether the partition
> > function is linear or not.
> >
>
> You are right that the current KIP does not mention it. My comment related
> to the partition function coordination was related to support the
> stream-use case which we have been discussing so far.
>
>
> > So, no, I really think KIP-253 is in good shape. I was really more
> talking
> > about the part of this thread that's outside of KIP-253's scope, namely,
> > creating the possibility of backfilling partitions after expansion.
> >
>
> Great! Can you also confirm that the main motivation for backfilling
> partitions after expansion is to support the stream use-case?
>
>
> > - Currently producer can forget about the message that has been
> > > acknowledged by the broker. Thus the producer probably does not know
> most
> > > of the exiting messages in topic, including those messages produced by
> > > other producers. We can have the owner of the producer to
> split+backfill.
> > > In my opion it will be a new program that wraps around the existing
> > > producer and consumer classes.
> > >
> >
> > This sounds fine by me!
> >
> > Really, I was just emphasizing that the part of the organization that
> > produces a topic shouldn't have to export their partition function to the
> > part(s) of the organization (or other organizations) that consume the
> > topic. Whether the backfill operation goes into the Producer interface is
> > secondary, I think.
> >
> > - Regarding point 5. The argument is in favor of the split+backfill but
> for
> > > changelog topic. And it intends to address the problem for stream
> > use-case
> > > in general. In this KIP we will provide interface (i.e.
> > > PartitionKeyRebalanceListener in the KIP) to be used by sream use-case
> > and
> > > the goal is that user can flush/re-consume the state as part of the
> > > interface implementation regardless of whether there is change log
> topic.
> > >
> > > Maybe you are suggesting that the main reason to do split+backfill of
> > input
> > > topic is to support log compacted topics? You mentioned in Point 1 that
> > log
> > > compacted topics is out of the scope of this KIP. Maybe I could
> > understand
> > > your position better. Regarding Jan's proposal to split partitions with
> > > backfill, do you think this should replace the proposal in the existing
> > > KIP, or do you think this is something that we should do in addition to
> > the
> > > existing KIP?
> > >
> >
> > I think that interface is a good/necessary component of KIP-253.
> >
> > I personally (FWIW) feel that KIP-253 is appropriately scoped, but I do
> > think its utility will be limited unless there is a later KIP offering
> > backfill. But, maybe unlike Jan, I think it makes sense to try and tackle
> > the ordering problem independently of backfill, so I'm in support of the
> > current KIP.
> >
> > - Regarding point 6. I guess we can agree that it is better not to have
> the
> > > performance overhread of copying the input data. Before we discuss more
> > on
> > > whether the performance overhead is acceptable or not, I am trying to
> > > figure out what is the benefit of introducing this overhread. You
> > mentioned
> > > that the benefit is the loose organizational coupling. By
> "organizational
> > > coupling", are you referring to the requirement that consumer needs to
> > know
> > > the hash function of producer? If so, maybe we can discuss the use-case
> > of
> > > custom partiton function and see whether we can find a way to support
> > such
> > > use-case without having to copy the input data.
> > >
> >
> > I'm not too sure about what an "input" is in this sense, since we are
> just
> > talking about topics. Actually the point I was making there is that
> AKAICT
> > the performance overhead of a backfill is less than any other option,
> > assuming you split partitions rarely.
> >
>
> By "input" I was referring to source Kafka topic of a stream processing
> job.
>
>
> > Separately, yes, "organizational coupling" increases if producers and
> > consumers have to share code, such as the partition function. This would
> > not be the case if producers could only pick from a menu of a few
> > well-known partition functions, but I think this is a poor tradeoff.
> >
>
> Maybe we can revisit the custom partition function and see whether we
> actually need it? Otherwise, I am concerned that every user will pay the
> overhead of data movement to support something that was not really needed
> for most users.
>
>
> >
> > To me, this is two strong arguments in favor of backfill being less
> > expensive than no backfill, but again, I think that particular debate
> comes
> > after KIP-253, so I don't want to create the impression of opposition to
> > your proposal.
> >
> >
> > Finally, to respond to a new email I just noticed:
> >
> > > BTW, here is my understanding of the scope of this KIP. We want to
> allow
> > > consumers to always consume messages with the same key from the same
> > > producer in the order they are produced. And we need to provide a way
> for
> > > stream use-case to be able to flush/load state when messages with the
> > same
> > > key are migrated between consumers. In addition to ensuring that this
> > goal
> > > is correctly supported, we should do our best to keep the performance
> and
> > > organization overhead of this KIP as low as possible.
> > >
> >
> > I think we're on the same page there! In fact, I would generalize a
> little
> > more and say that the mechanism you've designed provides *all consumers*
> > the ability "to flush/load state when messages with the same key are
> > migrated between consumers", not just Streams.
> >
>
> Thanks for all the comment!
>
>
> >
> > Thanks for the discussion,
> > -John
> >
> >
> >
> > On Tue, Mar 27, 2018 at 3:14 PM, Dong Lin <li...@gmail.com> wrote:
> >
> > > Hey John,
> > >
> > > Thanks much for the detailed comments. Here are my thoughts:
> > >
> > > - The need to delete messages from log compacted topics is mainly for
> > > performance (e.g. storage space) optimization than for correctness for
> > this
> > > KIP. I agree that we probably don't need to focus on this in our
> > discussion
> > > since it is mostly for performance optimization.
> > >
> > > - "Asking producers and consumers, or even two different producers, to
> > > share code like the partition function is a pretty huge ask. What if
> they
> > > are using different languages?". It seems that today we already require
> > > different producer's to use the same hash function -- otherwise
> messages
> > > with the same key will go to different partitions of the same topic
> which
> > > may cause problem for downstream consumption. So not sure if it adds
> any
> > > more constraint by assuming consumers know the hash function of
> producer.
> > > Could you explain more why user would want to use a cusmtom partition
> > > function? Maybe we can check if this is something that can be supported
> > in
> > > the default Kafka hash function. Also, can you explain more why it is
> > > difficuilt to implement the same hash function in different languages?
> > >
> > > - Besides the assumption that consumer needs to share the hash function
> > of
> > > producer, is there other organization overhead of the proposal in the
> > > current KIP?
> > >
> > > - Currently producer can forget about the message that has been
> > > acknowledged by the broker. Thus the producer probably does not know
> most
> > > of the exiting messages in topic, including those messages produced by
> > > other producers. We can have the owner of the producer to
> split+backfill.
> > > In my opion it will be a new program that wraps around the existing
> > > producer and consumer classes.
> > >
> > > - Regarding point 5. The argument is in favor of the split+backfill but
> > for
> > > changelog topic. And it intends to address the problem for stream
> > use-case
> > > in general. In this KIP we will provide interface (i.e.
> > > PartitionKeyRebalanceListener in the KIP) to be used by sream use-case
> > and
> > > the goal is that user can flush/re-consume the state as part of the
> > > interface implementation regardless of whether there is change log
> topic.
> > >
> > > Maybe you are suggesting that the main reason to do split+backfill of
> > input
> > > topic is to support log compacted topics? You mentioned in Point 1 that
> > log
> > > compacted topics is out of the scope of this KIP. Maybe I could
> > understand
> > > your position better. Regarding Jan's proposal to split partitions with
> > > backfill, do you think this should replace the proposal in the existing
> > > KIP, or do you think this is something that we should do in addition to
> > the
> > > existing KIP?
> > >
> > > - Regarding point 6. I guess we can agree that it is better not to have
> > the
> > > performance overhread of copying the input data. Before we discuss more
> > on
> > > whether the performance overhead is acceptable or not, I am trying to
> > > figure out what is the benefit of introducing this overhread. You
> > mentioned
> > > that the benefit is the loose organizational coupling. By
> "organizational
> > > coupling", are you referring to the requirement that consumer needs to
> > know
> > > the hash function of producer? If so, maybe we can discuss the use-case
> > of
> > > custom partiton function and see whether we can find a way to support
> > such
> > > use-case without having to copy the input data.
> > >
> > > Thanks,
> > > Dong
> > >
> > >
> > > On Tue, Mar 27, 2018 at 11:34 AM, John Roesler <jo...@confluent.io>
> > wrote:
> > >
> > > > Hey Dong and Jun,
> > > >
> > > > Thanks for the thoughtful responses. If you don't mind, I'll mix my
> > > replies
> > > > together to try for a coherent response. I'm not too familiar with
> > > > mailing-list etiquette, though.
> > > >
> > > > I'm going to keep numbering my points because it makes it easy for
> you
> > > all
> > > > to respond.
> > > >
> > > > Point 1:
> > > > As I read it, KIP-253 is *just* about properly fencing the producers
> > and
> > > > consumers so that you preserve the correct ordering of records during
> > > > partition expansion. This is clearly necessary regardless of anything
> > > else
> > > > we discuss. I think this whole discussion about backfill, consumers,
> > > > streams, etc., is beyond the scope of KIP-253. But it would be
> > cumbersome
> > > > to start a new thread at this point.
> > > >
> > > > I had missed KIP-253's Proposed Change #9 among all the details... I
> > > think
> > > > this is a nice addition to the proposal. One thought is that it's
> > > actually
> > > > irrelevant whether the hash function is linear. This is simply an
> > > algorithm
> > > > for moving a key from one partition to another, so the type of hash
> > > > function need not be a precondition. In fact, it also doesn't matter
> > > > whether the topic is compacted or not, the algorithm works
> regardless.
> > > >
> > > > I think this is a good algorithm to keep in mind, as it might solve a
> > > > variety of problems, but it does have a downside: that the producer
> > won't
> > > > know whether or not K1 was actually in P1, it just knows that K1 was
> in
> > > > P1's keyspace before the new epoch. Therefore, it will have to
> > > > pessimistically send (K1,null) to P1 just in case. But the next time
> K1
> > > > comes along, the producer *also* won't remember that it already
> > retracted
> > > > K1 from P1, so it will have to send (K1,null) *again*. By extension,
> > > every
> > > > time the producer sends to P2, it will also have to send a tombstone
> to
> > > P1,
> > > > which is a pretty big burden. To make the situation worse, if there
> is
> > a
> > > > second split, say P2 becomes P2 and P3, then any key Kx belonging to
> P3
> > > > will also have to be retracted from P2 *and* P1, since the producer
> > can't
> > > > know whether Kx had been last written to P2 or P1. Over a long period
> > of
> > > > time, this clearly becomes a issue, as the producer must send an
> > > arbitrary
> > > > number of retractions along with every update.
> > > >
> > > > In contrast, the proposed backfill operation has an end, and after it
> > > ends,
> > > > everyone can afford to forget that there ever was a different
> partition
> > > > layout.
> > > >
> > > > Really, though, figuring out how to split compacted topics is beyond
> > the
> > > > scope of KIP-253, so I'm not sure #9 really even needs to be in this
> > > KIP...
> > > > We do need in-order delivery during partition expansion. It would be
> > fine
> > > > by me to say that you *cannot* expand partitions of a log-compacted
> > topic
> > > > and call it a day. I think it would be better to tackle that in
> another
> > > > KIP.
> > > >
> > > >
> > > > Point 2:
> > > > Regarding whether the consumer re-shuffles its inputs, this is always
> > on
> > > > the table; any consumer who wants to re-shuffle its input is free to
> do
> > > so.
> > > > But this is currently not required. It's just that the current
> > high-level
> > > > story with Kafka encourages the use of partitions as a unit of
> > > concurrency.
> > > > As long as consumers are single-threaded, they can happily consume a
> > > single
> > > > partition without concurrency control of any kind. This is a key
> aspect
> > > to
> > > > this system that lets folks design high-throughput systems on top of
> it
> > > > surprisingly easily. If all consumers were instead
> encouraged/required
> > to
> > > > implement a repartition of their own, then the consumer becomes
> > > > significantly more complex, requiring either the consumer to first
> > > produce
> > > > to its own intermediate repartition topic or to ensure that consumer
> > > > threads have a reliable, high-bandwith channel of communication with
> > > every
> > > > other consumer thread.
> > > >
> > > > Either of those tradeoffs may be reasonable for a particular user of
> > > Kafka,
> > > > but I don't know if we're in a position to say that they are
> reasonable
> > > for
> > > > *every* user of Kafka.
> > > >
> > > >
> > > > Point 3:
> > > > Regarding Jun's point about this use case, "(3) stateful and
> > maintaining
> > > > the
> > > > states in a local store", I agree that they may use a framework
> *like*
> > > > Kafka Streams, but that is not the same as using Kafka Streams. This
> is
> > > why
> > > > I think it's better to solve it in Core: because it is then solved
> for
> > > > KStreams and also for everything else that facilitates local state
> > > > maintenance. To me, Streams is a member of the category of "stream
> > > > processing frameworks", which is itself a subcategory of "things
> > > requiring
> > > > local state maintenence". I'm not sure if it makes sense to assert
> that
> > > > Streams is a sufficient and practical replacement for everything in
> > > "things
> > > > requiring local state maintenence".
> > > >
> > > > But, yes, I do agree that per-key ordering is an absolute
> requirement,
> > > > therefore I think that KIP-253 itself is a necessary step. Regarding
> > the
> > > > coupling of the state store partitioning to the topic partitioning,
> > yes,
> > > > this is an issue we are discussing solutions to right now. We may go
> > > ahead
> > > > and introduce an overpartition layer on our inputs to solve it, but
> > then
> > > > again, if we get the ability to split partitions with backfill, we
> may
> > > not
> > > > need to!
> > > >
> > > >
> > > > Point 4:
> > > > On this:
> > > >
> > > > > Regarding thought 2: If we don't care about the stream use-case,
> then
> > > the
> > > > > current KIP probably has already addressed problem without
> requiring
> > > > > consumer to know the partition function. If we care about the
> stream
> > > > > use-case, we already need coordination across producers of
> different
> > > > > topics, i.e. the same partition function needs to be used by
> > producers
> > > of
> > > > > topics A and B in order to join topics A and B. Thus, it might be
> > > > > reasonable to extend coordination a bit and say we need
> coordination
> > > > across
> > > > > clients (i.e. producer and consumer), such that consumer knows the
> > > > > partition function used by producer. If we do so, then we can let
> > > > consumer
> > > > > re-copy data for the change log topic using the same partition
> > function
> > > > as
> > > > > producer. This approach has lower overhead as compared to having
> > > producer
> > > > > re-copy data of the input topic.
> > > > > Also, producer currently does not need to know the data already
> > > produced
> > > > to
> > > > > the topic. If we let producer split/merge partition, it would
> require
> > > > > producer to consume the existing data, which intuitively is the
> task
> > of
> > > > > consumer.
> > > >
> > > >
> > > > I think we do care about use cases *like* Streams, I just don't think
> > we
> > > > should rely on Streams to implement a feature of Core like partition
> > > > expansion.
> > > >
> > > > Note, though, that we (Streams) do not require coordination across
> > > > producers. If two topics are certified to be co-partitioned, then
> > Streams
> > > > apps can make use of that knowledge to optimize their topology
> > (skipping
> > > a
> > > > repartition). But if they don't know whether they are co-partitioned,
> > > then
> > > > they'd better go ahead and repartition within the topology. This is
> the
> > > > current state.
> > > >
> > > > A huge selling point of Kafka is enabling different parts of loosely
> > > > coupled organizations to produce and consume data independently. Some
> > > > coordination between producers and consumers is necessary, like
> > > > coordinating on the names of topics and their schemas. But Kafka's
> > value
> > > > proposition w.r.t. ESBs, etc. is inversely proportional to the amount
> > of
> > > > coordination required. I think it behooves us to be extremely
> skeptical
> > > > about introducing any coordination beyond correctness protocols.
> > > >
> > > > Asking producers and consumers, or even two different producers, to
> > share
> > > > code like the partition function is a pretty huge ask. What if they
> are
> > > > using different languages?
> > > >
> > > > Comparing organizational overhead vs computational overhead, there
> are
> > > > maybe two orders of magnitude difference between them. In other
> words,
> > I
> > > > would happily take on the (linear) overhead of having the producer
> > > re-copy
> > > > the data once during a re-partition in order to save the
> organizational
> > > > overhead of tying all the producers and consumers together across
> > > multiple
> > > > boundaries.
> > > >
> > > > On that last paragraph: note that the producer *did* know the data it
> > > > already produced. It handled it the first time around. Asking it to
> > > > re-produce it into a new partition layout is squarely within its
> scope
> > of
> > > > capabilities. Contrast this with the alternative, asking the consumer
> > to
> > > > re-partition the data. I think this is even less intuitive, when the
> > > > partition function belongs to the producer.
> > > >
> > > >
> > > > Point 5:
> > > > Dong asked this:
> > > >
> > > > > For stream use-case that needs to increase consumer number, the
> > > > > existing consumer can backfill the existing data in the change log
> > > topic
> > > > to
> > > > > the same change log topic with the new partition number, before the
> > new
> > > > set
> > > > > of consumers bootstrap state from the new partitions of the change
> > log
> > > > > topic, right?
> > > >
> > > >
> > > > In this sense, the "consumer" is actually the producer of the
> changelog
> > > > topic, so if we support partition expansion + backfill as a
> > > producer/broker
> > > > operation, then it would be very straightforward for Streams to
> split a
> > > > state store. As you say, they would simply instruct the broker to
> split
> > > the
> > > > changelog topic's partitions, then backfill. Once the backfill is
> > ready,
> > > > they can create a new crop of StandbyTasks to bootstrap the more
> > granular
> > > > state stores and finally switch over to them when they are ready.
> > > >
> > > > But this actually seems to be an argument in favor of split+backfill,
> > so
> > > > maybe I missed the point.
> > > >
> > > > You also asked me to explain why copying the "input" topic is better
> > than
> > > > copying the "changelog" topic. I think they are totally independent,
> > > > actually. For one thing, you can't depend on the existence of a
> > > "changelog"
> > > > topic in general, only within Streams, but Kafka's user base clearly
> > > > exceeds Streams's user base. Plus, you actually also can't depend on
> > the
> > > > existence of a changelog topic within Streams, since that is an
> > optional
> > > > feature of *some* state store implementations. Even in the situation
> > > where
> > > > you do have a changelog topic in Streams, there may be use cases
> where
> > it
> > > > makes sense to expand the partitions of just the input, or just the
> > > > changelog.
> > > >
> > > > The ask for a Core feature of split+backfill is really about
> supporting
> > > the
> > > > use case of splitting partitions in log-compacted topics, regardless
> of
> > > > whether that topic is an "input" or a "changelog" or anything else
> for
> > > that
> > > > matter.
> > > >
> > > >
> > > > Point 6:
> > > > On the concern about the performance overhead of copying data between
> > the
> > > > brokers, I think it's actually a bit overestimated. Splitting a
> topic's
> > > > partition is probably rare, certainly rarer in general than
> > bootstrapping
> > > > new consumers on that topic. If "bootstrapping new consumers" means
> > that
> > > > they have to re-shuffle the data before they consume it, then you
> wind
> > up
> > > > copying the same record multiple times:
> > > >
> > > > (broker: input topic) -> (initial consumer) -> (broker: repartition
> > > topic)
> > > > -> (real consumer)
> > > >
> > > > That's 3x, and it's also 3x for every new record after the split as
> > well,
> > > > since you don't get to stop repartitioning/reshuffling once you
> start.
> > > >
> > > > Whereas if you do a backfill in something like the procedure I
> > outlined,
> > > > you only copy the prefix of the partition before the split, and you
> > send
> > > it
> > > > once to the producer and then once to the new generation partition.
> > Plus,
> > > > assuming we're splitting the partition for the benefit of consumers,
> > > > there's no reason we can't co-locate the post-split partitions on the
> > > same
> > > > host as the pre-split partition, making the second copy a local
> > > filesystem
> > > > operation.
> > > >
> > > > Even if you follow these two copies up with bootstrapping a new
> > consumer,
> > > > it's still rare for this to occur, so you get to amortize these
> copies
> > > over
> > > > the lifetime of the topic, whereas a reshuffle just keeps making
> copies
> > > for
> > > > every new event.
> > > >
> > > > And finally, I really do think that regardless of any performance
> > > concerns
> > > > about this operation, if it preserves loose organizational coupling,
> it
> > > is
> > > > certainly worth it.
> > > >
> > > >
> > > > In conclusion:
> > > > It might actually be a good idea for us to clarify the scope of
> > KIP-253.
> > > If
> > > > we're all agreed that it's a good algorithm for allowing in-order
> > message
> > > > delivery during partition expansion, then we can continue this
> > discussion
> > > > as a new KIP, something like "backfill with partition expansion".
> This
> > > > would let Dong proceed with KIP-253. On the other hand, if it seems
> > like
> > > > this conversation may alter the design of KIP-253, then maybe we
> > *should*
> > > > just finish working it out.
> > > >
> > > > For my part, my only concern about KIP-253 is the one I raised
> earlier.
> > > >
> > > > Thanks again, all, for considering these points,
> > > > -John
> > > >
> > > >
> > > > On Tue, Mar 27, 2018 at 2:10 AM, Dong Lin <li...@gmail.com>
> wrote:
> > > >
> > > > > On Tue, Mar 27, 2018 at 12:04 AM, Dong Lin <li...@gmail.com>
> > > wrote:
> > > > >
> > > > > > Hey Jan,
> > > > > >
> > > > > > Thanks for the enthusiasm in improving Kafka's design. Now that I
> > > have
> > > > > > read through your discussion with Jun, here are my thoughts:
> > > > > >
> > > > > > - The latest proposal should with log compacted topics by
> properly
> > > > > > deleting old messages after a new message with the same key is
> > > > produced.
> > > > > So
> > > > > > it is probably not a concern anymore. Could you comment if there
> is
> > > > still
> > > > > > issue?
> > > > > >
> > > > > > - I wrote the SEP-5 and I am pretty familiar with the motivation
> > and
> > > > the
> > > > > > design of SEP-5. SEP-5 is probably orthornal to the motivation of
> > > this
> > > > > KIP.
> > > > > > The goal of SEP-5 is to allow user to increase task number of an
> > > > existing
> > > > > > Samza job. But if we increase the partition number of input
> topics,
> > > > > > messages may still be consumed out-of-order by tasks in Samza
> which
> > > > cause
> > > > > > incorrect result. Similarly, the approach you proposed does not
> > seem
> > > to
> > > > > > ensure that the messages can be delivered in order, even if we
> can
> > > make
> > > > > > sure that each consumer instance is assigned the set of new
> > > partitions
> > > > > > covering the same set of keys.
> > > > > >
> > > > >
> > > > > Let me correct this comment. The approach of copying data to a new
> > > topic
> > > > > can ensure in-order message delivery suppose we properly migrate
> > > offsets
> > > > > from old topic to new topic.
> > > > >
> > > > >
> > > > > > - I am trying to understand why it is better to copy the data
> > instead
> > > > of
> > > > > > copying the change log topic for streaming use-case. For core
> Kafka
> > > > > > use-case, and for the stream use-case that does not need to
> > increase
> > > > > > consumers, the current KIP already supports in-order delivery
> > without
> > > > the
> > > > > > overhead of copying the data. For stream use-case that needs to
> > > > increase
> > > > > > consumer number, the existing consumer can backfill the existing
> > data
> > > > in
> > > > > > the change log topic to the same change log topic with the new
> > > > partition
> > > > > > number, before the new set of consumers bootstrap state from the
> > new
> > > > > > partitions of the change log topic. If this solution works, then
> > > could
> > > > > you
> > > > > > summarize the advantage of copying the data of input topic as
> > > compared
> > > > to
> > > > > > copying the change log topic? For example, does it enable more
> > > > use-case,
> > > > > > simplify the implementation of Kafka library, or reduce the
> > operation
> > > > > > overhead etc?
> > > > > >
> > > > > > Thanks,
> > > > > > Dong
> > > > > >
> > > > > >
> > > > > > On Wed, Mar 21, 2018 at 6:57 AM, Jan Filipiak <
> > > > Jan.Filipiak@trivago.com>
> > > > > > wrote:
> > > > > >
> > > > > >> Hi Jun,
> > > > > >>
> > > > > >> I was really seeing progress in our conversation but your latest
> > > reply
> > > > > is
> > > > > >> just devastating.
> > > > > >> I though we were getting close being on the same page now it
> feels
> > > > like
> > > > > >> we are in different libraries.
> > > > > >>
> > > > > >> I just quickly slam my answers in here. If they are to brief I
> am
> > > > sorry
> > > > > >> give me a ping and try to go into details more.
> > > > > >> Just want to show that your pro/cons listing is broken.
> > > > > >>
> > > > > >> Best Jan
> > > > > >>
> > > > > >> and want to get rid of this horrible compromise
> > > > > >>
> > > > > >>
> > > > > >> On 19.03.2018 05:48, Jun Rao wrote:
> > > > > >>
> > > > > >>> Hi, Jan,
> > > > > >>>
> > > > > >>> Thanks for the discussion. Great points.
> > > > > >>>
> > > > > >>> Let me try to summarize the approach that you are proposing. On
> > the
> > > > > >>> broker
> > > > > >>> side, we reshuffle the existing data in a topic from current
> > > > partitions
> > > > > >>> to
> > > > > >>> the new partitions. Once the reshuffle fully catches up, switch
> > the
> > > > > >>> consumers to start consuming from the new partitions. If a
> > consumer
> > > > > needs
> > > > > >>> to rebuild its local state (due to partition changes), let the
> > > > consumer
> > > > > >>> rebuild its state by reading all existing data from the new
> > > > partitions.
> > > > > >>> Once all consumers have switches over, cut over the producer to
> > the
> > > > new
> > > > > >>> partitions.
> > > > > >>>
> > > > > >>> The pros for this approach are that :
> > > > > >>> 1. There is just one way to rebuild the local state, which is
> > > > simpler.
> > > > > >>>
> > > > > >> true thanks
> > > > > >>
> > > > > >>>
> > > > > >>> The cons for this approach are:
> > > > > >>> 1. Need to copy existing data.
> > > > > >>>
> > > > > >> Very unfair and not correct. It does not require you to copy
> over
> > > > > >> existing data. It _allows_ you to copy all existing data.
> > > > > >>
> > > > > >> 2. The cutover of the producer is a bit complicated since it
> needs
> > > to
> > > > > >>> coordinate with all consumer groups.
> > > > > >>>
> > > > > >> Also not true. I explicitly tried to make clear that there is
> only
> > > one
> > > > > >> special consumer (in the case of actually copying data)
> > coordination
> > > > is
> > > > > >> required.
> > > > > >>
> > > > > >>> 3. The rebuilding of the state in the consumer is from the
> input
> > > > topic,
> > > > > >>> which can be more expensive than rebuilding from the existing
> > > state.
> > > > > >>>
> > > > > >> true, but rebuilding state is only required if you want to
> > increase
> > > > > >> processing power, so we assume this is at hand.
> > > > > >>
> > > > > >>> 4. The broker potentially has to know the partitioning
> function.
> > If
> > > > > this
> > > > > >>> needs to be customized at the topic level, it can be a bit
> messy.
> > > > > >>>
> > > > > >> I would argue against having the operation being performed by
> the
> > > > > broker.
> > > > > >> This was not discussed yet but if you see my original email i
> > > > suggested
> > > > > >> otherwise from the beginning.
> > > > > >>
> > > > > >>>
> > > > > >>> Here is an alternative approach by applying your idea not in
> the
> > > > > broker,
> > > > > >>> but in the consumer. When new partitions are added, we don't
> move
> > > > > >>> existing
> > > > > >>> data. In KStreams, we first reshuffle the new input data to a
> new
> > > > topic
> > > > > >>> T1
> > > > > >>> with the old number of partitions and feed T1's data to the
> rest
> > of
> > > > the
> > > > > >>> pipeline. In the meantime, KStreams reshuffles all existing
> data
> > of
> > > > the
> > > > > >>> change capture topic to another topic C1 with the new number of
> > > > > >>> partitions.
> > > > > >>> We can then build the state of the new tasks from C1. Once the
> > new
> > > > > states
> > > > > >>> have been fully built, we can cut over the consumption to the
> > input
> > > > > topic
> > > > > >>> and delete T1. This approach works with compacted topic too. If
> > an
> > > > > >>> application reads from the beginning of a compacted topic, the
> > > > consumer
> > > > > >>> will reshuffle the portion of the input when the number of
> > > partitions
> > > > > >>> doesn't match the number of tasks.
> > > > > >>>
> > > > > >> We all wipe this idea from our heads instantly. Mixing Ideas
> from
> > an
> > > > > >> argument is not a resolution strategy
> > > > > >> just leads to horrible horrible software.
> > > > > >>
> > > > > >>
> > > > > >>> The pros of this approach are:
> > > > > >>> 1. No need to copy existing data.
> > > > > >>> 2. Each consumer group can cut over to the new partitions
> > > > > independently.
> > > > > >>> 3. The state is rebuilt from the change capture topic, which is
> > > > cheaper
> > > > > >>> than rebuilding from the input topic.
> > > > > >>> 4. Only the KStreams job needs to know the partitioning
> function.
> > > > > >>>
> > > > > >>> The cons of this approach are:
> > > > > >>> 1. Potentially the same input topic needs to be reshuffled more
> > > than
> > > > > once
> > > > > >>> in different consumer groups during the transition phase.
> > > > > >>>
> > > > > >>> What do you think?
> > > > > >>>
> > > > > >>> Thanks,
> > > > > >>>
> > > > > >>> Jun
> > > > > >>>
> > > > > >>>
> > > > > >>>
> > > > > >>> On Thu, Mar 15, 2018 at 1:04 AM, Jan Filipiak <
> > > > > Jan.Filipiak@trivago.com>
> > > > > >>> wrote:
> > > > > >>>
> > > > > >>> Hi Jun,
> > > > > >>>>
> > > > > >>>> thank you for following me on these thoughts. It was important
> > to
> > > me
> > > > > to
> > > > > >>>> feel that kind of understanding for my arguments.
> > > > > >>>>
> > > > > >>>> What I was hoping for (I mentioned this earlier) is that we
> can
> > > > model
> > > > > >>>> the
> > > > > >>>> case where we do not want to copy the data the exact same way
> as
> > > the
> > > > > >>>> case
> > > > > >>>> when we do copy the data. Maybe you can peek into the mails
> > before
> > > > to
> > > > > >>>> see
> > > > > >>>> more details for this.
> > > > > >>>>
> > > > > >>>> This means we have the same mechanism to transfer consumer
> > groups
> > > to
> > > > > >>>> switch topic. The offset mapping that would be generated would
> > > even
> > > > be
> > > > > >>>> simpler End Offset of the Old topic => offset 0 off all the
> > > > partitions
> > > > > >>>> of
> > > > > >>>> the new topic. Then we could model the transition of a
> non-copy
> > > > > >>>> expansion
> > > > > >>>> the exact same way as a copy-expansion.
> > > > > >>>>
> > > > > >>>> I know this only works when topic growth by a factor. But the
> > > > benefits
> > > > > >>>> of
> > > > > >>>> only growing by a factor are to strong anyways. See Clemens's
> > hint
> > > > and
> > > > > >>>> remember that state reshuffling is entirely not needed if one
> > > > doesn't
> > > > > >>>> want
> > > > > >>>> to grow processing power.
> > > > > >>>>
> > > > > >>>> I think these benefits should be clear, and that there is
> > > basically
> > > > no
> > > > > >>>> downside to what is currently at hand but just makes
> everything
> > > > easy.
> > > > > >>>>
> > > > > >>>> One thing you need to know is. that if you do not offer
> > > rebuilding a
> > > > > log
> > > > > >>>> compacted topic like i suggest that even if you have consumer
> > > state
> > > > > >>>> reshuffling. The topic is broken and can not be used to
> > bootstrap
> > > > new
> > > > > >>>> consumers. They don't know if they need to apply a key from
> and
> > > old
> > > > > >>>> partition or not. This is a horrible downside I haven't seen a
> > > > > solution
> > > > > >>>> for
> > > > > >>>> in the email conversation.
> > > > > >>>>
> > > > > >>>> I argue to:
> > > > > >>>>
> > > > > >>>> Only grow topic by a factor always.
> > > > > >>>> Have the "no copy consumer" transition as the trivial case of
> > the
> > > > > "copy
> > > > > >>>> consumer transition".
> > > > > >>>> If processors needs to be scaled, let them rebuild from the
> new
> > > > topic
> > > > > >>>> and
> > > > > >>>> leave the old running in the mean time.
> > > > > >>>> Do not implement key shuffling in streams.
> > > > > >>>>
> > > > > >>>> I hope I can convince you especially with the fact how I want
> to
> > > > > handle
> > > > > >>>> consumer transition. I think
> > > > > >>>> you didn't quite understood me there before. I think the term
> > "new
> > > > > >>>> topic"
> > > > > >>>> intimidated you a little.
> > > > > >>>> How we solve this on disc doesn't really matter, If the data
> > goes
> > > > into
> > > > > >>>> the
> > > > > >>>> same Dir or a different Dir or anything. I do think that it
> > needs
> > > to
> > > > > >>>> involve at least rolling a new segment for the existing
> > > partitions.
> > > > > >>>> But most of the transitions should work without restarting
> > > > consumers.
> > > > > >>>> (newer consumers with support for this). But with new topic i
> > just
> > > > > meant
> > > > > >>>> the topic that now has a different partition count. Plenty of
> > ways
> > > > to
> > > > > >>>> handle that (versions, aliases)
> > > > > >>>>
> > > > > >>>> Hope I can further get my idea across.
> > > > > >>>>
> > > > > >>>> Best Jan
> > > > > >>>>
> > > > > >>>>
> > > > > >>>>
> > > > > >>>>
> > > > > >>>>
> > > > > >>>>
> > > > > >>>> On 14.03.2018 02:45, Jun Rao wrote:
> > > > > >>>>
> > > > > >>>> Hi, Jan,
> > > > > >>>>>
> > > > > >>>>> Thanks for sharing your view.
> > > > > >>>>>
> > > > > >>>>> I agree with you that recopying the data potentially makes
> the
> > > > state
> > > > > >>>>> management easier since the consumer can just rebuild its
> state
> > > > from
> > > > > >>>>> scratch (i.e., no need for state reshuffling).
> > > > > >>>>>
> > > > > >>>>> On the flip slide, I saw a few disadvantages of the approach
> > that
> > > > you
> > > > > >>>>> suggested. (1) Building the state from the input topic from
> > > scratch
> > > > > is
> > > > > >>>>> in
> > > > > >>>>> general less efficient than state reshuffling. Let's say one
> > > > > computes a
> > > > > >>>>> count per key from an input topic. The former requires
> reading
> > > all
> > > > > >>>>> existing
> > > > > >>>>> records in the input topic whereas the latter only requires
> > > reading
> > > > > >>>>> data
> > > > > >>>>> proportional to the number of unique keys. (2) The switching
> of
> > > the
> > > > > >>>>> topic
> > > > > >>>>> needs modification to the application. If there are many
> > > > applications
> > > > > >>>>> on a
> > > > > >>>>> topic, coordinating such an effort may not be easy. Also,
> it's
> > > not
> > > > > >>>>> clear
> > > > > >>>>> how to enforce exactly-once semantic during the switch. (3)
> If
> > a
> > > > > topic
> > > > > >>>>> doesn't need any state management, recopying the data seems
> > > > wasteful.
> > > > > >>>>> In
> > > > > >>>>> that case, in place partition expansion seems more desirable.
> > > > > >>>>>
> > > > > >>>>> I understand your concern about adding complexity in
> KStreams.
> > > But,
> > > > > >>>>> perhaps
> > > > > >>>>> we could iterate on that a bit more to see if it can be
> > > simplified.
> > > > > >>>>>
> > > > > >>>>> Jun
> > > > > >>>>>
> > > > > >>>>>
> > > > > >>>>> On Mon, Mar 12, 2018 at 11:21 PM, Jan Filipiak <
> > > > > >>>>> Jan.Filipiak@trivago.com>
> > > > > >>>>> wrote:
> > > > > >>>>>
> > > > > >>>>> Hi Jun,
> > > > > >>>>>
> > > > > >>>>>> I will focus on point 61 as I think its _the_ fundamental
> part
> > > > that
> > > > > I
> > > > > >>>>>> cant
> > > > > >>>>>> get across at the moment.
> > > > > >>>>>>
> > > > > >>>>>> Kafka is the platform to have state materialized multiple
> > times
> > > > from
> > > > > >>>>>> one
> > > > > >>>>>> input. I emphasize this: It is the building block in
> > > architectures
> > > > > >>>>>> that
> > > > > >>>>>> allow you to
> > > > > >>>>>> have your state maintained multiple times. You put a message
> > in
> > > > > once,
> > > > > >>>>>> and
> > > > > >>>>>> you have it pop out as often as you like. I believe you
> > > understand
> > > > > >>>>>> this.
> > > > > >>>>>>
> > > > > >>>>>> Now! The path of thinking goes the following: I am using
> > apache
> > > > > kafka
> > > > > >>>>>> and
> > > > > >>>>>> I _want_ my state multiple times. What am I going todo?
> > > > > >>>>>>
> > > > > >>>>>> A) Am I going to take my state that I build up, plunge some
> > sort
> > > > of
> > > > > >>>>>> RPC
> > > > > >>>>>> layer ontop of it, use that RPC layer to throw my records
> > across
> > > > > >>>>>> instances?
> > > > > >>>>>> B) Am I just going to read the damn message twice?
> > > > > >>>>>>
> > > > > >>>>>> Approach A is fundamentally flawed and a violation of all
> that
> > > is
> > > > > good
> > > > > >>>>>> and
> > > > > >>>>>> holy in kafka deployments. I can not understand how this
> Idea
> > > can
> > > > > >>>>>> come in
> > > > > >>>>>> the first place.
> > > > > >>>>>> (I do understand: IQ in streams, they polluted the kafka
> > streams
> > > > > >>>>>> codebase
> > > > > >>>>>> really bad already. It is not funny! I think they are
> equally
> > > > flawed
> > > > > >>>>>> as
> > > > > >>>>>> A)
> > > > > >>>>>>
> > > > > >>>>>> I say, we do what Kafka is good at. We repartition the topic
> > > once.
> > > > > We
> > > > > >>>>>> switch the consumers.
> > > > > >>>>>> (Those that need more partitions are going to rebuild their
> > > state
> > > > in
> > > > > >>>>>> multiple partitions by reading the new topic, those that
> don't
> > > > just
> > > > > >>>>>> assign
> > > > > >>>>>> the new partitions properly)
> > > > > >>>>>> We switch producers. Done!
> > > > > >>>>>>
> > > > > >>>>>> The best thing! It is trivial, hipster stream processor will
> > > have
> > > > an
> > > > > >>>>>> easy
> > > > > >>>>>> time with that aswell. Its so super simple. And simple IS
> > good!
> > > > > >>>>>> It is what kafka was build todo. It is how we do it today.
> > All I
> > > > am
> > > > > >>>>>> saying
> > > > > >>>>>> is that a little broker help doing the producer swap is
> super
> > > > > useful.
> > > > > >>>>>>
> > > > > >>>>>> For everyone interested in why kafka is so powerful with
> > > approach
> > > > B,
> > > > > >>>>>> please watch https://youtu.be/bEbeZPVo98c?t=1633
> > > > > >>>>>> I already looked up a good point in time, I think after 5
> > > minutes
> > > > > the
> > > > > >>>>>> "state" topic is handled and you should be able to
> understand
> > me
> > > > > >>>>>> and inch better.
> > > > > >>>>>>
> > > > > >>>>>> Please do not do A to the project, it deserves better!
> > > > > >>>>>>
> > > > > >>>>>> Best Jan
> > > > > >>>>>>
> > > > > >>>>>>
> > > > > >>>>>>
> > > > > >>>>>> On 13.03.2018 02:40, Jun Rao wrote:
> > > > > >>>>>>
> > > > > >>>>>> Hi, Jan,
> > > > > >>>>>>
> > > > > >>>>>>> Thanks for the reply. A few more comments below.
> > > > > >>>>>>>
> > > > > >>>>>>> 50. Ok, we can think a bit harder for supporting compacted
> > > > topics.
> > > > > >>>>>>>
> > > > > >>>>>>> 51. This is a fundamental design question. In the more
> common
> > > > case,
> > > > > >>>>>>> the
> > > > > >>>>>>> reason why someone wants to increase the number of
> partitions
> > > is
> > > > > that
> > > > > >>>>>>> the
> > > > > >>>>>>> consumer application is slow and one wants to run more
> > consumer
> > > > > >>>>>>> instances
> > > > > >>>>>>> to increase the degree of parallelism. So, fixing the
> number
> > of
> > > > > >>>>>>> running
> > > > > >>>>>>> consumer instances when expanding the partitions won't help
> > > this
> > > > > >>>>>>> case.
> > > > > >>>>>>> If
> > > > > >>>>>>> we do need to increase the number of consumer instances, we
> > > need
> > > > to
> > > > > >>>>>>> somehow
> > > > > >>>>>>> reshuffle the state of the consumer across instances. What
> we
> > > > have
> > > > > >>>>>>> been
> > > > > >>>>>>> discussing in this KIP is whether we can do this more
> > > effectively
> > > > > >>>>>>> through
> > > > > >>>>>>> the KStream library (e.g. through a 2-phase partition
> > > expansion).
> > > > > >>>>>>> This
> > > > > >>>>>>> will
> > > > > >>>>>>> add some complexity, but it's probably better than everyone
> > > doing
> > > > > >>>>>>> this
> > > > > >>>>>>> in
> > > > > >>>>>>> the application space. The recopying approach that you
> > > mentioned
> > > > > >>>>>>> doesn't
> > > > > >>>>>>> seem to address the consumer state management issue when
> the
> > > > > consumer
> > > > > >>>>>>> switches from an old to a new topic.
> > > > > >>>>>>>
> > > > > >>>>>>> 52. As for your example, it depends on whether the join key
> > is
> > > > the
> > > > > >>>>>>> same
> > > > > >>>>>>> between (A,B) and (B,C). If the join key is the same, we
> can
> > > do a
> > > > > >>>>>>> 2-phase
> > > > > >>>>>>> partition expansion of A, B, and C together. If the join
> keys
> > > are
> > > > > >>>>>>> different, one would need to repartition the data on a
> > > different
> > > > > key
> > > > > >>>>>>> for
> > > > > >>>>>>> the second join, then the partition expansion can be done
> > > > > >>>>>>> independently
> > > > > >>>>>>> between (A,B) and (B,C).
> > > > > >>>>>>>
> > > > > >>>>>>> 53. If you always fix the number of consumer instances, we
> > you
> > > > > >>>>>>> described
> > > > > >>>>>>> works. However, as I mentioned in #51, I am not sure how
> your
> > > > > >>>>>>> proposal
> > > > > >>>>>>> deals with consumer states when the number of consumer
> > > instances
> > > > > >>>>>>> grows.
> > > > > >>>>>>> Also, it just seems that it's better to avoid re-copying
> the
> > > > > existing
> > > > > >>>>>>> data.
> > > > > >>>>>>>
> > > > > >>>>>>> 60. "just want to throw in my question from the longer
> email
> > in
> > > > the
> > > > > >>>>>>> other
> > > > > >>>>>>> Thread here. How will the bloom filter help a new consumer
> to
> > > > > decide
> > > > > >>>>>>> to
> > > > > >>>>>>> apply the key or not?" Not sure that I fully understood
> your
> > > > > >>>>>>> question.
> > > > > >>>>>>> The
> > > > > >>>>>>> consumer just reads whatever key is in the log. The bloom
> > > filter
> > > > > just
> > > > > >>>>>>> helps
> > > > > >>>>>>> clean up the old keys.
> > > > > >>>>>>>
> > > > > >>>>>>> 61. "Why can we afford having a topic where its apparently
> > not
> > > > > >>>>>>> possible
> > > > > >>>>>>> to
> > > > > >>>>>>> start a new application on? I think this is an overall flaw
> > of
> > > > the
> > > > > >>>>>>> discussed idea here. Not playing attention to the overall
> > > > > >>>>>>> architecture."
> > > > > >>>>>>> Could you explain a bit more when one can't start a new
> > > > > application?
> > > > > >>>>>>>
> > > > > >>>>>>> Jun
> > > > > >>>>>>>
> > > > > >>>>>>>
> > > > > >>>>>>>
> > > > > >>>>>>> On Sat, Mar 10, 2018 at 1:40 AM, Jan Filipiak <
> > > > > >>>>>>> Jan.Filipiak@trivago.com
> > > > > >>>>>>> wrote:
> > > > > >>>>>>>
> > > > > >>>>>>> Hi Jun, thanks for your mail.
> > > > > >>>>>>>
> > > > > >>>>>>> Thank you for your questions!
> > > > > >>>>>>>> I think they are really good and tackle the core of the
> > > problem
> > > > I
> > > > > >>>>>>>> see.
> > > > > >>>>>>>>
> > > > > >>>>>>>> I will answer inline, mostly but still want to set the
> tone
> > > > here.
> > > > > >>>>>>>>
> > > > > >>>>>>>> The core strength of kafka is what Martin once called the
> > > > > >>>>>>>> kappa-Architecture. How does this work?
> > > > > >>>>>>>> You have everything as a log as in kafka. When you need to
> > > > change
> > > > > >>>>>>>> something.
> > > > > >>>>>>>> You create the new version of your application and leave
> it
> > > > > running
> > > > > >>>>>>>> in
> > > > > >>>>>>>> parallel.
> > > > > >>>>>>>> Once the new version is good you switch your users to use
> > the
> > > > new
> > > > > >>>>>>>> application.
> > > > > >>>>>>>>
> > > > > >>>>>>>> The online reshuffling effectively breaks this
> architecture
> > > and
> > > > I
> > > > > >>>>>>>> think
> > > > > >>>>>>>> the switch in thinking here is more harmful
> > > > > >>>>>>>> than any details about the partitioning function to allow
> > > such a
> > > > > >>>>>>>> change.
> > > > > >>>>>>>> I
> > > > > >>>>>>>> feel with my suggestion we are the closest to
> > > > > >>>>>>>> the original and battle proven architecture and I can only
> > > warn
> > > > to
> > > > > >>>>>>>> move
> > > > > >>>>>>>> away from it.
> > > > > >>>>>>>>
> > > > > >>>>>>>> I might have forgotten something, sometimes its hard for
> me
> > to
> > > > > >>>>>>>> getting
> > > > > >>>>>>>> all
> > > > > >>>>>>>> the thoughts captured in a mail, but I hope the comments
> > > inline
> > > > > will
> > > > > >>>>>>>> further make my concern clear, and put some emphasis on
> why
> > I
> > > > > >>>>>>>> prefer my
> > > > > >>>>>>>> solution ;)
> > > > > >>>>>>>>
> > > > > >>>>>>>> One thing we should all be aware of when discussing this,
> > and
> > > I
> > > > > >>>>>>>> think
> > > > > >>>>>>>> Dong
> > > > > >>>>>>>> should have mentioned it (maybe he did).
> > > > > >>>>>>>> We are not discussing all of this out of thin air but
> there
> > is
> > > > an
> > > > > >>>>>>>> effort
> > > > > >>>>>>>> in the Samza project.
> > > > > >>>>>>>>
> > > > > >>>>>>>> https://cwiki.apache.org/confluence/display/SAMZA/SEP-
> 5%3A+
> > > > > >>>>>>>> Enable+partition+expansion+of+input+streams
> > > > > >>>>>>>> https://issues.apache.org/jira/browse/SAMZA-1293
> > > > > >>>>>>>>
> > > > > >>>>>>>> To be clear. I think SEP-5 (state of last week, dont know
> if
> > > it
> > > > > >>>>>>>> adapted
> > > > > >>>>>>>> to
> > > > > >>>>>>>> this discussion) is on a way better path than KIP-253,
> and I
> > > > can't
> > > > > >>>>>>>> really
> > > > > >>>>>>>> explain why.
> > > > > >>>>>>>>
> > > > > >>>>>>>> Best Jan,
> > > > > >>>>>>>>
> > > > > >>>>>>>> nice weekend everyone
> > > > > >>>>>>>>
> > > > > >>>>>>>>
> > > > > >>>>>>>> On 09.03.2018 03:36, Jun Rao wrote:
> > > > > >>>>>>>>
> > > > > >>>>>>>> Hi, Jan,
> > > > > >>>>>>>>
> > > > > >>>>>>>> Thanks for the feedback. Just some comments on the earlier
> > > > points
> > > > > >>>>>>>>> that
> > > > > >>>>>>>>> you
> > > > > >>>>>>>>> mentioned.
> > > > > >>>>>>>>>
> > > > > >>>>>>>>> 50. You brought up the question of whether existing data
> > > needs
> > > > to
> > > > > >>>>>>>>> be
> > > > > >>>>>>>>> copied
> > > > > >>>>>>>>> during partition expansion. My understand of your view is
> > > that
> > > > > >>>>>>>>> avoid
> > > > > >>>>>>>>> copying existing data will be more efficient, but it
> > doesn't
> > > > work
> > > > > >>>>>>>>> well
> > > > > >>>>>>>>> with
> > > > > >>>>>>>>> compacted topics since some keys in the original
> partitions
> > > > will
> > > > > >>>>>>>>> never
> > > > > >>>>>>>>> be
> > > > > >>>>>>>>> cleaned. It would be useful to understand your use case
> of
> > > > > >>>>>>>>> compacted
> > > > > >>>>>>>>> topics
> > > > > >>>>>>>>> a bit more. In the common use case, the data volume in a
> > > > > compacted
> > > > > >>>>>>>>> topic
> > > > > >>>>>>>>> may not be large. So, I am not sure if there is a strong
> > need
> > > > to
> > > > > >>>>>>>>> expand
> > > > > >>>>>>>>> partitions in a compacted topic, at least initially.
> > > > > >>>>>>>>>
> > > > > >>>>>>>>> I do agree. State is usually smaller. Update rates might
> be
> > > > also
> > > > > >>>>>>>>>
> > > > > >>>>>>>>> competitively high.
> > > > > >>>>>>>> Doing Log-compaction (even beeing very efficient and
> > > > configurable)
> > > > > >>>>>>>> is
> > > > > >>>>>>>> also
> > > > > >>>>>>>> a more expensive operation than
> > > > > >>>>>>>> just discarding old segments. Further if you want to use
> > more
> > > > > >>>>>>>> consumers
> > > > > >>>>>>>> processing the events
> > > > > >>>>>>>> you also have to grow the number of partitions. Especially
> > for
> > > > > >>>>>>>> use-cases
> > > > > >>>>>>>> we do (KIP-213) a tiny state full
> > > > > >>>>>>>> table might be very expensive to process if it joins
> > against a
> > > > > huge
> > > > > >>>>>>>> table.
> > > > > >>>>>>>>
> > > > > >>>>>>>> I can just say we have been in the spot of needing to grow
> > log
> > > > > >>>>>>>> compacted
> > > > > >>>>>>>> topics. Mainly for processing power we can bring to the
> > table.
> > > > > >>>>>>>>
> > > > > >>>>>>>> Further i am not at all concerned about the extra spaced
> > used
> > > by
> > > > > >>>>>>>> "garbage
> > > > > >>>>>>>> keys". I am more concerned about the correctness of
> innocent
> > > > > >>>>>>>> consumers.
> > > > > >>>>>>>> The
> > > > > >>>>>>>> logic becomes complicated. Say for streams one would need
> to
> > > > load
> > > > > >>>>>>>> the
> > > > > >>>>>>>> record into state but not forward it the topology ( to
> have
> > it
> > > > > >>>>>>>> available
> > > > > >>>>>>>> for shuffeling). I rather have it simple and a topic clean
> > > > > >>>>>>>> regardless
> > > > > >>>>>>>> if
> > > > > >>>>>>>> it
> > > > > >>>>>>>> still has its old partition count. Especially with
> multiple
> > > > > >>>>>>>> partitions
> > > > > >>>>>>>> growth's I think it becomes insanely hard to to this
> shuffle
> > > > > >>>>>>>> correct.
> > > > > >>>>>>>> Maybe
> > > > > >>>>>>>> Streams and Samza can do it. Especially if you do "hipster
> > > > stream
> > > > > >>>>>>>> processing" <https://www.confluent.io/blog
> > > > > >>>>>>>> /introducing-kafka-streams-
> > > > > >>>>>>>> stream-processing-made-simple/>. This makes kafka way to
> > > > > >>>>>>>> complicated.
> > > > > >>>>>>>> With my approach I think its way simpler because the topic
> > has
> > > > no
> > > > > >>>>>>>> "history"
> > > > > >>>>>>>> in terms of partitioning but is always clean.
> > > > > >>>>>>>>
> > > > > >>>>>>>>
> > > > > >>>>>>>> 51. "Growing the topic by an integer factor does not
> require
> > > any
> > > > > >>>>>>>> state
> > > > > >>>>>>>>
> > > > > >>>>>>>> redistribution at all." Could you clarify this a bit more?
> > > Let's
> > > > > say
> > > > > >>>>>>>>> you
> > > > > >>>>>>>>> have a consumer app that computes the windowed count per
> > key.
> > > > If
> > > > > >>>>>>>>> you
> > > > > >>>>>>>>> double
> > > > > >>>>>>>>> the number of partitions from 1 to 2 and grow the
> consumer
> > > > > >>>>>>>>> instances
> > > > > >>>>>>>>> from
> > > > > >>>>>>>>> 1
> > > > > >>>>>>>>> to 2, we would need to redistribute some of the counts to
> > the
> > > > new
> > > > > >>>>>>>>> consumer
> > > > > >>>>>>>>> instance. Regarding to linear hashing, it's true that it
> > > won't
> > > > > >>>>>>>>> solve
> > > > > >>>>>>>>> the
> > > > > >>>>>>>>> problem with compacted topics. The main benefit is that
> it
> > > > > >>>>>>>>> redistributes
> > > > > >>>>>>>>> the keys in one partition to no more than two partitions,
> > > which
> > > > > >>>>>>>>> could
> > > > > >>>>>>>>> help
> > > > > >>>>>>>>> redistribute the state.
> > > > > >>>>>>>>>
> > > > > >>>>>>>>> You don't need to spin up a new consumer in this case.
> > every
> > > > > >>>>>>>>> consumer
> > > > > >>>>>>>>>
> > > > > >>>>>>>>> would just read every partition with the (partition %
> > > num_task)
> > > > > >>>>>>>> task.
> > > > > >>>>>>>> it
> > > > > >>>>>>>> will still have the previous data right there and can go
> on.
> > > > > >>>>>>>>
> > > > > >>>>>>>> This sounds contradictory to what I said before, but
> please
> > > bear
> > > > > >>>>>>>> with
> > > > > >>>>>>>> me.
> > > > > >>>>>>>>
> > > > > >>>>>>>> 52. Good point on coordinating the expansion of 2 topics
> > that
> > > > need
> > > > > >>>>>>>> to
> > > > > >>>>>>>> be
> > > > > >>>>>>>>
> > > > > >>>>>>>> joined together. This is where the 2-phase partition
> > expansion
> > > > > could
> > > > > >>>>>>>>> potentially help. In the first phase, we could add new
> > > > partitions
> > > > > >>>>>>>>> to
> > > > > >>>>>>>>> the 2
> > > > > >>>>>>>>> topics one at a time but without publishing to the new
> > > > patitions.
> > > > > >>>>>>>>> Then,
> > > > > >>>>>>>>> we
> > > > > >>>>>>>>> can add new consumer instances to pick up the new
> > partitions.
> > > > In
> > > > > >>>>>>>>> this
> > > > > >>>>>>>>> transition phase, no reshuffling is needed since no data
> is
> > > > > coming
> > > > > >>>>>>>>> from
> > > > > >>>>>>>>> the
> > > > > >>>>>>>>> new partitions. Finally, we can enable the publishing to
> > the
> > > > new
> > > > > >>>>>>>>> partitions.
> > > > > >>>>>>>>>
> > > > > >>>>>>>>> I think its even worse than you think. I would like to
> > > > introduce
> > > > > >>>>>>>>> the
> > > > > >>>>>>>>>
> > > > > >>>>>>>>> Term
> > > > > >>>>>>>> transitive copartitioning. Imagine
> > > > > >>>>>>>> 2 streams application. One joins (A,B) the other (B,C)
> then
> > > > there
> > > > > >>>>>>>> is a
> > > > > >>>>>>>> transitive copartition requirement for
> > > > > >>>>>>>> (A,C) to be copartitioned aswell. This can spread
> > > significantly
> > > > > and
> > > > > >>>>>>>> require many consumers to adapt at the same time.
> > > > > >>>>>>>>
> > > > > >>>>>>>> It is also not entirely clear to me how you not need
> > > reshuffling
> > > > > in
> > > > > >>>>>>>> this
> > > > > >>>>>>>> case. If A has a record that never gets updated after the
> > > > > expansion
> > > > > >>>>>>>> and
> > > > > >>>>>>>> the
> > > > > >>>>>>>> coresponding B record moves to a new partition. How shall
> > they
> > > > > meet
> > > > > >>>>>>>> w/o
> > > > > >>>>>>>> shuffle?
> > > > > >>>>>>>>
> > > > > >>>>>>>> 53. "Migrating consumer is a step that might be made
> > completly
> > > > > >>>>>>>>
> > > > > >>>>>>>> unnecessary
> > > > > >>>>>>>>> if - for example streams - takes the gcd as partitioning
> > > scheme
> > > > > >>>>>>>>> instead
> > > > > >>>>>>>>> of
> > > > > >>>>>>>>> enforcing 1 to 1." Not sure that I fully understand
> this. I
> > > > think
> > > > > >>>>>>>>> you
> > > > > >>>>>>>>> mean
> > > > > >>>>>>>>> that a consumer application can run more instances than
> the
> > > > > number
> > > > > >>>>>>>>> of
> > > > > >>>>>>>>> partitions. In that case, the consumer can just
> > > repartitioning
> > > > > the
> > > > > >>>>>>>>> input
> > > > > >>>>>>>>> data according to the number of instances. This is
> > possible,
> > > > but
> > > > > >>>>>>>>> just
> > > > > >>>>>>>>> has
> > > > > >>>>>>>>> the overhead of reshuffling the data.
> > > > > >>>>>>>>>
> > > > > >>>>>>>>> No what I meant is ( that is also your question i think
> > > > Mathias)
> > > > > >>>>>>>>> that
> > > > > >>>>>>>>> if
> > > > > >>>>>>>>>
> > > > > >>>>>>>>> you grow a topic by a factor.
> > > > > >>>>>>>> Even if your processor is statefull you can can just
> assign
> > > all
> > > > > the
> > > > > >>>>>>>> multiples of the previous partition to
> > > > > >>>>>>>> this consumer and the state to keep processing correctly
> > will
> > > be
> > > > > >>>>>>>> present
> > > > > >>>>>>>> w/o any shuffling.
> > > > > >>>>>>>>
> > > > > >>>>>>>> Say you have an assignment
> > > > > >>>>>>>> Statefull consumer => partition
> > > > > >>>>>>>> 0 => 0
> > > > > >>>>>>>> 1 => 1
> > > > > >>>>>>>> 2 => 2
> > > > > >>>>>>>>
> > > > > >>>>>>>> and you grow you topic by 4 you get,
> > > > > >>>>>>>>
> > > > > >>>>>>>> 0 => 0,3,6,9
> > > > > >>>>>>>> 1 => 1,4,7,10
> > > > > >>>>>>>> 2 => 2,5,8,11
> > > > > >>>>>>>>
> > > > > >>>>>>>> Say your hashcode is 8. 8%3 => 2  before so consumer for
> > > > > partition 2
> > > > > >>>>>>>> has
> > > > > >>>>>>>> it.
> > > > > >>>>>>>> Now you you have 12 partitions so 8%12 => 8, so it goes
> into
> > > > > >>>>>>>> partition
> > > > > >>>>>>>> 8
> > > > > >>>>>>>> which is assigned to the same consumer
> > > > > >>>>>>>> who had 2 before and therefore knows the key.
> > > > > >>>>>>>>
> > > > > >>>>>>>> Userland reshuffeling is there as an options. And it does
> > > > exactly
> > > > > >>>>>>>> what
> > > > > >>>>>>>> I
> > > > > >>>>>>>> suggest. And I think its the perfect strategie. All I am
> > > > > suggestion
> > > > > >>>>>>>> is
> > > > > >>>>>>>> broker side support to switch the producers to the newly
> > > > > partitioned
> > > > > >>>>>>>> topic.
> > > > > >>>>>>>> Then the old (to few partition topic) can go away.
> Remember
> > > the
> > > > > >>>>>>>> list
> > > > > >>>>>>>> of
> > > > > >>>>>>>> steps in the beginning of this thread. If one has broker
> > > support
> > > > > for
> > > > > >>>>>>>> all
> > > > > >>>>>>>> where its required and streams support for those that
> aren’t
> > > > > >>>>>>>> necessarily.
> > > > > >>>>>>>> Then one has solved the problem.
> > > > > >>>>>>>> I repeat it because I think its important. I am really
> happy
> > > > that
> > > > > >>>>>>>> you
> > > > > >>>>>>>> brought that up! because its 100% what I want just with
> the
> > > > > >>>>>>>> differences
> > > > > >>>>>>>> to
> > > > > >>>>>>>> have an option to discard the to small topic later (after
> > all
> > > > > >>>>>>>> consumers
> > > > > >>>>>>>> adapted). And to have order correct there. I need broker
> > > support
> > > > > >>>>>>>> managing
> > > > > >>>>>>>> the copy process + the produces and fence them against
> each
> > > > > other. I
> > > > > >>>>>>>> also
> > > > > >>>>>>>> repeat. the copy process can run for weeks in the worst
> > case.
> > > > > >>>>>>>> Copying
> > > > > >>>>>>>> the
> > > > > >>>>>>>> data is not the longest task migrating consumers might
> very
> > > well
> > > > > be.
> > > > > >>>>>>>> Once all consumers switched and copying is really up to
> date
> > > > > (think
> > > > > >>>>>>>> ISR
> > > > > >>>>>>>> like up to date) only then we stop the producer, wait for
> > the
> > > > copy
> > > > > >>>>>>>> to
> > > > > >>>>>>>> finish and use the new topic for producing.
> > > > > >>>>>>>>
> > > > > >>>>>>>> After this the topic is perfect in shape. and no one needs
> > to
> > > > > worry
> > > > > >>>>>>>> about
> > > > > >>>>>>>> complicated stuff. (old keys hanging around might arrive
> in
> > > some
> > > > > >>>>>>>> other
> > > > > >>>>>>>> topic later.....). can only imagine how many tricky bugs
> > gonna
> > > > > >>>>>>>> arrive
> > > > > >>>>>>>> after
> > > > > >>>>>>>> someone had grown and shrunken is topic 10 times.
> > > > > >>>>>>>>
> > > > > >>>>>>>>
> > > > > >>>>>>>>
> > > > > >>>>>>>>
> > > > > >>>>>>>>
> > > > > >>>>>>>>
> > > > > >>>>>>>> 54. "The other thing I wanted to mention is that I believe
> > the
> > > > > >>>>>>>> current
> > > > > >>>>>>>>
> > > > > >>>>>>>> suggestion (without copying data over) can be implemented
> in
> > > > pure
> > > > > >>>>>>>>> userland
> > > > > >>>>>>>>> with a custom partitioner and a small feedbackloop from
> > > > > >>>>>>>>> ProduceResponse
> > > > > >>>>>>>>> =>
> > > > > >>>>>>>>> Partitionier in coorporation with a change management
> > > system."
> > > > I
> > > > > am
> > > > > >>>>>>>>> not
> > > > > >>>>>>>>> sure a customized partitioner itself solves the problem.
> We
> > > > > >>>>>>>>> probably
> > > > > >>>>>>>>> need
> > > > > >>>>>>>>> some broker side support to enforce when the new
> partitions
> > > can
> > > > > be
> > > > > >>>>>>>>> used.
> > > > > >>>>>>>>> We
> > > > > >>>>>>>>> also need some support on the consumer/kstream side to
> > > preserve
> > > > > the
> > > > > >>>>>>>>> per
> > > > > >>>>>>>>> key
> > > > > >>>>>>>>> ordering and potentially migrate the processing state.
> This
> > > is
> > > > > not
> > > > > >>>>>>>>> trivial
> > > > > >>>>>>>>> and I am not sure if it's ideal to fully push to the
> > > > application
> > > > > >>>>>>>>> space.
> > > > > >>>>>>>>>
> > > > > >>>>>>>>> Broker support is defenitly the preferred way here. I
> have
> > > > > nothing
> > > > > >>>>>>>>>
> > > > > >>>>>>>>> against
> > > > > >>>>>>>> broker support.
> > > > > >>>>>>>> I tried to say that for what I would preffer - copying the
> > > data
> > > > > >>>>>>>> over,
> > > > > >>>>>>>> at
> > > > > >>>>>>>> least for log compacted topics -
> > > > > >>>>>>>> I would require more broker support than the KIP currently
> > > > offers.
> > > > > >>>>>>>>
> > > > > >>>>>>>>
> > > > > >>>>>>>>
> > > > > >>>>>>>> Jun
> > > > > >>>>>>>>
> > > > > >>>>>>>> On Tue, Mar 6, 2018 at 10:33 PM, Jan Filipiak <
> > > > > >>>>>>>>> Jan.Filipiak@trivago.com
> > > > > >>>>>>>>> wrote:
> > > > > >>>>>>>>>
> > > > > >>>>>>>>> Hi Dong,
> > > > > >>>>>>>>>
> > > > > >>>>>>>>> are you actually reading my emails, or are you just using
> > the
> > > > > >>>>>>>>> thread I
> > > > > >>>>>>>>>
> > > > > >>>>>>>>>> started for general announcements regarding the KIP?
> > > > > >>>>>>>>>>
> > > > > >>>>>>>>>> I tried to argue really hard against linear hashing.
> > Growing
> > > > the
> > > > > >>>>>>>>>> topic
> > > > > >>>>>>>>>> by
> > > > > >>>>>>>>>> an integer factor does not require any state
> > redistribution
> > > at
> > > > > >>>>>>>>>> all. I
> > > > > >>>>>>>>>> fail
> > > > > >>>>>>>>>> to see completely where linear hashing helps on log
> > > compacted
> > > > > >>>>>>>>>> topics.
> > > > > >>>>>>>>>>
> > > > > >>>>>>>>>> If you are not willing to explain to me what I might be
> > > > > >>>>>>>>>> overlooking:
> > > > > >>>>>>>>>> that
> > > > > >>>>>>>>>> is fine.
> > > > > >>>>>>>>>> But I ask you to not reply to my emails then. Please
> > > > understand
> > > > > my
> > > > > >>>>>>>>>> frustration with this.
> > > > > >>>>>>>>>>
> > > > > >>>>>>>>>> Best Jan
> > > > > >>>>>>>>>>
> > > > > >>>>>>>>>>
> > > > > >>>>>>>>>>
> > > > > >>>>>>>>>> On 06.03.2018 19:38, Dong Lin wrote:
> > > > > >>>>>>>>>>
> > > > > >>>>>>>>>> Hi everyone,
> > > > > >>>>>>>>>>
> > > > > >>>>>>>>>> Thanks for all the comments! It appears that everyone
> > > prefers
> > > > > >>>>>>>>>> linear
> > > > > >>>>>>>>>>
> > > > > >>>>>>>>>>> hashing because it reduces the amount of state that
> needs
> > > to
> > > > be
> > > > > >>>>>>>>>>> moved
> > > > > >>>>>>>>>>> between consumers (for stream processing). The KIP has
> > been
> > > > > >>>>>>>>>>> updated
> > > > > >>>>>>>>>>> to
> > > > > >>>>>>>>>>> use
> > > > > >>>>>>>>>>> linear hashing.
> > > > > >>>>>>>>>>>
> > > > > >>>>>>>>>>> Regarding the migration endeavor: it seems that
> migrating
> > > > > >>>>>>>>>>> producer
> > > > > >>>>>>>>>>> library
> > > > > >>>>>>>>>>> to use linear hashing should be pretty straightforward
> > > > without
> > > > > >>>>>>>>>>> much operational endeavor. If we don't upgrade client
> > > library
> > > > > to
> > > > > >>>>>>>>>>> use
> > > > > >>>>>>>>>>> this
> > > > > >>>>>>>>>>> KIP, we can not support in-order delivery after
> partition
> > > is
> > > > > >>>>>>>>>>> changed
> > > > > >>>>>>>>>>> anyway. Suppose we upgrade client library to use this
> > KIP,
> > > if
> > > > > >>>>>>>>>>> partition
> > > > > >>>>>>>>>>> number is not changed, the key -> partition mapping
> will
> > be
> > > > > >>>>>>>>>>> exactly
> > > > > >>>>>>>>>>> the
> > > > > >>>>>>>>>>> same as it is now because it is still determined using
> > > > > >>>>>>>>>>> murmur_hash(key)
> > > > > >>>>>>>>>>> %
> > > > > >>>>>>>>>>> original_partition_num. In other words, this change is
> > > > backward
> > > > > >>>>>>>>>>> compatible.
> > > > > >>>>>>>>>>>
> > > > > >>>>>>>>>>> Regarding the load distribution: if we use linear
> > hashing,
> > > > the
> > > > > >>>>>>>>>>> load
> > > > > >>>>>>>>>>> may
> > > > > >>>>>>>>>>> be
> > > > > >>>>>>>>>>> unevenly distributed because those partitions which are
> > not
> > > > > split
> > > > > >>>>>>>>>>> may
> > > > > >>>>>>>>>>> receive twice as much traffic as other partitions that
> > are
> > > > > split.
> > > > > >>>>>>>>>>> This
> > > > > >>>>>>>>>>> issue can be mitigated by creating topic with
> partitions
> > > that
> > > > > are
> > > > > >>>>>>>>>>> several
> > > > > >>>>>>>>>>> times the number of consumers. And there will be no
> > > imbalance
> > > > > if
> > > > > >>>>>>>>>>> the
> > > > > >>>>>>>>>>> partition number is always doubled. So this imbalance
> > seems
> > > > > >>>>>>>>>>> acceptable.
> > > > > >>>>>>>>>>>
> > > > > >>>>>>>>>>> Regarding storing the partition strategy as per-topic
> > > config:
> > > > > It
> > > > > >>>>>>>>>>> seems
> > > > > >>>>>>>>>>> not
> > > > > >>>>>>>>>>> necessary since we can still use murmur_hash as the
> > default
> > > > > hash
> > > > > >>>>>>>>>>> function
> > > > > >>>>>>>>>>> and additionally apply the linear hashing algorithm if
> > the
> > > > > >>>>>>>>>>> partition
> > > > > >>>>>>>>>>> number
> > > > > >>>>>>>>>>> has increased. Not sure if there is any use-case for
> > > producer
> > > > > to
> > > > > >>>>>>>>>>> use a
> > > > > >>>>>>>>>>> different hash function. Jason, can you check if there
> is
> > > > some
> > > > > >>>>>>>>>>> use-case
> > > > > >>>>>>>>>>> that I missed for using the per-topic partition
> strategy?
> > > > > >>>>>>>>>>>
> > > > > >>>>>>>>>>> Regarding how to reduce latency (due to state
> store/load)
> > > in
> > > > > >>>>>>>>>>> stream
> > > > > >>>>>>>>>>> processing consumer when partition number changes: I
> need
> > > to
> > > > > read
> > > > > >>>>>>>>>>> the
> > > > > >>>>>>>>>>> Kafka
> > > > > >>>>>>>>>>> Stream code to understand how Kafka Stream currently
> > > migrate
> > > > > >>>>>>>>>>> state
> > > > > >>>>>>>>>>> between
> > > > > >>>>>>>>>>> consumers when the application is added/removed for a
> > given
> > > > > job.
> > > > > >>>>>>>>>>> I
> > > > > >>>>>>>>>>> will
> > > > > >>>>>>>>>>> reply after I finish reading the documentation and
> code.
> > > > > >>>>>>>>>>>
> > > > > >>>>>>>>>>>
> > > > > >>>>>>>>>>> Thanks,
> > > > > >>>>>>>>>>> Dong
> > > > > >>>>>>>>>>>
> > > > > >>>>>>>>>>>
> > > > > >>>>>>>>>>> On Mon, Mar 5, 2018 at 10:43 AM, Jason Gustafson <
> > > > > >>>>>>>>>>> jason@confluent.io>
> > > > > >>>>>>>>>>> wrote:
> > > > > >>>>>>>>>>>
> > > > > >>>>>>>>>>> Great discussion. I think I'm wondering whether we can
> > > > continue
> > > > > >>>>>>>>>>> to
> > > > > >>>>>>>>>>> leave
> > > > > >>>>>>>>>>>
> > > > > >>>>>>>>>>> Kafka agnostic to the partitioning strategy. The
> > challenge
> > > is
> > > > > >>>>>>>>>>>
> > > > > >>>>>>>>>>> communicating
> > > > > >>>>>>>>>>>> the partitioning logic from producers to consumers so
> > that
> > > > the
> > > > > >>>>>>>>>>>> dependencies
> > > > > >>>>>>>>>>>> between each epoch can be determined. For the sake of
> > > > > >>>>>>>>>>>> discussion,
> > > > > >>>>>>>>>>>> imagine
> > > > > >>>>>>>>>>>> you did something like the following:
> > > > > >>>>>>>>>>>>
> > > > > >>>>>>>>>>>> 1. The name (and perhaps version) of a partitioning
> > > strategy
> > > > > is
> > > > > >>>>>>>>>>>> stored
> > > > > >>>>>>>>>>>> in
> > > > > >>>>>>>>>>>> topic configuration when a topic is created.
> > > > > >>>>>>>>>>>> 2. The producer looks up the partitioning strategy
> > before
> > > > > >>>>>>>>>>>> writing
> > > > > >>>>>>>>>>>> to
> > > > > >>>>>>>>>>>> a
> > > > > >>>>>>>>>>>> topic and includes it in the produce request (for
> > > fencing).
> > > > If
> > > > > >>>>>>>>>>>> it
> > > > > >>>>>>>>>>>> doesn't
> > > > > >>>>>>>>>>>> have an implementation for the configured strategy, it
> > > > fails.
> > > > > >>>>>>>>>>>> 3. The consumer also looks up the partitioning
> strategy
> > > and
> > > > > >>>>>>>>>>>> uses it
> > > > > >>>>>>>>>>>> to
> > > > > >>>>>>>>>>>> determine dependencies when reading a new epoch. It
> > could
> > > > > either
> > > > > >>>>>>>>>>>> fail
> > > > > >>>>>>>>>>>> or
> > > > > >>>>>>>>>>>> make the most conservative dependency assumptions if
> it
> > > > > doesn't
> > > > > >>>>>>>>>>>> know
> > > > > >>>>>>>>>>>> how
> > > > > >>>>>>>>>>>> to
> > > > > >>>>>>>>>>>> implement the partitioning strategy. For the consumer,
> > the
> > > > new
> > > > > >>>>>>>>>>>> interface
> > > > > >>>>>>>>>>>> might look something like this:
> > > > > >>>>>>>>>>>>
> > > > > >>>>>>>>>>>> // Return the partition dependencies following an
> epoch
> > > bump
> > > > > >>>>>>>>>>>> Map<Integer, List<Integer>> dependencies(int
> > > > > >>>>>>>>>>>> numPartitionsBeforeEpochBump,
> > > > > >>>>>>>>>>>> int numPartitionsAfterEpochBump)
> > > > > >>>>>>>>>>>>
> > > > > >>>>>>>>>>>> The unordered case then is just a particular
> > > implementation
> > > > > >>>>>>>>>>>> which
> > > > > >>>>>>>>>>>> never
> > > > > >>>>>>>>>>>> has
> > > > > >>>>>>>>>>>> any epoch dependencies. To implement this, we would
> need
> > > > some
> > > > > >>>>>>>>>>>> way
> > > > > >>>>>>>>>>>> for
> > > > > >>>>>>>>>>>> the
> > > > > >>>>>>>>>>>> consumer to find out how many partitions there were in
> > > each
> > > > > >>>>>>>>>>>> epoch,
> > > > > >>>>>>>>>>>> but
> > > > > >>>>>>>>>>>> maybe that's not too unreasonable.
> > > > > >>>>>>>>>>>>
> > > > > >>>>>>>>>>>> Thanks,
> > > > > >>>>>>>>>>>> Jason
> > > > > >>>>>>>>>>>>
> > > > > >>>>>>>>>>>>
> > > > > >>>>>>>>>>>> On Mon, Mar 5, 2018 at 4:51 AM, Jan Filipiak <
> > > > > >>>>>>>>>>>> Jan.Filipiak@trivago.com
> > > > > >>>>>>>>>>>> wrote:
> > > > > >>>>>>>>>>>>
> > > > > >>>>>>>>>>>> Hi Dong
> > > > > >>>>>>>>>>>>
> > > > > >>>>>>>>>>>> thank you very much for your questions.
> > > > > >>>>>>>>>>>>
> > > > > >>>>>>>>>>>> regarding the time spend copying data across:
> > > > > >>>>>>>>>>>>> It is correct that copying data from a topic with one
> > > > > partition
> > > > > >>>>>>>>>>>>> mapping
> > > > > >>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>> to
> > > > > >>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>> a topic with a different partition mapping takes way
> > > longer
> > > > > >>>>>>>>>>>>> than
> > > > > >>>>>>>>>>>>>
> > > > > >>>>>>>>>>>> we
> > > > > >>>>>>>>>>>> can
> > > > > >>>>>>>>>>>>
> > > > > >>>>>>>>>>>> stop producers. Tens of minutes is a very optimistic
> > > > estimate
> > > > > >>>>>>>>>>>> here.
> > > > > >>>>>>>>>>>>
> > > > > >>>>>>>>>>>>> Many
> > > > > >>>>>>>>>>>>> people can not afford copy full steam and therefore
> > will
> > > > have
> > > > > >>>>>>>>>>>>> some
> > > > > >>>>>>>>>>>>> rate
> > > > > >>>>>>>>>>>>> limiting in place, this can bump the timespan into
> the
> > > > day's.
> > > > > >>>>>>>>>>>>> The
> > > > > >>>>>>>>>>>>> good
> > > > > >>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>> part
> > > > > >>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>> is that the vast majority of the data can be copied
> > while
> > > > the
> > > > > >>>>>>>>>>>>>
> > > > > >>>>>>>>>>>> producers
> > > > > >>>>>>>>>>>>
> > > > > >>>>>>>>>>>> are
> > > > > >>>>>>>>>>>>
> > > > > >>>>>>>>>>>>> still going. One can then, piggyback the consumers
> > ontop
> > > of
> > > > > >>>>>>>>>>>>> this
> > > > > >>>>>>>>>>>>>
> > > > > >>>>>>>>>>>> timeframe,
> > > > > >>>>>>>>>>>>
> > > > > >>>>>>>>>>>>> by the method mentioned (provide them an mapping from
> > > their
> > > > > old
> > > > > >>>>>>>>>>>>>
> > > > > >>>>>>>>>>>> offsets
> > > > > >>>>>>>>>>>>
> > > > > >>>>>>>>>>>> to
> > > > > >>>>>>>>>>>>
> > > > > >>>>>>>>>>>>> new offsets in their repartitioned topics. In that
> way
> > we
> > > > > >>>>>>>>>>>>> separate
> > > > > >>>>>>>>>>>>>
> > > > > >>>>>>>>>>>> migration of consumers from migration of producers
> > > > (decoupling
> > > > > >>>>>>>>>>>>
> > > > > >>>>>>>>>>>>> these
> > > > > >>>>>>>>>>>>> is
> > > > > >>>>>>>>>>>>> what kafka is strongest at). The time to actually
> swap
> > > over
> > > > > the
> > > > > >>>>>>>>>>>>> producers
> > > > > >>>>>>>>>>>>> should be kept minimal by ensuring that when a swap
> > > attempt
> > > > > is
> > > > > >>>>>>>>>>>>> started
> > > > > >>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>> the
> > > > > >>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>> consumer copying over should be very close to the log
> > end
> > > > and
> > > > > >>>>>>>>>>>>> is
> > > > > >>>>>>>>>>>>>
> > > > > >>>>>>>>>>>> expected
> > > > > >>>>>>>>>>>>
> > > > > >>>>>>>>>>>>> to finish within the next fetch. The operation should
> > > have
> > > > a
> > > > > >>>>>>>>>>>>> time-out
> > > > > >>>>>>>>>>>>> and
> > > > > >>>>>>>>>>>>> should be "reattemtable".
> > > > > >>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>> Importance of logcompaction:
> > > > > >>>>>>>>>>>>> If a producer produces key A, to partiton 0, its
> > forever
> > > > > gonna
> > > > > >>>>>>>>>>>>> be
> > > > > >>>>>>>>>>>>> there,
> > > > > >>>>>>>>>>>>> unless it gets deleted. The record might sit in there
> > for
> > > > > >>>>>>>>>>>>> years. A
> > > > > >>>>>>>>>>>>> new
> > > > > >>>>>>>>>>>>> producer started with the new partitions will fail to
> > > > delete
> > > > > >>>>>>>>>>>>> the
> > > > > >>>>>>>>>>>>> record
> > > > > >>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>> in
> > > > > >>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>> the correct partition. Th record will be there
> forever
> > > and
> > > > > one
> > > > > >>>>>>>>>>>>> can
> > > > > >>>>>>>>>>>>>
> > > > > >>>>>>>>>>>> not
> > > > > >>>>>>>>>>>>
> > > > > >>>>>>>>>>>> reliable bootstrap new consumers. I cannot see how
> > linear
> > > > > >>>>>>>>>>>> hashing
> > > > > >>>>>>>>>>>>
> > > > > >>>>>>>>>>>>> can
> > > > > >>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>> solve
> > > > > >>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>> this.
> > > > > >>>>>>>>>>>>>
> > > > > >>>>>>>>>>>> Regarding your skipping of userland copying:
> > > > > >>>>>>>>>>>>
> > > > > >>>>>>>>>>>>> 100%, copying the data across in userland is, as far
> > as i
> > > > can
> > > > > >>>>>>>>>>>>> see,
> > > > > >>>>>>>>>>>>> only
> > > > > >>>>>>>>>>>>> a
> > > > > >>>>>>>>>>>>> usecase for log compacted topics. Even for
> > logcompaction
> > > +
> > > > > >>>>>>>>>>>>> retentions
> > > > > >>>>>>>>>>>>> it
> > > > > >>>>>>>>>>>>> should only be opt-in. Why did I bring it up? I think
> > log
> > > > > >>>>>>>>>>>>> compaction
> > > > > >>>>>>>>>>>>> is
> > > > > >>>>>>>>>>>>> a
> > > > > >>>>>>>>>>>>> very important feature to really embrace kafka as a
> > "data
> > > > > >>>>>>>>>>>>> plattform".
> > > > > >>>>>>>>>>>>> The
> > > > > >>>>>>>>>>>>> point I also want to make is that copying data this
> way
> > > is
> > > > > >>>>>>>>>>>>> completely
> > > > > >>>>>>>>>>>>> inline with the kafka architecture. it only consists
> of
> > > > > reading
> > > > > >>>>>>>>>>>>> and
> > > > > >>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>> writing
> > > > > >>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>> to topics.
> > > > > >>>>>>>>>>>>>
> > > > > >>>>>>>>>>>> I hope it clarifies more why I think we should aim for
> > > more
> > > > > than
> > > > > >>>>>>>>>>>>
> > > > > >>>>>>>>>>>>> the
> > > > > >>>>>>>>>>>>> current KIP. I fear that once the KIP is done not
> much
> > > more
> > > > > >>>>>>>>>>>>> effort
> > > > > >>>>>>>>>>>>> will
> > > > > >>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>> be
> > > > > >>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>> taken.
> > > > > >>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>
> > > > > >>>>>>>>>>>> On 04.03.2018 02:28, Dong Lin wrote:
> > > > > >>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>> Hey Jan,
> > > > > >>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>> In the current proposal, the consumer will be blocked
> > on
> > > > > >>>>>>>>>>>>> waiting
> > > > > >>>>>>>>>>>>> for
> > > > > >>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>> other
> > > > > >>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>> consumers of the group to consume up to a given
> > offset.
> > > In
> > > > > >>>>>>>>>>>>>> most
> > > > > >>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>> cases,
> > > > > >>>>>>>>>>>>> all
> > > > > >>>>>>>>>>>>> consumers should be close to the LEO of the
> partitions
> > > when
> > > > > the
> > > > > >>>>>>>>>>>>> partition
> > > > > >>>>>>>>>>>>> expansion happens. Thus the time waiting should not
> be
> > > long
> > > > > >>>>>>>>>>>>> e.g.
> > > > > >>>>>>>>>>>>> on
> > > > > >>>>>>>>>>>>> the
> > > > > >>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>> order of seconds. On the other hand, it may take a
> long
> > > > time
> > > > > to
> > > > > >>>>>>>>>>>>> wait
> > > > > >>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>> for
> > > > > >>>>>>>>>>>>>> the entire partition to be copied -- the amount of
> > time
> > > is
> > > > > >>>>>>>>>>>>>> proportional
> > > > > >>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>> to
> > > > > >>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>> the amount of existing data in the partition, which
> > can
> > > > take
> > > > > >>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>> tens of
> > > > > >>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>> minutes. So the amount of time that we stop consumers
> > may
> > > > not
> > > > > >>>>>>>>>>>>> be
> > > > > >>>>>>>>>>>>> on
> > > > > >>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>> the
> > > > > >>>>>>>>>>>>>> same order of magnitude.
> > > > > >>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>> If we can implement this suggestion without copying
> > data
> > > > > over
> > > > > >>>>>>>>>>>>>> in
> > > > > >>>>>>>>>>>>>> purse
> > > > > >>>>>>>>>>>>>> userland, it will be much more valuable. Do you have
> > > ideas
> > > > > on
> > > > > >>>>>>>>>>>>>> how
> > > > > >>>>>>>>>>>>>> this
> > > > > >>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>> can
> > > > > >>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>> be done?
> > > > > >>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>> Not sure why the current KIP not help people who
> depend
> > > on
> > > > > log
> > > > > >>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>> compaction.
> > > > > >>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>> Could you elaborate more on this point?
> > > > > >>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>> Thanks,
> > > > > >>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>> Dong
> > > > > >>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>> On Wed, Feb 28, 2018 at 10:55 PM, Jan
> > > > > >>>>>>>>>>>>>> Filipiak<Jan.Filipiak@trivago.
> > > > > >>>>>>>>>>>>>> com
> > > > > >>>>>>>>>>>>>> wrote:
> > > > > >>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>> Hi Dong,
> > > > > >>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>> I tried to focus on what the steps are one can
> > currently
> > > > > >>>>>>>>>>>>>> perform
> > > > > >>>>>>>>>>>>>> to
> > > > > >>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>> expand
> > > > > >>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>> or shrink a keyed topic while maintaining a top
> notch
> > > > > >>>>>>>>>>>>>>> semantics.
> > > > > >>>>>>>>>>>>>>> I can understand that there might be confusion
> about
> > > > > >>>>>>>>>>>>>>> "stopping
> > > > > >>>>>>>>>>>>>>> the
> > > > > >>>>>>>>>>>>>>> consumer". It is exactly the same as proposed in
> the
> > > KIP.
> > > > > >>>>>>>>>>>>>>> there
> > > > > >>>>>>>>>>>>>>> needs
> > > > > >>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>> to
> > > > > >>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>> be
> > > > > >>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>> a time the producers agree on the new partitioning.
> > The
> > > > > extra
> > > > > >>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>> semantics I
> > > > > >>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>> want to put in there is that we have a possibility
> to
> > > > wait
> > > > > >>>>>>>>>>>>>>> until
> > > > > >>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>> all
> > > > > >>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>> the
> > > > > >>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>> existing data
> > > > > >>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>> is copied over into the new partitioning scheme.
> When
> > I
> > > > say
> > > > > >>>>>>>>>>>>> stopping
> > > > > >>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>> I
> > > > > >>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>> think more of having a memory barrier that ensures
> > the
> > > > > >>>>>>>>>>>>>>> ordering. I
> > > > > >>>>>>>>>>>>>>> am
> > > > > >>>>>>>>>>>>>>> still
> > > > > >>>>>>>>>>>>>>> aming for latencies  on the scale of leader
> > failovers.
> > > > > >>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>> Consumers have to explicitly adapt the new
> > partitioning
> > > > > >>>>>>>>>>>>>>> scheme
> > > > > >>>>>>>>>>>>>>> in
> > > > > >>>>>>>>>>>>>>> the
> > > > > >>>>>>>>>>>>>>> above scenario. The reason is that in these cases
> > where
> > > > you
> > > > > >>>>>>>>>>>>>>> are
> > > > > >>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>> dependent
> > > > > >>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>> on a particular partitioning scheme, you also have
> > > other
> > > > > >>>>>>>>>>>>>>> topics
> > > > > >>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>> that
> > > > > >>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>> have
> > > > > >>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>> co-partition enforcements or the kind -frequently.
> > > > Therefore
> > > > > >>>>>>>>>>>>>> all
> > > > > >>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>> your
> > > > > >>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>> other
> > > > > >>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>> input topics might need to grow accordingly.
> > > > > >>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>> What I was suggesting was to streamline all these
> > > > > operations
> > > > > >>>>>>>>>>>>>>> as
> > > > > >>>>>>>>>>>>>>> best
> > > > > >>>>>>>>>>>>>>> as
> > > > > >>>>>>>>>>>>>>> possible to have "real" partition grow and
> shrinkage
> > > > going
> > > > > >>>>>>>>>>>>>>> on.
> > > > > >>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>> Migrating
> > > > > >>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>> the producers to a new partitioning scheme can be
> > much
> > > > more
> > > > > >>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>> streamlined
> > > > > >>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>> with proper broker support for this. Migrating
> consumer
> > > is
> > > > a
> > > > > >>>>>>>>>>>>> step
> > > > > >>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>> that
> > > > > >>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>> might be made completly unnecessary if - for
> example
> > > > > streams
> > > > > >>>>>>>>>>>>>>> -
> > > > > >>>>>>>>>>>>>>> takes
> > > > > >>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>> the
> > > > > >>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>> gcd as partitioning scheme instead of enforcing 1
> to
> > 1.
> > > > > >>>>>>>>>>>>>>> Connect
> > > > > >>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>> consumers
> > > > > >>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>> and other consumers should be fine anyways.
> > > > > >>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>> I hope this makes more clear where I was aiming at.
> > The
> > > > rest
> > > > > >>>>>>>>>>>>> needs
> > > > > >>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>> to
> > > > > >>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>> be
> > > > > >>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>> figured out. The only danger i see is that when we
> > are
> > > > > >>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>> introducing
> > > > > >>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>> this
> > > > > >>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>> feature as supposed in the KIP, it wont help any
> people
> > > > > >>>>>>>>>>>>> depending
> > > > > >>>>>>>>>>>>> on
> > > > > >>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>> log
> > > > > >>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>> compaction.
> > > > > >>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>> The other thing I wanted to mention is that I
> believe
> > > the
> > > > > >>>>>>>>>>>>> current
> > > > > >>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>> suggestion (without copying data over) can be
> > implemented
> > > > in
> > > > > >>>>>>>>>>>>>> pure
> > > > > >>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>> userland
> > > > > >>>>>>>>>>>>>>> with a custom partitioner and a small feedbackloop
> > from
> > > > > >>>>>>>>>>>>>>> ProduceResponse
> > > > > >>>>>>>>>>>>>>> =>
> > > > > >>>>>>>>>>>>>>> Partitionier in coorporation with a change
> management
> > > > > system.
> > > > > >>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>> Best Jan
> > > > > >>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>> On 28.02.2018 07:13, Dong Lin wrote:
> > > > > >>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>> Hey Jan,
> > > > > >>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>> I am not sure if it is acceptable for producer to
> be
> > > > > stopped
> > > > > >>>>>>>>>>>>>>> for a
> > > > > >>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>> while,
> > > > > >>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>> particularly for online application which requires
> > low
> > > > > >>>>>>>>>>>>>>>> latency. I
> > > > > >>>>>>>>>>>>>>>> am
> > > > > >>>>>>>>>>>>>>>> also
> > > > > >>>>>>>>>>>>>>>> not sure how consumers can switch to a new topic.
> > Does
> > > > > user
> > > > > >>>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>> application
> > > > > >>>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>> needs to explicitly specify a different topic for
> > > > > >>>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>> producer/consumer
> > > > > >>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>> to
> > > > > >>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>> subscribe to? It will be helpful for discussion if
> you
> > > can
> > > > > >>>>>>>>>>>>> provide
> > > > > >>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>> more
> > > > > >>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>> detail on the interface change for this solution.
> > > > > >>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>> Thanks,
> > > > > >>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>> Dong
> > > > > >>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>> On Mon, Feb 26, 2018 at 12:48 AM, Jan
> > > > > >>>>>>>>>>>>>>>> Filipiak<Jan.Filipiak@trivago.
> > > > > >>>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>> com
> > > > > >>>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>> wrote:
> > > > > >>>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>> Hi,
> > > > > >>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>> just want to throw my though in. In general the
> > > > > functionality
> > > > > >>>>>>>>>>>>>> is
> > > > > >>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>> very
> > > > > >>>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>> usefull, we should though not try to find the
> > > > architecture
> > > > > >>>>>>>>>>>>>>>> to
> > > > > >>>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>> hard
> > > > > >>>>>>>>>>>>>>>>> while
> > > > > >>>>>>>>>>>>>>>>> implementing.
> > > > > >>>>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>>> The manual steps would be to
> > > > > >>>>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>>> create a new topic
> > > > > >>>>>>>>>>>>>>>>> the mirrormake from the new old topic to the new
> > > topic
> > > > > >>>>>>>>>>>>>>>>> wait for mirror making to catch up.
> > > > > >>>>>>>>>>>>>>>>> then put the consumers onto the new topic
> > > > > >>>>>>>>>>>>>>>>>            (having mirrormaker spit out a mapping
> > > from
> > > > > old
> > > > > >>>>>>>>>>>>>>>>> offsets to
> > > > > >>>>>>>>>>>>>>>>> new
> > > > > >>>>>>>>>>>>>>>>> offsets:
> > > > > >>>>>>>>>>>>>>>>>                if topic is increased by factor X
> > > there
> > > > is
> > > > > >>>>>>>>>>>>>>>>> gonna
> > > > > >>>>>>>>>>>>>>>>> be a
> > > > > >>>>>>>>>>>>>>>>> clean
> > > > > >>>>>>>>>>>>>>>>> mapping from 1 offset in the old topic to X
> offsets
> > > in
> > > > > the
> > > > > >>>>>>>>>>>>>>>>> new
> > > > > >>>>>>>>>>>>>>>>> topic,
> > > > > >>>>>>>>>>>>>>>>>                if there is no factor then there
> is
> > no
> > > > > >>>>>>>>>>>>>>>>> chance to
> > > > > >>>>>>>>>>>>>>>>> generate a
> > > > > >>>>>>>>>>>>>>>>> mapping that can be reasonable used for
> continuing)
> > > > > >>>>>>>>>>>>>>>>>            make consumers stop at appropriate
> > points
> > > > and
> > > > > >>>>>>>>>>>>>>>>> continue
> > > > > >>>>>>>>>>>>>>>>> consumption
> > > > > >>>>>>>>>>>>>>>>> with offsets from the mapping.
> > > > > >>>>>>>>>>>>>>>>> have the producers stop for a minimal time.
> > > > > >>>>>>>>>>>>>>>>> wait for mirrormaker to finish
> > > > > >>>>>>>>>>>>>>>>> let producer produce with the new metadata.
> > > > > >>>>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>>> Instead of implementing the approach suggest in
> the
> > > KIP
> > > > > >>>>>>>>>>>>>>>>> which
> > > > > >>>>>>>>>>>>>>>>> will
> > > > > >>>>>>>>>>>>>>>>> leave
> > > > > >>>>>>>>>>>>>>>>> log compacted topic completely crumbled and
> > unusable.
> > > > > >>>>>>>>>>>>>>>>> I would much rather try to build infrastructure
> to
> > > > > support
> > > > > >>>>>>>>>>>>>>>>> the
> > > > > >>>>>>>>>>>>>>>>> mentioned
> > > > > >>>>>>>>>>>>>>>>> above operations more smoothly.
> > > > > >>>>>>>>>>>>>>>>> Especially having producers stop and use another
> > > topic
> > > > is
> > > > > >>>>>>>>>>>>>>>>> difficult
> > > > > >>>>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>>> and
> > > > > >>>>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>>> it would be nice if one can trigger "invalid
> > > metadata"
> > > > > >>>>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>> exceptions
> > > > > >>>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>> for
> > > > > >>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>> them
> > > > > >>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>> and
> > > > > >>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>> if one could give topics aliases so that their
> > produces
> > > > > with
> > > > > >>>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>>> the
> > > > > >>>>>>>>>>>>>>>>> old
> > > > > >>>>>>>>>>>>>>>>> topic
> > > > > >>>>>>>>>>>>>>>>> will arrive in the new topic.
> > > > > >>>>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>>> The downsides are obvious I guess ( having the
> same
> > > > data
> > > > > >>>>>>>>>>>>>>>>> twice
> > > > > >>>>>>>>>>>>>>>>> for
> > > > > >>>>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>>> the
> > > > > >>>>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>>> transition period, but kafka tends to scale well
> > with
> > > > > >>>>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>> datasize).
> > > > > >>>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>> So
> > > > > >>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>> its a
> > > > > >>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>> nicer fit into the architecture.
> > > > > >>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>> I further want to argument that the functionality
> by
> > > the
> > > > > KIP
> > > > > >>>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>>> can
> > > > > >>>>>>>>>>>>>>>>> completely be implementing in "userland" with a
> > > custom
> > > > > >>>>>>>>>>>>>>>>> partitioner
> > > > > >>>>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>>> that
> > > > > >>>>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>>> handles the transition as needed. I would
> > appreciate
> > > if
> > > > > >>>>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>> someone
> > > > > >>>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>> could
> > > > > >>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>> point
> > > > > >>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>> out what a custom partitioner couldn't handle in this
> > > case?
> > > > > >>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>> With the above approach, shrinking a topic becomes
> > the
> > > > same
> > > > > >>>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>>> steps.
> > > > > >>>>>>>>>>>>>>>>> Without
> > > > > >>>>>>>>>>>>>>>>> loosing keys in the discontinued partitions.
> > > > > >>>>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>>> Would love to hear what everyone thinks.
> > > > > >>>>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>>> Best Jan
> > > > > >>>>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>>> On 11.02.2018 00:35, Dong Lin wrote:
> > > > > >>>>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>>> Hi all,
> > > > > >>>>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>>> I have created KIP-253: Support in-order message
> > > > delivery
> > > > > >>>>>>>>>>>>>>>>> with
> > > > > >>>>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>>> partition
> > > > > >>>>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>>> expansion. See
> > > > > >>>>>>>>>>>>>>>>>> https://cwiki.apache.org/confl
> > > > > >>>>>>>>>>>>>>>>>> uence/display/KAFKA/KIP-253%
> > > > > >>>>>>>>>>>>>>>>>> 3A+Support+in-order+message+de
> > > > > >>>>>>>>>>>>>>>>>> livery+with+partition+expansio
> > > > > >>>>>>>>>>>>>>>>>> n
> > > > > >>>>>>>>>>>>>>>>>> .
> > > > > >>>>>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>>>> This KIP provides a way to allow messages of the
> > > same
> > > > > key
> > > > > >>>>>>>>>>>>>>>>>> from
> > > > > >>>>>>>>>>>>>>>>>> the
> > > > > >>>>>>>>>>>>>>>>>> same
> > > > > >>>>>>>>>>>>>>>>>> producer to be consumed in the same order they
> are
> > > > > >>>>>>>>>>>>>>>>>> produced
> > > > > >>>>>>>>>>>>>>>>>> even
> > > > > >>>>>>>>>>>>>>>>>> if
> > > > > >>>>>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>>>> we
> > > > > >>>>>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>>>> expand partition of the topic.
> > > > > >>>>>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>>> Thanks,
> > > > > >>>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>> Dong
> > > > > >>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>>>>
> > > > > >>>>>>>>>>>>>>>>>>
> > > > > >>>>
> > > > > >>
> > > > > >>
> > > > > >
> > > > >
> > > >
> > >
> >
>

Re: [DISCUSS] KIP-253: Support in-order message delivery with partition expansion

Posted by Dong Lin <li...@gmail.com>.
Hey John,

Great! Thanks for all the comment. It seems that we agree that the current
KIP is in good shape for core Kafka. IMO, what we have been discussing in
the recent email exchanges is mostly about the second step, i.e. how to
address problem for the stream use-case (or stateful processing in general).

I will comment inline.




On Tue, Mar 27, 2018 at 4:38 PM, John Roesler <jo...@confluent.io> wrote:

> Thanks for the response, Dong.
>
> Here are my answers to your questions:
>
> - "Asking producers and consumers, or even two different producers, to
> > share code like the partition function is a pretty huge ask. What if they
> > are using different languages?". It seems that today we already require
> > different producer's to use the same hash function -- otherwise messages
> > with the same key will go to different partitions of the same topic which
> > may cause problem for downstream consumption. So not sure if it adds any
> > more constraint by assuming consumers know the hash function of producer.
> > Could you explain more why user would want to use a cusmtom partition
> > function? Maybe we can check if this is something that can be supported
> in
> > the default Kafka hash function. Also, can you explain more why it is
> > difficuilt to implement the same hash function in different languages?
>
>
> Sorry, I meant two different producers as in producers to two different
> topics. This was in response to the suggestion that we already require
> coordination among producers to different topics in order to achieve
> co-partitioning. I was saying that we do not (and should not).


It is probably common for producers of different team to produce message to
the same topic. In order to ensure that messages with the same key go to
same partition, we need producers of different team to share the same
partition algorithm, which by definition requires coordination among
producers of different teams in an organization. Even for producers of
different topics, it may be common to require producers to use the same
partition algorithm in order to join two topics for stream processing. Does
this make it reasonable to say we already require coordination across
producers?


> By design, consumers are currently ignorant of the partitioning scheme. It
> suffices to trust that the producer has partitioned the topic by key, if
> they claim to have done so. If you don't trust that, or even if you just
> need some other partitioning scheme, then you must re-partition it
> yourself. Nothing we're discussing can or should change that. The value of
> backfill is that it preserves the ability for consumers to avoid
> re-partitioning before consuming, in the case where they don't need to
> today.


> Regarding shared "hash functions", note that it's a bit inaccurate to talk
> about the "hash function" of the producer. Properly speaking, the producer
> has only a "partition function". We do not know that it is a hash. The
> producer can use any method at their disposal to assign a partition to a
> record. The partition function obviously may we written in any programming
> language, so in general it's not something that can be shared around
> without a formal spec or the ability to execute arbitrary executables in
> arbitrary runtime environments.
>

Yeah it is probably better to say partition algorithm. I guess it should
not be difficult to implement same partition algorithms in different
languages, right? Yes we would need a formal specification of the default
partition algorithm in the producer. I think that can be documented as part
of the producer interface.


>
> Why would a producer want a custom partition function? I don't know... why
> did we design the interface so that our users can provide one? In general,
> such systems provide custom partitioners because some data sets may be
> unbalanced under the default or because they can provide some interesting
> functionality built on top of the partitioning scheme, etc. Having provided
> this ability, I don't know why we would remove it.
>

Yeah it is reasonable to assume that there was reason to support custom
partition function in producer. On the other hand it may also be reasonable
to revisit this interface and discuss whether we actually need to support
custom partition function. If we don't have a good reason, we can choose
not to support custom partition function in this KIP in a backward
compatible manner, i.e. user can still use custom partition function but
they would not get the benefit of in-order delivery when there is partition
expansion. What do you think?


>
> - Besides the assumption that consumer needs to share the hash function of
> > producer, is there other organization overhead of the proposal in the
> > current KIP?
> >
>
> It wasn't clear to me that KIP-253 currently required the producer and
> consumer to share the partition function, or in fact that it had a hard
> requirement to abandon the general partition function and use a linear hash
> function instead.


> In my reading, there is a requirement to track the metadata about what
> partitions split into what other partitions during an expansion operation.
> If the partition function is linear, this is easy. If not, you can always
> just record that all old partitions split into all new partitions. This has
> the effect of forcing all consumers to wait until the old epoch is
> completely consumed before starting on the new epoch. But this may be a
> reasonable tradeoff, and it doesn't otherwise alter your design.
>
> You only mention the consumer needing to know that the partition function
> is linear, not what the actual function is, so I don't think your design
> actually calls for sharing the function. Plus, really all the consumer
> needs is the metadata about what old-epoch partitions to wait for before
> consuming a new-epoch partition. This information is directly captured in
> metadata, so I don't think it actually even cares whether the partition
> function is linear or not.
>

You are right that the current KIP does not mention it. My comment related
to the partition function coordination was related to support the
stream-use case which we have been discussing so far.


> So, no, I really think KIP-253 is in good shape. I was really more talking
> about the part of this thread that's outside of KIP-253's scope, namely,
> creating the possibility of backfilling partitions after expansion.
>

Great! Can you also confirm that the main motivation for backfilling
partitions after expansion is to support the stream use-case?


> - Currently producer can forget about the message that has been
> > acknowledged by the broker. Thus the producer probably does not know most
> > of the exiting messages in topic, including those messages produced by
> > other producers. We can have the owner of the producer to split+backfill.
> > In my opion it will be a new program that wraps around the existing
> > producer and consumer classes.
> >
>
> This sounds fine by me!
>
> Really, I was just emphasizing that the part of the organization that
> produces a topic shouldn't have to export their partition function to the
> part(s) of the organization (or other organizations) that consume the
> topic. Whether the backfill operation goes into the Producer interface is
> secondary, I think.
>
> - Regarding point 5. The argument is in favor of the split+backfill but for
> > changelog topic. And it intends to address the problem for stream
> use-case
> > in general. In this KIP we will provide interface (i.e.
> > PartitionKeyRebalanceListener in the KIP) to be used by sream use-case
> and
> > the goal is that user can flush/re-consume the state as part of the
> > interface implementation regardless of whether there is change log topic.
> >
> > Maybe you are suggesting that the main reason to do split+backfill of
> input
> > topic is to support log compacted topics? You mentioned in Point 1 that
> log
> > compacted topics is out of the scope of this KIP. Maybe I could
> understand
> > your position better. Regarding Jan's proposal to split partitions with
> > backfill, do you think this should replace the proposal in the existing
> > KIP, or do you think this is something that we should do in addition to
> the
> > existing KIP?
> >
>
> I think that interface is a good/necessary component of KIP-253.
>
> I personally (FWIW) feel that KIP-253 is appropriately scoped, but I do
> think its utility will be limited unless there is a later KIP offering
> backfill. But, maybe unlike Jan, I think it makes sense to try and tackle
> the ordering problem independently of backfill, so I'm in support of the
> current KIP.
>
> - Regarding point 6. I guess we can agree that it is better not to have the
> > performance overhread of copying the input data. Before we discuss more
> on
> > whether the performance overhead is acceptable or not, I am trying to
> > figure out what is the benefit of introducing this overhread. You
> mentioned
> > that the benefit is the loose organizational coupling. By "organizational
> > coupling", are you referring to the requirement that consumer needs to
> know
> > the hash function of producer? If so, maybe we can discuss the use-case
> of
> > custom partiton function and see whether we can find a way to support
> such
> > use-case without having to copy the input data.
> >
>
> I'm not too sure about what an "input" is in this sense, since we are just
> talking about topics. Actually the point I was making there is that AKAICT
> the performance overhead of a backfill is less than any other option,
> assuming you split partitions rarely.
>

By "input" I was referring to source Kafka topic of a stream processing job.


> Separately, yes, "organizational coupling" increases if producers and
> consumers have to share code, such as the partition function. This would
> not be the case if producers could only pick from a menu of a few
> well-known partition functions, but I think this is a poor tradeoff.
>

Maybe we can revisit the custom partition function and see whether we
actually need it? Otherwise, I am concerned that every user will pay the
overhead of data movement to support something that was not really needed
for most users.


>
> To me, this is two strong arguments in favor of backfill being less
> expensive than no backfill, but again, I think that particular debate comes
> after KIP-253, so I don't want to create the impression of opposition to
> your proposal.
>
>
> Finally, to respond to a new email I just noticed:
>
> > BTW, here is my understanding of the scope of this KIP. We want to allow
> > consumers to always consume messages with the same key from the same
> > producer in the order they are produced. And we need to provide a way for
> > stream use-case to be able to flush/load state when messages with the
> same
> > key are migrated between consumers. In addition to ensuring that this
> goal
> > is correctly supported, we should do our best to keep the performance and
> > organization overhead of this KIP as low as possible.
> >
>
> I think we're on the same page there! In fact, I would generalize a little
> more and say that the mechanism you've designed provides *all consumers*
> the ability "to flush/load state when messages with the same key are
> migrated between consumers", not just Streams.
>

Thanks for all the comment!


>
> Thanks for the discussion,
> -John
>
>
>
> On Tue, Mar 27, 2018 at 3:14 PM, Dong Lin <li...@gmail.com> wrote:
>
> > Hey John,
> >
> > Thanks much for the detailed comments. Here are my thoughts:
> >
> > - The need to delete messages from log compacted topics is mainly for
> > performance (e.g. storage space) optimization than for correctness for
> this
> > KIP. I agree that we probably don't need to focus on this in our
> discussion
> > since it is mostly for performance optimization.
> >
> > - "Asking producers and consumers, or even two different producers, to
> > share code like the partition function is a pretty huge ask. What if they
> > are using different languages?". It seems that today we already require
> > different producer's to use the same hash function -- otherwise messages
> > with the same key will go to different partitions of the same topic which
> > may cause problem for downstream consumption. So not sure if it adds any
> > more constraint by assuming consumers know the hash function of producer.
> > Could you explain more why user would want to use a cusmtom partition
> > function? Maybe we can check if this is something that can be supported
> in
> > the default Kafka hash function. Also, can you explain more why it is
> > difficuilt to implement the same hash function in different languages?
> >
> > - Besides the assumption that consumer needs to share the hash function
> of
> > producer, is there other organization overhead of the proposal in the
> > current KIP?
> >
> > - Currently producer can forget about the message that has been
> > acknowledged by the broker. Thus the producer probably does not know most
> > of the exiting messages in topic, including those messages produced by
> > other producers. We can have the owner of the producer to split+backfill.
> > In my opion it will be a new program that wraps around the existing
> > producer and consumer classes.
> >
> > - Regarding point 5. The argument is in favor of the split+backfill but
> for
> > changelog topic. And it intends to address the problem for stream
> use-case
> > in general. In this KIP we will provide interface (i.e.
> > PartitionKeyRebalanceListener in the KIP) to be used by sream use-case
> and
> > the goal is that user can flush/re-consume the state as part of the
> > interface implementation regardless of whether there is change log topic.
> >
> > Maybe you are suggesting that the main reason to do split+backfill of
> input
> > topic is to support log compacted topics? You mentioned in Point 1 that
> log
> > compacted topics is out of the scope of this KIP. Maybe I could
> understand
> > your position better. Regarding Jan's proposal to split partitions with
> > backfill, do you think this should replace the proposal in the existing
> > KIP, or do you think this is something that we should do in addition to
> the
> > existing KIP?
> >
> > - Regarding point 6. I guess we can agree that it is better not to have
> the
> > performance overhread of copying the input data. Before we discuss more
> on
> > whether the performance overhead is acceptable or not, I am trying to
> > figure out what is the benefit of introducing this overhread. You
> mentioned
> > that the benefit is the loose organizational coupling. By "organizational
> > coupling", are you referring to the requirement that consumer needs to
> know
> > the hash function of producer? If so, maybe we can discuss the use-case
> of
> > custom partiton function and see whether we can find a way to support
> such
> > use-case without having to copy the input data.
> >
> > Thanks,
> > Dong
> >
> >
> > On Tue, Mar 27, 2018 at 11:34 AM, John Roesler <jo...@confluent.io>
> wrote:
> >
> > > Hey Dong and Jun,
> > >
> > > Thanks for the thoughtful responses. If you don't mind, I'll mix my
> > replies
> > > together to try for a coherent response. I'm not too familiar with
> > > mailing-list etiquette, though.
> > >
> > > I'm going to keep numbering my points because it makes it easy for you
> > all
> > > to respond.
> > >
> > > Point 1:
> > > As I read it, KIP-253 is *just* about properly fencing the producers
> and
> > > consumers so that you preserve the correct ordering of records during
> > > partition expansion. This is clearly necessary regardless of anything
> > else
> > > we discuss. I think this whole discussion about backfill, consumers,
> > > streams, etc., is beyond the scope of KIP-253. But it would be
> cumbersome
> > > to start a new thread at this point.
> > >
> > > I had missed KIP-253's Proposed Change #9 among all the details... I
> > think
> > > this is a nice addition to the proposal. One thought is that it's
> > actually
> > > irrelevant whether the hash function is linear. This is simply an
> > algorithm
> > > for moving a key from one partition to another, so the type of hash
> > > function need not be a precondition. In fact, it also doesn't matter
> > > whether the topic is compacted or not, the algorithm works regardless.
> > >
> > > I think this is a good algorithm to keep in mind, as it might solve a
> > > variety of problems, but it does have a downside: that the producer
> won't
> > > know whether or not K1 was actually in P1, it just knows that K1 was in
> > > P1's keyspace before the new epoch. Therefore, it will have to
> > > pessimistically send (K1,null) to P1 just in case. But the next time K1
> > > comes along, the producer *also* won't remember that it already
> retracted
> > > K1 from P1, so it will have to send (K1,null) *again*. By extension,
> > every
> > > time the producer sends to P2, it will also have to send a tombstone to
> > P1,
> > > which is a pretty big burden. To make the situation worse, if there is
> a
> > > second split, say P2 becomes P2 and P3, then any key Kx belonging to P3
> > > will also have to be retracted from P2 *and* P1, since the producer
> can't
> > > know whether Kx had been last written to P2 or P1. Over a long period
> of
> > > time, this clearly becomes a issue, as the producer must send an
> > arbitrary
> > > number of retractions along with every update.
> > >
> > > In contrast, the proposed backfill operation has an end, and after it
> > ends,
> > > everyone can afford to forget that there ever was a different partition
> > > layout.
> > >
> > > Really, though, figuring out how to split compacted topics is beyond
> the
> > > scope of KIP-253, so I'm not sure #9 really even needs to be in this
> > KIP...
> > > We do need in-order delivery during partition expansion. It would be
> fine
> > > by me to say that you *cannot* expand partitions of a log-compacted
> topic
> > > and call it a day. I think it would be better to tackle that in another
> > > KIP.
> > >
> > >
> > > Point 2:
> > > Regarding whether the consumer re-shuffles its inputs, this is always
> on
> > > the table; any consumer who wants to re-shuffle its input is free to do
> > so.
> > > But this is currently not required. It's just that the current
> high-level
> > > story with Kafka encourages the use of partitions as a unit of
> > concurrency.
> > > As long as consumers are single-threaded, they can happily consume a
> > single
> > > partition without concurrency control of any kind. This is a key aspect
> > to
> > > this system that lets folks design high-throughput systems on top of it
> > > surprisingly easily. If all consumers were instead encouraged/required
> to
> > > implement a repartition of their own, then the consumer becomes
> > > significantly more complex, requiring either the consumer to first
> > produce
> > > to its own intermediate repartition topic or to ensure that consumer
> > > threads have a reliable, high-bandwith channel of communication with
> > every
> > > other consumer thread.
> > >
> > > Either of those tradeoffs may be reasonable for a particular user of
> > Kafka,
> > > but I don't know if we're in a position to say that they are reasonable
> > for
> > > *every* user of Kafka.
> > >
> > >
> > > Point 3:
> > > Regarding Jun's point about this use case, "(3) stateful and
> maintaining
> > > the
> > > states in a local store", I agree that they may use a framework *like*
> > > Kafka Streams, but that is not the same as using Kafka Streams. This is
> > why
> > > I think it's better to solve it in Core: because it is then solved for
> > > KStreams and also for everything else that facilitates local state
> > > maintenance. To me, Streams is a member of the category of "stream
> > > processing frameworks", which is itself a subcategory of "things
> > requiring
> > > local state maintenence". I'm not sure if it makes sense to assert that
> > > Streams is a sufficient and practical replacement for everything in
> > "things
> > > requiring local state maintenence".
> > >
> > > But, yes, I do agree that per-key ordering is an absolute requirement,
> > > therefore I think that KIP-253 itself is a necessary step. Regarding
> the
> > > coupling of the state store partitioning to the topic partitioning,
> yes,
> > > this is an issue we are discussing solutions to right now. We may go
> > ahead
> > > and introduce an overpartition layer on our inputs to solve it, but
> then
> > > again, if we get the ability to split partitions with backfill, we may
> > not
> > > need to!
> > >
> > >
> > > Point 4:
> > > On this:
> > >
> > > > Regarding thought 2: If we don't care about the stream use-case, then
> > the
> > > > current KIP probably has already addressed problem without requiring
> > > > consumer to know the partition function. If we care about the stream
> > > > use-case, we already need coordination across producers of different
> > > > topics, i.e. the same partition function needs to be used by
> producers
> > of
> > > > topics A and B in order to join topics A and B. Thus, it might be
> > > > reasonable to extend coordination a bit and say we need coordination
> > > across
> > > > clients (i.e. producer and consumer), such that consumer knows the
> > > > partition function used by producer. If we do so, then we can let
> > > consumer
> > > > re-copy data for the change log topic using the same partition
> function
> > > as
> > > > producer. This approach has lower overhead as compared to having
> > producer
> > > > re-copy data of the input topic.
> > > > Also, producer currently does not need to know the data already
> > produced
> > > to
> > > > the topic. If we let producer split/merge partition, it would require
> > > > producer to consume the existing data, which intuitively is the task
> of
> > > > consumer.
> > >
> > >
> > > I think we do care about use cases *like* Streams, I just don't think
> we
> > > should rely on Streams to implement a feature of Core like partition
> > > expansion.
> > >
> > > Note, though, that we (Streams) do not require coordination across
> > > producers. If two topics are certified to be co-partitioned, then
> Streams
> > > apps can make use of that knowledge to optimize their topology
> (skipping
> > a
> > > repartition). But if they don't know whether they are co-partitioned,
> > then
> > > they'd better go ahead and repartition within the topology. This is the
> > > current state.
> > >
> > > A huge selling point of Kafka is enabling different parts of loosely
> > > coupled organizations to produce and consume data independently. Some
> > > coordination between producers and consumers is necessary, like
> > > coordinating on the names of topics and their schemas. But Kafka's
> value
> > > proposition w.r.t. ESBs, etc. is inversely proportional to the amount
> of
> > > coordination required. I think it behooves us to be extremely skeptical
> > > about introducing any coordination beyond correctness protocols.
> > >
> > > Asking producers and consumers, or even two different producers, to
> share
> > > code like the partition function is a pretty huge ask. What if they are
> > > using different languages?
> > >
> > > Comparing organizational overhead vs computational overhead, there are
> > > maybe two orders of magnitude difference between them. In other words,
> I
> > > would happily take on the (linear) overhead of having the producer
> > re-copy
> > > the data once during a re-partition in order to save the organizational
> > > overhead of tying all the producers and consumers together across
> > multiple
> > > boundaries.
> > >
> > > On that last paragraph: note that the producer *did* know the data it
> > > already produced. It handled it the first time around. Asking it to
> > > re-produce it into a new partition layout is squarely within its scope
> of
> > > capabilities. Contrast this with the alternative, asking the consumer
> to
> > > re-partition the data. I think this is even less intuitive, when the
> > > partition function belongs to the producer.
> > >
> > >
> > > Point 5:
> > > Dong asked this:
> > >
> > > > For stream use-case that needs to increase consumer number, the
> > > > existing consumer can backfill the existing data in the change log
> > topic
> > > to
> > > > the same change log topic with the new partition number, before the
> new
> > > set
> > > > of consumers bootstrap state from the new partitions of the change
> log
> > > > topic, right?
> > >
> > >
> > > In this sense, the "consumer" is actually the producer of the changelog
> > > topic, so if we support partition expansion + backfill as a
> > producer/broker
> > > operation, then it would be very straightforward for Streams to split a
> > > state store. As you say, they would simply instruct the broker to split
> > the
> > > changelog topic's partitions, then backfill. Once the backfill is
> ready,
> > > they can create a new crop of StandbyTasks to bootstrap the more
> granular
> > > state stores and finally switch over to them when they are ready.
> > >
> > > But this actually seems to be an argument in favor of split+backfill,
> so
> > > maybe I missed the point.
> > >
> > > You also asked me to explain why copying the "input" topic is better
> than
> > > copying the "changelog" topic. I think they are totally independent,
> > > actually. For one thing, you can't depend on the existence of a
> > "changelog"
> > > topic in general, only within Streams, but Kafka's user base clearly
> > > exceeds Streams's user base. Plus, you actually also can't depend on
> the
> > > existence of a changelog topic within Streams, since that is an
> optional
> > > feature of *some* state store implementations. Even in the situation
> > where
> > > you do have a changelog topic in Streams, there may be use cases where
> it
> > > makes sense to expand the partitions of just the input, or just the
> > > changelog.
> > >
> > > The ask for a Core feature of split+backfill is really about supporting
> > the
> > > use case of splitting partitions in log-compacted topics, regardless of
> > > whether that topic is an "input" or a "changelog" or anything else for
> > that
> > > matter.
> > >
> > >
> > > Point 6:
> > > On the concern about the performance overhead of copying data between
> the
> > > brokers, I think it's actually a bit overestimated. Splitting a topic's
> > > partition is probably rare, certainly rarer in general than
> bootstrapping
> > > new consumers on that topic. If "bootstrapping new consumers" means
> that
> > > they have to re-shuffle the data before they consume it, then you wind
> up
> > > copying the same record multiple times:
> > >
> > > (broker: input topic) -> (initial consumer) -> (broker: repartition
> > topic)
> > > -> (real consumer)
> > >
> > > That's 3x, and it's also 3x for every new record after the split as
> well,
> > > since you don't get to stop repartitioning/reshuffling once you start.
> > >
> > > Whereas if you do a backfill in something like the procedure I
> outlined,
> > > you only copy the prefix of the partition before the split, and you
> send
> > it
> > > once to the producer and then once to the new generation partition.
> Plus,
> > > assuming we're splitting the partition for the benefit of consumers,
> > > there's no reason we can't co-locate the post-split partitions on the
> > same
> > > host as the pre-split partition, making the second copy a local
> > filesystem
> > > operation.
> > >
> > > Even if you follow these two copies up with bootstrapping a new
> consumer,
> > > it's still rare for this to occur, so you get to amortize these copies
> > over
> > > the lifetime of the topic, whereas a reshuffle just keeps making copies
> > for
> > > every new event.
> > >
> > > And finally, I really do think that regardless of any performance
> > concerns
> > > about this operation, if it preserves loose organizational coupling, it
> > is
> > > certainly worth it.
> > >
> > >
> > > In conclusion:
> > > It might actually be a good idea for us to clarify the scope of
> KIP-253.
> > If
> > > we're all agreed that it's a good algorithm for allowing in-order
> message
> > > delivery during partition expansion, then we can continue this
> discussion
> > > as a new KIP, something like "backfill with partition expansion". This
> > > would let Dong proceed with KIP-253. On the other hand, if it seems
> like
> > > this conversation may alter the design of KIP-253, then maybe we
> *should*
> > > just finish working it out.
> > >
> > > For my part, my only concern about KIP-253 is the one I raised earlier.
> > >
> > > Thanks again, all, for considering these points,
> > > -John
> > >
> > >
> > > On Tue, Mar 27, 2018 at 2:10 AM, Dong Lin <li...@gmail.com> wrote:
> > >
> > > > On Tue, Mar 27, 2018 at 12:04 AM, Dong Lin <li...@gmail.com>
> > wrote:
> > > >
> > > > > Hey Jan,
> > > > >
> > > > > Thanks for the enthusiasm in improving Kafka's design. Now that I
> > have
> > > > > read through your discussion with Jun, here are my thoughts:
> > > > >
> > > > > - The latest proposal should with log compacted topics by properly
> > > > > deleting old messages after a new message with the same key is
> > > produced.
> > > > So
> > > > > it is probably not a concern anymore. Could you comment if there is
> > > still
> > > > > issue?
> > > > >
> > > > > - I wrote the SEP-5 and I am pretty familiar with the motivation
> and
> > > the
> > > > > design of SEP-5. SEP-5 is probably orthornal to the motivation of
> > this
> > > > KIP.
> > > > > The goal of SEP-5 is to allow user to increase task number of an
> > > existing
> > > > > Samza job. But if we increase the partition number of input topics,
> > > > > messages may still be consumed out-of-order by tasks in Samza which
> > > cause
> > > > > incorrect result. Similarly, the approach you proposed does not
> seem
> > to
> > > > > ensure that the messages can be delivered in order, even if we can
> > make
> > > > > sure that each consumer instance is assigned the set of new
> > partitions
> > > > > covering the same set of keys.
> > > > >
> > > >
> > > > Let me correct this comment. The approach of copying data to a new
> > topic
> > > > can ensure in-order message delivery suppose we properly migrate
> > offsets
> > > > from old topic to new topic.
> > > >
> > > >
> > > > > - I am trying to understand why it is better to copy the data
> instead
> > > of
> > > > > copying the change log topic for streaming use-case. For core Kafka
> > > > > use-case, and for the stream use-case that does not need to
> increase
> > > > > consumers, the current KIP already supports in-order delivery
> without
> > > the
> > > > > overhead of copying the data. For stream use-case that needs to
> > > increase
> > > > > consumer number, the existing consumer can backfill the existing
> data
> > > in
> > > > > the change log topic to the same change log topic with the new
> > > partition
> > > > > number, before the new set of consumers bootstrap state from the
> new
> > > > > partitions of the change log topic. If this solution works, then
> > could
> > > > you
> > > > > summarize the advantage of copying the data of input topic as
> > compared
> > > to
> > > > > copying the change log topic? For example, does it enable more
> > > use-case,
> > > > > simplify the implementation of Kafka library, or reduce the
> operation
> > > > > overhead etc?
> > > > >
> > > > > Thanks,
> > > > > Dong
> > > > >
> > > > >
> > > > > On Wed, Mar 21, 2018 at 6:57 AM, Jan Filipiak <
> > > Jan.Filipiak@trivago.com>
> > > > > wrote:
> > > > >
> > > > >> Hi Jun,
> > > > >>
> > > > >> I was really seeing progress in our conversation but your latest
> > reply
> > > > is
> > > > >> just devastating.
> > > > >> I though we were getting close being on the same page now it feels
> > > like
> > > > >> we are in different libraries.
> > > > >>
> > > > >> I just quickly slam my answers in here. If they are to brief I am
> > > sorry
> > > > >> give me a ping and try to go into details more.
> > > > >> Just want to show that your pro/cons listing is broken.
> > > > >>
> > > > >> Best Jan
> > > > >>
> > > > >> and want to get rid of this horrible compromise
> > > > >>
> > > > >>
> > > > >> On 19.03.2018 05:48, Jun Rao wrote:
> > > > >>
> > > > >>> Hi, Jan,
> > > > >>>
> > > > >>> Thanks for the discussion. Great points.
> > > > >>>
> > > > >>> Let me try to summarize the approach that you are proposing. On
> the
> > > > >>> broker
> > > > >>> side, we reshuffle the existing data in a topic from current
> > > partitions
> > > > >>> to
> > > > >>> the new partitions. Once the reshuffle fully catches up, switch
> the
> > > > >>> consumers to start consuming from the new partitions. If a
> consumer
> > > > needs
> > > > >>> to rebuild its local state (due to partition changes), let the
> > > consumer
> > > > >>> rebuild its state by reading all existing data from the new
> > > partitions.
> > > > >>> Once all consumers have switches over, cut over the producer to
> the
> > > new
> > > > >>> partitions.
> > > > >>>
> > > > >>> The pros for this approach are that :
> > > > >>> 1. There is just one way to rebuild the local state, which is
> > > simpler.
> > > > >>>
> > > > >> true thanks
> > > > >>
> > > > >>>
> > > > >>> The cons for this approach are:
> > > > >>> 1. Need to copy existing data.
> > > > >>>
> > > > >> Very unfair and not correct. It does not require you to copy over
> > > > >> existing data. It _allows_ you to copy all existing data.
> > > > >>
> > > > >> 2. The cutover of the producer is a bit complicated since it needs
> > to
> > > > >>> coordinate with all consumer groups.
> > > > >>>
> > > > >> Also not true. I explicitly tried to make clear that there is only
> > one
> > > > >> special consumer (in the case of actually copying data)
> coordination
> > > is
> > > > >> required.
> > > > >>
> > > > >>> 3. The rebuilding of the state in the consumer is from the input
> > > topic,
> > > > >>> which can be more expensive than rebuilding from the existing
> > state.
> > > > >>>
> > > > >> true, but rebuilding state is only required if you want to
> increase
> > > > >> processing power, so we assume this is at hand.
> > > > >>
> > > > >>> 4. The broker potentially has to know the partitioning function.
> If
> > > > this
> > > > >>> needs to be customized at the topic level, it can be a bit messy.
> > > > >>>
> > > > >> I would argue against having the operation being performed by the
> > > > broker.
> > > > >> This was not discussed yet but if you see my original email i
> > > suggested
> > > > >> otherwise from the beginning.
> > > > >>
> > > > >>>
> > > > >>> Here is an alternative approach by applying your idea not in the
> > > > broker,
> > > > >>> but in the consumer. When new partitions are added, we don't move
> > > > >>> existing
> > > > >>> data. In KStreams, we first reshuffle the new input data to a new
> > > topic
> > > > >>> T1
> > > > >>> with the old number of partitions and feed T1's data to the rest
> of
> > > the
> > > > >>> pipeline. In the meantime, KStreams reshuffles all existing data
> of
> > > the
> > > > >>> change capture topic to another topic C1 with the new number of
> > > > >>> partitions.
> > > > >>> We can then build the state of the new tasks from C1. Once the
> new
> > > > states
> > > > >>> have been fully built, we can cut over the consumption to the
> input
> > > > topic
> > > > >>> and delete T1. This approach works with compacted topic too. If
> an
> > > > >>> application reads from the beginning of a compacted topic, the
> > > consumer
> > > > >>> will reshuffle the portion of the input when the number of
> > partitions
> > > > >>> doesn't match the number of tasks.
> > > > >>>
> > > > >> We all wipe this idea from our heads instantly. Mixing Ideas from
> an
> > > > >> argument is not a resolution strategy
> > > > >> just leads to horrible horrible software.
> > > > >>
> > > > >>
> > > > >>> The pros of this approach are:
> > > > >>> 1. No need to copy existing data.
> > > > >>> 2. Each consumer group can cut over to the new partitions
> > > > independently.
> > > > >>> 3. The state is rebuilt from the change capture topic, which is
> > > cheaper
> > > > >>> than rebuilding from the input topic.
> > > > >>> 4. Only the KStreams job needs to know the partitioning function.
> > > > >>>
> > > > >>> The cons of this approach are:
> > > > >>> 1. Potentially the same input topic needs to be reshuffled more
> > than
> > > > once
> > > > >>> in different consumer groups during the transition phase.
> > > > >>>
> > > > >>> What do you think?
> > > > >>>
> > > > >>> Thanks,
> > > > >>>
> > > > >>> Jun
> > > > >>>
> > > > >>>
> > > > >>>
> > > > >>> On Thu, Mar 15, 2018 at 1:04 AM, Jan Filipiak <
> > > > Jan.Filipiak@trivago.com>
> > > > >>> wrote:
> > > > >>>
> > > > >>> Hi Jun,
> > > > >>>>
> > > > >>>> thank you for following me on these thoughts. It was important
> to
> > me
> > > > to
> > > > >>>> feel that kind of understanding for my arguments.
> > > > >>>>
> > > > >>>> What I was hoping for (I mentioned this earlier) is that we can
> > > model
> > > > >>>> the
> > > > >>>> case where we do not want to copy the data the exact same way as
> > the
> > > > >>>> case
> > > > >>>> when we do copy the data. Maybe you can peek into the mails
> before
> > > to
> > > > >>>> see
> > > > >>>> more details for this.
> > > > >>>>
> > > > >>>> This means we have the same mechanism to transfer consumer
> groups
> > to
> > > > >>>> switch topic. The offset mapping that would be generated would
> > even
> > > be
> > > > >>>> simpler End Offset of the Old topic => offset 0 off all the
> > > partitions
> > > > >>>> of
> > > > >>>> the new topic. Then we could model the transition of a non-copy
> > > > >>>> expansion
> > > > >>>> the exact same way as a copy-expansion.
> > > > >>>>
> > > > >>>> I know this only works when topic growth by a factor. But the
> > > benefits
> > > > >>>> of
> > > > >>>> only growing by a factor are to strong anyways. See Clemens's
> hint
> > > and
> > > > >>>> remember that state reshuffling is entirely not needed if one
> > > doesn't
> > > > >>>> want
> > > > >>>> to grow processing power.
> > > > >>>>
> > > > >>>> I think these benefits should be clear, and that there is
> > basically
> > > no
> > > > >>>> downside to what is currently at hand but just makes everything
> > > easy.
> > > > >>>>
> > > > >>>> One thing you need to know is. that if you do not offer
> > rebuilding a
> > > > log
> > > > >>>> compacted topic like i suggest that even if you have consumer
> > state
> > > > >>>> reshuffling. The topic is broken and can not be used to
> bootstrap
> > > new
> > > > >>>> consumers. They don't know if they need to apply a key from and
> > old
> > > > >>>> partition or not. This is a horrible downside I haven't seen a
> > > > solution
> > > > >>>> for
> > > > >>>> in the email conversation.
> > > > >>>>
> > > > >>>> I argue to:
> > > > >>>>
> > > > >>>> Only grow topic by a factor always.
> > > > >>>> Have the "no copy consumer" transition as the trivial case of
> the
> > > > "copy
> > > > >>>> consumer transition".
> > > > >>>> If processors needs to be scaled, let them rebuild from the new
> > > topic
> > > > >>>> and
> > > > >>>> leave the old running in the mean time.
> > > > >>>> Do not implement key shuffling in streams.
> > > > >>>>
> > > > >>>> I hope I can convince you especially with the fact how I want to
> > > > handle
> > > > >>>> consumer transition. I think
> > > > >>>> you didn't quite understood me there before. I think the term
> "new
> > > > >>>> topic"
> > > > >>>> intimidated you a little.
> > > > >>>> How we solve this on disc doesn't really matter, If the data
> goes
> > > into
> > > > >>>> the
> > > > >>>> same Dir or a different Dir or anything. I do think that it
> needs
> > to
> > > > >>>> involve at least rolling a new segment for the existing
> > partitions.
> > > > >>>> But most of the transitions should work without restarting
> > > consumers.
> > > > >>>> (newer consumers with support for this). But with new topic i
> just
> > > > meant
> > > > >>>> the topic that now has a different partition count. Plenty of
> ways
> > > to
> > > > >>>> handle that (versions, aliases)
> > > > >>>>
> > > > >>>> Hope I can further get my idea across.
> > > > >>>>
> > > > >>>> Best Jan
> > > > >>>>
> > > > >>>>
> > > > >>>>
> > > > >>>>
> > > > >>>>
> > > > >>>>
> > > > >>>> On 14.03.2018 02:45, Jun Rao wrote:
> > > > >>>>
> > > > >>>> Hi, Jan,
> > > > >>>>>
> > > > >>>>> Thanks for sharing your view.
> > > > >>>>>
> > > > >>>>> I agree with you that recopying the data potentially makes the
> > > state
> > > > >>>>> management easier since the consumer can just rebuild its state
> > > from
> > > > >>>>> scratch (i.e., no need for state reshuffling).
> > > > >>>>>
> > > > >>>>> On the flip slide, I saw a few disadvantages of the approach
> that
> > > you
> > > > >>>>> suggested. (1) Building the state from the input topic from
> > scratch
> > > > is
> > > > >>>>> in
> > > > >>>>> general less efficient than state reshuffling. Let's say one
> > > > computes a
> > > > >>>>> count per key from an input topic. The former requires reading
> > all
> > > > >>>>> existing
> > > > >>>>> records in the input topic whereas the latter only requires
> > reading
> > > > >>>>> data
> > > > >>>>> proportional to the number of unique keys. (2) The switching of
> > the
> > > > >>>>> topic
> > > > >>>>> needs modification to the application. If there are many
> > > applications
> > > > >>>>> on a
> > > > >>>>> topic, coordinating such an effort may not be easy. Also, it's
> > not
> > > > >>>>> clear
> > > > >>>>> how to enforce exactly-once semantic during the switch. (3) If
> a
> > > > topic
> > > > >>>>> doesn't need any state management, recopying the data seems
> > > wasteful.
> > > > >>>>> In
> > > > >>>>> that case, in place partition expansion seems more desirable.
> > > > >>>>>
> > > > >>>>> I understand your concern about adding complexity in KStreams.
> > But,
> > > > >>>>> perhaps
> > > > >>>>> we could iterate on that a bit more to see if it can be
> > simplified.
> > > > >>>>>
> > > > >>>>> Jun
> > > > >>>>>
> > > > >>>>>
> > > > >>>>> On Mon, Mar 12, 2018 at 11:21 PM, Jan Filipiak <
> > > > >>>>> Jan.Filipiak@trivago.com>
> > > > >>>>> wrote:
> > > > >>>>>
> > > > >>>>> Hi Jun,
> > > > >>>>>
> > > > >>>>>> I will focus on point 61 as I think its _the_ fundamental part
> > > that
> > > > I
> > > > >>>>>> cant
> > > > >>>>>> get across at the moment.
> > > > >>>>>>
> > > > >>>>>> Kafka is the platform to have state materialized multiple
> times
> > > from
> > > > >>>>>> one
> > > > >>>>>> input. I emphasize this: It is the building block in
> > architectures
> > > > >>>>>> that
> > > > >>>>>> allow you to
> > > > >>>>>> have your state maintained multiple times. You put a message
> in
> > > > once,
> > > > >>>>>> and
> > > > >>>>>> you have it pop out as often as you like. I believe you
> > understand
> > > > >>>>>> this.
> > > > >>>>>>
> > > > >>>>>> Now! The path of thinking goes the following: I am using
> apache
> > > > kafka
> > > > >>>>>> and
> > > > >>>>>> I _want_ my state multiple times. What am I going todo?
> > > > >>>>>>
> > > > >>>>>> A) Am I going to take my state that I build up, plunge some
> sort
> > > of
> > > > >>>>>> RPC
> > > > >>>>>> layer ontop of it, use that RPC layer to throw my records
> across
> > > > >>>>>> instances?
> > > > >>>>>> B) Am I just going to read the damn message twice?
> > > > >>>>>>
> > > > >>>>>> Approach A is fundamentally flawed and a violation of all that
> > is
> > > > good
> > > > >>>>>> and
> > > > >>>>>> holy in kafka deployments. I can not understand how this Idea
> > can
> > > > >>>>>> come in
> > > > >>>>>> the first place.
> > > > >>>>>> (I do understand: IQ in streams, they polluted the kafka
> streams
> > > > >>>>>> codebase
> > > > >>>>>> really bad already. It is not funny! I think they are equally
> > > flawed
> > > > >>>>>> as
> > > > >>>>>> A)
> > > > >>>>>>
> > > > >>>>>> I say, we do what Kafka is good at. We repartition the topic
> > once.
> > > > We
> > > > >>>>>> switch the consumers.
> > > > >>>>>> (Those that need more partitions are going to rebuild their
> > state
> > > in
> > > > >>>>>> multiple partitions by reading the new topic, those that don't
> > > just
> > > > >>>>>> assign
> > > > >>>>>> the new partitions properly)
> > > > >>>>>> We switch producers. Done!
> > > > >>>>>>
> > > > >>>>>> The best thing! It is trivial, hipster stream processor will
> > have
> > > an
> > > > >>>>>> easy
> > > > >>>>>> time with that aswell. Its so super simple. And simple IS
> good!
> > > > >>>>>> It is what kafka was build todo. It is how we do it today.
> All I
> > > am
> > > > >>>>>> saying
> > > > >>>>>> is that a little broker help doing the producer swap is super
> > > > useful.
> > > > >>>>>>
> > > > >>>>>> For everyone interested in why kafka is so powerful with
> > approach
> > > B,
> > > > >>>>>> please watch https://youtu.be/bEbeZPVo98c?t=1633
> > > > >>>>>> I already looked up a good point in time, I think after 5
> > minutes
> > > > the
> > > > >>>>>> "state" topic is handled and you should be able to understand
> me
> > > > >>>>>> and inch better.
> > > > >>>>>>
> > > > >>>>>> Please do not do A to the project, it deserves better!
> > > > >>>>>>
> > > > >>>>>> Best Jan
> > > > >>>>>>
> > > > >>>>>>
> > > > >>>>>>
> > > > >>>>>> On 13.03.2018 02:40, Jun Rao wrote:
> > > > >>>>>>
> > > > >>>>>> Hi, Jan,
> > > > >>>>>>
> > > > >>>>>>> Thanks for the reply. A few more comments below.
> > > > >>>>>>>
> > > > >>>>>>> 50. Ok, we can think a bit harder for supporting compacted
> > > topics.
> > > > >>>>>>>
> > > > >>>>>>> 51. This is a fundamental design question. In the more common
> > > case,
> > > > >>>>>>> the
> > > > >>>>>>> reason why someone wants to increase the number of partitions
> > is
> > > > that
> > > > >>>>>>> the
> > > > >>>>>>> consumer application is slow and one wants to run more
> consumer
> > > > >>>>>>> instances
> > > > >>>>>>> to increase the degree of parallelism. So, fixing the number
> of
> > > > >>>>>>> running
> > > > >>>>>>> consumer instances when expanding the partitions won't help
> > this
> > > > >>>>>>> case.
> > > > >>>>>>> If
> > > > >>>>>>> we do need to increase the number of consumer instances, we
> > need
> > > to
> > > > >>>>>>> somehow
> > > > >>>>>>> reshuffle the state of the consumer across instances. What we
> > > have
> > > > >>>>>>> been
> > > > >>>>>>> discussing in this KIP is whether we can do this more
> > effectively
> > > > >>>>>>> through
> > > > >>>>>>> the KStream library (e.g. through a 2-phase partition
> > expansion).
> > > > >>>>>>> This
> > > > >>>>>>> will
> > > > >>>>>>> add some complexity, but it's probably better than everyone
> > doing
> > > > >>>>>>> this
> > > > >>>>>>> in
> > > > >>>>>>> the application space. The recopying approach that you
> > mentioned
> > > > >>>>>>> doesn't
> > > > >>>>>>> seem to address the consumer state management issue when the
> > > > consumer
> > > > >>>>>>> switches from an old to a new topic.
> > > > >>>>>>>
> > > > >>>>>>> 52. As for your example, it depends on whether the join key
> is
> > > the
> > > > >>>>>>> same
> > > > >>>>>>> between (A,B) and (B,C). If the join key is the same, we can
> > do a
> > > > >>>>>>> 2-phase
> > > > >>>>>>> partition expansion of A, B, and C together. If the join keys
> > are
> > > > >>>>>>> different, one would need to repartition the data on a
> > different
> > > > key
> > > > >>>>>>> for
> > > > >>>>>>> the second join, then the partition expansion can be done
> > > > >>>>>>> independently
> > > > >>>>>>> between (A,B) and (B,C).
> > > > >>>>>>>
> > > > >>>>>>> 53. If you always fix the number of consumer instances, we
> you
> > > > >>>>>>> described
> > > > >>>>>>> works. However, as I mentioned in #51, I am not sure how your
> > > > >>>>>>> proposal
> > > > >>>>>>> deals with consumer states when the number of consumer
> > instances
> > > > >>>>>>> grows.
> > > > >>>>>>> Also, it just seems that it's better to avoid re-copying the
> > > > existing
> > > > >>>>>>> data.
> > > > >>>>>>>
> > > > >>>>>>> 60. "just want to throw in my question from the longer email
> in
> > > the
> > > > >>>>>>> other
> > > > >>>>>>> Thread here. How will the bloom filter help a new consumer to
> > > > decide
> > > > >>>>>>> to
> > > > >>>>>>> apply the key or not?" Not sure that I fully understood your
> > > > >>>>>>> question.
> > > > >>>>>>> The
> > > > >>>>>>> consumer just reads whatever key is in the log. The bloom
> > filter
> > > > just
> > > > >>>>>>> helps
> > > > >>>>>>> clean up the old keys.
> > > > >>>>>>>
> > > > >>>>>>> 61. "Why can we afford having a topic where its apparently
> not
> > > > >>>>>>> possible
> > > > >>>>>>> to
> > > > >>>>>>> start a new application on? I think this is an overall flaw
> of
> > > the
> > > > >>>>>>> discussed idea here. Not playing attention to the overall
> > > > >>>>>>> architecture."
> > > > >>>>>>> Could you explain a bit more when one can't start a new
> > > > application?
> > > > >>>>>>>
> > > > >>>>>>> Jun
> > > > >>>>>>>
> > > > >>>>>>>
> > > > >>>>>>>
> > > > >>>>>>> On Sat, Mar 10, 2018 at 1:40 AM, Jan Filipiak <
> > > > >>>>>>> Jan.Filipiak@trivago.com
> > > > >>>>>>> wrote:
> > > > >>>>>>>
> > > > >>>>>>> Hi Jun, thanks for your mail.
> > > > >>>>>>>
> > > > >>>>>>> Thank you for your questions!
> > > > >>>>>>>> I think they are really good and tackle the core of the
> > problem
> > > I
> > > > >>>>>>>> see.
> > > > >>>>>>>>
> > > > >>>>>>>> I will answer inline, mostly but still want to set the tone
> > > here.
> > > > >>>>>>>>
> > > > >>>>>>>> The core strength of kafka is what Martin once called the
> > > > >>>>>>>> kappa-Architecture. How does this work?
> > > > >>>>>>>> You have everything as a log as in kafka. When you need to
> > > change
> > > > >>>>>>>> something.
> > > > >>>>>>>> You create the new version of your application and leave it
> > > > running
> > > > >>>>>>>> in
> > > > >>>>>>>> parallel.
> > > > >>>>>>>> Once the new version is good you switch your users to use
> the
> > > new
> > > > >>>>>>>> application.
> > > > >>>>>>>>
> > > > >>>>>>>> The online reshuffling effectively breaks this architecture
> > and
> > > I
> > > > >>>>>>>> think
> > > > >>>>>>>> the switch in thinking here is more harmful
> > > > >>>>>>>> than any details about the partitioning function to allow
> > such a
> > > > >>>>>>>> change.
> > > > >>>>>>>> I
> > > > >>>>>>>> feel with my suggestion we are the closest to
> > > > >>>>>>>> the original and battle proven architecture and I can only
> > warn
> > > to
> > > > >>>>>>>> move
> > > > >>>>>>>> away from it.
> > > > >>>>>>>>
> > > > >>>>>>>> I might have forgotten something, sometimes its hard for me
> to
> > > > >>>>>>>> getting
> > > > >>>>>>>> all
> > > > >>>>>>>> the thoughts captured in a mail, but I hope the comments
> > inline
> > > > will
> > > > >>>>>>>> further make my concern clear, and put some emphasis on why
> I
> > > > >>>>>>>> prefer my
> > > > >>>>>>>> solution ;)
> > > > >>>>>>>>
> > > > >>>>>>>> One thing we should all be aware of when discussing this,
> and
> > I
> > > > >>>>>>>> think
> > > > >>>>>>>> Dong
> > > > >>>>>>>> should have mentioned it (maybe he did).
> > > > >>>>>>>> We are not discussing all of this out of thin air but there
> is
> > > an
> > > > >>>>>>>> effort
> > > > >>>>>>>> in the Samza project.
> > > > >>>>>>>>
> > > > >>>>>>>> https://cwiki.apache.org/confluence/display/SAMZA/SEP-5%3A+
> > > > >>>>>>>> Enable+partition+expansion+of+input+streams
> > > > >>>>>>>> https://issues.apache.org/jira/browse/SAMZA-1293
> > > > >>>>>>>>
> > > > >>>>>>>> To be clear. I think SEP-5 (state of last week, dont know if
> > it
> > > > >>>>>>>> adapted
> > > > >>>>>>>> to
> > > > >>>>>>>> this discussion) is on a way better path than KIP-253, and I
> > > can't
> > > > >>>>>>>> really
> > > > >>>>>>>> explain why.
> > > > >>>>>>>>
> > > > >>>>>>>> Best Jan,
> > > > >>>>>>>>
> > > > >>>>>>>> nice weekend everyone
> > > > >>>>>>>>
> > > > >>>>>>>>
> > > > >>>>>>>> On 09.03.2018 03:36, Jun Rao wrote:
> > > > >>>>>>>>
> > > > >>>>>>>> Hi, Jan,
> > > > >>>>>>>>
> > > > >>>>>>>> Thanks for the feedback. Just some comments on the earlier
> > > points
> > > > >>>>>>>>> that
> > > > >>>>>>>>> you
> > > > >>>>>>>>> mentioned.
> > > > >>>>>>>>>
> > > > >>>>>>>>> 50. You brought up the question of whether existing data
> > needs
> > > to
> > > > >>>>>>>>> be
> > > > >>>>>>>>> copied
> > > > >>>>>>>>> during partition expansion. My understand of your view is
> > that
> > > > >>>>>>>>> avoid
> > > > >>>>>>>>> copying existing data will be more efficient, but it
> doesn't
> > > work
> > > > >>>>>>>>> well
> > > > >>>>>>>>> with
> > > > >>>>>>>>> compacted topics since some keys in the original partitions
> > > will
> > > > >>>>>>>>> never
> > > > >>>>>>>>> be
> > > > >>>>>>>>> cleaned. It would be useful to understand your use case of
> > > > >>>>>>>>> compacted
> > > > >>>>>>>>> topics
> > > > >>>>>>>>> a bit more. In the common use case, the data volume in a
> > > > compacted
> > > > >>>>>>>>> topic
> > > > >>>>>>>>> may not be large. So, I am not sure if there is a strong
> need
> > > to
> > > > >>>>>>>>> expand
> > > > >>>>>>>>> partitions in a compacted topic, at least initially.
> > > > >>>>>>>>>
> > > > >>>>>>>>> I do agree. State is usually smaller. Update rates might be
> > > also
> > > > >>>>>>>>>
> > > > >>>>>>>>> competitively high.
> > > > >>>>>>>> Doing Log-compaction (even beeing very efficient and
> > > configurable)
> > > > >>>>>>>> is
> > > > >>>>>>>> also
> > > > >>>>>>>> a more expensive operation than
> > > > >>>>>>>> just discarding old segments. Further if you want to use
> more
> > > > >>>>>>>> consumers
> > > > >>>>>>>> processing the events
> > > > >>>>>>>> you also have to grow the number of partitions. Especially
> for
> > > > >>>>>>>> use-cases
> > > > >>>>>>>> we do (KIP-213) a tiny state full
> > > > >>>>>>>> table might be very expensive to process if it joins
> against a
> > > > huge
> > > > >>>>>>>> table.
> > > > >>>>>>>>
> > > > >>>>>>>> I can just say we have been in the spot of needing to grow
> log
> > > > >>>>>>>> compacted
> > > > >>>>>>>> topics. Mainly for processing power we can bring to the
> table.
> > > > >>>>>>>>
> > > > >>>>>>>> Further i am not at all concerned about the extra spaced
> used
> > by
> > > > >>>>>>>> "garbage
> > > > >>>>>>>> keys". I am more concerned about the correctness of innocent
> > > > >>>>>>>> consumers.
> > > > >>>>>>>> The
> > > > >>>>>>>> logic becomes complicated. Say for streams one would need to
> > > load
> > > > >>>>>>>> the
> > > > >>>>>>>> record into state but not forward it the topology ( to have
> it
> > > > >>>>>>>> available
> > > > >>>>>>>> for shuffeling). I rather have it simple and a topic clean
> > > > >>>>>>>> regardless
> > > > >>>>>>>> if
> > > > >>>>>>>> it
> > > > >>>>>>>> still has its old partition count. Especially with multiple
> > > > >>>>>>>> partitions
> > > > >>>>>>>> growth's I think it becomes insanely hard to to this shuffle
> > > > >>>>>>>> correct.
> > > > >>>>>>>> Maybe
> > > > >>>>>>>> Streams and Samza can do it. Especially if you do "hipster
> > > stream
> > > > >>>>>>>> processing" <https://www.confluent.io/blog
> > > > >>>>>>>> /introducing-kafka-streams-
> > > > >>>>>>>> stream-processing-made-simple/>. This makes kafka way to
> > > > >>>>>>>> complicated.
> > > > >>>>>>>> With my approach I think its way simpler because the topic
> has
> > > no
> > > > >>>>>>>> "history"
> > > > >>>>>>>> in terms of partitioning but is always clean.
> > > > >>>>>>>>
> > > > >>>>>>>>
> > > > >>>>>>>> 51. "Growing the topic by an integer factor does not require
> > any
> > > > >>>>>>>> state
> > > > >>>>>>>>
> > > > >>>>>>>> redistribution at all." Could you clarify this a bit more?
> > Let's
> > > > say
> > > > >>>>>>>>> you
> > > > >>>>>>>>> have a consumer app that computes the windowed count per
> key.
> > > If
> > > > >>>>>>>>> you
> > > > >>>>>>>>> double
> > > > >>>>>>>>> the number of partitions from 1 to 2 and grow the consumer
> > > > >>>>>>>>> instances
> > > > >>>>>>>>> from
> > > > >>>>>>>>> 1
> > > > >>>>>>>>> to 2, we would need to redistribute some of the counts to
> the
> > > new
> > > > >>>>>>>>> consumer
> > > > >>>>>>>>> instance. Regarding to linear hashing, it's true that it
> > won't
> > > > >>>>>>>>> solve
> > > > >>>>>>>>> the
> > > > >>>>>>>>> problem with compacted topics. The main benefit is that it
> > > > >>>>>>>>> redistributes
> > > > >>>>>>>>> the keys in one partition to no more than two partitions,
> > which
> > > > >>>>>>>>> could
> > > > >>>>>>>>> help
> > > > >>>>>>>>> redistribute the state.
> > > > >>>>>>>>>
> > > > >>>>>>>>> You don't need to spin up a new consumer in this case.
> every
> > > > >>>>>>>>> consumer
> > > > >>>>>>>>>
> > > > >>>>>>>>> would just read every partition with the (partition %
> > num_task)
> > > > >>>>>>>> task.
> > > > >>>>>>>> it
> > > > >>>>>>>> will still have the previous data right there and can go on.
> > > > >>>>>>>>
> > > > >>>>>>>> This sounds contradictory to what I said before, but please
> > bear
> > > > >>>>>>>> with
> > > > >>>>>>>> me.
> > > > >>>>>>>>
> > > > >>>>>>>> 52. Good point on coordinating the expansion of 2 topics
> that
> > > need
> > > > >>>>>>>> to
> > > > >>>>>>>> be
> > > > >>>>>>>>
> > > > >>>>>>>> joined together. This is where the 2-phase partition
> expansion
> > > > could
> > > > >>>>>>>>> potentially help. In the first phase, we could add new
> > > partitions
> > > > >>>>>>>>> to
> > > > >>>>>>>>> the 2
> > > > >>>>>>>>> topics one at a time but without publishing to the new
> > > patitions.
> > > > >>>>>>>>> Then,
> > > > >>>>>>>>> we
> > > > >>>>>>>>> can add new consumer instances to pick up the new
> partitions.
> > > In
> > > > >>>>>>>>> this
> > > > >>>>>>>>> transition phase, no reshuffling is needed since no data is
> > > > coming
> > > > >>>>>>>>> from
> > > > >>>>>>>>> the
> > > > >>>>>>>>> new partitions. Finally, we can enable the publishing to
> the
> > > new
> > > > >>>>>>>>> partitions.
> > > > >>>>>>>>>
> > > > >>>>>>>>> I think its even worse than you think. I would like to
> > > introduce
> > > > >>>>>>>>> the
> > > > >>>>>>>>>
> > > > >>>>>>>>> Term
> > > > >>>>>>>> transitive copartitioning. Imagine
> > > > >>>>>>>> 2 streams application. One joins (A,B) the other (B,C) then
> > > there
> > > > >>>>>>>> is a
> > > > >>>>>>>> transitive copartition requirement for
> > > > >>>>>>>> (A,C) to be copartitioned aswell. This can spread
> > significantly
> > > > and
> > > > >>>>>>>> require many consumers to adapt at the same time.
> > > > >>>>>>>>
> > > > >>>>>>>> It is also not entirely clear to me how you not need
> > reshuffling
> > > > in
> > > > >>>>>>>> this
> > > > >>>>>>>> case. If A has a record that never gets updated after the
> > > > expansion
> > > > >>>>>>>> and
> > > > >>>>>>>> the
> > > > >>>>>>>> coresponding B record moves to a new partition. How shall
> they
> > > > meet
> > > > >>>>>>>> w/o
> > > > >>>>>>>> shuffle?
> > > > >>>>>>>>
> > > > >>>>>>>> 53. "Migrating consumer is a step that might be made
> completly
> > > > >>>>>>>>
> > > > >>>>>>>> unnecessary
> > > > >>>>>>>>> if - for example streams - takes the gcd as partitioning
> > scheme
> > > > >>>>>>>>> instead
> > > > >>>>>>>>> of
> > > > >>>>>>>>> enforcing 1 to 1." Not sure that I fully understand this. I
> > > think
> > > > >>>>>>>>> you
> > > > >>>>>>>>> mean
> > > > >>>>>>>>> that a consumer application can run more instances than the
> > > > number
> > > > >>>>>>>>> of
> > > > >>>>>>>>> partitions. In that case, the consumer can just
> > repartitioning
> > > > the
> > > > >>>>>>>>> input
> > > > >>>>>>>>> data according to the number of instances. This is
> possible,
> > > but
> > > > >>>>>>>>> just
> > > > >>>>>>>>> has
> > > > >>>>>>>>> the overhead of reshuffling the data.
> > > > >>>>>>>>>
> > > > >>>>>>>>> No what I meant is ( that is also your question i think
> > > Mathias)
> > > > >>>>>>>>> that
> > > > >>>>>>>>> if
> > > > >>>>>>>>>
> > > > >>>>>>>>> you grow a topic by a factor.
> > > > >>>>>>>> Even if your processor is statefull you can can just assign
> > all
> > > > the
> > > > >>>>>>>> multiples of the previous partition to
> > > > >>>>>>>> this consumer and the state to keep processing correctly
> will
> > be
> > > > >>>>>>>> present
> > > > >>>>>>>> w/o any shuffling.
> > > > >>>>>>>>
> > > > >>>>>>>> Say you have an assignment
> > > > >>>>>>>> Statefull consumer => partition
> > > > >>>>>>>> 0 => 0
> > > > >>>>>>>> 1 => 1
> > > > >>>>>>>> 2 => 2
> > > > >>>>>>>>
> > > > >>>>>>>> and you grow you topic by 4 you get,
> > > > >>>>>>>>
> > > > >>>>>>>> 0 => 0,3,6,9
> > > > >>>>>>>> 1 => 1,4,7,10
> > > > >>>>>>>> 2 => 2,5,8,11
> > > > >>>>>>>>
> > > > >>>>>>>> Say your hashcode is 8. 8%3 => 2  before so consumer for
> > > > partition 2
> > > > >>>>>>>> has
> > > > >>>>>>>> it.
> > > > >>>>>>>> Now you you have 12 partitions so 8%12 => 8, so it goes into
> > > > >>>>>>>> partition
> > > > >>>>>>>> 8
> > > > >>>>>>>> which is assigned to the same consumer
> > > > >>>>>>>> who had 2 before and therefore knows the key.
> > > > >>>>>>>>
> > > > >>>>>>>> Userland reshuffeling is there as an options. And it does
> > > exactly
> > > > >>>>>>>> what
> > > > >>>>>>>> I
> > > > >>>>>>>> suggest. And I think its the perfect strategie. All I am
> > > > suggestion
> > > > >>>>>>>> is
> > > > >>>>>>>> broker side support to switch the producers to the newly
> > > > partitioned
> > > > >>>>>>>> topic.
> > > > >>>>>>>> Then the old (to few partition topic) can go away.  Remember
> > the
> > > > >>>>>>>> list
> > > > >>>>>>>> of
> > > > >>>>>>>> steps in the beginning of this thread. If one has broker
> > support
> > > > for
> > > > >>>>>>>> all
> > > > >>>>>>>> where its required and streams support for those that aren’t
> > > > >>>>>>>> necessarily.
> > > > >>>>>>>> Then one has solved the problem.
> > > > >>>>>>>> I repeat it because I think its important. I am really happy
> > > that
> > > > >>>>>>>> you
> > > > >>>>>>>> brought that up! because its 100% what I want just with the
> > > > >>>>>>>> differences
> > > > >>>>>>>> to
> > > > >>>>>>>> have an option to discard the to small topic later (after
> all
> > > > >>>>>>>> consumers
> > > > >>>>>>>> adapted). And to have order correct there. I need broker
> > support
> > > > >>>>>>>> managing
> > > > >>>>>>>> the copy process + the produces and fence them against each
> > > > other. I
> > > > >>>>>>>> also
> > > > >>>>>>>> repeat. the copy process can run for weeks in the worst
> case.
> > > > >>>>>>>> Copying
> > > > >>>>>>>> the
> > > > >>>>>>>> data is not the longest task migrating consumers might very
> > well
> > > > be.
> > > > >>>>>>>> Once all consumers switched and copying is really up to date
> > > > (think
> > > > >>>>>>>> ISR
> > > > >>>>>>>> like up to date) only then we stop the producer, wait for
> the
> > > copy
> > > > >>>>>>>> to
> > > > >>>>>>>> finish and use the new topic for producing.
> > > > >>>>>>>>
> > > > >>>>>>>> After this the topic is perfect in shape. and no one needs
> to
> > > > worry
> > > > >>>>>>>> about
> > > > >>>>>>>> complicated stuff. (old keys hanging around might arrive in
> > some
> > > > >>>>>>>> other
> > > > >>>>>>>> topic later.....). can only imagine how many tricky bugs
> gonna
> > > > >>>>>>>> arrive
> > > > >>>>>>>> after
> > > > >>>>>>>> someone had grown and shrunken is topic 10 times.
> > > > >>>>>>>>
> > > > >>>>>>>>
> > > > >>>>>>>>
> > > > >>>>>>>>
> > > > >>>>>>>>
> > > > >>>>>>>>
> > > > >>>>>>>> 54. "The other thing I wanted to mention is that I believe
> the
> > > > >>>>>>>> current
> > > > >>>>>>>>
> > > > >>>>>>>> suggestion (without copying data over) can be implemented in
> > > pure
> > > > >>>>>>>>> userland
> > > > >>>>>>>>> with a custom partitioner and a small feedbackloop from
> > > > >>>>>>>>> ProduceResponse
> > > > >>>>>>>>> =>
> > > > >>>>>>>>> Partitionier in coorporation with a change management
> > system."
> > > I
> > > > am
> > > > >>>>>>>>> not
> > > > >>>>>>>>> sure a customized partitioner itself solves the problem. We
> > > > >>>>>>>>> probably
> > > > >>>>>>>>> need
> > > > >>>>>>>>> some broker side support to enforce when the new partitions
> > can
> > > > be
> > > > >>>>>>>>> used.
> > > > >>>>>>>>> We
> > > > >>>>>>>>> also need some support on the consumer/kstream side to
> > preserve
> > > > the
> > > > >>>>>>>>> per
> > > > >>>>>>>>> key
> > > > >>>>>>>>> ordering and potentially migrate the processing state. This
> > is
> > > > not
> > > > >>>>>>>>> trivial
> > > > >>>>>>>>> and I am not sure if it's ideal to fully push to the
> > > application
> > > > >>>>>>>>> space.
> > > > >>>>>>>>>
> > > > >>>>>>>>> Broker support is defenitly the preferred way here. I have
> > > > nothing
> > > > >>>>>>>>>
> > > > >>>>>>>>> against
> > > > >>>>>>>> broker support.
> > > > >>>>>>>> I tried to say that for what I would preffer - copying the
> > data
> > > > >>>>>>>> over,
> > > > >>>>>>>> at
> > > > >>>>>>>> least for log compacted topics -
> > > > >>>>>>>> I would require more broker support than the KIP currently
> > > offers.
> > > > >>>>>>>>
> > > > >>>>>>>>
> > > > >>>>>>>>
> > > > >>>>>>>> Jun
> > > > >>>>>>>>
> > > > >>>>>>>> On Tue, Mar 6, 2018 at 10:33 PM, Jan Filipiak <
> > > > >>>>>>>>> Jan.Filipiak@trivago.com
> > > > >>>>>>>>> wrote:
> > > > >>>>>>>>>
> > > > >>>>>>>>> Hi Dong,
> > > > >>>>>>>>>
> > > > >>>>>>>>> are you actually reading my emails, or are you just using
> the
> > > > >>>>>>>>> thread I
> > > > >>>>>>>>>
> > > > >>>>>>>>>> started for general announcements regarding the KIP?
> > > > >>>>>>>>>>
> > > > >>>>>>>>>> I tried to argue really hard against linear hashing.
> Growing
> > > the
> > > > >>>>>>>>>> topic
> > > > >>>>>>>>>> by
> > > > >>>>>>>>>> an integer factor does not require any state
> redistribution
> > at
> > > > >>>>>>>>>> all. I
> > > > >>>>>>>>>> fail
> > > > >>>>>>>>>> to see completely where linear hashing helps on log
> > compacted
> > > > >>>>>>>>>> topics.
> > > > >>>>>>>>>>
> > > > >>>>>>>>>> If you are not willing to explain to me what I might be
> > > > >>>>>>>>>> overlooking:
> > > > >>>>>>>>>> that
> > > > >>>>>>>>>> is fine.
> > > > >>>>>>>>>> But I ask you to not reply to my emails then. Please
> > > understand
> > > > my
> > > > >>>>>>>>>> frustration with this.
> > > > >>>>>>>>>>
> > > > >>>>>>>>>> Best Jan
> > > > >>>>>>>>>>
> > > > >>>>>>>>>>
> > > > >>>>>>>>>>
> > > > >>>>>>>>>> On 06.03.2018 19:38, Dong Lin wrote:
> > > > >>>>>>>>>>
> > > > >>>>>>>>>> Hi everyone,
> > > > >>>>>>>>>>
> > > > >>>>>>>>>> Thanks for all the comments! It appears that everyone
> > prefers
> > > > >>>>>>>>>> linear
> > > > >>>>>>>>>>
> > > > >>>>>>>>>>> hashing because it reduces the amount of state that needs
> > to
> > > be
> > > > >>>>>>>>>>> moved
> > > > >>>>>>>>>>> between consumers (for stream processing). The KIP has
> been
> > > > >>>>>>>>>>> updated
> > > > >>>>>>>>>>> to
> > > > >>>>>>>>>>> use
> > > > >>>>>>>>>>> linear hashing.
> > > > >>>>>>>>>>>
> > > > >>>>>>>>>>> Regarding the migration endeavor: it seems that migrating
> > > > >>>>>>>>>>> producer
> > > > >>>>>>>>>>> library
> > > > >>>>>>>>>>> to use linear hashing should be pretty straightforward
> > > without
> > > > >>>>>>>>>>> much operational endeavor. If we don't upgrade client
> > library
> > > > to
> > > > >>>>>>>>>>> use
> > > > >>>>>>>>>>> this
> > > > >>>>>>>>>>> KIP, we can not support in-order delivery after partition
> > is
> > > > >>>>>>>>>>> changed
> > > > >>>>>>>>>>> anyway. Suppose we upgrade client library to use this
> KIP,
> > if
> > > > >>>>>>>>>>> partition
> > > > >>>>>>>>>>> number is not changed, the key -> partition mapping will
> be
> > > > >>>>>>>>>>> exactly
> > > > >>>>>>>>>>> the
> > > > >>>>>>>>>>> same as it is now because it is still determined using
> > > > >>>>>>>>>>> murmur_hash(key)
> > > > >>>>>>>>>>> %
> > > > >>>>>>>>>>> original_partition_num. In other words, this change is
> > > backward
> > > > >>>>>>>>>>> compatible.
> > > > >>>>>>>>>>>
> > > > >>>>>>>>>>> Regarding the load distribution: if we use linear
> hashing,
> > > the
> > > > >>>>>>>>>>> load
> > > > >>>>>>>>>>> may
> > > > >>>>>>>>>>> be
> > > > >>>>>>>>>>> unevenly distributed because those partitions which are
> not
> > > > split
> > > > >>>>>>>>>>> may
> > > > >>>>>>>>>>> receive twice as much traffic as other partitions that
> are
> > > > split.
> > > > >>>>>>>>>>> This
> > > > >>>>>>>>>>> issue can be mitigated by creating topic with partitions
> > that
> > > > are
> > > > >>>>>>>>>>> several
> > > > >>>>>>>>>>> times the number of consumers. And there will be no
> > imbalance
> > > > if
> > > > >>>>>>>>>>> the
> > > > >>>>>>>>>>> partition number is always doubled. So this imbalance
> seems
> > > > >>>>>>>>>>> acceptable.
> > > > >>>>>>>>>>>
> > > > >>>>>>>>>>> Regarding storing the partition strategy as per-topic
> > config:
> > > > It
> > > > >>>>>>>>>>> seems
> > > > >>>>>>>>>>> not
> > > > >>>>>>>>>>> necessary since we can still use murmur_hash as the
> default
> > > > hash
> > > > >>>>>>>>>>> function
> > > > >>>>>>>>>>> and additionally apply the linear hashing algorithm if
> the
> > > > >>>>>>>>>>> partition
> > > > >>>>>>>>>>> number
> > > > >>>>>>>>>>> has increased. Not sure if there is any use-case for
> > producer
> > > > to
> > > > >>>>>>>>>>> use a
> > > > >>>>>>>>>>> different hash function. Jason, can you check if there is
> > > some
> > > > >>>>>>>>>>> use-case
> > > > >>>>>>>>>>> that I missed for using the per-topic partition strategy?
> > > > >>>>>>>>>>>
> > > > >>>>>>>>>>> Regarding how to reduce latency (due to state store/load)
> > in
> > > > >>>>>>>>>>> stream
> > > > >>>>>>>>>>> processing consumer when partition number changes: I need
> > to
> > > > read
> > > > >>>>>>>>>>> the
> > > > >>>>>>>>>>> Kafka
> > > > >>>>>>>>>>> Stream code to understand how Kafka Stream currently
> > migrate
> > > > >>>>>>>>>>> state
> > > > >>>>>>>>>>> between
> > > > >>>>>>>>>>> consumers when the application is added/removed for a
> given
> > > > job.
> > > > >>>>>>>>>>> I
> > > > >>>>>>>>>>> will
> > > > >>>>>>>>>>> reply after I finish reading the documentation and code.
> > > > >>>>>>>>>>>
> > > > >>>>>>>>>>>
> > > > >>>>>>>>>>> Thanks,
> > > > >>>>>>>>>>> Dong
> > > > >>>>>>>>>>>
> > > > >>>>>>>>>>>
> > > > >>>>>>>>>>> On Mon, Mar 5, 2018 at 10:43 AM, Jason Gustafson <
> > > > >>>>>>>>>>> jason@confluent.io>
> > > > >>>>>>>>>>> wrote:
> > > > >>>>>>>>>>>
> > > > >>>>>>>>>>> Great discussion. I think I'm wondering whether we can
> > > continue
> > > > >>>>>>>>>>> to
> > > > >>>>>>>>>>> leave
> > > > >>>>>>>>>>>
> > > > >>>>>>>>>>> Kafka agnostic to the partitioning strategy. The
> challenge
> > is
> > > > >>>>>>>>>>>
> > > > >>>>>>>>>>> communicating
> > > > >>>>>>>>>>>> the partitioning logic from producers to consumers so
> that
> > > the
> > > > >>>>>>>>>>>> dependencies
> > > > >>>>>>>>>>>> between each epoch can be determined. For the sake of
> > > > >>>>>>>>>>>> discussion,
> > > > >>>>>>>>>>>> imagine
> > > > >>>>>>>>>>>> you did something like the following:
> > > > >>>>>>>>>>>>
> > > > >>>>>>>>>>>> 1. The name (and perhaps version) of a partitioning
> > strategy
> > > > is
> > > > >>>>>>>>>>>> stored
> > > > >>>>>>>>>>>> in
> > > > >>>>>>>>>>>> topic configuration when a topic is created.
> > > > >>>>>>>>>>>> 2. The producer looks up the partitioning strategy
> before
> > > > >>>>>>>>>>>> writing
> > > > >>>>>>>>>>>> to
> > > > >>>>>>>>>>>> a
> > > > >>>>>>>>>>>> topic and includes it in the produce request (for
> > fencing).
> > > If
> > > > >>>>>>>>>>>> it
> > > > >>>>>>>>>>>> doesn't
> > > > >>>>>>>>>>>> have an implementation for the configured strategy, it
> > > fails.
> > > > >>>>>>>>>>>> 3. The consumer also looks up the partitioning strategy
> > and
> > > > >>>>>>>>>>>> uses it
> > > > >>>>>>>>>>>> to
> > > > >>>>>>>>>>>> determine dependencies when reading a new epoch. It
> could
> > > > either
> > > > >>>>>>>>>>>> fail
> > > > >>>>>>>>>>>> or
> > > > >>>>>>>>>>>> make the most conservative dependency assumptions if it
> > > > doesn't
> > > > >>>>>>>>>>>> know
> > > > >>>>>>>>>>>> how
> > > > >>>>>>>>>>>> to
> > > > >>>>>>>>>>>> implement the partitioning strategy. For the consumer,
> the
> > > new
> > > > >>>>>>>>>>>> interface
> > > > >>>>>>>>>>>> might look something like this:
> > > > >>>>>>>>>>>>
> > > > >>>>>>>>>>>> // Return the partition dependencies following an epoch
> > bump
> > > > >>>>>>>>>>>> Map<Integer, List<Integer>> dependencies(int
> > > > >>>>>>>>>>>> numPartitionsBeforeEpochBump,
> > > > >>>>>>>>>>>> int numPartitionsAfterEpochBump)
> > > > >>>>>>>>>>>>
> > > > >>>>>>>>>>>> The unordered case then is just a particular
> > implementation
> > > > >>>>>>>>>>>> which
> > > > >>>>>>>>>>>> never
> > > > >>>>>>>>>>>> has
> > > > >>>>>>>>>>>> any epoch dependencies. To implement this, we would need
> > > some
> > > > >>>>>>>>>>>> way
> > > > >>>>>>>>>>>> for
> > > > >>>>>>>>>>>> the
> > > > >>>>>>>>>>>> consumer to find out how many partitions there were in
> > each
> > > > >>>>>>>>>>>> epoch,
> > > > >>>>>>>>>>>> but
> > > > >>>>>>>>>>>> maybe that's not too unreasonable.
> > > > >>>>>>>>>>>>
> > > > >>>>>>>>>>>> Thanks,
> > > > >>>>>>>>>>>> Jason
> > > > >>>>>>>>>>>>
> > > > >>>>>>>>>>>>
> > > > >>>>>>>>>>>> On Mon, Mar 5, 2018 at 4:51 AM, Jan Filipiak <
> > > > >>>>>>>>>>>> Jan.Filipiak@trivago.com
> > > > >>>>>>>>>>>> wrote:
> > > > >>>>>>>>>>>>
> > > > >>>>>>>>>>>> Hi Dong
> > > > >>>>>>>>>>>>
> > > > >>>>>>>>>>>> thank you very much for your questions.
> > > > >>>>>>>>>>>>
> > > > >>>>>>>>>>>> regarding the time spend copying data across:
> > > > >>>>>>>>>>>>> It is correct that copying data from a topic with one
> > > > partition
> > > > >>>>>>>>>>>>> mapping
> > > > >>>>>>>>>>>>>
> > > > >>>>>>>>>>>>> to
> > > > >>>>>>>>>>>>>
> > > > >>>>>>>>>>>>> a topic with a different partition mapping takes way
> > longer
> > > > >>>>>>>>>>>>> than
> > > > >>>>>>>>>>>>>
> > > > >>>>>>>>>>>> we
> > > > >>>>>>>>>>>> can
> > > > >>>>>>>>>>>>
> > > > >>>>>>>>>>>> stop producers. Tens of minutes is a very optimistic
> > > estimate
> > > > >>>>>>>>>>>> here.
> > > > >>>>>>>>>>>>
> > > > >>>>>>>>>>>>> Many
> > > > >>>>>>>>>>>>> people can not afford copy full steam and therefore
> will
> > > have
> > > > >>>>>>>>>>>>> some
> > > > >>>>>>>>>>>>> rate
> > > > >>>>>>>>>>>>> limiting in place, this can bump the timespan into the
> > > day's.
> > > > >>>>>>>>>>>>> The
> > > > >>>>>>>>>>>>> good
> > > > >>>>>>>>>>>>>
> > > > >>>>>>>>>>>>> part
> > > > >>>>>>>>>>>>>
> > > > >>>>>>>>>>>>> is that the vast majority of the data can be copied
> while
> > > the
> > > > >>>>>>>>>>>>>
> > > > >>>>>>>>>>>> producers
> > > > >>>>>>>>>>>>
> > > > >>>>>>>>>>>> are
> > > > >>>>>>>>>>>>
> > > > >>>>>>>>>>>>> still going. One can then, piggyback the consumers
> ontop
> > of
> > > > >>>>>>>>>>>>> this
> > > > >>>>>>>>>>>>>
> > > > >>>>>>>>>>>> timeframe,
> > > > >>>>>>>>>>>>
> > > > >>>>>>>>>>>>> by the method mentioned (provide them an mapping from
> > their
> > > > old
> > > > >>>>>>>>>>>>>
> > > > >>>>>>>>>>>> offsets
> > > > >>>>>>>>>>>>
> > > > >>>>>>>>>>>> to
> > > > >>>>>>>>>>>>
> > > > >>>>>>>>>>>>> new offsets in their repartitioned topics. In that way
> we
> > > > >>>>>>>>>>>>> separate
> > > > >>>>>>>>>>>>>
> > > > >>>>>>>>>>>> migration of consumers from migration of producers
> > > (decoupling
> > > > >>>>>>>>>>>>
> > > > >>>>>>>>>>>>> these
> > > > >>>>>>>>>>>>> is
> > > > >>>>>>>>>>>>> what kafka is strongest at). The time to actually swap
> > over
> > > > the
> > > > >>>>>>>>>>>>> producers
> > > > >>>>>>>>>>>>> should be kept minimal by ensuring that when a swap
> > attempt
> > > > is
> > > > >>>>>>>>>>>>> started
> > > > >>>>>>>>>>>>>
> > > > >>>>>>>>>>>>> the
> > > > >>>>>>>>>>>>>
> > > > >>>>>>>>>>>>> consumer copying over should be very close to the log
> end
> > > and
> > > > >>>>>>>>>>>>> is
> > > > >>>>>>>>>>>>>
> > > > >>>>>>>>>>>> expected
> > > > >>>>>>>>>>>>
> > > > >>>>>>>>>>>>> to finish within the next fetch. The operation should
> > have
> > > a
> > > > >>>>>>>>>>>>> time-out
> > > > >>>>>>>>>>>>> and
> > > > >>>>>>>>>>>>> should be "reattemtable".
> > > > >>>>>>>>>>>>>
> > > > >>>>>>>>>>>>> Importance of logcompaction:
> > > > >>>>>>>>>>>>> If a producer produces key A, to partiton 0, its
> forever
> > > > gonna
> > > > >>>>>>>>>>>>> be
> > > > >>>>>>>>>>>>> there,
> > > > >>>>>>>>>>>>> unless it gets deleted. The record might sit in there
> for
> > > > >>>>>>>>>>>>> years. A
> > > > >>>>>>>>>>>>> new
> > > > >>>>>>>>>>>>> producer started with the new partitions will fail to
> > > delete
> > > > >>>>>>>>>>>>> the
> > > > >>>>>>>>>>>>> record
> > > > >>>>>>>>>>>>>
> > > > >>>>>>>>>>>>> in
> > > > >>>>>>>>>>>>>
> > > > >>>>>>>>>>>>> the correct partition. Th record will be there forever
> > and
> > > > one
> > > > >>>>>>>>>>>>> can
> > > > >>>>>>>>>>>>>
> > > > >>>>>>>>>>>> not
> > > > >>>>>>>>>>>>
> > > > >>>>>>>>>>>> reliable bootstrap new consumers. I cannot see how
> linear
> > > > >>>>>>>>>>>> hashing
> > > > >>>>>>>>>>>>
> > > > >>>>>>>>>>>>> can
> > > > >>>>>>>>>>>>>
> > > > >>>>>>>>>>>>> solve
> > > > >>>>>>>>>>>>>
> > > > >>>>>>>>>>>>> this.
> > > > >>>>>>>>>>>>>
> > > > >>>>>>>>>>>> Regarding your skipping of userland copying:
> > > > >>>>>>>>>>>>
> > > > >>>>>>>>>>>>> 100%, copying the data across in userland is, as far
> as i
> > > can
> > > > >>>>>>>>>>>>> see,
> > > > >>>>>>>>>>>>> only
> > > > >>>>>>>>>>>>> a
> > > > >>>>>>>>>>>>> usecase for log compacted topics. Even for
> logcompaction
> > +
> > > > >>>>>>>>>>>>> retentions
> > > > >>>>>>>>>>>>> it
> > > > >>>>>>>>>>>>> should only be opt-in. Why did I bring it up? I think
> log
> > > > >>>>>>>>>>>>> compaction
> > > > >>>>>>>>>>>>> is
> > > > >>>>>>>>>>>>> a
> > > > >>>>>>>>>>>>> very important feature to really embrace kafka as a
> "data
> > > > >>>>>>>>>>>>> plattform".
> > > > >>>>>>>>>>>>> The
> > > > >>>>>>>>>>>>> point I also want to make is that copying data this way
> > is
> > > > >>>>>>>>>>>>> completely
> > > > >>>>>>>>>>>>> inline with the kafka architecture. it only consists of
> > > > reading
> > > > >>>>>>>>>>>>> and
> > > > >>>>>>>>>>>>>
> > > > >>>>>>>>>>>>> writing
> > > > >>>>>>>>>>>>>
> > > > >>>>>>>>>>>>> to topics.
> > > > >>>>>>>>>>>>>
> > > > >>>>>>>>>>>> I hope it clarifies more why I think we should aim for
> > more
> > > > than
> > > > >>>>>>>>>>>>
> > > > >>>>>>>>>>>>> the
> > > > >>>>>>>>>>>>> current KIP. I fear that once the KIP is done not much
> > more
> > > > >>>>>>>>>>>>> effort
> > > > >>>>>>>>>>>>> will
> > > > >>>>>>>>>>>>>
> > > > >>>>>>>>>>>>> be
> > > > >>>>>>>>>>>>>
> > > > >>>>>>>>>>>>> taken.
> > > > >>>>>>>>>>>>>
> > > > >>>>>>>>>>>>
> > > > >>>>>>>>>>>> On 04.03.2018 02:28, Dong Lin wrote:
> > > > >>>>>>>>>>>>>
> > > > >>>>>>>>>>>>> Hey Jan,
> > > > >>>>>>>>>>>>>
> > > > >>>>>>>>>>>>> In the current proposal, the consumer will be blocked
> on
> > > > >>>>>>>>>>>>> waiting
> > > > >>>>>>>>>>>>> for
> > > > >>>>>>>>>>>>>
> > > > >>>>>>>>>>>>> other
> > > > >>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>> consumers of the group to consume up to a given
> offset.
> > In
> > > > >>>>>>>>>>>>>> most
> > > > >>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>> cases,
> > > > >>>>>>>>>>>>> all
> > > > >>>>>>>>>>>>> consumers should be close to the LEO of the partitions
> > when
> > > > the
> > > > >>>>>>>>>>>>> partition
> > > > >>>>>>>>>>>>> expansion happens. Thus the time waiting should not be
> > long
> > > > >>>>>>>>>>>>> e.g.
> > > > >>>>>>>>>>>>> on
> > > > >>>>>>>>>>>>> the
> > > > >>>>>>>>>>>>>
> > > > >>>>>>>>>>>>> order of seconds. On the other hand, it may take a long
> > > time
> > > > to
> > > > >>>>>>>>>>>>> wait
> > > > >>>>>>>>>>>>>
> > > > >>>>>>>>>>>>> for
> > > > >>>>>>>>>>>>>> the entire partition to be copied -- the amount of
> time
> > is
> > > > >>>>>>>>>>>>>> proportional
> > > > >>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>> to
> > > > >>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>> the amount of existing data in the partition, which
> can
> > > take
> > > > >>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>> tens of
> > > > >>>>>>>>>>>>>
> > > > >>>>>>>>>>>>> minutes. So the amount of time that we stop consumers
> may
> > > not
> > > > >>>>>>>>>>>>> be
> > > > >>>>>>>>>>>>> on
> > > > >>>>>>>>>>>>>
> > > > >>>>>>>>>>>>> the
> > > > >>>>>>>>>>>>>> same order of magnitude.
> > > > >>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>> If we can implement this suggestion without copying
> data
> > > > over
> > > > >>>>>>>>>>>>>> in
> > > > >>>>>>>>>>>>>> purse
> > > > >>>>>>>>>>>>>> userland, it will be much more valuable. Do you have
> > ideas
> > > > on
> > > > >>>>>>>>>>>>>> how
> > > > >>>>>>>>>>>>>> this
> > > > >>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>> can
> > > > >>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>> be done?
> > > > >>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>> Not sure why the current KIP not help people who depend
> > on
> > > > log
> > > > >>>>>>>>>>>>>
> > > > >>>>>>>>>>>>> compaction.
> > > > >>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>> Could you elaborate more on this point?
> > > > >>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>> Thanks,
> > > > >>>>>>>>>>>>>
> > > > >>>>>>>>>>>>> Dong
> > > > >>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>> On Wed, Feb 28, 2018 at 10:55 PM, Jan
> > > > >>>>>>>>>>>>>> Filipiak<Jan.Filipiak@trivago.
> > > > >>>>>>>>>>>>>> com
> > > > >>>>>>>>>>>>>> wrote:
> > > > >>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>> Hi Dong,
> > > > >>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>> I tried to focus on what the steps are one can
> currently
> > > > >>>>>>>>>>>>>> perform
> > > > >>>>>>>>>>>>>> to
> > > > >>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>> expand
> > > > >>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>> or shrink a keyed topic while maintaining a top notch
> > > > >>>>>>>>>>>>>>> semantics.
> > > > >>>>>>>>>>>>>>> I can understand that there might be confusion about
> > > > >>>>>>>>>>>>>>> "stopping
> > > > >>>>>>>>>>>>>>> the
> > > > >>>>>>>>>>>>>>> consumer". It is exactly the same as proposed in the
> > KIP.
> > > > >>>>>>>>>>>>>>> there
> > > > >>>>>>>>>>>>>>> needs
> > > > >>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>> to
> > > > >>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>> be
> > > > >>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>> a time the producers agree on the new partitioning.
> The
> > > > extra
> > > > >>>>>>>>>>>>>
> > > > >>>>>>>>>>>>> semantics I
> > > > >>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>> want to put in there is that we have a possibility to
> > > wait
> > > > >>>>>>>>>>>>>>> until
> > > > >>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>> all
> > > > >>>>>>>>>>>>>
> > > > >>>>>>>>>>>>> the
> > > > >>>>>>>>>>>>>
> > > > >>>>>>>>>>>>> existing data
> > > > >>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>> is copied over into the new partitioning scheme. When
> I
> > > say
> > > > >>>>>>>>>>>>> stopping
> > > > >>>>>>>>>>>>>
> > > > >>>>>>>>>>>>> I
> > > > >>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>> think more of having a memory barrier that ensures
> the
> > > > >>>>>>>>>>>>>>> ordering. I
> > > > >>>>>>>>>>>>>>> am
> > > > >>>>>>>>>>>>>>> still
> > > > >>>>>>>>>>>>>>> aming for latencies  on the scale of leader
> failovers.
> > > > >>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>> Consumers have to explicitly adapt the new
> partitioning
> > > > >>>>>>>>>>>>>>> scheme
> > > > >>>>>>>>>>>>>>> in
> > > > >>>>>>>>>>>>>>> the
> > > > >>>>>>>>>>>>>>> above scenario. The reason is that in these cases
> where
> > > you
> > > > >>>>>>>>>>>>>>> are
> > > > >>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>> dependent
> > > > >>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>> on a particular partitioning scheme, you also have
> > other
> > > > >>>>>>>>>>>>>>> topics
> > > > >>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>> that
> > > > >>>>>>>>>>>>>
> > > > >>>>>>>>>>>>> have
> > > > >>>>>>>>>>>>>
> > > > >>>>>>>>>>>>> co-partition enforcements or the kind -frequently.
> > > Therefore
> > > > >>>>>>>>>>>>>> all
> > > > >>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>> your
> > > > >>>>>>>>>>>>>
> > > > >>>>>>>>>>>>> other
> > > > >>>>>>>>>>>>>
> > > > >>>>>>>>>>>>> input topics might need to grow accordingly.
> > > > >>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>> What I was suggesting was to streamline all these
> > > > operations
> > > > >>>>>>>>>>>>>>> as
> > > > >>>>>>>>>>>>>>> best
> > > > >>>>>>>>>>>>>>> as
> > > > >>>>>>>>>>>>>>> possible to have "real" partition grow and shrinkage
> > > going
> > > > >>>>>>>>>>>>>>> on.
> > > > >>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>> Migrating
> > > > >>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>> the producers to a new partitioning scheme can be
> much
> > > more
> > > > >>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>> streamlined
> > > > >>>>>>>>>>>>>
> > > > >>>>>>>>>>>>> with proper broker support for this. Migrating consumer
> > is
> > > a
> > > > >>>>>>>>>>>>> step
> > > > >>>>>>>>>>>>>
> > > > >>>>>>>>>>>>> that
> > > > >>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>> might be made completly unnecessary if - for example
> > > > streams
> > > > >>>>>>>>>>>>>>> -
> > > > >>>>>>>>>>>>>>> takes
> > > > >>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>> the
> > > > >>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>> gcd as partitioning scheme instead of enforcing 1 to
> 1.
> > > > >>>>>>>>>>>>>>> Connect
> > > > >>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>> consumers
> > > > >>>>>>>>>>>>>
> > > > >>>>>>>>>>>>> and other consumers should be fine anyways.
> > > > >>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>> I hope this makes more clear where I was aiming at.
> The
> > > rest
> > > > >>>>>>>>>>>>> needs
> > > > >>>>>>>>>>>>>
> > > > >>>>>>>>>>>>> to
> > > > >>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>> be
> > > > >>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>> figured out. The only danger i see is that when we
> are
> > > > >>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>> introducing
> > > > >>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>> this
> > > > >>>>>>>>>>>>>
> > > > >>>>>>>>>>>>> feature as supposed in the KIP, it wont help any people
> > > > >>>>>>>>>>>>> depending
> > > > >>>>>>>>>>>>> on
> > > > >>>>>>>>>>>>>
> > > > >>>>>>>>>>>>> log
> > > > >>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>> compaction.
> > > > >>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>> The other thing I wanted to mention is that I believe
> > the
> > > > >>>>>>>>>>>>> current
> > > > >>>>>>>>>>>>>
> > > > >>>>>>>>>>>>> suggestion (without copying data over) can be
> implemented
> > > in
> > > > >>>>>>>>>>>>>> pure
> > > > >>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>> userland
> > > > >>>>>>>>>>>>>>> with a custom partitioner and a small feedbackloop
> from
> > > > >>>>>>>>>>>>>>> ProduceResponse
> > > > >>>>>>>>>>>>>>> =>
> > > > >>>>>>>>>>>>>>> Partitionier in coorporation with a change management
> > > > system.
> > > > >>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>> Best Jan
> > > > >>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>> On 28.02.2018 07:13, Dong Lin wrote:
> > > > >>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>> Hey Jan,
> > > > >>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>> I am not sure if it is acceptable for producer to be
> > > > stopped
> > > > >>>>>>>>>>>>>>> for a
> > > > >>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>> while,
> > > > >>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>> particularly for online application which requires
> low
> > > > >>>>>>>>>>>>>>>> latency. I
> > > > >>>>>>>>>>>>>>>> am
> > > > >>>>>>>>>>>>>>>> also
> > > > >>>>>>>>>>>>>>>> not sure how consumers can switch to a new topic.
> Does
> > > > user
> > > > >>>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>> application
> > > > >>>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>> needs to explicitly specify a different topic for
> > > > >>>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>> producer/consumer
> > > > >>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>> to
> > > > >>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>> subscribe to? It will be helpful for discussion if you
> > can
> > > > >>>>>>>>>>>>> provide
> > > > >>>>>>>>>>>>>
> > > > >>>>>>>>>>>>> more
> > > > >>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>> detail on the interface change for this solution.
> > > > >>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>> Thanks,
> > > > >>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>> Dong
> > > > >>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>> On Mon, Feb 26, 2018 at 12:48 AM, Jan
> > > > >>>>>>>>>>>>>>>> Filipiak<Jan.Filipiak@trivago.
> > > > >>>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>> com
> > > > >>>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>> wrote:
> > > > >>>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>> Hi,
> > > > >>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>> just want to throw my though in. In general the
> > > > functionality
> > > > >>>>>>>>>>>>>> is
> > > > >>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>> very
> > > > >>>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>> usefull, we should though not try to find the
> > > architecture
> > > > >>>>>>>>>>>>>>>> to
> > > > >>>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>> hard
> > > > >>>>>>>>>>>>>>>>> while
> > > > >>>>>>>>>>>>>>>>> implementing.
> > > > >>>>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>>> The manual steps would be to
> > > > >>>>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>>> create a new topic
> > > > >>>>>>>>>>>>>>>>> the mirrormake from the new old topic to the new
> > topic
> > > > >>>>>>>>>>>>>>>>> wait for mirror making to catch up.
> > > > >>>>>>>>>>>>>>>>> then put the consumers onto the new topic
> > > > >>>>>>>>>>>>>>>>>            (having mirrormaker spit out a mapping
> > from
> > > > old
> > > > >>>>>>>>>>>>>>>>> offsets to
> > > > >>>>>>>>>>>>>>>>> new
> > > > >>>>>>>>>>>>>>>>> offsets:
> > > > >>>>>>>>>>>>>>>>>                if topic is increased by factor X
> > there
> > > is
> > > > >>>>>>>>>>>>>>>>> gonna
> > > > >>>>>>>>>>>>>>>>> be a
> > > > >>>>>>>>>>>>>>>>> clean
> > > > >>>>>>>>>>>>>>>>> mapping from 1 offset in the old topic to X offsets
> > in
> > > > the
> > > > >>>>>>>>>>>>>>>>> new
> > > > >>>>>>>>>>>>>>>>> topic,
> > > > >>>>>>>>>>>>>>>>>                if there is no factor then there is
> no
> > > > >>>>>>>>>>>>>>>>> chance to
> > > > >>>>>>>>>>>>>>>>> generate a
> > > > >>>>>>>>>>>>>>>>> mapping that can be reasonable used for continuing)
> > > > >>>>>>>>>>>>>>>>>            make consumers stop at appropriate
> points
> > > and
> > > > >>>>>>>>>>>>>>>>> continue
> > > > >>>>>>>>>>>>>>>>> consumption
> > > > >>>>>>>>>>>>>>>>> with offsets from the mapping.
> > > > >>>>>>>>>>>>>>>>> have the producers stop for a minimal time.
> > > > >>>>>>>>>>>>>>>>> wait for mirrormaker to finish
> > > > >>>>>>>>>>>>>>>>> let producer produce with the new metadata.
> > > > >>>>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>>> Instead of implementing the approach suggest in the
> > KIP
> > > > >>>>>>>>>>>>>>>>> which
> > > > >>>>>>>>>>>>>>>>> will
> > > > >>>>>>>>>>>>>>>>> leave
> > > > >>>>>>>>>>>>>>>>> log compacted topic completely crumbled and
> unusable.
> > > > >>>>>>>>>>>>>>>>> I would much rather try to build infrastructure to
> > > > support
> > > > >>>>>>>>>>>>>>>>> the
> > > > >>>>>>>>>>>>>>>>> mentioned
> > > > >>>>>>>>>>>>>>>>> above operations more smoothly.
> > > > >>>>>>>>>>>>>>>>> Especially having producers stop and use another
> > topic
> > > is
> > > > >>>>>>>>>>>>>>>>> difficult
> > > > >>>>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>>> and
> > > > >>>>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>>> it would be nice if one can trigger "invalid
> > metadata"
> > > > >>>>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>> exceptions
> > > > >>>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>> for
> > > > >>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>> them
> > > > >>>>>>>>>>>>>
> > > > >>>>>>>>>>>>> and
> > > > >>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>> if one could give topics aliases so that their
> produces
> > > > with
> > > > >>>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>>> the
> > > > >>>>>>>>>>>>>>>>> old
> > > > >>>>>>>>>>>>>>>>> topic
> > > > >>>>>>>>>>>>>>>>> will arrive in the new topic.
> > > > >>>>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>>> The downsides are obvious I guess ( having the same
> > > data
> > > > >>>>>>>>>>>>>>>>> twice
> > > > >>>>>>>>>>>>>>>>> for
> > > > >>>>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>>> the
> > > > >>>>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>>> transition period, but kafka tends to scale well
> with
> > > > >>>>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>> datasize).
> > > > >>>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>> So
> > > > >>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>> its a
> > > > >>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>> nicer fit into the architecture.
> > > > >>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>> I further want to argument that the functionality by
> > the
> > > > KIP
> > > > >>>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>>> can
> > > > >>>>>>>>>>>>>>>>> completely be implementing in "userland" with a
> > custom
> > > > >>>>>>>>>>>>>>>>> partitioner
> > > > >>>>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>>> that
> > > > >>>>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>>> handles the transition as needed. I would
> appreciate
> > if
> > > > >>>>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>> someone
> > > > >>>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>> could
> > > > >>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>> point
> > > > >>>>>>>>>>>>>
> > > > >>>>>>>>>>>>> out what a custom partitioner couldn't handle in this
> > case?
> > > > >>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>> With the above approach, shrinking a topic becomes
> the
> > > same
> > > > >>>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>>> steps.
> > > > >>>>>>>>>>>>>>>>> Without
> > > > >>>>>>>>>>>>>>>>> loosing keys in the discontinued partitions.
> > > > >>>>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>>> Would love to hear what everyone thinks.
> > > > >>>>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>>> Best Jan
> > > > >>>>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>>> On 11.02.2018 00:35, Dong Lin wrote:
> > > > >>>>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>>> Hi all,
> > > > >>>>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>>> I have created KIP-253: Support in-order message
> > > delivery
> > > > >>>>>>>>>>>>>>>>> with
> > > > >>>>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>>> partition
> > > > >>>>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>>> expansion. See
> > > > >>>>>>>>>>>>>>>>>> https://cwiki.apache.org/confl
> > > > >>>>>>>>>>>>>>>>>> uence/display/KAFKA/KIP-253%
> > > > >>>>>>>>>>>>>>>>>> 3A+Support+in-order+message+de
> > > > >>>>>>>>>>>>>>>>>> livery+with+partition+expansio
> > > > >>>>>>>>>>>>>>>>>> n
> > > > >>>>>>>>>>>>>>>>>> .
> > > > >>>>>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>>>> This KIP provides a way to allow messages of the
> > same
> > > > key
> > > > >>>>>>>>>>>>>>>>>> from
> > > > >>>>>>>>>>>>>>>>>> the
> > > > >>>>>>>>>>>>>>>>>> same
> > > > >>>>>>>>>>>>>>>>>> producer to be consumed in the same order they are
> > > > >>>>>>>>>>>>>>>>>> produced
> > > > >>>>>>>>>>>>>>>>>> even
> > > > >>>>>>>>>>>>>>>>>> if
> > > > >>>>>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>>>> we
> > > > >>>>>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>>>> expand partition of the topic.
> > > > >>>>>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>>> Thanks,
> > > > >>>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>> Dong
> > > > >>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>>>>
> > > > >>>>>>>>>>>>>>>>>>
> > > > >>>>
> > > > >>
> > > > >>
> > > > >
> > > >
> > >
> >
>

Re: [DISCUSS] KIP-253: Support in-order message delivery with partition expansion

Posted by John Roesler <jo...@confluent.io>.
Thanks for the response, Dong.

Here are my answers to your questions:

- "Asking producers and consumers, or even two different producers, to
> share code like the partition function is a pretty huge ask. What if they
> are using different languages?". It seems that today we already require
> different producer's to use the same hash function -- otherwise messages
> with the same key will go to different partitions of the same topic which
> may cause problem for downstream consumption. So not sure if it adds any
> more constraint by assuming consumers know the hash function of producer.
> Could you explain more why user would want to use a cusmtom partition
> function? Maybe we can check if this is something that can be supported in
> the default Kafka hash function. Also, can you explain more why it is
> difficuilt to implement the same hash function in different languages?


Sorry, I meant two different producers as in producers to two different
topics. This was in response to the suggestion that we already require
coordination among producers to different topics in order to achieve
co-partitioning. I was saying that we do not (and should not).

By design, consumers are currently ignorant of the partitioning scheme. It
suffices to trust that the producer has partitioned the topic by key, if
they claim to have done so. If you don't trust that, or even if you just
need some other partitioning scheme, then you must re-partition it
yourself. Nothing we're discussing can or should change that. The value of
backfill is that it preserves the ability for consumers to avoid
re-partitioning before consuming, in the case where they don't need to
today.

Regarding shared "hash functions", note that it's a bit inaccurate to talk
about the "hash function" of the producer. Properly speaking, the producer
has only a "partition function". We do not know that it is a hash. The
producer can use any method at their disposal to assign a partition to a
record. The partition function obviously may we written in any programming
language, so in general it's not something that can be shared around
without a formal spec or the ability to execute arbitrary executables in
arbitrary runtime environments.

Why would a producer want a custom partition function? I don't know... why
did we design the interface so that our users can provide one? In general,
such systems provide custom partitioners because some data sets may be
unbalanced under the default or because they can provide some interesting
functionality built on top of the partitioning scheme, etc. Having provided
this ability, I don't know why we would remove it.

- Besides the assumption that consumer needs to share the hash function of
> producer, is there other organization overhead of the proposal in the
> current KIP?
>

It wasn't clear to me that KIP-253 currently required the producer and
consumer to share the partition function, or in fact that it had a hard
requirement to abandon the general partition function and use a linear hash
function instead.

In my reading, there is a requirement to track the metadata about what
partitions split into what other partitions during an expansion operation.
If the partition function is linear, this is easy. If not, you can always
just record that all old partitions split into all new partitions. This has
the effect of forcing all consumers to wait until the old epoch is
completely consumed before starting on the new epoch. But this may be a
reasonable tradeoff, and it doesn't otherwise alter your design.

You only mention the consumer needing to know that the partition function
is linear, not what the actual function is, so I don't think your design
actually calls for sharing the function. Plus, really all the consumer
needs is the metadata about what old-epoch partitions to wait for before
consuming a new-epoch partition. This information is directly captured in
metadata, so I don't think it actually even cares whether the partition
function is linear or not.

So, no, I really think KIP-253 is in good shape. I was really more talking
about the part of this thread that's outside of KIP-253's scope, namely,
creating the possibility of backfilling partitions after expansion.

- Currently producer can forget about the message that has been
> acknowledged by the broker. Thus the producer probably does not know most
> of the exiting messages in topic, including those messages produced by
> other producers. We can have the owner of the producer to split+backfill.
> In my opion it will be a new program that wraps around the existing
> producer and consumer classes.
>

This sounds fine by me!

Really, I was just emphasizing that the part of the organization that
produces a topic shouldn't have to export their partition function to the
part(s) of the organization (or other organizations) that consume the
topic. Whether the backfill operation goes into the Producer interface is
secondary, I think.

- Regarding point 5. The argument is in favor of the split+backfill but for
> changelog topic. And it intends to address the problem for stream use-case
> in general. In this KIP we will provide interface (i.e.
> PartitionKeyRebalanceListener in the KIP) to be used by sream use-case and
> the goal is that user can flush/re-consume the state as part of the
> interface implementation regardless of whether there is change log topic.
>
> Maybe you are suggesting that the main reason to do split+backfill of input
> topic is to support log compacted topics? You mentioned in Point 1 that log
> compacted topics is out of the scope of this KIP. Maybe I could understand
> your position better. Regarding Jan's proposal to split partitions with
> backfill, do you think this should replace the proposal in the existing
> KIP, or do you think this is something that we should do in addition to the
> existing KIP?
>

I think that interface is a good/necessary component of KIP-253.

I personally (FWIW) feel that KIP-253 is appropriately scoped, but I do
think its utility will be limited unless there is a later KIP offering
backfill. But, maybe unlike Jan, I think it makes sense to try and tackle
the ordering problem independently of backfill, so I'm in support of the
current KIP.

- Regarding point 6. I guess we can agree that it is better not to have the
> performance overhread of copying the input data. Before we discuss more on
> whether the performance overhead is acceptable or not, I am trying to
> figure out what is the benefit of introducing this overhread. You mentioned
> that the benefit is the loose organizational coupling. By "organizational
> coupling", are you referring to the requirement that consumer needs to know
> the hash function of producer? If so, maybe we can discuss the use-case of
> custom partiton function and see whether we can find a way to support such
> use-case without having to copy the input data.
>

I'm not too sure about what an "input" is in this sense, since we are just
talking about topics. Actually the point I was making there is that AKAICT
the performance overhead of a backfill is less than any other option,
assuming you split partitions rarely.

Separately, yes, "organizational coupling" increases if producers and
consumers have to share code, such as the partition function. This would
not be the case if producers could only pick from a menu of a few
well-known partition functions, but I think this is a poor tradeoff.

To me, this is two strong arguments in favor of backfill being less
expensive than no backfill, but again, I think that particular debate comes
after KIP-253, so I don't want to create the impression of opposition to
your proposal.


Finally, to respond to a new email I just noticed:

> BTW, here is my understanding of the scope of this KIP. We want to allow
> consumers to always consume messages with the same key from the same
> producer in the order they are produced. And we need to provide a way for
> stream use-case to be able to flush/load state when messages with the same
> key are migrated between consumers. In addition to ensuring that this goal
> is correctly supported, we should do our best to keep the performance and
> organization overhead of this KIP as low as possible.
>

I think we're on the same page there! In fact, I would generalize a little
more and say that the mechanism you've designed provides *all consumers*
the ability "to flush/load state when messages with the same key are
migrated between consumers", not just Streams.

Thanks for the discussion,
-John



On Tue, Mar 27, 2018 at 3:14 PM, Dong Lin <li...@gmail.com> wrote:

> Hey John,
>
> Thanks much for the detailed comments. Here are my thoughts:
>
> - The need to delete messages from log compacted topics is mainly for
> performance (e.g. storage space) optimization than for correctness for this
> KIP. I agree that we probably don't need to focus on this in our discussion
> since it is mostly for performance optimization.
>
> - "Asking producers and consumers, or even two different producers, to
> share code like the partition function is a pretty huge ask. What if they
> are using different languages?". It seems that today we already require
> different producer's to use the same hash function -- otherwise messages
> with the same key will go to different partitions of the same topic which
> may cause problem for downstream consumption. So not sure if it adds any
> more constraint by assuming consumers know the hash function of producer.
> Could you explain more why user would want to use a cusmtom partition
> function? Maybe we can check if this is something that can be supported in
> the default Kafka hash function. Also, can you explain more why it is
> difficuilt to implement the same hash function in different languages?
>
> - Besides the assumption that consumer needs to share the hash function of
> producer, is there other organization overhead of the proposal in the
> current KIP?
>
> - Currently producer can forget about the message that has been
> acknowledged by the broker. Thus the producer probably does not know most
> of the exiting messages in topic, including those messages produced by
> other producers. We can have the owner of the producer to split+backfill.
> In my opion it will be a new program that wraps around the existing
> producer and consumer classes.
>
> - Regarding point 5. The argument is in favor of the split+backfill but for
> changelog topic. And it intends to address the problem for stream use-case
> in general. In this KIP we will provide interface (i.e.
> PartitionKeyRebalanceListener in the KIP) to be used by sream use-case and
> the goal is that user can flush/re-consume the state as part of the
> interface implementation regardless of whether there is change log topic.
>
> Maybe you are suggesting that the main reason to do split+backfill of input
> topic is to support log compacted topics? You mentioned in Point 1 that log
> compacted topics is out of the scope of this KIP. Maybe I could understand
> your position better. Regarding Jan's proposal to split partitions with
> backfill, do you think this should replace the proposal in the existing
> KIP, or do you think this is something that we should do in addition to the
> existing KIP?
>
> - Regarding point 6. I guess we can agree that it is better not to have the
> performance overhread of copying the input data. Before we discuss more on
> whether the performance overhead is acceptable or not, I am trying to
> figure out what is the benefit of introducing this overhread. You mentioned
> that the benefit is the loose organizational coupling. By "organizational
> coupling", are you referring to the requirement that consumer needs to know
> the hash function of producer? If so, maybe we can discuss the use-case of
> custom partiton function and see whether we can find a way to support such
> use-case without having to copy the input data.
>
> Thanks,
> Dong
>
>
> On Tue, Mar 27, 2018 at 11:34 AM, John Roesler <jo...@confluent.io> wrote:
>
> > Hey Dong and Jun,
> >
> > Thanks for the thoughtful responses. If you don't mind, I'll mix my
> replies
> > together to try for a coherent response. I'm not too familiar with
> > mailing-list etiquette, though.
> >
> > I'm going to keep numbering my points because it makes it easy for you
> all
> > to respond.
> >
> > Point 1:
> > As I read it, KIP-253 is *just* about properly fencing the producers and
> > consumers so that you preserve the correct ordering of records during
> > partition expansion. This is clearly necessary regardless of anything
> else
> > we discuss. I think this whole discussion about backfill, consumers,
> > streams, etc., is beyond the scope of KIP-253. But it would be cumbersome
> > to start a new thread at this point.
> >
> > I had missed KIP-253's Proposed Change #9 among all the details... I
> think
> > this is a nice addition to the proposal. One thought is that it's
> actually
> > irrelevant whether the hash function is linear. This is simply an
> algorithm
> > for moving a key from one partition to another, so the type of hash
> > function need not be a precondition. In fact, it also doesn't matter
> > whether the topic is compacted or not, the algorithm works regardless.
> >
> > I think this is a good algorithm to keep in mind, as it might solve a
> > variety of problems, but it does have a downside: that the producer won't
> > know whether or not K1 was actually in P1, it just knows that K1 was in
> > P1's keyspace before the new epoch. Therefore, it will have to
> > pessimistically send (K1,null) to P1 just in case. But the next time K1
> > comes along, the producer *also* won't remember that it already retracted
> > K1 from P1, so it will have to send (K1,null) *again*. By extension,
> every
> > time the producer sends to P2, it will also have to send a tombstone to
> P1,
> > which is a pretty big burden. To make the situation worse, if there is a
> > second split, say P2 becomes P2 and P3, then any key Kx belonging to P3
> > will also have to be retracted from P2 *and* P1, since the producer can't
> > know whether Kx had been last written to P2 or P1. Over a long period of
> > time, this clearly becomes a issue, as the producer must send an
> arbitrary
> > number of retractions along with every update.
> >
> > In contrast, the proposed backfill operation has an end, and after it
> ends,
> > everyone can afford to forget that there ever was a different partition
> > layout.
> >
> > Really, though, figuring out how to split compacted topics is beyond the
> > scope of KIP-253, so I'm not sure #9 really even needs to be in this
> KIP...
> > We do need in-order delivery during partition expansion. It would be fine
> > by me to say that you *cannot* expand partitions of a log-compacted topic
> > and call it a day. I think it would be better to tackle that in another
> > KIP.
> >
> >
> > Point 2:
> > Regarding whether the consumer re-shuffles its inputs, this is always on
> > the table; any consumer who wants to re-shuffle its input is free to do
> so.
> > But this is currently not required. It's just that the current high-level
> > story with Kafka encourages the use of partitions as a unit of
> concurrency.
> > As long as consumers are single-threaded, they can happily consume a
> single
> > partition without concurrency control of any kind. This is a key aspect
> to
> > this system that lets folks design high-throughput systems on top of it
> > surprisingly easily. If all consumers were instead encouraged/required to
> > implement a repartition of their own, then the consumer becomes
> > significantly more complex, requiring either the consumer to first
> produce
> > to its own intermediate repartition topic or to ensure that consumer
> > threads have a reliable, high-bandwith channel of communication with
> every
> > other consumer thread.
> >
> > Either of those tradeoffs may be reasonable for a particular user of
> Kafka,
> > but I don't know if we're in a position to say that they are reasonable
> for
> > *every* user of Kafka.
> >
> >
> > Point 3:
> > Regarding Jun's point about this use case, "(3) stateful and maintaining
> > the
> > states in a local store", I agree that they may use a framework *like*
> > Kafka Streams, but that is not the same as using Kafka Streams. This is
> why
> > I think it's better to solve it in Core: because it is then solved for
> > KStreams and also for everything else that facilitates local state
> > maintenance. To me, Streams is a member of the category of "stream
> > processing frameworks", which is itself a subcategory of "things
> requiring
> > local state maintenence". I'm not sure if it makes sense to assert that
> > Streams is a sufficient and practical replacement for everything in
> "things
> > requiring local state maintenence".
> >
> > But, yes, I do agree that per-key ordering is an absolute requirement,
> > therefore I think that KIP-253 itself is a necessary step. Regarding the
> > coupling of the state store partitioning to the topic partitioning, yes,
> > this is an issue we are discussing solutions to right now. We may go
> ahead
> > and introduce an overpartition layer on our inputs to solve it, but then
> > again, if we get the ability to split partitions with backfill, we may
> not
> > need to!
> >
> >
> > Point 4:
> > On this:
> >
> > > Regarding thought 2: If we don't care about the stream use-case, then
> the
> > > current KIP probably has already addressed problem without requiring
> > > consumer to know the partition function. If we care about the stream
> > > use-case, we already need coordination across producers of different
> > > topics, i.e. the same partition function needs to be used by producers
> of
> > > topics A and B in order to join topics A and B. Thus, it might be
> > > reasonable to extend coordination a bit and say we need coordination
> > across
> > > clients (i.e. producer and consumer), such that consumer knows the
> > > partition function used by producer. If we do so, then we can let
> > consumer
> > > re-copy data for the change log topic using the same partition function
> > as
> > > producer. This approach has lower overhead as compared to having
> producer
> > > re-copy data of the input topic.
> > > Also, producer currently does not need to know the data already
> produced
> > to
> > > the topic. If we let producer split/merge partition, it would require
> > > producer to consume the existing data, which intuitively is the task of
> > > consumer.
> >
> >
> > I think we do care about use cases *like* Streams, I just don't think we
> > should rely on Streams to implement a feature of Core like partition
> > expansion.
> >
> > Note, though, that we (Streams) do not require coordination across
> > producers. If two topics are certified to be co-partitioned, then Streams
> > apps can make use of that knowledge to optimize their topology (skipping
> a
> > repartition). But if they don't know whether they are co-partitioned,
> then
> > they'd better go ahead and repartition within the topology. This is the
> > current state.
> >
> > A huge selling point of Kafka is enabling different parts of loosely
> > coupled organizations to produce and consume data independently. Some
> > coordination between producers and consumers is necessary, like
> > coordinating on the names of topics and their schemas. But Kafka's value
> > proposition w.r.t. ESBs, etc. is inversely proportional to the amount of
> > coordination required. I think it behooves us to be extremely skeptical
> > about introducing any coordination beyond correctness protocols.
> >
> > Asking producers and consumers, or even two different producers, to share
> > code like the partition function is a pretty huge ask. What if they are
> > using different languages?
> >
> > Comparing organizational overhead vs computational overhead, there are
> > maybe two orders of magnitude difference between them. In other words, I
> > would happily take on the (linear) overhead of having the producer
> re-copy
> > the data once during a re-partition in order to save the organizational
> > overhead of tying all the producers and consumers together across
> multiple
> > boundaries.
> >
> > On that last paragraph: note that the producer *did* know the data it
> > already produced. It handled it the first time around. Asking it to
> > re-produce it into a new partition layout is squarely within its scope of
> > capabilities. Contrast this with the alternative, asking the consumer to
> > re-partition the data. I think this is even less intuitive, when the
> > partition function belongs to the producer.
> >
> >
> > Point 5:
> > Dong asked this:
> >
> > > For stream use-case that needs to increase consumer number, the
> > > existing consumer can backfill the existing data in the change log
> topic
> > to
> > > the same change log topic with the new partition number, before the new
> > set
> > > of consumers bootstrap state from the new partitions of the change log
> > > topic, right?
> >
> >
> > In this sense, the "consumer" is actually the producer of the changelog
> > topic, so if we support partition expansion + backfill as a
> producer/broker
> > operation, then it would be very straightforward for Streams to split a
> > state store. As you say, they would simply instruct the broker to split
> the
> > changelog topic's partitions, then backfill. Once the backfill is ready,
> > they can create a new crop of StandbyTasks to bootstrap the more granular
> > state stores and finally switch over to them when they are ready.
> >
> > But this actually seems to be an argument in favor of split+backfill, so
> > maybe I missed the point.
> >
> > You also asked me to explain why copying the "input" topic is better than
> > copying the "changelog" topic. I think they are totally independent,
> > actually. For one thing, you can't depend on the existence of a
> "changelog"
> > topic in general, only within Streams, but Kafka's user base clearly
> > exceeds Streams's user base. Plus, you actually also can't depend on the
> > existence of a changelog topic within Streams, since that is an optional
> > feature of *some* state store implementations. Even in the situation
> where
> > you do have a changelog topic in Streams, there may be use cases where it
> > makes sense to expand the partitions of just the input, or just the
> > changelog.
> >
> > The ask for a Core feature of split+backfill is really about supporting
> the
> > use case of splitting partitions in log-compacted topics, regardless of
> > whether that topic is an "input" or a "changelog" or anything else for
> that
> > matter.
> >
> >
> > Point 6:
> > On the concern about the performance overhead of copying data between the
> > brokers, I think it's actually a bit overestimated. Splitting a topic's
> > partition is probably rare, certainly rarer in general than bootstrapping
> > new consumers on that topic. If "bootstrapping new consumers" means that
> > they have to re-shuffle the data before they consume it, then you wind up
> > copying the same record multiple times:
> >
> > (broker: input topic) -> (initial consumer) -> (broker: repartition
> topic)
> > -> (real consumer)
> >
> > That's 3x, and it's also 3x for every new record after the split as well,
> > since you don't get to stop repartitioning/reshuffling once you start.
> >
> > Whereas if you do a backfill in something like the procedure I outlined,
> > you only copy the prefix of the partition before the split, and you send
> it
> > once to the producer and then once to the new generation partition. Plus,
> > assuming we're splitting the partition for the benefit of consumers,
> > there's no reason we can't co-locate the post-split partitions on the
> same
> > host as the pre-split partition, making the second copy a local
> filesystem
> > operation.
> >
> > Even if you follow these two copies up with bootstrapping a new consumer,
> > it's still rare for this to occur, so you get to amortize these copies
> over
> > the lifetime of the topic, whereas a reshuffle just keeps making copies
> for
> > every new event.
> >
> > And finally, I really do think that regardless of any performance
> concerns
> > about this operation, if it preserves loose organizational coupling, it
> is
> > certainly worth it.
> >
> >
> > In conclusion:
> > It might actually be a good idea for us to clarify the scope of KIP-253.
> If
> > we're all agreed that it's a good algorithm for allowing in-order message
> > delivery during partition expansion, then we can continue this discussion
> > as a new KIP, something like "backfill with partition expansion". This
> > would let Dong proceed with KIP-253. On the other hand, if it seems like
> > this conversation may alter the design of KIP-253, then maybe we *should*
> > just finish working it out.
> >
> > For my part, my only concern about KIP-253 is the one I raised earlier.
> >
> > Thanks again, all, for considering these points,
> > -John
> >
> >
> > On Tue, Mar 27, 2018 at 2:10 AM, Dong Lin <li...@gmail.com> wrote:
> >
> > > On Tue, Mar 27, 2018 at 12:04 AM, Dong Lin <li...@gmail.com>
> wrote:
> > >
> > > > Hey Jan,
> > > >
> > > > Thanks for the enthusiasm in improving Kafka's design. Now that I
> have
> > > > read through your discussion with Jun, here are my thoughts:
> > > >
> > > > - The latest proposal should with log compacted topics by properly
> > > > deleting old messages after a new message with the same key is
> > produced.
> > > So
> > > > it is probably not a concern anymore. Could you comment if there is
> > still
> > > > issue?
> > > >
> > > > - I wrote the SEP-5 and I am pretty familiar with the motivation and
> > the
> > > > design of SEP-5. SEP-5 is probably orthornal to the motivation of
> this
> > > KIP.
> > > > The goal of SEP-5 is to allow user to increase task number of an
> > existing
> > > > Samza job. But if we increase the partition number of input topics,
> > > > messages may still be consumed out-of-order by tasks in Samza which
> > cause
> > > > incorrect result. Similarly, the approach you proposed does not seem
> to
> > > > ensure that the messages can be delivered in order, even if we can
> make
> > > > sure that each consumer instance is assigned the set of new
> partitions
> > > > covering the same set of keys.
> > > >
> > >
> > > Let me correct this comment. The approach of copying data to a new
> topic
> > > can ensure in-order message delivery suppose we properly migrate
> offsets
> > > from old topic to new topic.
> > >
> > >
> > > > - I am trying to understand why it is better to copy the data instead
> > of
> > > > copying the change log topic for streaming use-case. For core Kafka
> > > > use-case, and for the stream use-case that does not need to increase
> > > > consumers, the current KIP already supports in-order delivery without
> > the
> > > > overhead of copying the data. For stream use-case that needs to
> > increase
> > > > consumer number, the existing consumer can backfill the existing data
> > in
> > > > the change log topic to the same change log topic with the new
> > partition
> > > > number, before the new set of consumers bootstrap state from the new
> > > > partitions of the change log topic. If this solution works, then
> could
> > > you
> > > > summarize the advantage of copying the data of input topic as
> compared
> > to
> > > > copying the change log topic? For example, does it enable more
> > use-case,
> > > > simplify the implementation of Kafka library, or reduce the operation
> > > > overhead etc?
> > > >
> > > > Thanks,
> > > > Dong
> > > >
> > > >
> > > > On Wed, Mar 21, 2018 at 6:57 AM, Jan Filipiak <
> > Jan.Filipiak@trivago.com>
> > > > wrote:
> > > >
> > > >> Hi Jun,
> > > >>
> > > >> I was really seeing progress in our conversation but your latest
> reply
> > > is
> > > >> just devastating.
> > > >> I though we were getting close being on the same page now it feels
> > like
> > > >> we are in different libraries.
> > > >>
> > > >> I just quickly slam my answers in here. If they are to brief I am
> > sorry
> > > >> give me a ping and try to go into details more.
> > > >> Just want to show that your pro/cons listing is broken.
> > > >>
> > > >> Best Jan
> > > >>
> > > >> and want to get rid of this horrible compromise
> > > >>
> > > >>
> > > >> On 19.03.2018 05:48, Jun Rao wrote:
> > > >>
> > > >>> Hi, Jan,
> > > >>>
> > > >>> Thanks for the discussion. Great points.
> > > >>>
> > > >>> Let me try to summarize the approach that you are proposing. On the
> > > >>> broker
> > > >>> side, we reshuffle the existing data in a topic from current
> > partitions
> > > >>> to
> > > >>> the new partitions. Once the reshuffle fully catches up, switch the
> > > >>> consumers to start consuming from the new partitions. If a consumer
> > > needs
> > > >>> to rebuild its local state (due to partition changes), let the
> > consumer
> > > >>> rebuild its state by reading all existing data from the new
> > partitions.
> > > >>> Once all consumers have switches over, cut over the producer to the
> > new
> > > >>> partitions.
> > > >>>
> > > >>> The pros for this approach are that :
> > > >>> 1. There is just one way to rebuild the local state, which is
> > simpler.
> > > >>>
> > > >> true thanks
> > > >>
> > > >>>
> > > >>> The cons for this approach are:
> > > >>> 1. Need to copy existing data.
> > > >>>
> > > >> Very unfair and not correct. It does not require you to copy over
> > > >> existing data. It _allows_ you to copy all existing data.
> > > >>
> > > >> 2. The cutover of the producer is a bit complicated since it needs
> to
> > > >>> coordinate with all consumer groups.
> > > >>>
> > > >> Also not true. I explicitly tried to make clear that there is only
> one
> > > >> special consumer (in the case of actually copying data) coordination
> > is
> > > >> required.
> > > >>
> > > >>> 3. The rebuilding of the state in the consumer is from the input
> > topic,
> > > >>> which can be more expensive than rebuilding from the existing
> state.
> > > >>>
> > > >> true, but rebuilding state is only required if you want to increase
> > > >> processing power, so we assume this is at hand.
> > > >>
> > > >>> 4. The broker potentially has to know the partitioning function. If
> > > this
> > > >>> needs to be customized at the topic level, it can be a bit messy.
> > > >>>
> > > >> I would argue against having the operation being performed by the
> > > broker.
> > > >> This was not discussed yet but if you see my original email i
> > suggested
> > > >> otherwise from the beginning.
> > > >>
> > > >>>
> > > >>> Here is an alternative approach by applying your idea not in the
> > > broker,
> > > >>> but in the consumer. When new partitions are added, we don't move
> > > >>> existing
> > > >>> data. In KStreams, we first reshuffle the new input data to a new
> > topic
> > > >>> T1
> > > >>> with the old number of partitions and feed T1's data to the rest of
> > the
> > > >>> pipeline. In the meantime, KStreams reshuffles all existing data of
> > the
> > > >>> change capture topic to another topic C1 with the new number of
> > > >>> partitions.
> > > >>> We can then build the state of the new tasks from C1. Once the new
> > > states
> > > >>> have been fully built, we can cut over the consumption to the input
> > > topic
> > > >>> and delete T1. This approach works with compacted topic too. If an
> > > >>> application reads from the beginning of a compacted topic, the
> > consumer
> > > >>> will reshuffle the portion of the input when the number of
> partitions
> > > >>> doesn't match the number of tasks.
> > > >>>
> > > >> We all wipe this idea from our heads instantly. Mixing Ideas from an
> > > >> argument is not a resolution strategy
> > > >> just leads to horrible horrible software.
> > > >>
> > > >>
> > > >>> The pros of this approach are:
> > > >>> 1. No need to copy existing data.
> > > >>> 2. Each consumer group can cut over to the new partitions
> > > independently.
> > > >>> 3. The state is rebuilt from the change capture topic, which is
> > cheaper
> > > >>> than rebuilding from the input topic.
> > > >>> 4. Only the KStreams job needs to know the partitioning function.
> > > >>>
> > > >>> The cons of this approach are:
> > > >>> 1. Potentially the same input topic needs to be reshuffled more
> than
> > > once
> > > >>> in different consumer groups during the transition phase.
> > > >>>
> > > >>> What do you think?
> > > >>>
> > > >>> Thanks,
> > > >>>
> > > >>> Jun
> > > >>>
> > > >>>
> > > >>>
> > > >>> On Thu, Mar 15, 2018 at 1:04 AM, Jan Filipiak <
> > > Jan.Filipiak@trivago.com>
> > > >>> wrote:
> > > >>>
> > > >>> Hi Jun,
> > > >>>>
> > > >>>> thank you for following me on these thoughts. It was important to
> me
> > > to
> > > >>>> feel that kind of understanding for my arguments.
> > > >>>>
> > > >>>> What I was hoping for (I mentioned this earlier) is that we can
> > model
> > > >>>> the
> > > >>>> case where we do not want to copy the data the exact same way as
> the
> > > >>>> case
> > > >>>> when we do copy the data. Maybe you can peek into the mails before
> > to
> > > >>>> see
> > > >>>> more details for this.
> > > >>>>
> > > >>>> This means we have the same mechanism to transfer consumer groups
> to
> > > >>>> switch topic. The offset mapping that would be generated would
> even
> > be
> > > >>>> simpler End Offset of the Old topic => offset 0 off all the
> > partitions
> > > >>>> of
> > > >>>> the new topic. Then we could model the transition of a non-copy
> > > >>>> expansion
> > > >>>> the exact same way as a copy-expansion.
> > > >>>>
> > > >>>> I know this only works when topic growth by a factor. But the
> > benefits
> > > >>>> of
> > > >>>> only growing by a factor are to strong anyways. See Clemens's hint
> > and
> > > >>>> remember that state reshuffling is entirely not needed if one
> > doesn't
> > > >>>> want
> > > >>>> to grow processing power.
> > > >>>>
> > > >>>> I think these benefits should be clear, and that there is
> basically
> > no
> > > >>>> downside to what is currently at hand but just makes everything
> > easy.
> > > >>>>
> > > >>>> One thing you need to know is. that if you do not offer
> rebuilding a
> > > log
> > > >>>> compacted topic like i suggest that even if you have consumer
> state
> > > >>>> reshuffling. The topic is broken and can not be used to bootstrap
> > new
> > > >>>> consumers. They don't know if they need to apply a key from and
> old
> > > >>>> partition or not. This is a horrible downside I haven't seen a
> > > solution
> > > >>>> for
> > > >>>> in the email conversation.
> > > >>>>
> > > >>>> I argue to:
> > > >>>>
> > > >>>> Only grow topic by a factor always.
> > > >>>> Have the "no copy consumer" transition as the trivial case of the
> > > "copy
> > > >>>> consumer transition".
> > > >>>> If processors needs to be scaled, let them rebuild from the new
> > topic
> > > >>>> and
> > > >>>> leave the old running in the mean time.
> > > >>>> Do not implement key shuffling in streams.
> > > >>>>
> > > >>>> I hope I can convince you especially with the fact how I want to
> > > handle
> > > >>>> consumer transition. I think
> > > >>>> you didn't quite understood me there before. I think the term "new
> > > >>>> topic"
> > > >>>> intimidated you a little.
> > > >>>> How we solve this on disc doesn't really matter, If the data goes
> > into
> > > >>>> the
> > > >>>> same Dir or a different Dir or anything. I do think that it needs
> to
> > > >>>> involve at least rolling a new segment for the existing
> partitions.
> > > >>>> But most of the transitions should work without restarting
> > consumers.
> > > >>>> (newer consumers with support for this). But with new topic i just
> > > meant
> > > >>>> the topic that now has a different partition count. Plenty of ways
> > to
> > > >>>> handle that (versions, aliases)
> > > >>>>
> > > >>>> Hope I can further get my idea across.
> > > >>>>
> > > >>>> Best Jan
> > > >>>>
> > > >>>>
> > > >>>>
> > > >>>>
> > > >>>>
> > > >>>>
> > > >>>> On 14.03.2018 02:45, Jun Rao wrote:
> > > >>>>
> > > >>>> Hi, Jan,
> > > >>>>>
> > > >>>>> Thanks for sharing your view.
> > > >>>>>
> > > >>>>> I agree with you that recopying the data potentially makes the
> > state
> > > >>>>> management easier since the consumer can just rebuild its state
> > from
> > > >>>>> scratch (i.e., no need for state reshuffling).
> > > >>>>>
> > > >>>>> On the flip slide, I saw a few disadvantages of the approach that
> > you
> > > >>>>> suggested. (1) Building the state from the input topic from
> scratch
> > > is
> > > >>>>> in
> > > >>>>> general less efficient than state reshuffling. Let's say one
> > > computes a
> > > >>>>> count per key from an input topic. The former requires reading
> all
> > > >>>>> existing
> > > >>>>> records in the input topic whereas the latter only requires
> reading
> > > >>>>> data
> > > >>>>> proportional to the number of unique keys. (2) The switching of
> the
> > > >>>>> topic
> > > >>>>> needs modification to the application. If there are many
> > applications
> > > >>>>> on a
> > > >>>>> topic, coordinating such an effort may not be easy. Also, it's
> not
> > > >>>>> clear
> > > >>>>> how to enforce exactly-once semantic during the switch. (3) If a
> > > topic
> > > >>>>> doesn't need any state management, recopying the data seems
> > wasteful.
> > > >>>>> In
> > > >>>>> that case, in place partition expansion seems more desirable.
> > > >>>>>
> > > >>>>> I understand your concern about adding complexity in KStreams.
> But,
> > > >>>>> perhaps
> > > >>>>> we could iterate on that a bit more to see if it can be
> simplified.
> > > >>>>>
> > > >>>>> Jun
> > > >>>>>
> > > >>>>>
> > > >>>>> On Mon, Mar 12, 2018 at 11:21 PM, Jan Filipiak <
> > > >>>>> Jan.Filipiak@trivago.com>
> > > >>>>> wrote:
> > > >>>>>
> > > >>>>> Hi Jun,
> > > >>>>>
> > > >>>>>> I will focus on point 61 as I think its _the_ fundamental part
> > that
> > > I
> > > >>>>>> cant
> > > >>>>>> get across at the moment.
> > > >>>>>>
> > > >>>>>> Kafka is the platform to have state materialized multiple times
> > from
> > > >>>>>> one
> > > >>>>>> input. I emphasize this: It is the building block in
> architectures
> > > >>>>>> that
> > > >>>>>> allow you to
> > > >>>>>> have your state maintained multiple times. You put a message in
> > > once,
> > > >>>>>> and
> > > >>>>>> you have it pop out as often as you like. I believe you
> understand
> > > >>>>>> this.
> > > >>>>>>
> > > >>>>>> Now! The path of thinking goes the following: I am using apache
> > > kafka
> > > >>>>>> and
> > > >>>>>> I _want_ my state multiple times. What am I going todo?
> > > >>>>>>
> > > >>>>>> A) Am I going to take my state that I build up, plunge some sort
> > of
> > > >>>>>> RPC
> > > >>>>>> layer ontop of it, use that RPC layer to throw my records across
> > > >>>>>> instances?
> > > >>>>>> B) Am I just going to read the damn message twice?
> > > >>>>>>
> > > >>>>>> Approach A is fundamentally flawed and a violation of all that
> is
> > > good
> > > >>>>>> and
> > > >>>>>> holy in kafka deployments. I can not understand how this Idea
> can
> > > >>>>>> come in
> > > >>>>>> the first place.
> > > >>>>>> (I do understand: IQ in streams, they polluted the kafka streams
> > > >>>>>> codebase
> > > >>>>>> really bad already. It is not funny! I think they are equally
> > flawed
> > > >>>>>> as
> > > >>>>>> A)
> > > >>>>>>
> > > >>>>>> I say, we do what Kafka is good at. We repartition the topic
> once.
> > > We
> > > >>>>>> switch the consumers.
> > > >>>>>> (Those that need more partitions are going to rebuild their
> state
> > in
> > > >>>>>> multiple partitions by reading the new topic, those that don't
> > just
> > > >>>>>> assign
> > > >>>>>> the new partitions properly)
> > > >>>>>> We switch producers. Done!
> > > >>>>>>
> > > >>>>>> The best thing! It is trivial, hipster stream processor will
> have
> > an
> > > >>>>>> easy
> > > >>>>>> time with that aswell. Its so super simple. And simple IS good!
> > > >>>>>> It is what kafka was build todo. It is how we do it today. All I
> > am
> > > >>>>>> saying
> > > >>>>>> is that a little broker help doing the producer swap is super
> > > useful.
> > > >>>>>>
> > > >>>>>> For everyone interested in why kafka is so powerful with
> approach
> > B,
> > > >>>>>> please watch https://youtu.be/bEbeZPVo98c?t=1633
> > > >>>>>> I already looked up a good point in time, I think after 5
> minutes
> > > the
> > > >>>>>> "state" topic is handled and you should be able to understand me
> > > >>>>>> and inch better.
> > > >>>>>>
> > > >>>>>> Please do not do A to the project, it deserves better!
> > > >>>>>>
> > > >>>>>> Best Jan
> > > >>>>>>
> > > >>>>>>
> > > >>>>>>
> > > >>>>>> On 13.03.2018 02:40, Jun Rao wrote:
> > > >>>>>>
> > > >>>>>> Hi, Jan,
> > > >>>>>>
> > > >>>>>>> Thanks for the reply. A few more comments below.
> > > >>>>>>>
> > > >>>>>>> 50. Ok, we can think a bit harder for supporting compacted
> > topics.
> > > >>>>>>>
> > > >>>>>>> 51. This is a fundamental design question. In the more common
> > case,
> > > >>>>>>> the
> > > >>>>>>> reason why someone wants to increase the number of partitions
> is
> > > that
> > > >>>>>>> the
> > > >>>>>>> consumer application is slow and one wants to run more consumer
> > > >>>>>>> instances
> > > >>>>>>> to increase the degree of parallelism. So, fixing the number of
> > > >>>>>>> running
> > > >>>>>>> consumer instances when expanding the partitions won't help
> this
> > > >>>>>>> case.
> > > >>>>>>> If
> > > >>>>>>> we do need to increase the number of consumer instances, we
> need
> > to
> > > >>>>>>> somehow
> > > >>>>>>> reshuffle the state of the consumer across instances. What we
> > have
> > > >>>>>>> been
> > > >>>>>>> discussing in this KIP is whether we can do this more
> effectively
> > > >>>>>>> through
> > > >>>>>>> the KStream library (e.g. through a 2-phase partition
> expansion).
> > > >>>>>>> This
> > > >>>>>>> will
> > > >>>>>>> add some complexity, but it's probably better than everyone
> doing
> > > >>>>>>> this
> > > >>>>>>> in
> > > >>>>>>> the application space. The recopying approach that you
> mentioned
> > > >>>>>>> doesn't
> > > >>>>>>> seem to address the consumer state management issue when the
> > > consumer
> > > >>>>>>> switches from an old to a new topic.
> > > >>>>>>>
> > > >>>>>>> 52. As for your example, it depends on whether the join key is
> > the
> > > >>>>>>> same
> > > >>>>>>> between (A,B) and (B,C). If the join key is the same, we can
> do a
> > > >>>>>>> 2-phase
> > > >>>>>>> partition expansion of A, B, and C together. If the join keys
> are
> > > >>>>>>> different, one would need to repartition the data on a
> different
> > > key
> > > >>>>>>> for
> > > >>>>>>> the second join, then the partition expansion can be done
> > > >>>>>>> independently
> > > >>>>>>> between (A,B) and (B,C).
> > > >>>>>>>
> > > >>>>>>> 53. If you always fix the number of consumer instances, we you
> > > >>>>>>> described
> > > >>>>>>> works. However, as I mentioned in #51, I am not sure how your
> > > >>>>>>> proposal
> > > >>>>>>> deals with consumer states when the number of consumer
> instances
> > > >>>>>>> grows.
> > > >>>>>>> Also, it just seems that it's better to avoid re-copying the
> > > existing
> > > >>>>>>> data.
> > > >>>>>>>
> > > >>>>>>> 60. "just want to throw in my question from the longer email in
> > the
> > > >>>>>>> other
> > > >>>>>>> Thread here. How will the bloom filter help a new consumer to
> > > decide
> > > >>>>>>> to
> > > >>>>>>> apply the key or not?" Not sure that I fully understood your
> > > >>>>>>> question.
> > > >>>>>>> The
> > > >>>>>>> consumer just reads whatever key is in the log. The bloom
> filter
> > > just
> > > >>>>>>> helps
> > > >>>>>>> clean up the old keys.
> > > >>>>>>>
> > > >>>>>>> 61. "Why can we afford having a topic where its apparently not
> > > >>>>>>> possible
> > > >>>>>>> to
> > > >>>>>>> start a new application on? I think this is an overall flaw of
> > the
> > > >>>>>>> discussed idea here. Not playing attention to the overall
> > > >>>>>>> architecture."
> > > >>>>>>> Could you explain a bit more when one can't start a new
> > > application?
> > > >>>>>>>
> > > >>>>>>> Jun
> > > >>>>>>>
> > > >>>>>>>
> > > >>>>>>>
> > > >>>>>>> On Sat, Mar 10, 2018 at 1:40 AM, Jan Filipiak <
> > > >>>>>>> Jan.Filipiak@trivago.com
> > > >>>>>>> wrote:
> > > >>>>>>>
> > > >>>>>>> Hi Jun, thanks for your mail.
> > > >>>>>>>
> > > >>>>>>> Thank you for your questions!
> > > >>>>>>>> I think they are really good and tackle the core of the
> problem
> > I
> > > >>>>>>>> see.
> > > >>>>>>>>
> > > >>>>>>>> I will answer inline, mostly but still want to set the tone
> > here.
> > > >>>>>>>>
> > > >>>>>>>> The core strength of kafka is what Martin once called the
> > > >>>>>>>> kappa-Architecture. How does this work?
> > > >>>>>>>> You have everything as a log as in kafka. When you need to
> > change
> > > >>>>>>>> something.
> > > >>>>>>>> You create the new version of your application and leave it
> > > running
> > > >>>>>>>> in
> > > >>>>>>>> parallel.
> > > >>>>>>>> Once the new version is good you switch your users to use the
> > new
> > > >>>>>>>> application.
> > > >>>>>>>>
> > > >>>>>>>> The online reshuffling effectively breaks this architecture
> and
> > I
> > > >>>>>>>> think
> > > >>>>>>>> the switch in thinking here is more harmful
> > > >>>>>>>> than any details about the partitioning function to allow
> such a
> > > >>>>>>>> change.
> > > >>>>>>>> I
> > > >>>>>>>> feel with my suggestion we are the closest to
> > > >>>>>>>> the original and battle proven architecture and I can only
> warn
> > to
> > > >>>>>>>> move
> > > >>>>>>>> away from it.
> > > >>>>>>>>
> > > >>>>>>>> I might have forgotten something, sometimes its hard for me to
> > > >>>>>>>> getting
> > > >>>>>>>> all
> > > >>>>>>>> the thoughts captured in a mail, but I hope the comments
> inline
> > > will
> > > >>>>>>>> further make my concern clear, and put some emphasis on why I
> > > >>>>>>>> prefer my
> > > >>>>>>>> solution ;)
> > > >>>>>>>>
> > > >>>>>>>> One thing we should all be aware of when discussing this, and
> I
> > > >>>>>>>> think
> > > >>>>>>>> Dong
> > > >>>>>>>> should have mentioned it (maybe he did).
> > > >>>>>>>> We are not discussing all of this out of thin air but there is
> > an
> > > >>>>>>>> effort
> > > >>>>>>>> in the Samza project.
> > > >>>>>>>>
> > > >>>>>>>> https://cwiki.apache.org/confluence/display/SAMZA/SEP-5%3A+
> > > >>>>>>>> Enable+partition+expansion+of+input+streams
> > > >>>>>>>> https://issues.apache.org/jira/browse/SAMZA-1293
> > > >>>>>>>>
> > > >>>>>>>> To be clear. I think SEP-5 (state of last week, dont know if
> it
> > > >>>>>>>> adapted
> > > >>>>>>>> to
> > > >>>>>>>> this discussion) is on a way better path than KIP-253, and I
> > can't
> > > >>>>>>>> really
> > > >>>>>>>> explain why.
> > > >>>>>>>>
> > > >>>>>>>> Best Jan,
> > > >>>>>>>>
> > > >>>>>>>> nice weekend everyone
> > > >>>>>>>>
> > > >>>>>>>>
> > > >>>>>>>> On 09.03.2018 03:36, Jun Rao wrote:
> > > >>>>>>>>
> > > >>>>>>>> Hi, Jan,
> > > >>>>>>>>
> > > >>>>>>>> Thanks for the feedback. Just some comments on the earlier
> > points
> > > >>>>>>>>> that
> > > >>>>>>>>> you
> > > >>>>>>>>> mentioned.
> > > >>>>>>>>>
> > > >>>>>>>>> 50. You brought up the question of whether existing data
> needs
> > to
> > > >>>>>>>>> be
> > > >>>>>>>>> copied
> > > >>>>>>>>> during partition expansion. My understand of your view is
> that
> > > >>>>>>>>> avoid
> > > >>>>>>>>> copying existing data will be more efficient, but it doesn't
> > work
> > > >>>>>>>>> well
> > > >>>>>>>>> with
> > > >>>>>>>>> compacted topics since some keys in the original partitions
> > will
> > > >>>>>>>>> never
> > > >>>>>>>>> be
> > > >>>>>>>>> cleaned. It would be useful to understand your use case of
> > > >>>>>>>>> compacted
> > > >>>>>>>>> topics
> > > >>>>>>>>> a bit more. In the common use case, the data volume in a
> > > compacted
> > > >>>>>>>>> topic
> > > >>>>>>>>> may not be large. So, I am not sure if there is a strong need
> > to
> > > >>>>>>>>> expand
> > > >>>>>>>>> partitions in a compacted topic, at least initially.
> > > >>>>>>>>>
> > > >>>>>>>>> I do agree. State is usually smaller. Update rates might be
> > also
> > > >>>>>>>>>
> > > >>>>>>>>> competitively high.
> > > >>>>>>>> Doing Log-compaction (even beeing very efficient and
> > configurable)
> > > >>>>>>>> is
> > > >>>>>>>> also
> > > >>>>>>>> a more expensive operation than
> > > >>>>>>>> just discarding old segments. Further if you want to use more
> > > >>>>>>>> consumers
> > > >>>>>>>> processing the events
> > > >>>>>>>> you also have to grow the number of partitions. Especially for
> > > >>>>>>>> use-cases
> > > >>>>>>>> we do (KIP-213) a tiny state full
> > > >>>>>>>> table might be very expensive to process if it joins against a
> > > huge
> > > >>>>>>>> table.
> > > >>>>>>>>
> > > >>>>>>>> I can just say we have been in the spot of needing to grow log
> > > >>>>>>>> compacted
> > > >>>>>>>> topics. Mainly for processing power we can bring to the table.
> > > >>>>>>>>
> > > >>>>>>>> Further i am not at all concerned about the extra spaced used
> by
> > > >>>>>>>> "garbage
> > > >>>>>>>> keys". I am more concerned about the correctness of innocent
> > > >>>>>>>> consumers.
> > > >>>>>>>> The
> > > >>>>>>>> logic becomes complicated. Say for streams one would need to
> > load
> > > >>>>>>>> the
> > > >>>>>>>> record into state but not forward it the topology ( to have it
> > > >>>>>>>> available
> > > >>>>>>>> for shuffeling). I rather have it simple and a topic clean
> > > >>>>>>>> regardless
> > > >>>>>>>> if
> > > >>>>>>>> it
> > > >>>>>>>> still has its old partition count. Especially with multiple
> > > >>>>>>>> partitions
> > > >>>>>>>> growth's I think it becomes insanely hard to to this shuffle
> > > >>>>>>>> correct.
> > > >>>>>>>> Maybe
> > > >>>>>>>> Streams and Samza can do it. Especially if you do "hipster
> > stream
> > > >>>>>>>> processing" <https://www.confluent.io/blog
> > > >>>>>>>> /introducing-kafka-streams-
> > > >>>>>>>> stream-processing-made-simple/>. This makes kafka way to
> > > >>>>>>>> complicated.
> > > >>>>>>>> With my approach I think its way simpler because the topic has
> > no
> > > >>>>>>>> "history"
> > > >>>>>>>> in terms of partitioning but is always clean.
> > > >>>>>>>>
> > > >>>>>>>>
> > > >>>>>>>> 51. "Growing the topic by an integer factor does not require
> any
> > > >>>>>>>> state
> > > >>>>>>>>
> > > >>>>>>>> redistribution at all." Could you clarify this a bit more?
> Let's
> > > say
> > > >>>>>>>>> you
> > > >>>>>>>>> have a consumer app that computes the windowed count per key.
> > If
> > > >>>>>>>>> you
> > > >>>>>>>>> double
> > > >>>>>>>>> the number of partitions from 1 to 2 and grow the consumer
> > > >>>>>>>>> instances
> > > >>>>>>>>> from
> > > >>>>>>>>> 1
> > > >>>>>>>>> to 2, we would need to redistribute some of the counts to the
> > new
> > > >>>>>>>>> consumer
> > > >>>>>>>>> instance. Regarding to linear hashing, it's true that it
> won't
> > > >>>>>>>>> solve
> > > >>>>>>>>> the
> > > >>>>>>>>> problem with compacted topics. The main benefit is that it
> > > >>>>>>>>> redistributes
> > > >>>>>>>>> the keys in one partition to no more than two partitions,
> which
> > > >>>>>>>>> could
> > > >>>>>>>>> help
> > > >>>>>>>>> redistribute the state.
> > > >>>>>>>>>
> > > >>>>>>>>> You don't need to spin up a new consumer in this case. every
> > > >>>>>>>>> consumer
> > > >>>>>>>>>
> > > >>>>>>>>> would just read every partition with the (partition %
> num_task)
> > > >>>>>>>> task.
> > > >>>>>>>> it
> > > >>>>>>>> will still have the previous data right there and can go on.
> > > >>>>>>>>
> > > >>>>>>>> This sounds contradictory to what I said before, but please
> bear
> > > >>>>>>>> with
> > > >>>>>>>> me.
> > > >>>>>>>>
> > > >>>>>>>> 52. Good point on coordinating the expansion of 2 topics that
> > need
> > > >>>>>>>> to
> > > >>>>>>>> be
> > > >>>>>>>>
> > > >>>>>>>> joined together. This is where the 2-phase partition expansion
> > > could
> > > >>>>>>>>> potentially help. In the first phase, we could add new
> > partitions
> > > >>>>>>>>> to
> > > >>>>>>>>> the 2
> > > >>>>>>>>> topics one at a time but without publishing to the new
> > patitions.
> > > >>>>>>>>> Then,
> > > >>>>>>>>> we
> > > >>>>>>>>> can add new consumer instances to pick up the new partitions.
> > In
> > > >>>>>>>>> this
> > > >>>>>>>>> transition phase, no reshuffling is needed since no data is
> > > coming
> > > >>>>>>>>> from
> > > >>>>>>>>> the
> > > >>>>>>>>> new partitions. Finally, we can enable the publishing to the
> > new
> > > >>>>>>>>> partitions.
> > > >>>>>>>>>
> > > >>>>>>>>> I think its even worse than you think. I would like to
> > introduce
> > > >>>>>>>>> the
> > > >>>>>>>>>
> > > >>>>>>>>> Term
> > > >>>>>>>> transitive copartitioning. Imagine
> > > >>>>>>>> 2 streams application. One joins (A,B) the other (B,C) then
> > there
> > > >>>>>>>> is a
> > > >>>>>>>> transitive copartition requirement for
> > > >>>>>>>> (A,C) to be copartitioned aswell. This can spread
> significantly
> > > and
> > > >>>>>>>> require many consumers to adapt at the same time.
> > > >>>>>>>>
> > > >>>>>>>> It is also not entirely clear to me how you not need
> reshuffling
> > > in
> > > >>>>>>>> this
> > > >>>>>>>> case. If A has a record that never gets updated after the
> > > expansion
> > > >>>>>>>> and
> > > >>>>>>>> the
> > > >>>>>>>> coresponding B record moves to a new partition. How shall they
> > > meet
> > > >>>>>>>> w/o
> > > >>>>>>>> shuffle?
> > > >>>>>>>>
> > > >>>>>>>> 53. "Migrating consumer is a step that might be made completly
> > > >>>>>>>>
> > > >>>>>>>> unnecessary
> > > >>>>>>>>> if - for example streams - takes the gcd as partitioning
> scheme
> > > >>>>>>>>> instead
> > > >>>>>>>>> of
> > > >>>>>>>>> enforcing 1 to 1." Not sure that I fully understand this. I
> > think
> > > >>>>>>>>> you
> > > >>>>>>>>> mean
> > > >>>>>>>>> that a consumer application can run more instances than the
> > > number
> > > >>>>>>>>> of
> > > >>>>>>>>> partitions. In that case, the consumer can just
> repartitioning
> > > the
> > > >>>>>>>>> input
> > > >>>>>>>>> data according to the number of instances. This is possible,
> > but
> > > >>>>>>>>> just
> > > >>>>>>>>> has
> > > >>>>>>>>> the overhead of reshuffling the data.
> > > >>>>>>>>>
> > > >>>>>>>>> No what I meant is ( that is also your question i think
> > Mathias)
> > > >>>>>>>>> that
> > > >>>>>>>>> if
> > > >>>>>>>>>
> > > >>>>>>>>> you grow a topic by a factor.
> > > >>>>>>>> Even if your processor is statefull you can can just assign
> all
> > > the
> > > >>>>>>>> multiples of the previous partition to
> > > >>>>>>>> this consumer and the state to keep processing correctly will
> be
> > > >>>>>>>> present
> > > >>>>>>>> w/o any shuffling.
> > > >>>>>>>>
> > > >>>>>>>> Say you have an assignment
> > > >>>>>>>> Statefull consumer => partition
> > > >>>>>>>> 0 => 0
> > > >>>>>>>> 1 => 1
> > > >>>>>>>> 2 => 2
> > > >>>>>>>>
> > > >>>>>>>> and you grow you topic by 4 you get,
> > > >>>>>>>>
> > > >>>>>>>> 0 => 0,3,6,9
> > > >>>>>>>> 1 => 1,4,7,10
> > > >>>>>>>> 2 => 2,5,8,11
> > > >>>>>>>>
> > > >>>>>>>> Say your hashcode is 8. 8%3 => 2  before so consumer for
> > > partition 2
> > > >>>>>>>> has
> > > >>>>>>>> it.
> > > >>>>>>>> Now you you have 12 partitions so 8%12 => 8, so it goes into
> > > >>>>>>>> partition
> > > >>>>>>>> 8
> > > >>>>>>>> which is assigned to the same consumer
> > > >>>>>>>> who had 2 before and therefore knows the key.
> > > >>>>>>>>
> > > >>>>>>>> Userland reshuffeling is there as an options. And it does
> > exactly
> > > >>>>>>>> what
> > > >>>>>>>> I
> > > >>>>>>>> suggest. And I think its the perfect strategie. All I am
> > > suggestion
> > > >>>>>>>> is
> > > >>>>>>>> broker side support to switch the producers to the newly
> > > partitioned
> > > >>>>>>>> topic.
> > > >>>>>>>> Then the old (to few partition topic) can go away.  Remember
> the
> > > >>>>>>>> list
> > > >>>>>>>> of
> > > >>>>>>>> steps in the beginning of this thread. If one has broker
> support
> > > for
> > > >>>>>>>> all
> > > >>>>>>>> where its required and streams support for those that aren’t
> > > >>>>>>>> necessarily.
> > > >>>>>>>> Then one has solved the problem.
> > > >>>>>>>> I repeat it because I think its important. I am really happy
> > that
> > > >>>>>>>> you
> > > >>>>>>>> brought that up! because its 100% what I want just with the
> > > >>>>>>>> differences
> > > >>>>>>>> to
> > > >>>>>>>> have an option to discard the to small topic later (after all
> > > >>>>>>>> consumers
> > > >>>>>>>> adapted). And to have order correct there. I need broker
> support
> > > >>>>>>>> managing
> > > >>>>>>>> the copy process + the produces and fence them against each
> > > other. I
> > > >>>>>>>> also
> > > >>>>>>>> repeat. the copy process can run for weeks in the worst case.
> > > >>>>>>>> Copying
> > > >>>>>>>> the
> > > >>>>>>>> data is not the longest task migrating consumers might very
> well
> > > be.
> > > >>>>>>>> Once all consumers switched and copying is really up to date
> > > (think
> > > >>>>>>>> ISR
> > > >>>>>>>> like up to date) only then we stop the producer, wait for the
> > copy
> > > >>>>>>>> to
> > > >>>>>>>> finish and use the new topic for producing.
> > > >>>>>>>>
> > > >>>>>>>> After this the topic is perfect in shape. and no one needs to
> > > worry
> > > >>>>>>>> about
> > > >>>>>>>> complicated stuff. (old keys hanging around might arrive in
> some
> > > >>>>>>>> other
> > > >>>>>>>> topic later.....). can only imagine how many tricky bugs gonna
> > > >>>>>>>> arrive
> > > >>>>>>>> after
> > > >>>>>>>> someone had grown and shrunken is topic 10 times.
> > > >>>>>>>>
> > > >>>>>>>>
> > > >>>>>>>>
> > > >>>>>>>>
> > > >>>>>>>>
> > > >>>>>>>>
> > > >>>>>>>> 54. "The other thing I wanted to mention is that I believe the
> > > >>>>>>>> current
> > > >>>>>>>>
> > > >>>>>>>> suggestion (without copying data over) can be implemented in
> > pure
> > > >>>>>>>>> userland
> > > >>>>>>>>> with a custom partitioner and a small feedbackloop from
> > > >>>>>>>>> ProduceResponse
> > > >>>>>>>>> =>
> > > >>>>>>>>> Partitionier in coorporation with a change management
> system."
> > I
> > > am
> > > >>>>>>>>> not
> > > >>>>>>>>> sure a customized partitioner itself solves the problem. We
> > > >>>>>>>>> probably
> > > >>>>>>>>> need
> > > >>>>>>>>> some broker side support to enforce when the new partitions
> can
> > > be
> > > >>>>>>>>> used.
> > > >>>>>>>>> We
> > > >>>>>>>>> also need some support on the consumer/kstream side to
> preserve
> > > the
> > > >>>>>>>>> per
> > > >>>>>>>>> key
> > > >>>>>>>>> ordering and potentially migrate the processing state. This
> is
> > > not
> > > >>>>>>>>> trivial
> > > >>>>>>>>> and I am not sure if it's ideal to fully push to the
> > application
> > > >>>>>>>>> space.
> > > >>>>>>>>>
> > > >>>>>>>>> Broker support is defenitly the preferred way here. I have
> > > nothing
> > > >>>>>>>>>
> > > >>>>>>>>> against
> > > >>>>>>>> broker support.
> > > >>>>>>>> I tried to say that for what I would preffer - copying the
> data
> > > >>>>>>>> over,
> > > >>>>>>>> at
> > > >>>>>>>> least for log compacted topics -
> > > >>>>>>>> I would require more broker support than the KIP currently
> > offers.
> > > >>>>>>>>
> > > >>>>>>>>
> > > >>>>>>>>
> > > >>>>>>>> Jun
> > > >>>>>>>>
> > > >>>>>>>> On Tue, Mar 6, 2018 at 10:33 PM, Jan Filipiak <
> > > >>>>>>>>> Jan.Filipiak@trivago.com
> > > >>>>>>>>> wrote:
> > > >>>>>>>>>
> > > >>>>>>>>> Hi Dong,
> > > >>>>>>>>>
> > > >>>>>>>>> are you actually reading my emails, or are you just using the
> > > >>>>>>>>> thread I
> > > >>>>>>>>>
> > > >>>>>>>>>> started for general announcements regarding the KIP?
> > > >>>>>>>>>>
> > > >>>>>>>>>> I tried to argue really hard against linear hashing. Growing
> > the
> > > >>>>>>>>>> topic
> > > >>>>>>>>>> by
> > > >>>>>>>>>> an integer factor does not require any state redistribution
> at
> > > >>>>>>>>>> all. I
> > > >>>>>>>>>> fail
> > > >>>>>>>>>> to see completely where linear hashing helps on log
> compacted
> > > >>>>>>>>>> topics.
> > > >>>>>>>>>>
> > > >>>>>>>>>> If you are not willing to explain to me what I might be
> > > >>>>>>>>>> overlooking:
> > > >>>>>>>>>> that
> > > >>>>>>>>>> is fine.
> > > >>>>>>>>>> But I ask you to not reply to my emails then. Please
> > understand
> > > my
> > > >>>>>>>>>> frustration with this.
> > > >>>>>>>>>>
> > > >>>>>>>>>> Best Jan
> > > >>>>>>>>>>
> > > >>>>>>>>>>
> > > >>>>>>>>>>
> > > >>>>>>>>>> On 06.03.2018 19:38, Dong Lin wrote:
> > > >>>>>>>>>>
> > > >>>>>>>>>> Hi everyone,
> > > >>>>>>>>>>
> > > >>>>>>>>>> Thanks for all the comments! It appears that everyone
> prefers
> > > >>>>>>>>>> linear
> > > >>>>>>>>>>
> > > >>>>>>>>>>> hashing because it reduces the amount of state that needs
> to
> > be
> > > >>>>>>>>>>> moved
> > > >>>>>>>>>>> between consumers (for stream processing). The KIP has been
> > > >>>>>>>>>>> updated
> > > >>>>>>>>>>> to
> > > >>>>>>>>>>> use
> > > >>>>>>>>>>> linear hashing.
> > > >>>>>>>>>>>
> > > >>>>>>>>>>> Regarding the migration endeavor: it seems that migrating
> > > >>>>>>>>>>> producer
> > > >>>>>>>>>>> library
> > > >>>>>>>>>>> to use linear hashing should be pretty straightforward
> > without
> > > >>>>>>>>>>> much operational endeavor. If we don't upgrade client
> library
> > > to
> > > >>>>>>>>>>> use
> > > >>>>>>>>>>> this
> > > >>>>>>>>>>> KIP, we can not support in-order delivery after partition
> is
> > > >>>>>>>>>>> changed
> > > >>>>>>>>>>> anyway. Suppose we upgrade client library to use this KIP,
> if
> > > >>>>>>>>>>> partition
> > > >>>>>>>>>>> number is not changed, the key -> partition mapping will be
> > > >>>>>>>>>>> exactly
> > > >>>>>>>>>>> the
> > > >>>>>>>>>>> same as it is now because it is still determined using
> > > >>>>>>>>>>> murmur_hash(key)
> > > >>>>>>>>>>> %
> > > >>>>>>>>>>> original_partition_num. In other words, this change is
> > backward
> > > >>>>>>>>>>> compatible.
> > > >>>>>>>>>>>
> > > >>>>>>>>>>> Regarding the load distribution: if we use linear hashing,
> > the
> > > >>>>>>>>>>> load
> > > >>>>>>>>>>> may
> > > >>>>>>>>>>> be
> > > >>>>>>>>>>> unevenly distributed because those partitions which are not
> > > split
> > > >>>>>>>>>>> may
> > > >>>>>>>>>>> receive twice as much traffic as other partitions that are
> > > split.
> > > >>>>>>>>>>> This
> > > >>>>>>>>>>> issue can be mitigated by creating topic with partitions
> that
> > > are
> > > >>>>>>>>>>> several
> > > >>>>>>>>>>> times the number of consumers. And there will be no
> imbalance
> > > if
> > > >>>>>>>>>>> the
> > > >>>>>>>>>>> partition number is always doubled. So this imbalance seems
> > > >>>>>>>>>>> acceptable.
> > > >>>>>>>>>>>
> > > >>>>>>>>>>> Regarding storing the partition strategy as per-topic
> config:
> > > It
> > > >>>>>>>>>>> seems
> > > >>>>>>>>>>> not
> > > >>>>>>>>>>> necessary since we can still use murmur_hash as the default
> > > hash
> > > >>>>>>>>>>> function
> > > >>>>>>>>>>> and additionally apply the linear hashing algorithm if the
> > > >>>>>>>>>>> partition
> > > >>>>>>>>>>> number
> > > >>>>>>>>>>> has increased. Not sure if there is any use-case for
> producer
> > > to
> > > >>>>>>>>>>> use a
> > > >>>>>>>>>>> different hash function. Jason, can you check if there is
> > some
> > > >>>>>>>>>>> use-case
> > > >>>>>>>>>>> that I missed for using the per-topic partition strategy?
> > > >>>>>>>>>>>
> > > >>>>>>>>>>> Regarding how to reduce latency (due to state store/load)
> in
> > > >>>>>>>>>>> stream
> > > >>>>>>>>>>> processing consumer when partition number changes: I need
> to
> > > read
> > > >>>>>>>>>>> the
> > > >>>>>>>>>>> Kafka
> > > >>>>>>>>>>> Stream code to understand how Kafka Stream currently
> migrate
> > > >>>>>>>>>>> state
> > > >>>>>>>>>>> between
> > > >>>>>>>>>>> consumers when the application is added/removed for a given
> > > job.
> > > >>>>>>>>>>> I
> > > >>>>>>>>>>> will
> > > >>>>>>>>>>> reply after I finish reading the documentation and code.
> > > >>>>>>>>>>>
> > > >>>>>>>>>>>
> > > >>>>>>>>>>> Thanks,
> > > >>>>>>>>>>> Dong
> > > >>>>>>>>>>>
> > > >>>>>>>>>>>
> > > >>>>>>>>>>> On Mon, Mar 5, 2018 at 10:43 AM, Jason Gustafson <
> > > >>>>>>>>>>> jason@confluent.io>
> > > >>>>>>>>>>> wrote:
> > > >>>>>>>>>>>
> > > >>>>>>>>>>> Great discussion. I think I'm wondering whether we can
> > continue
> > > >>>>>>>>>>> to
> > > >>>>>>>>>>> leave
> > > >>>>>>>>>>>
> > > >>>>>>>>>>> Kafka agnostic to the partitioning strategy. The challenge
> is
> > > >>>>>>>>>>>
> > > >>>>>>>>>>> communicating
> > > >>>>>>>>>>>> the partitioning logic from producers to consumers so that
> > the
> > > >>>>>>>>>>>> dependencies
> > > >>>>>>>>>>>> between each epoch can be determined. For the sake of
> > > >>>>>>>>>>>> discussion,
> > > >>>>>>>>>>>> imagine
> > > >>>>>>>>>>>> you did something like the following:
> > > >>>>>>>>>>>>
> > > >>>>>>>>>>>> 1. The name (and perhaps version) of a partitioning
> strategy
> > > is
> > > >>>>>>>>>>>> stored
> > > >>>>>>>>>>>> in
> > > >>>>>>>>>>>> topic configuration when a topic is created.
> > > >>>>>>>>>>>> 2. The producer looks up the partitioning strategy before
> > > >>>>>>>>>>>> writing
> > > >>>>>>>>>>>> to
> > > >>>>>>>>>>>> a
> > > >>>>>>>>>>>> topic and includes it in the produce request (for
> fencing).
> > If
> > > >>>>>>>>>>>> it
> > > >>>>>>>>>>>> doesn't
> > > >>>>>>>>>>>> have an implementation for the configured strategy, it
> > fails.
> > > >>>>>>>>>>>> 3. The consumer also looks up the partitioning strategy
> and
> > > >>>>>>>>>>>> uses it
> > > >>>>>>>>>>>> to
> > > >>>>>>>>>>>> determine dependencies when reading a new epoch. It could
> > > either
> > > >>>>>>>>>>>> fail
> > > >>>>>>>>>>>> or
> > > >>>>>>>>>>>> make the most conservative dependency assumptions if it
> > > doesn't
> > > >>>>>>>>>>>> know
> > > >>>>>>>>>>>> how
> > > >>>>>>>>>>>> to
> > > >>>>>>>>>>>> implement the partitioning strategy. For the consumer, the
> > new
> > > >>>>>>>>>>>> interface
> > > >>>>>>>>>>>> might look something like this:
> > > >>>>>>>>>>>>
> > > >>>>>>>>>>>> // Return the partition dependencies following an epoch
> bump
> > > >>>>>>>>>>>> Map<Integer, List<Integer>> dependencies(int
> > > >>>>>>>>>>>> numPartitionsBeforeEpochBump,
> > > >>>>>>>>>>>> int numPartitionsAfterEpochBump)
> > > >>>>>>>>>>>>
> > > >>>>>>>>>>>> The unordered case then is just a particular
> implementation
> > > >>>>>>>>>>>> which
> > > >>>>>>>>>>>> never
> > > >>>>>>>>>>>> has
> > > >>>>>>>>>>>> any epoch dependencies. To implement this, we would need
> > some
> > > >>>>>>>>>>>> way
> > > >>>>>>>>>>>> for
> > > >>>>>>>>>>>> the
> > > >>>>>>>>>>>> consumer to find out how many partitions there were in
> each
> > > >>>>>>>>>>>> epoch,
> > > >>>>>>>>>>>> but
> > > >>>>>>>>>>>> maybe that's not too unreasonable.
> > > >>>>>>>>>>>>
> > > >>>>>>>>>>>> Thanks,
> > > >>>>>>>>>>>> Jason
> > > >>>>>>>>>>>>
> > > >>>>>>>>>>>>
> > > >>>>>>>>>>>> On Mon, Mar 5, 2018 at 4:51 AM, Jan Filipiak <
> > > >>>>>>>>>>>> Jan.Filipiak@trivago.com
> > > >>>>>>>>>>>> wrote:
> > > >>>>>>>>>>>>
> > > >>>>>>>>>>>> Hi Dong
> > > >>>>>>>>>>>>
> > > >>>>>>>>>>>> thank you very much for your questions.
> > > >>>>>>>>>>>>
> > > >>>>>>>>>>>> regarding the time spend copying data across:
> > > >>>>>>>>>>>>> It is correct that copying data from a topic with one
> > > partition
> > > >>>>>>>>>>>>> mapping
> > > >>>>>>>>>>>>>
> > > >>>>>>>>>>>>> to
> > > >>>>>>>>>>>>>
> > > >>>>>>>>>>>>> a topic with a different partition mapping takes way
> longer
> > > >>>>>>>>>>>>> than
> > > >>>>>>>>>>>>>
> > > >>>>>>>>>>>> we
> > > >>>>>>>>>>>> can
> > > >>>>>>>>>>>>
> > > >>>>>>>>>>>> stop producers. Tens of minutes is a very optimistic
> > estimate
> > > >>>>>>>>>>>> here.
> > > >>>>>>>>>>>>
> > > >>>>>>>>>>>>> Many
> > > >>>>>>>>>>>>> people can not afford copy full steam and therefore will
> > have
> > > >>>>>>>>>>>>> some
> > > >>>>>>>>>>>>> rate
> > > >>>>>>>>>>>>> limiting in place, this can bump the timespan into the
> > day's.
> > > >>>>>>>>>>>>> The
> > > >>>>>>>>>>>>> good
> > > >>>>>>>>>>>>>
> > > >>>>>>>>>>>>> part
> > > >>>>>>>>>>>>>
> > > >>>>>>>>>>>>> is that the vast majority of the data can be copied while
> > the
> > > >>>>>>>>>>>>>
> > > >>>>>>>>>>>> producers
> > > >>>>>>>>>>>>
> > > >>>>>>>>>>>> are
> > > >>>>>>>>>>>>
> > > >>>>>>>>>>>>> still going. One can then, piggyback the consumers ontop
> of
> > > >>>>>>>>>>>>> this
> > > >>>>>>>>>>>>>
> > > >>>>>>>>>>>> timeframe,
> > > >>>>>>>>>>>>
> > > >>>>>>>>>>>>> by the method mentioned (provide them an mapping from
> their
> > > old
> > > >>>>>>>>>>>>>
> > > >>>>>>>>>>>> offsets
> > > >>>>>>>>>>>>
> > > >>>>>>>>>>>> to
> > > >>>>>>>>>>>>
> > > >>>>>>>>>>>>> new offsets in their repartitioned topics. In that way we
> > > >>>>>>>>>>>>> separate
> > > >>>>>>>>>>>>>
> > > >>>>>>>>>>>> migration of consumers from migration of producers
> > (decoupling
> > > >>>>>>>>>>>>
> > > >>>>>>>>>>>>> these
> > > >>>>>>>>>>>>> is
> > > >>>>>>>>>>>>> what kafka is strongest at). The time to actually swap
> over
> > > the
> > > >>>>>>>>>>>>> producers
> > > >>>>>>>>>>>>> should be kept minimal by ensuring that when a swap
> attempt
> > > is
> > > >>>>>>>>>>>>> started
> > > >>>>>>>>>>>>>
> > > >>>>>>>>>>>>> the
> > > >>>>>>>>>>>>>
> > > >>>>>>>>>>>>> consumer copying over should be very close to the log end
> > and
> > > >>>>>>>>>>>>> is
> > > >>>>>>>>>>>>>
> > > >>>>>>>>>>>> expected
> > > >>>>>>>>>>>>
> > > >>>>>>>>>>>>> to finish within the next fetch. The operation should
> have
> > a
> > > >>>>>>>>>>>>> time-out
> > > >>>>>>>>>>>>> and
> > > >>>>>>>>>>>>> should be "reattemtable".
> > > >>>>>>>>>>>>>
> > > >>>>>>>>>>>>> Importance of logcompaction:
> > > >>>>>>>>>>>>> If a producer produces key A, to partiton 0, its forever
> > > gonna
> > > >>>>>>>>>>>>> be
> > > >>>>>>>>>>>>> there,
> > > >>>>>>>>>>>>> unless it gets deleted. The record might sit in there for
> > > >>>>>>>>>>>>> years. A
> > > >>>>>>>>>>>>> new
> > > >>>>>>>>>>>>> producer started with the new partitions will fail to
> > delete
> > > >>>>>>>>>>>>> the
> > > >>>>>>>>>>>>> record
> > > >>>>>>>>>>>>>
> > > >>>>>>>>>>>>> in
> > > >>>>>>>>>>>>>
> > > >>>>>>>>>>>>> the correct partition. Th record will be there forever
> and
> > > one
> > > >>>>>>>>>>>>> can
> > > >>>>>>>>>>>>>
> > > >>>>>>>>>>>> not
> > > >>>>>>>>>>>>
> > > >>>>>>>>>>>> reliable bootstrap new consumers. I cannot see how linear
> > > >>>>>>>>>>>> hashing
> > > >>>>>>>>>>>>
> > > >>>>>>>>>>>>> can
> > > >>>>>>>>>>>>>
> > > >>>>>>>>>>>>> solve
> > > >>>>>>>>>>>>>
> > > >>>>>>>>>>>>> this.
> > > >>>>>>>>>>>>>
> > > >>>>>>>>>>>> Regarding your skipping of userland copying:
> > > >>>>>>>>>>>>
> > > >>>>>>>>>>>>> 100%, copying the data across in userland is, as far as i
> > can
> > > >>>>>>>>>>>>> see,
> > > >>>>>>>>>>>>> only
> > > >>>>>>>>>>>>> a
> > > >>>>>>>>>>>>> usecase for log compacted topics. Even for logcompaction
> +
> > > >>>>>>>>>>>>> retentions
> > > >>>>>>>>>>>>> it
> > > >>>>>>>>>>>>> should only be opt-in. Why did I bring it up? I think log
> > > >>>>>>>>>>>>> compaction
> > > >>>>>>>>>>>>> is
> > > >>>>>>>>>>>>> a
> > > >>>>>>>>>>>>> very important feature to really embrace kafka as a "data
> > > >>>>>>>>>>>>> plattform".
> > > >>>>>>>>>>>>> The
> > > >>>>>>>>>>>>> point I also want to make is that copying data this way
> is
> > > >>>>>>>>>>>>> completely
> > > >>>>>>>>>>>>> inline with the kafka architecture. it only consists of
> > > reading
> > > >>>>>>>>>>>>> and
> > > >>>>>>>>>>>>>
> > > >>>>>>>>>>>>> writing
> > > >>>>>>>>>>>>>
> > > >>>>>>>>>>>>> to topics.
> > > >>>>>>>>>>>>>
> > > >>>>>>>>>>>> I hope it clarifies more why I think we should aim for
> more
> > > than
> > > >>>>>>>>>>>>
> > > >>>>>>>>>>>>> the
> > > >>>>>>>>>>>>> current KIP. I fear that once the KIP is done not much
> more
> > > >>>>>>>>>>>>> effort
> > > >>>>>>>>>>>>> will
> > > >>>>>>>>>>>>>
> > > >>>>>>>>>>>>> be
> > > >>>>>>>>>>>>>
> > > >>>>>>>>>>>>> taken.
> > > >>>>>>>>>>>>>
> > > >>>>>>>>>>>>
> > > >>>>>>>>>>>> On 04.03.2018 02:28, Dong Lin wrote:
> > > >>>>>>>>>>>>>
> > > >>>>>>>>>>>>> Hey Jan,
> > > >>>>>>>>>>>>>
> > > >>>>>>>>>>>>> In the current proposal, the consumer will be blocked on
> > > >>>>>>>>>>>>> waiting
> > > >>>>>>>>>>>>> for
> > > >>>>>>>>>>>>>
> > > >>>>>>>>>>>>> other
> > > >>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>> consumers of the group to consume up to a given offset.
> In
> > > >>>>>>>>>>>>>> most
> > > >>>>>>>>>>>>>>
> > > >>>>>>>>>>>>> cases,
> > > >>>>>>>>>>>>> all
> > > >>>>>>>>>>>>> consumers should be close to the LEO of the partitions
> when
> > > the
> > > >>>>>>>>>>>>> partition
> > > >>>>>>>>>>>>> expansion happens. Thus the time waiting should not be
> long
> > > >>>>>>>>>>>>> e.g.
> > > >>>>>>>>>>>>> on
> > > >>>>>>>>>>>>> the
> > > >>>>>>>>>>>>>
> > > >>>>>>>>>>>>> order of seconds. On the other hand, it may take a long
> > time
> > > to
> > > >>>>>>>>>>>>> wait
> > > >>>>>>>>>>>>>
> > > >>>>>>>>>>>>> for
> > > >>>>>>>>>>>>>> the entire partition to be copied -- the amount of time
> is
> > > >>>>>>>>>>>>>> proportional
> > > >>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>> to
> > > >>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>> the amount of existing data in the partition, which can
> > take
> > > >>>>>>>>>>>>>>
> > > >>>>>>>>>>>>> tens of
> > > >>>>>>>>>>>>>
> > > >>>>>>>>>>>>> minutes. So the amount of time that we stop consumers may
> > not
> > > >>>>>>>>>>>>> be
> > > >>>>>>>>>>>>> on
> > > >>>>>>>>>>>>>
> > > >>>>>>>>>>>>> the
> > > >>>>>>>>>>>>>> same order of magnitude.
> > > >>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>> If we can implement this suggestion without copying data
> > > over
> > > >>>>>>>>>>>>>> in
> > > >>>>>>>>>>>>>> purse
> > > >>>>>>>>>>>>>> userland, it will be much more valuable. Do you have
> ideas
> > > on
> > > >>>>>>>>>>>>>> how
> > > >>>>>>>>>>>>>> this
> > > >>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>> can
> > > >>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>> be done?
> > > >>>>>>>>>>>>>>
> > > >>>>>>>>>>>>> Not sure why the current KIP not help people who depend
> on
> > > log
> > > >>>>>>>>>>>>>
> > > >>>>>>>>>>>>> compaction.
> > > >>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>> Could you elaborate more on this point?
> > > >>>>>>>>>>>>>>
> > > >>>>>>>>>>>>> Thanks,
> > > >>>>>>>>>>>>>
> > > >>>>>>>>>>>>> Dong
> > > >>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>> On Wed, Feb 28, 2018 at 10:55 PM, Jan
> > > >>>>>>>>>>>>>> Filipiak<Jan.Filipiak@trivago.
> > > >>>>>>>>>>>>>> com
> > > >>>>>>>>>>>>>> wrote:
> > > >>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>> Hi Dong,
> > > >>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>> I tried to focus on what the steps are one can currently
> > > >>>>>>>>>>>>>> perform
> > > >>>>>>>>>>>>>> to
> > > >>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>> expand
> > > >>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>> or shrink a keyed topic while maintaining a top notch
> > > >>>>>>>>>>>>>>> semantics.
> > > >>>>>>>>>>>>>>> I can understand that there might be confusion about
> > > >>>>>>>>>>>>>>> "stopping
> > > >>>>>>>>>>>>>>> the
> > > >>>>>>>>>>>>>>> consumer". It is exactly the same as proposed in the
> KIP.
> > > >>>>>>>>>>>>>>> there
> > > >>>>>>>>>>>>>>> needs
> > > >>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>> to
> > > >>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>> be
> > > >>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>> a time the producers agree on the new partitioning. The
> > > extra
> > > >>>>>>>>>>>>>
> > > >>>>>>>>>>>>> semantics I
> > > >>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>> want to put in there is that we have a possibility to
> > wait
> > > >>>>>>>>>>>>>>> until
> > > >>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>> all
> > > >>>>>>>>>>>>>
> > > >>>>>>>>>>>>> the
> > > >>>>>>>>>>>>>
> > > >>>>>>>>>>>>> existing data
> > > >>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>> is copied over into the new partitioning scheme. When I
> > say
> > > >>>>>>>>>>>>> stopping
> > > >>>>>>>>>>>>>
> > > >>>>>>>>>>>>> I
> > > >>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>> think more of having a memory barrier that ensures the
> > > >>>>>>>>>>>>>>> ordering. I
> > > >>>>>>>>>>>>>>> am
> > > >>>>>>>>>>>>>>> still
> > > >>>>>>>>>>>>>>> aming for latencies  on the scale of leader failovers.
> > > >>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>> Consumers have to explicitly adapt the new partitioning
> > > >>>>>>>>>>>>>>> scheme
> > > >>>>>>>>>>>>>>> in
> > > >>>>>>>>>>>>>>> the
> > > >>>>>>>>>>>>>>> above scenario. The reason is that in these cases where
> > you
> > > >>>>>>>>>>>>>>> are
> > > >>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>> dependent
> > > >>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>> on a particular partitioning scheme, you also have
> other
> > > >>>>>>>>>>>>>>> topics
> > > >>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>> that
> > > >>>>>>>>>>>>>
> > > >>>>>>>>>>>>> have
> > > >>>>>>>>>>>>>
> > > >>>>>>>>>>>>> co-partition enforcements or the kind -frequently.
> > Therefore
> > > >>>>>>>>>>>>>> all
> > > >>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>> your
> > > >>>>>>>>>>>>>
> > > >>>>>>>>>>>>> other
> > > >>>>>>>>>>>>>
> > > >>>>>>>>>>>>> input topics might need to grow accordingly.
> > > >>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>> What I was suggesting was to streamline all these
> > > operations
> > > >>>>>>>>>>>>>>> as
> > > >>>>>>>>>>>>>>> best
> > > >>>>>>>>>>>>>>> as
> > > >>>>>>>>>>>>>>> possible to have "real" partition grow and shrinkage
> > going
> > > >>>>>>>>>>>>>>> on.
> > > >>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>> Migrating
> > > >>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>> the producers to a new partitioning scheme can be much
> > more
> > > >>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>> streamlined
> > > >>>>>>>>>>>>>
> > > >>>>>>>>>>>>> with proper broker support for this. Migrating consumer
> is
> > a
> > > >>>>>>>>>>>>> step
> > > >>>>>>>>>>>>>
> > > >>>>>>>>>>>>> that
> > > >>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>> might be made completly unnecessary if - for example
> > > streams
> > > >>>>>>>>>>>>>>> -
> > > >>>>>>>>>>>>>>> takes
> > > >>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>> the
> > > >>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>> gcd as partitioning scheme instead of enforcing 1 to 1.
> > > >>>>>>>>>>>>>>> Connect
> > > >>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>> consumers
> > > >>>>>>>>>>>>>
> > > >>>>>>>>>>>>> and other consumers should be fine anyways.
> > > >>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>> I hope this makes more clear where I was aiming at. The
> > rest
> > > >>>>>>>>>>>>> needs
> > > >>>>>>>>>>>>>
> > > >>>>>>>>>>>>> to
> > > >>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>> be
> > > >>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>> figured out. The only danger i see is that when we are
> > > >>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>> introducing
> > > >>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>> this
> > > >>>>>>>>>>>>>
> > > >>>>>>>>>>>>> feature as supposed in the KIP, it wont help any people
> > > >>>>>>>>>>>>> depending
> > > >>>>>>>>>>>>> on
> > > >>>>>>>>>>>>>
> > > >>>>>>>>>>>>> log
> > > >>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>> compaction.
> > > >>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>> The other thing I wanted to mention is that I believe
> the
> > > >>>>>>>>>>>>> current
> > > >>>>>>>>>>>>>
> > > >>>>>>>>>>>>> suggestion (without copying data over) can be implemented
> > in
> > > >>>>>>>>>>>>>> pure
> > > >>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>> userland
> > > >>>>>>>>>>>>>>> with a custom partitioner and a small feedbackloop from
> > > >>>>>>>>>>>>>>> ProduceResponse
> > > >>>>>>>>>>>>>>> =>
> > > >>>>>>>>>>>>>>> Partitionier in coorporation with a change management
> > > system.
> > > >>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>> Best Jan
> > > >>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>> On 28.02.2018 07:13, Dong Lin wrote:
> > > >>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>> Hey Jan,
> > > >>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>> I am not sure if it is acceptable for producer to be
> > > stopped
> > > >>>>>>>>>>>>>>> for a
> > > >>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>> while,
> > > >>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>> particularly for online application which requires low
> > > >>>>>>>>>>>>>>>> latency. I
> > > >>>>>>>>>>>>>>>> am
> > > >>>>>>>>>>>>>>>> also
> > > >>>>>>>>>>>>>>>> not sure how consumers can switch to a new topic. Does
> > > user
> > > >>>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>> application
> > > >>>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>> needs to explicitly specify a different topic for
> > > >>>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>> producer/consumer
> > > >>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>> to
> > > >>>>>>>>>>>>>>
> > > >>>>>>>>>>>>> subscribe to? It will be helpful for discussion if you
> can
> > > >>>>>>>>>>>>> provide
> > > >>>>>>>>>>>>>
> > > >>>>>>>>>>>>> more
> > > >>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>> detail on the interface change for this solution.
> > > >>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>> Thanks,
> > > >>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>> Dong
> > > >>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>> On Mon, Feb 26, 2018 at 12:48 AM, Jan
> > > >>>>>>>>>>>>>>>> Filipiak<Jan.Filipiak@trivago.
> > > >>>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>> com
> > > >>>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>> wrote:
> > > >>>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>> Hi,
> > > >>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>> just want to throw my though in. In general the
> > > functionality
> > > >>>>>>>>>>>>>> is
> > > >>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>> very
> > > >>>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>> usefull, we should though not try to find the
> > architecture
> > > >>>>>>>>>>>>>>>> to
> > > >>>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>> hard
> > > >>>>>>>>>>>>>>>>> while
> > > >>>>>>>>>>>>>>>>> implementing.
> > > >>>>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>>> The manual steps would be to
> > > >>>>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>>> create a new topic
> > > >>>>>>>>>>>>>>>>> the mirrormake from the new old topic to the new
> topic
> > > >>>>>>>>>>>>>>>>> wait for mirror making to catch up.
> > > >>>>>>>>>>>>>>>>> then put the consumers onto the new topic
> > > >>>>>>>>>>>>>>>>>            (having mirrormaker spit out a mapping
> from
> > > old
> > > >>>>>>>>>>>>>>>>> offsets to
> > > >>>>>>>>>>>>>>>>> new
> > > >>>>>>>>>>>>>>>>> offsets:
> > > >>>>>>>>>>>>>>>>>                if topic is increased by factor X
> there
> > is
> > > >>>>>>>>>>>>>>>>> gonna
> > > >>>>>>>>>>>>>>>>> be a
> > > >>>>>>>>>>>>>>>>> clean
> > > >>>>>>>>>>>>>>>>> mapping from 1 offset in the old topic to X offsets
> in
> > > the
> > > >>>>>>>>>>>>>>>>> new
> > > >>>>>>>>>>>>>>>>> topic,
> > > >>>>>>>>>>>>>>>>>                if there is no factor then there is no
> > > >>>>>>>>>>>>>>>>> chance to
> > > >>>>>>>>>>>>>>>>> generate a
> > > >>>>>>>>>>>>>>>>> mapping that can be reasonable used for continuing)
> > > >>>>>>>>>>>>>>>>>            make consumers stop at appropriate points
> > and
> > > >>>>>>>>>>>>>>>>> continue
> > > >>>>>>>>>>>>>>>>> consumption
> > > >>>>>>>>>>>>>>>>> with offsets from the mapping.
> > > >>>>>>>>>>>>>>>>> have the producers stop for a minimal time.
> > > >>>>>>>>>>>>>>>>> wait for mirrormaker to finish
> > > >>>>>>>>>>>>>>>>> let producer produce with the new metadata.
> > > >>>>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>>> Instead of implementing the approach suggest in the
> KIP
> > > >>>>>>>>>>>>>>>>> which
> > > >>>>>>>>>>>>>>>>> will
> > > >>>>>>>>>>>>>>>>> leave
> > > >>>>>>>>>>>>>>>>> log compacted topic completely crumbled and unusable.
> > > >>>>>>>>>>>>>>>>> I would much rather try to build infrastructure to
> > > support
> > > >>>>>>>>>>>>>>>>> the
> > > >>>>>>>>>>>>>>>>> mentioned
> > > >>>>>>>>>>>>>>>>> above operations more smoothly.
> > > >>>>>>>>>>>>>>>>> Especially having producers stop and use another
> topic
> > is
> > > >>>>>>>>>>>>>>>>> difficult
> > > >>>>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>>> and
> > > >>>>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>>> it would be nice if one can trigger "invalid
> metadata"
> > > >>>>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>> exceptions
> > > >>>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>> for
> > > >>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>> them
> > > >>>>>>>>>>>>>
> > > >>>>>>>>>>>>> and
> > > >>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>> if one could give topics aliases so that their produces
> > > with
> > > >>>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>>> the
> > > >>>>>>>>>>>>>>>>> old
> > > >>>>>>>>>>>>>>>>> topic
> > > >>>>>>>>>>>>>>>>> will arrive in the new topic.
> > > >>>>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>>> The downsides are obvious I guess ( having the same
> > data
> > > >>>>>>>>>>>>>>>>> twice
> > > >>>>>>>>>>>>>>>>> for
> > > >>>>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>>> the
> > > >>>>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>>> transition period, but kafka tends to scale well with
> > > >>>>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>> datasize).
> > > >>>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>> So
> > > >>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>> its a
> > > >>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>> nicer fit into the architecture.
> > > >>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>> I further want to argument that the functionality by
> the
> > > KIP
> > > >>>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>>> can
> > > >>>>>>>>>>>>>>>>> completely be implementing in "userland" with a
> custom
> > > >>>>>>>>>>>>>>>>> partitioner
> > > >>>>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>>> that
> > > >>>>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>>> handles the transition as needed. I would appreciate
> if
> > > >>>>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>> someone
> > > >>>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>> could
> > > >>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>> point
> > > >>>>>>>>>>>>>
> > > >>>>>>>>>>>>> out what a custom partitioner couldn't handle in this
> case?
> > > >>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>> With the above approach, shrinking a topic becomes the
> > same
> > > >>>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>>> steps.
> > > >>>>>>>>>>>>>>>>> Without
> > > >>>>>>>>>>>>>>>>> loosing keys in the discontinued partitions.
> > > >>>>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>>> Would love to hear what everyone thinks.
> > > >>>>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>>> Best Jan
> > > >>>>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>>> On 11.02.2018 00:35, Dong Lin wrote:
> > > >>>>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>>> Hi all,
> > > >>>>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>>> I have created KIP-253: Support in-order message
> > delivery
> > > >>>>>>>>>>>>>>>>> with
> > > >>>>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>>> partition
> > > >>>>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>>> expansion. See
> > > >>>>>>>>>>>>>>>>>> https://cwiki.apache.org/confl
> > > >>>>>>>>>>>>>>>>>> uence/display/KAFKA/KIP-253%
> > > >>>>>>>>>>>>>>>>>> 3A+Support+in-order+message+de
> > > >>>>>>>>>>>>>>>>>> livery+with+partition+expansio
> > > >>>>>>>>>>>>>>>>>> n
> > > >>>>>>>>>>>>>>>>>> .
> > > >>>>>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>>>> This KIP provides a way to allow messages of the
> same
> > > key
> > > >>>>>>>>>>>>>>>>>> from
> > > >>>>>>>>>>>>>>>>>> the
> > > >>>>>>>>>>>>>>>>>> same
> > > >>>>>>>>>>>>>>>>>> producer to be consumed in the same order they are
> > > >>>>>>>>>>>>>>>>>> produced
> > > >>>>>>>>>>>>>>>>>> even
> > > >>>>>>>>>>>>>>>>>> if
> > > >>>>>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>>>> we
> > > >>>>>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>>>> expand partition of the topic.
> > > >>>>>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>>> Thanks,
> > > >>>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>> Dong
> > > >>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>>>>
> > > >>>>>>>>>>>>>>>>>>
> > > >>>>
> > > >>
> > > >>
> > > >
> > >
> >
>

Re: [DISCUSS] KIP-253: Support in-order message delivery with partition expansion

Posted by Dong Lin <li...@gmail.com>.
BTW, here is my understanding of the scope of this KIP. We want to allow
consumers to always consume messages with the same key from the same
producer in the order they are produced. And we need to provide a way for
stream use-case to be able to flush/load state when messages with the same
key are migrated between consumers. In addition to ensuring that this goal
is correctly supported, we should do our best to keep the performance and
organization overhead of this KIP as low as possible.


On Tue, Mar 27, 2018 at 1:14 PM, Dong Lin <li...@gmail.com> wrote:

> Hey John,
>
> Thanks much for the detailed comments. Here are my thoughts:
>
> - The need to delete messages from log compacted topics is mainly for
> performance (e.g. storage space) optimization than for correctness for this
> KIP. I agree that we probably don't need to focus on this in our discussion
> since it is mostly for performance optimization.
>
> - "Asking producers and consumers, or even two different producers, to
> share code like the partition function is a pretty huge ask. What if they
> are using different languages?". It seems that today we already require
> different producer's to use the same hash function -- otherwise messages
> with the same key will go to different partitions of the same topic which
> may cause problem for downstream consumption. So not sure if it adds any
> more constraint by assuming consumers know the hash function of producer.
> Could you explain more why user would want to use a cusmtom partition
> function? Maybe we can check if this is something that can be supported in
> the default Kafka hash function. Also, can you explain more why it is
> difficuilt to implement the same hash function in different languages?
>
> - Besides the assumption that consumer needs to share the hash function of
> producer, is there other organization overhead of the proposal in the
> current KIP?
>
> - Currently producer can forget about the message that has been
> acknowledged by the broker. Thus the producer probably does not know most
> of the exiting messages in topic, including those messages produced by
> other producers. We can have the owner of the producer to split+backfill.
> In my opion it will be a new program that wraps around the existing
> producer and consumer classes.
>
> - Regarding point 5. The argument is in favor of the split+backfill but
> for changelog topic. And it intends to address the problem for stream
> use-case in general. In this KIP we will provide interface (i.e.
> PartitionKeyRebalanceListener in the KIP) to be used by sream use-case and
> the goal is that user can flush/re-consume the state as part of the
> interface implementation regardless of whether there is change log topic.
>
> Maybe you are suggesting that the main reason to do split+backfill of
> input topic is to support log compacted topics? You mentioned in Point 1
> that log compacted topics is out of the scope of this KIP. Maybe I could
> understand your position better. Regarding Jan's proposal to split
> partitions with backfill, do you think this should replace the proposal in
> the existing KIP, or do you think this is something that we should do in
> addition to the existing KIP?
>
> - Regarding point 6. I guess we can agree that it is better not to have
> the performance overhread of copying the input data. Before we discuss more
> on whether the performance overhead is acceptable or not, I am trying to
> figure out what is the benefit of introducing this overhread. You mentioned
> that the benefit is the loose organizational coupling. By "organizational
> coupling", are you referring to the requirement that consumer needs to know
> the hash function of producer? If so, maybe we can discuss the use-case of
> custom partiton function and see whether we can find a way to support such
> use-case without having to copy the input data.
>
> Thanks,
> Dong
>
>
> On Tue, Mar 27, 2018 at 11:34 AM, John Roesler <jo...@confluent.io> wrote:
>
>> Hey Dong and Jun,
>>
>> Thanks for the thoughtful responses. If you don't mind, I'll mix my
>> replies
>> together to try for a coherent response. I'm not too familiar with
>> mailing-list etiquette, though.
>>
>> I'm going to keep numbering my points because it makes it easy for you all
>> to respond.
>>
>> Point 1:
>> As I read it, KIP-253 is *just* about properly fencing the producers and
>> consumers so that you preserve the correct ordering of records during
>> partition expansion. This is clearly necessary regardless of anything else
>> we discuss. I think this whole discussion about backfill, consumers,
>> streams, etc., is beyond the scope of KIP-253. But it would be cumbersome
>> to start a new thread at this point.
>>
>> I had missed KIP-253's Proposed Change #9 among all the details... I think
>> this is a nice addition to the proposal. One thought is that it's actually
>> irrelevant whether the hash function is linear. This is simply an
>> algorithm
>> for moving a key from one partition to another, so the type of hash
>> function need not be a precondition. In fact, it also doesn't matter
>> whether the topic is compacted or not, the algorithm works regardless.
>>
>> I think this is a good algorithm to keep in mind, as it might solve a
>> variety of problems, but it does have a downside: that the producer won't
>> know whether or not K1 was actually in P1, it just knows that K1 was in
>> P1's keyspace before the new epoch. Therefore, it will have to
>> pessimistically send (K1,null) to P1 just in case. But the next time K1
>> comes along, the producer *also* won't remember that it already retracted
>> K1 from P1, so it will have to send (K1,null) *again*. By extension, every
>> time the producer sends to P2, it will also have to send a tombstone to
>> P1,
>> which is a pretty big burden. To make the situation worse, if there is a
>> second split, say P2 becomes P2 and P3, then any key Kx belonging to P3
>> will also have to be retracted from P2 *and* P1, since the producer can't
>> know whether Kx had been last written to P2 or P1. Over a long period of
>> time, this clearly becomes a issue, as the producer must send an arbitrary
>> number of retractions along with every update.
>>
>> In contrast, the proposed backfill operation has an end, and after it
>> ends,
>> everyone can afford to forget that there ever was a different partition
>> layout.
>>
>> Really, though, figuring out how to split compacted topics is beyond the
>> scope of KIP-253, so I'm not sure #9 really even needs to be in this
>> KIP...
>> We do need in-order delivery during partition expansion. It would be fine
>> by me to say that you *cannot* expand partitions of a log-compacted topic
>> and call it a day. I think it would be better to tackle that in another
>> KIP.
>>
>>
>> Point 2:
>> Regarding whether the consumer re-shuffles its inputs, this is always on
>> the table; any consumer who wants to re-shuffle its input is free to do
>> so.
>> But this is currently not required. It's just that the current high-level
>> story with Kafka encourages the use of partitions as a unit of
>> concurrency.
>> As long as consumers are single-threaded, they can happily consume a
>> single
>> partition without concurrency control of any kind. This is a key aspect to
>> this system that lets folks design high-throughput systems on top of it
>> surprisingly easily. If all consumers were instead encouraged/required to
>> implement a repartition of their own, then the consumer becomes
>> significantly more complex, requiring either the consumer to first produce
>> to its own intermediate repartition topic or to ensure that consumer
>> threads have a reliable, high-bandwith channel of communication with every
>> other consumer thread.
>>
>> Either of those tradeoffs may be reasonable for a particular user of
>> Kafka,
>> but I don't know if we're in a position to say that they are reasonable
>> for
>> *every* user of Kafka.
>>
>>
>> Point 3:
>> Regarding Jun's point about this use case, "(3) stateful and maintaining
>> the
>> states in a local store", I agree that they may use a framework *like*
>> Kafka Streams, but that is not the same as using Kafka Streams. This is
>> why
>> I think it's better to solve it in Core: because it is then solved for
>> KStreams and also for everything else that facilitates local state
>> maintenance. To me, Streams is a member of the category of "stream
>> processing frameworks", which is itself a subcategory of "things requiring
>> local state maintenence". I'm not sure if it makes sense to assert that
>> Streams is a sufficient and practical replacement for everything in
>> "things
>> requiring local state maintenence".
>>
>> But, yes, I do agree that per-key ordering is an absolute requirement,
>> therefore I think that KIP-253 itself is a necessary step. Regarding the
>> coupling of the state store partitioning to the topic partitioning, yes,
>> this is an issue we are discussing solutions to right now. We may go ahead
>> and introduce an overpartition layer on our inputs to solve it, but then
>> again, if we get the ability to split partitions with backfill, we may not
>> need to!
>>
>>
>> Point 4:
>> On this:
>>
>> > Regarding thought 2: If we don't care about the stream use-case, then
>> the
>> > current KIP probably has already addressed problem without requiring
>> > consumer to know the partition function. If we care about the stream
>> > use-case, we already need coordination across producers of different
>> > topics, i.e. the same partition function needs to be used by producers
>> of
>> > topics A and B in order to join topics A and B. Thus, it might be
>> > reasonable to extend coordination a bit and say we need coordination
>> across
>> > clients (i.e. producer and consumer), such that consumer knows the
>> > partition function used by producer. If we do so, then we can let
>> consumer
>> > re-copy data for the change log topic using the same partition function
>> as
>> > producer. This approach has lower overhead as compared to having
>> producer
>> > re-copy data of the input topic.
>> > Also, producer currently does not need to know the data already
>> produced to
>> > the topic. If we let producer split/merge partition, it would require
>> > producer to consume the existing data, which intuitively is the task of
>> > consumer.
>>
>>
>> I think we do care about use cases *like* Streams, I just don't think we
>> should rely on Streams to implement a feature of Core like partition
>> expansion.
>>
>> Note, though, that we (Streams) do not require coordination across
>> producers. If two topics are certified to be co-partitioned, then Streams
>> apps can make use of that knowledge to optimize their topology (skipping a
>> repartition). But if they don't know whether they are co-partitioned, then
>> they'd better go ahead and repartition within the topology. This is the
>> current state.
>>
>> A huge selling point of Kafka is enabling different parts of loosely
>> coupled organizations to produce and consume data independently. Some
>> coordination between producers and consumers is necessary, like
>> coordinating on the names of topics and their schemas. But Kafka's value
>> proposition w.r.t. ESBs, etc. is inversely proportional to the amount of
>> coordination required. I think it behooves us to be extremely skeptical
>> about introducing any coordination beyond correctness protocols.
>>
>> Asking producers and consumers, or even two different producers, to share
>> code like the partition function is a pretty huge ask. What if they are
>> using different languages?
>>
>> Comparing organizational overhead vs computational overhead, there are
>> maybe two orders of magnitude difference between them. In other words, I
>> would happily take on the (linear) overhead of having the producer re-copy
>> the data once during a re-partition in order to save the organizational
>> overhead of tying all the producers and consumers together across multiple
>> boundaries.
>>
>> On that last paragraph: note that the producer *did* know the data it
>> already produced. It handled it the first time around. Asking it to
>> re-produce it into a new partition layout is squarely within its scope of
>> capabilities. Contrast this with the alternative, asking the consumer to
>> re-partition the data. I think this is even less intuitive, when the
>> partition function belongs to the producer.
>>
>>
>> Point 5:
>> Dong asked this:
>>
>> > For stream use-case that needs to increase consumer number, the
>> > existing consumer can backfill the existing data in the change log
>> topic to
>> > the same change log topic with the new partition number, before the new
>> set
>> > of consumers bootstrap state from the new partitions of the change log
>> > topic, right?
>>
>>
>> In this sense, the "consumer" is actually the producer of the changelog
>> topic, so if we support partition expansion + backfill as a
>> producer/broker
>> operation, then it would be very straightforward for Streams to split a
>> state store. As you say, they would simply instruct the broker to split
>> the
>> changelog topic's partitions, then backfill. Once the backfill is ready,
>> they can create a new crop of StandbyTasks to bootstrap the more granular
>> state stores and finally switch over to them when they are ready.
>>
>> But this actually seems to be an argument in favor of split+backfill, so
>> maybe I missed the point.
>>
>> You also asked me to explain why copying the "input" topic is better than
>> copying the "changelog" topic. I think they are totally independent,
>> actually. For one thing, you can't depend on the existence of a
>> "changelog"
>> topic in general, only within Streams, but Kafka's user base clearly
>> exceeds Streams's user base. Plus, you actually also can't depend on the
>> existence of a changelog topic within Streams, since that is an optional
>> feature of *some* state store implementations. Even in the situation where
>> you do have a changelog topic in Streams, there may be use cases where it
>> makes sense to expand the partitions of just the input, or just the
>> changelog.
>>
>> The ask for a Core feature of split+backfill is really about supporting
>> the
>> use case of splitting partitions in log-compacted topics, regardless of
>> whether that topic is an "input" or a "changelog" or anything else for
>> that
>> matter.
>>
>>
>> Point 6:
>> On the concern about the performance overhead of copying data between the
>> brokers, I think it's actually a bit overestimated. Splitting a topic's
>> partition is probably rare, certainly rarer in general than bootstrapping
>> new consumers on that topic. If "bootstrapping new consumers" means that
>> they have to re-shuffle the data before they consume it, then you wind up
>> copying the same record multiple times:
>>
>> (broker: input topic) -> (initial consumer) -> (broker: repartition topic)
>> -> (real consumer)
>>
>> That's 3x, and it's also 3x for every new record after the split as well,
>> since you don't get to stop repartitioning/reshuffling once you start.
>>
>> Whereas if you do a backfill in something like the procedure I outlined,
>> you only copy the prefix of the partition before the split, and you send
>> it
>> once to the producer and then once to the new generation partition. Plus,
>> assuming we're splitting the partition for the benefit of consumers,
>> there's no reason we can't co-locate the post-split partitions on the same
>> host as the pre-split partition, making the second copy a local filesystem
>> operation.
>>
>> Even if you follow these two copies up with bootstrapping a new consumer,
>> it's still rare for this to occur, so you get to amortize these copies
>> over
>> the lifetime of the topic, whereas a reshuffle just keeps making copies
>> for
>> every new event.
>>
>> And finally, I really do think that regardless of any performance concerns
>> about this operation, if it preserves loose organizational coupling, it is
>> certainly worth it.
>>
>>
>> In conclusion:
>> It might actually be a good idea for us to clarify the scope of KIP-253.
>> If
>> we're all agreed that it's a good algorithm for allowing in-order message
>> delivery during partition expansion, then we can continue this discussion
>> as a new KIP, something like "backfill with partition expansion". This
>> would let Dong proceed with KIP-253. On the other hand, if it seems like
>> this conversation may alter the design of KIP-253, then maybe we *should*
>> just finish working it out.
>>
>> For my part, my only concern about KIP-253 is the one I raised earlier.
>>
>> Thanks again, all, for considering these points,
>> -John
>>
>>
>> On Tue, Mar 27, 2018 at 2:10 AM, Dong Lin <li...@gmail.com> wrote:
>>
>> > On Tue, Mar 27, 2018 at 12:04 AM, Dong Lin <li...@gmail.com> wrote:
>> >
>> > > Hey Jan,
>> > >
>> > > Thanks for the enthusiasm in improving Kafka's design. Now that I have
>> > > read through your discussion with Jun, here are my thoughts:
>> > >
>> > > - The latest proposal should with log compacted topics by properly
>> > > deleting old messages after a new message with the same key is
>> produced.
>> > So
>> > > it is probably not a concern anymore. Could you comment if there is
>> still
>> > > issue?
>> > >
>> > > - I wrote the SEP-5 and I am pretty familiar with the motivation and
>> the
>> > > design of SEP-5. SEP-5 is probably orthornal to the motivation of this
>> > KIP.
>> > > The goal of SEP-5 is to allow user to increase task number of an
>> existing
>> > > Samza job. But if we increase the partition number of input topics,
>> > > messages may still be consumed out-of-order by tasks in Samza which
>> cause
>> > > incorrect result. Similarly, the approach you proposed does not seem
>> to
>> > > ensure that the messages can be delivered in order, even if we can
>> make
>> > > sure that each consumer instance is assigned the set of new partitions
>> > > covering the same set of keys.
>> > >
>> >
>> > Let me correct this comment. The approach of copying data to a new topic
>> > can ensure in-order message delivery suppose we properly migrate offsets
>> > from old topic to new topic.
>> >
>> >
>> > > - I am trying to understand why it is better to copy the data instead
>> of
>> > > copying the change log topic for streaming use-case. For core Kafka
>> > > use-case, and for the stream use-case that does not need to increase
>> > > consumers, the current KIP already supports in-order delivery without
>> the
>> > > overhead of copying the data. For stream use-case that needs to
>> increase
>> > > consumer number, the existing consumer can backfill the existing data
>> in
>> > > the change log topic to the same change log topic with the new
>> partition
>> > > number, before the new set of consumers bootstrap state from the new
>> > > partitions of the change log topic. If this solution works, then could
>> > you
>> > > summarize the advantage of copying the data of input topic as
>> compared to
>> > > copying the change log topic? For example, does it enable more
>> use-case,
>> > > simplify the implementation of Kafka library, or reduce the operation
>> > > overhead etc?
>> > >
>> > > Thanks,
>> > > Dong
>> > >
>> > >
>> > > On Wed, Mar 21, 2018 at 6:57 AM, Jan Filipiak <
>> Jan.Filipiak@trivago.com>
>> > > wrote:
>> > >
>> > >> Hi Jun,
>> > >>
>> > >> I was really seeing progress in our conversation but your latest
>> reply
>> > is
>> > >> just devastating.
>> > >> I though we were getting close being on the same page now it feels
>> like
>> > >> we are in different libraries.
>> > >>
>> > >> I just quickly slam my answers in here. If they are to brief I am
>> sorry
>> > >> give me a ping and try to go into details more.
>> > >> Just want to show that your pro/cons listing is broken.
>> > >>
>> > >> Best Jan
>> > >>
>> > >> and want to get rid of this horrible compromise
>> > >>
>> > >>
>> > >> On 19.03.2018 05:48, Jun Rao wrote:
>> > >>
>> > >>> Hi, Jan,
>> > >>>
>> > >>> Thanks for the discussion. Great points.
>> > >>>
>> > >>> Let me try to summarize the approach that you are proposing. On the
>> > >>> broker
>> > >>> side, we reshuffle the existing data in a topic from current
>> partitions
>> > >>> to
>> > >>> the new partitions. Once the reshuffle fully catches up, switch the
>> > >>> consumers to start consuming from the new partitions. If a consumer
>> > needs
>> > >>> to rebuild its local state (due to partition changes), let the
>> consumer
>> > >>> rebuild its state by reading all existing data from the new
>> partitions.
>> > >>> Once all consumers have switches over, cut over the producer to the
>> new
>> > >>> partitions.
>> > >>>
>> > >>> The pros for this approach are that :
>> > >>> 1. There is just one way to rebuild the local state, which is
>> simpler.
>> > >>>
>> > >> true thanks
>> > >>
>> > >>>
>> > >>> The cons for this approach are:
>> > >>> 1. Need to copy existing data.
>> > >>>
>> > >> Very unfair and not correct. It does not require you to copy over
>> > >> existing data. It _allows_ you to copy all existing data.
>> > >>
>> > >> 2. The cutover of the producer is a bit complicated since it needs to
>> > >>> coordinate with all consumer groups.
>> > >>>
>> > >> Also not true. I explicitly tried to make clear that there is only
>> one
>> > >> special consumer (in the case of actually copying data) coordination
>> is
>> > >> required.
>> > >>
>> > >>> 3. The rebuilding of the state in the consumer is from the input
>> topic,
>> > >>> which can be more expensive than rebuilding from the existing state.
>> > >>>
>> > >> true, but rebuilding state is only required if you want to increase
>> > >> processing power, so we assume this is at hand.
>> > >>
>> > >>> 4. The broker potentially has to know the partitioning function. If
>> > this
>> > >>> needs to be customized at the topic level, it can be a bit messy.
>> > >>>
>> > >> I would argue against having the operation being performed by the
>> > broker.
>> > >> This was not discussed yet but if you see my original email i
>> suggested
>> > >> otherwise from the beginning.
>> > >>
>> > >>>
>> > >>> Here is an alternative approach by applying your idea not in the
>> > broker,
>> > >>> but in the consumer. When new partitions are added, we don't move
>> > >>> existing
>> > >>> data. In KStreams, we first reshuffle the new input data to a new
>> topic
>> > >>> T1
>> > >>> with the old number of partitions and feed T1's data to the rest of
>> the
>> > >>> pipeline. In the meantime, KStreams reshuffles all existing data of
>> the
>> > >>> change capture topic to another topic C1 with the new number of
>> > >>> partitions.
>> > >>> We can then build the state of the new tasks from C1. Once the new
>> > states
>> > >>> have been fully built, we can cut over the consumption to the input
>> > topic
>> > >>> and delete T1. This approach works with compacted topic too. If an
>> > >>> application reads from the beginning of a compacted topic, the
>> consumer
>> > >>> will reshuffle the portion of the input when the number of
>> partitions
>> > >>> doesn't match the number of tasks.
>> > >>>
>> > >> We all wipe this idea from our heads instantly. Mixing Ideas from an
>> > >> argument is not a resolution strategy
>> > >> just leads to horrible horrible software.
>> > >>
>> > >>
>> > >>> The pros of this approach are:
>> > >>> 1. No need to copy existing data.
>> > >>> 2. Each consumer group can cut over to the new partitions
>> > independently.
>> > >>> 3. The state is rebuilt from the change capture topic, which is
>> cheaper
>> > >>> than rebuilding from the input topic.
>> > >>> 4. Only the KStreams job needs to know the partitioning function.
>> > >>>
>> > >>> The cons of this approach are:
>> > >>> 1. Potentially the same input topic needs to be reshuffled more than
>> > once
>> > >>> in different consumer groups during the transition phase.
>> > >>>
>> > >>> What do you think?
>> > >>>
>> > >>> Thanks,
>> > >>>
>> > >>> Jun
>> > >>>
>> > >>>
>> > >>>
>> > >>> On Thu, Mar 15, 2018 at 1:04 AM, Jan Filipiak <
>> > Jan.Filipiak@trivago.com>
>> > >>> wrote:
>> > >>>
>> > >>> Hi Jun,
>> > >>>>
>> > >>>> thank you for following me on these thoughts. It was important to
>> me
>> > to
>> > >>>> feel that kind of understanding for my arguments.
>> > >>>>
>> > >>>> What I was hoping for (I mentioned this earlier) is that we can
>> model
>> > >>>> the
>> > >>>> case where we do not want to copy the data the exact same way as
>> the
>> > >>>> case
>> > >>>> when we do copy the data. Maybe you can peek into the mails before
>> to
>> > >>>> see
>> > >>>> more details for this.
>> > >>>>
>> > >>>> This means we have the same mechanism to transfer consumer groups
>> to
>> > >>>> switch topic. The offset mapping that would be generated would
>> even be
>> > >>>> simpler End Offset of the Old topic => offset 0 off all the
>> partitions
>> > >>>> of
>> > >>>> the new topic. Then we could model the transition of a non-copy
>> > >>>> expansion
>> > >>>> the exact same way as a copy-expansion.
>> > >>>>
>> > >>>> I know this only works when topic growth by a factor. But the
>> benefits
>> > >>>> of
>> > >>>> only growing by a factor are to strong anyways. See Clemens's hint
>> and
>> > >>>> remember that state reshuffling is entirely not needed if one
>> doesn't
>> > >>>> want
>> > >>>> to grow processing power.
>> > >>>>
>> > >>>> I think these benefits should be clear, and that there is
>> basically no
>> > >>>> downside to what is currently at hand but just makes everything
>> easy.
>> > >>>>
>> > >>>> One thing you need to know is. that if you do not offer rebuilding
>> a
>> > log
>> > >>>> compacted topic like i suggest that even if you have consumer state
>> > >>>> reshuffling. The topic is broken and can not be used to bootstrap
>> new
>> > >>>> consumers. They don't know if they need to apply a key from and old
>> > >>>> partition or not. This is a horrible downside I haven't seen a
>> > solution
>> > >>>> for
>> > >>>> in the email conversation.
>> > >>>>
>> > >>>> I argue to:
>> > >>>>
>> > >>>> Only grow topic by a factor always.
>> > >>>> Have the "no copy consumer" transition as the trivial case of the
>> > "copy
>> > >>>> consumer transition".
>> > >>>> If processors needs to be scaled, let them rebuild from the new
>> topic
>> > >>>> and
>> > >>>> leave the old running in the mean time.
>> > >>>> Do not implement key shuffling in streams.
>> > >>>>
>> > >>>> I hope I can convince you especially with the fact how I want to
>> > handle
>> > >>>> consumer transition. I think
>> > >>>> you didn't quite understood me there before. I think the term "new
>> > >>>> topic"
>> > >>>> intimidated you a little.
>> > >>>> How we solve this on disc doesn't really matter, If the data goes
>> into
>> > >>>> the
>> > >>>> same Dir or a different Dir or anything. I do think that it needs
>> to
>> > >>>> involve at least rolling a new segment for the existing partitions.
>> > >>>> But most of the transitions should work without restarting
>> consumers.
>> > >>>> (newer consumers with support for this). But with new topic i just
>> > meant
>> > >>>> the topic that now has a different partition count. Plenty of ways
>> to
>> > >>>> handle that (versions, aliases)
>> > >>>>
>> > >>>> Hope I can further get my idea across.
>> > >>>>
>> > >>>> Best Jan
>> > >>>>
>> > >>>>
>> > >>>>
>> > >>>>
>> > >>>>
>> > >>>>
>> > >>>> On 14.03.2018 02:45, Jun Rao wrote:
>> > >>>>
>> > >>>> Hi, Jan,
>> > >>>>>
>> > >>>>> Thanks for sharing your view.
>> > >>>>>
>> > >>>>> I agree with you that recopying the data potentially makes the
>> state
>> > >>>>> management easier since the consumer can just rebuild its state
>> from
>> > >>>>> scratch (i.e., no need for state reshuffling).
>> > >>>>>
>> > >>>>> On the flip slide, I saw a few disadvantages of the approach that
>> you
>> > >>>>> suggested. (1) Building the state from the input topic from
>> scratch
>> > is
>> > >>>>> in
>> > >>>>> general less efficient than state reshuffling. Let's say one
>> > computes a
>> > >>>>> count per key from an input topic. The former requires reading all
>> > >>>>> existing
>> > >>>>> records in the input topic whereas the latter only requires
>> reading
>> > >>>>> data
>> > >>>>> proportional to the number of unique keys. (2) The switching of
>> the
>> > >>>>> topic
>> > >>>>> needs modification to the application. If there are many
>> applications
>> > >>>>> on a
>> > >>>>> topic, coordinating such an effort may not be easy. Also, it's not
>> > >>>>> clear
>> > >>>>> how to enforce exactly-once semantic during the switch. (3) If a
>> > topic
>> > >>>>> doesn't need any state management, recopying the data seems
>> wasteful.
>> > >>>>> In
>> > >>>>> that case, in place partition expansion seems more desirable.
>> > >>>>>
>> > >>>>> I understand your concern about adding complexity in KStreams.
>> But,
>> > >>>>> perhaps
>> > >>>>> we could iterate on that a bit more to see if it can be
>> simplified.
>> > >>>>>
>> > >>>>> Jun
>> > >>>>>
>> > >>>>>
>> > >>>>> On Mon, Mar 12, 2018 at 11:21 PM, Jan Filipiak <
>> > >>>>> Jan.Filipiak@trivago.com>
>> > >>>>> wrote:
>> > >>>>>
>> > >>>>> Hi Jun,
>> > >>>>>
>> > >>>>>> I will focus on point 61 as I think its _the_ fundamental part
>> that
>> > I
>> > >>>>>> cant
>> > >>>>>> get across at the moment.
>> > >>>>>>
>> > >>>>>> Kafka is the platform to have state materialized multiple times
>> from
>> > >>>>>> one
>> > >>>>>> input. I emphasize this: It is the building block in
>> architectures
>> > >>>>>> that
>> > >>>>>> allow you to
>> > >>>>>> have your state maintained multiple times. You put a message in
>> > once,
>> > >>>>>> and
>> > >>>>>> you have it pop out as often as you like. I believe you
>> understand
>> > >>>>>> this.
>> > >>>>>>
>> > >>>>>> Now! The path of thinking goes the following: I am using apache
>> > kafka
>> > >>>>>> and
>> > >>>>>> I _want_ my state multiple times. What am I going todo?
>> > >>>>>>
>> > >>>>>> A) Am I going to take my state that I build up, plunge some sort
>> of
>> > >>>>>> RPC
>> > >>>>>> layer ontop of it, use that RPC layer to throw my records across
>> > >>>>>> instances?
>> > >>>>>> B) Am I just going to read the damn message twice?
>> > >>>>>>
>> > >>>>>> Approach A is fundamentally flawed and a violation of all that is
>> > good
>> > >>>>>> and
>> > >>>>>> holy in kafka deployments. I can not understand how this Idea can
>> > >>>>>> come in
>> > >>>>>> the first place.
>> > >>>>>> (I do understand: IQ in streams, they polluted the kafka streams
>> > >>>>>> codebase
>> > >>>>>> really bad already. It is not funny! I think they are equally
>> flawed
>> > >>>>>> as
>> > >>>>>> A)
>> > >>>>>>
>> > >>>>>> I say, we do what Kafka is good at. We repartition the topic
>> once.
>> > We
>> > >>>>>> switch the consumers.
>> > >>>>>> (Those that need more partitions are going to rebuild their
>> state in
>> > >>>>>> multiple partitions by reading the new topic, those that don't
>> just
>> > >>>>>> assign
>> > >>>>>> the new partitions properly)
>> > >>>>>> We switch producers. Done!
>> > >>>>>>
>> > >>>>>> The best thing! It is trivial, hipster stream processor will
>> have an
>> > >>>>>> easy
>> > >>>>>> time with that aswell. Its so super simple. And simple IS good!
>> > >>>>>> It is what kafka was build todo. It is how we do it today. All I
>> am
>> > >>>>>> saying
>> > >>>>>> is that a little broker help doing the producer swap is super
>> > useful.
>> > >>>>>>
>> > >>>>>> For everyone interested in why kafka is so powerful with
>> approach B,
>> > >>>>>> please watch https://youtu.be/bEbeZPVo98c?t=1633
>> > >>>>>> I already looked up a good point in time, I think after 5 minutes
>> > the
>> > >>>>>> "state" topic is handled and you should be able to understand me
>> > >>>>>> and inch better.
>> > >>>>>>
>> > >>>>>> Please do not do A to the project, it deserves better!
>> > >>>>>>
>> > >>>>>> Best Jan
>> > >>>>>>
>> > >>>>>>
>> > >>>>>>
>> > >>>>>> On 13.03.2018 02:40, Jun Rao wrote:
>> > >>>>>>
>> > >>>>>> Hi, Jan,
>> > >>>>>>
>> > >>>>>>> Thanks for the reply. A few more comments below.
>> > >>>>>>>
>> > >>>>>>> 50. Ok, we can think a bit harder for supporting compacted
>> topics.
>> > >>>>>>>
>> > >>>>>>> 51. This is a fundamental design question. In the more common
>> case,
>> > >>>>>>> the
>> > >>>>>>> reason why someone wants to increase the number of partitions is
>> > that
>> > >>>>>>> the
>> > >>>>>>> consumer application is slow and one wants to run more consumer
>> > >>>>>>> instances
>> > >>>>>>> to increase the degree of parallelism. So, fixing the number of
>> > >>>>>>> running
>> > >>>>>>> consumer instances when expanding the partitions won't help this
>> > >>>>>>> case.
>> > >>>>>>> If
>> > >>>>>>> we do need to increase the number of consumer instances, we
>> need to
>> > >>>>>>> somehow
>> > >>>>>>> reshuffle the state of the consumer across instances. What we
>> have
>> > >>>>>>> been
>> > >>>>>>> discussing in this KIP is whether we can do this more
>> effectively
>> > >>>>>>> through
>> > >>>>>>> the KStream library (e.g. through a 2-phase partition
>> expansion).
>> > >>>>>>> This
>> > >>>>>>> will
>> > >>>>>>> add some complexity, but it's probably better than everyone
>> doing
>> > >>>>>>> this
>> > >>>>>>> in
>> > >>>>>>> the application space. The recopying approach that you mentioned
>> > >>>>>>> doesn't
>> > >>>>>>> seem to address the consumer state management issue when the
>> > consumer
>> > >>>>>>> switches from an old to a new topic.
>> > >>>>>>>
>> > >>>>>>> 52. As for your example, it depends on whether the join key is
>> the
>> > >>>>>>> same
>> > >>>>>>> between (A,B) and (B,C). If the join key is the same, we can do
>> a
>> > >>>>>>> 2-phase
>> > >>>>>>> partition expansion of A, B, and C together. If the join keys
>> are
>> > >>>>>>> different, one would need to repartition the data on a different
>> > key
>> > >>>>>>> for
>> > >>>>>>> the second join, then the partition expansion can be done
>> > >>>>>>> independently
>> > >>>>>>> between (A,B) and (B,C).
>> > >>>>>>>
>> > >>>>>>> 53. If you always fix the number of consumer instances, we you
>> > >>>>>>> described
>> > >>>>>>> works. However, as I mentioned in #51, I am not sure how your
>> > >>>>>>> proposal
>> > >>>>>>> deals with consumer states when the number of consumer instances
>> > >>>>>>> grows.
>> > >>>>>>> Also, it just seems that it's better to avoid re-copying the
>> > existing
>> > >>>>>>> data.
>> > >>>>>>>
>> > >>>>>>> 60. "just want to throw in my question from the longer email in
>> the
>> > >>>>>>> other
>> > >>>>>>> Thread here. How will the bloom filter help a new consumer to
>> > decide
>> > >>>>>>> to
>> > >>>>>>> apply the key or not?" Not sure that I fully understood your
>> > >>>>>>> question.
>> > >>>>>>> The
>> > >>>>>>> consumer just reads whatever key is in the log. The bloom filter
>> > just
>> > >>>>>>> helps
>> > >>>>>>> clean up the old keys.
>> > >>>>>>>
>> > >>>>>>> 61. "Why can we afford having a topic where its apparently not
>> > >>>>>>> possible
>> > >>>>>>> to
>> > >>>>>>> start a new application on? I think this is an overall flaw of
>> the
>> > >>>>>>> discussed idea here. Not playing attention to the overall
>> > >>>>>>> architecture."
>> > >>>>>>> Could you explain a bit more when one can't start a new
>> > application?
>> > >>>>>>>
>> > >>>>>>> Jun
>> > >>>>>>>
>> > >>>>>>>
>> > >>>>>>>
>> > >>>>>>> On Sat, Mar 10, 2018 at 1:40 AM, Jan Filipiak <
>> > >>>>>>> Jan.Filipiak@trivago.com
>> > >>>>>>> wrote:
>> > >>>>>>>
>> > >>>>>>> Hi Jun, thanks for your mail.
>> > >>>>>>>
>> > >>>>>>> Thank you for your questions!
>> > >>>>>>>> I think they are really good and tackle the core of the
>> problem I
>> > >>>>>>>> see.
>> > >>>>>>>>
>> > >>>>>>>> I will answer inline, mostly but still want to set the tone
>> here.
>> > >>>>>>>>
>> > >>>>>>>> The core strength of kafka is what Martin once called the
>> > >>>>>>>> kappa-Architecture. How does this work?
>> > >>>>>>>> You have everything as a log as in kafka. When you need to
>> change
>> > >>>>>>>> something.
>> > >>>>>>>> You create the new version of your application and leave it
>> > running
>> > >>>>>>>> in
>> > >>>>>>>> parallel.
>> > >>>>>>>> Once the new version is good you switch your users to use the
>> new
>> > >>>>>>>> application.
>> > >>>>>>>>
>> > >>>>>>>> The online reshuffling effectively breaks this architecture
>> and I
>> > >>>>>>>> think
>> > >>>>>>>> the switch in thinking here is more harmful
>> > >>>>>>>> than any details about the partitioning function to allow such
>> a
>> > >>>>>>>> change.
>> > >>>>>>>> I
>> > >>>>>>>> feel with my suggestion we are the closest to
>> > >>>>>>>> the original and battle proven architecture and I can only
>> warn to
>> > >>>>>>>> move
>> > >>>>>>>> away from it.
>> > >>>>>>>>
>> > >>>>>>>> I might have forgotten something, sometimes its hard for me to
>> > >>>>>>>> getting
>> > >>>>>>>> all
>> > >>>>>>>> the thoughts captured in a mail, but I hope the comments inline
>> > will
>> > >>>>>>>> further make my concern clear, and put some emphasis on why I
>> > >>>>>>>> prefer my
>> > >>>>>>>> solution ;)
>> > >>>>>>>>
>> > >>>>>>>> One thing we should all be aware of when discussing this, and I
>> > >>>>>>>> think
>> > >>>>>>>> Dong
>> > >>>>>>>> should have mentioned it (maybe he did).
>> > >>>>>>>> We are not discussing all of this out of thin air but there is
>> an
>> > >>>>>>>> effort
>> > >>>>>>>> in the Samza project.
>> > >>>>>>>>
>> > >>>>>>>> https://cwiki.apache.org/confluence/display/SAMZA/SEP-5%3A+
>> > >>>>>>>> Enable+partition+expansion+of+input+streams
>> > >>>>>>>> https://issues.apache.org/jira/browse/SAMZA-1293
>> > >>>>>>>>
>> > >>>>>>>> To be clear. I think SEP-5 (state of last week, dont know if it
>> > >>>>>>>> adapted
>> > >>>>>>>> to
>> > >>>>>>>> this discussion) is on a way better path than KIP-253, and I
>> can't
>> > >>>>>>>> really
>> > >>>>>>>> explain why.
>> > >>>>>>>>
>> > >>>>>>>> Best Jan,
>> > >>>>>>>>
>> > >>>>>>>> nice weekend everyone
>> > >>>>>>>>
>> > >>>>>>>>
>> > >>>>>>>> On 09.03.2018 03:36, Jun Rao wrote:
>> > >>>>>>>>
>> > >>>>>>>> Hi, Jan,
>> > >>>>>>>>
>> > >>>>>>>> Thanks for the feedback. Just some comments on the earlier
>> points
>> > >>>>>>>>> that
>> > >>>>>>>>> you
>> > >>>>>>>>> mentioned.
>> > >>>>>>>>>
>> > >>>>>>>>> 50. You brought up the question of whether existing data
>> needs to
>> > >>>>>>>>> be
>> > >>>>>>>>> copied
>> > >>>>>>>>> during partition expansion. My understand of your view is that
>> > >>>>>>>>> avoid
>> > >>>>>>>>> copying existing data will be more efficient, but it doesn't
>> work
>> > >>>>>>>>> well
>> > >>>>>>>>> with
>> > >>>>>>>>> compacted topics since some keys in the original partitions
>> will
>> > >>>>>>>>> never
>> > >>>>>>>>> be
>> > >>>>>>>>> cleaned. It would be useful to understand your use case of
>> > >>>>>>>>> compacted
>> > >>>>>>>>> topics
>> > >>>>>>>>> a bit more. In the common use case, the data volume in a
>> > compacted
>> > >>>>>>>>> topic
>> > >>>>>>>>> may not be large. So, I am not sure if there is a strong need
>> to
>> > >>>>>>>>> expand
>> > >>>>>>>>> partitions in a compacted topic, at least initially.
>> > >>>>>>>>>
>> > >>>>>>>>> I do agree. State is usually smaller. Update rates might be
>> also
>> > >>>>>>>>>
>> > >>>>>>>>> competitively high.
>> > >>>>>>>> Doing Log-compaction (even beeing very efficient and
>> configurable)
>> > >>>>>>>> is
>> > >>>>>>>> also
>> > >>>>>>>> a more expensive operation than
>> > >>>>>>>> just discarding old segments. Further if you want to use more
>> > >>>>>>>> consumers
>> > >>>>>>>> processing the events
>> > >>>>>>>> you also have to grow the number of partitions. Especially for
>> > >>>>>>>> use-cases
>> > >>>>>>>> we do (KIP-213) a tiny state full
>> > >>>>>>>> table might be very expensive to process if it joins against a
>> > huge
>> > >>>>>>>> table.
>> > >>>>>>>>
>> > >>>>>>>> I can just say we have been in the spot of needing to grow log
>> > >>>>>>>> compacted
>> > >>>>>>>> topics. Mainly for processing power we can bring to the table.
>> > >>>>>>>>
>> > >>>>>>>> Further i am not at all concerned about the extra spaced used
>> by
>> > >>>>>>>> "garbage
>> > >>>>>>>> keys". I am more concerned about the correctness of innocent
>> > >>>>>>>> consumers.
>> > >>>>>>>> The
>> > >>>>>>>> logic becomes complicated. Say for streams one would need to
>> load
>> > >>>>>>>> the
>> > >>>>>>>> record into state but not forward it the topology ( to have it
>> > >>>>>>>> available
>> > >>>>>>>> for shuffeling). I rather have it simple and a topic clean
>> > >>>>>>>> regardless
>> > >>>>>>>> if
>> > >>>>>>>> it
>> > >>>>>>>> still has its old partition count. Especially with multiple
>> > >>>>>>>> partitions
>> > >>>>>>>> growth's I think it becomes insanely hard to to this shuffle
>> > >>>>>>>> correct.
>> > >>>>>>>> Maybe
>> > >>>>>>>> Streams and Samza can do it. Especially if you do "hipster
>> stream
>> > >>>>>>>> processing" <https://www.confluent.io/blog
>> > >>>>>>>> /introducing-kafka-streams-
>> > >>>>>>>> stream-processing-made-simple/>. This makes kafka way to
>> > >>>>>>>> complicated.
>> > >>>>>>>> With my approach I think its way simpler because the topic has
>> no
>> > >>>>>>>> "history"
>> > >>>>>>>> in terms of partitioning but is always clean.
>> > >>>>>>>>
>> > >>>>>>>>
>> > >>>>>>>> 51. "Growing the topic by an integer factor does not require
>> any
>> > >>>>>>>> state
>> > >>>>>>>>
>> > >>>>>>>> redistribution at all." Could you clarify this a bit more?
>> Let's
>> > say
>> > >>>>>>>>> you
>> > >>>>>>>>> have a consumer app that computes the windowed count per key.
>> If
>> > >>>>>>>>> you
>> > >>>>>>>>> double
>> > >>>>>>>>> the number of partitions from 1 to 2 and grow the consumer
>> > >>>>>>>>> instances
>> > >>>>>>>>> from
>> > >>>>>>>>> 1
>> > >>>>>>>>> to 2, we would need to redistribute some of the counts to the
>> new
>> > >>>>>>>>> consumer
>> > >>>>>>>>> instance. Regarding to linear hashing, it's true that it won't
>> > >>>>>>>>> solve
>> > >>>>>>>>> the
>> > >>>>>>>>> problem with compacted topics. The main benefit is that it
>> > >>>>>>>>> redistributes
>> > >>>>>>>>> the keys in one partition to no more than two partitions,
>> which
>> > >>>>>>>>> could
>> > >>>>>>>>> help
>> > >>>>>>>>> redistribute the state.
>> > >>>>>>>>>
>> > >>>>>>>>> You don't need to spin up a new consumer in this case. every
>> > >>>>>>>>> consumer
>> > >>>>>>>>>
>> > >>>>>>>>> would just read every partition with the (partition %
>> num_task)
>> > >>>>>>>> task.
>> > >>>>>>>> it
>> > >>>>>>>> will still have the previous data right there and can go on.
>> > >>>>>>>>
>> > >>>>>>>> This sounds contradictory to what I said before, but please
>> bear
>> > >>>>>>>> with
>> > >>>>>>>> me.
>> > >>>>>>>>
>> > >>>>>>>> 52. Good point on coordinating the expansion of 2 topics that
>> need
>> > >>>>>>>> to
>> > >>>>>>>> be
>> > >>>>>>>>
>> > >>>>>>>> joined together. This is where the 2-phase partition expansion
>> > could
>> > >>>>>>>>> potentially help. In the first phase, we could add new
>> partitions
>> > >>>>>>>>> to
>> > >>>>>>>>> the 2
>> > >>>>>>>>> topics one at a time but without publishing to the new
>> patitions.
>> > >>>>>>>>> Then,
>> > >>>>>>>>> we
>> > >>>>>>>>> can add new consumer instances to pick up the new partitions.
>> In
>> > >>>>>>>>> this
>> > >>>>>>>>> transition phase, no reshuffling is needed since no data is
>> > coming
>> > >>>>>>>>> from
>> > >>>>>>>>> the
>> > >>>>>>>>> new partitions. Finally, we can enable the publishing to the
>> new
>> > >>>>>>>>> partitions.
>> > >>>>>>>>>
>> > >>>>>>>>> I think its even worse than you think. I would like to
>> introduce
>> > >>>>>>>>> the
>> > >>>>>>>>>
>> > >>>>>>>>> Term
>> > >>>>>>>> transitive copartitioning. Imagine
>> > >>>>>>>> 2 streams application. One joins (A,B) the other (B,C) then
>> there
>> > >>>>>>>> is a
>> > >>>>>>>> transitive copartition requirement for
>> > >>>>>>>> (A,C) to be copartitioned aswell. This can spread significantly
>> > and
>> > >>>>>>>> require many consumers to adapt at the same time.
>> > >>>>>>>>
>> > >>>>>>>> It is also not entirely clear to me how you not need
>> reshuffling
>> > in
>> > >>>>>>>> this
>> > >>>>>>>> case. If A has a record that never gets updated after the
>> > expansion
>> > >>>>>>>> and
>> > >>>>>>>> the
>> > >>>>>>>> coresponding B record moves to a new partition. How shall they
>> > meet
>> > >>>>>>>> w/o
>> > >>>>>>>> shuffle?
>> > >>>>>>>>
>> > >>>>>>>> 53. "Migrating consumer is a step that might be made completly
>> > >>>>>>>>
>> > >>>>>>>> unnecessary
>> > >>>>>>>>> if - for example streams - takes the gcd as partitioning
>> scheme
>> > >>>>>>>>> instead
>> > >>>>>>>>> of
>> > >>>>>>>>> enforcing 1 to 1." Not sure that I fully understand this. I
>> think
>> > >>>>>>>>> you
>> > >>>>>>>>> mean
>> > >>>>>>>>> that a consumer application can run more instances than the
>> > number
>> > >>>>>>>>> of
>> > >>>>>>>>> partitions. In that case, the consumer can just repartitioning
>> > the
>> > >>>>>>>>> input
>> > >>>>>>>>> data according to the number of instances. This is possible,
>> but
>> > >>>>>>>>> just
>> > >>>>>>>>> has
>> > >>>>>>>>> the overhead of reshuffling the data.
>> > >>>>>>>>>
>> > >>>>>>>>> No what I meant is ( that is also your question i think
>> Mathias)
>> > >>>>>>>>> that
>> > >>>>>>>>> if
>> > >>>>>>>>>
>> > >>>>>>>>> you grow a topic by a factor.
>> > >>>>>>>> Even if your processor is statefull you can can just assign all
>> > the
>> > >>>>>>>> multiples of the previous partition to
>> > >>>>>>>> this consumer and the state to keep processing correctly will
>> be
>> > >>>>>>>> present
>> > >>>>>>>> w/o any shuffling.
>> > >>>>>>>>
>> > >>>>>>>> Say you have an assignment
>> > >>>>>>>> Statefull consumer => partition
>> > >>>>>>>> 0 => 0
>> > >>>>>>>> 1 => 1
>> > >>>>>>>> 2 => 2
>> > >>>>>>>>
>> > >>>>>>>> and you grow you topic by 4 you get,
>> > >>>>>>>>
>> > >>>>>>>> 0 => 0,3,6,9
>> > >>>>>>>> 1 => 1,4,7,10
>> > >>>>>>>> 2 => 2,5,8,11
>> > >>>>>>>>
>> > >>>>>>>> Say your hashcode is 8. 8%3 => 2  before so consumer for
>> > partition 2
>> > >>>>>>>> has
>> > >>>>>>>> it.
>> > >>>>>>>> Now you you have 12 partitions so 8%12 => 8, so it goes into
>> > >>>>>>>> partition
>> > >>>>>>>> 8
>> > >>>>>>>> which is assigned to the same consumer
>> > >>>>>>>> who had 2 before and therefore knows the key.
>> > >>>>>>>>
>> > >>>>>>>> Userland reshuffeling is there as an options. And it does
>> exactly
>> > >>>>>>>> what
>> > >>>>>>>> I
>> > >>>>>>>> suggest. And I think its the perfect strategie. All I am
>> > suggestion
>> > >>>>>>>> is
>> > >>>>>>>> broker side support to switch the producers to the newly
>> > partitioned
>> > >>>>>>>> topic.
>> > >>>>>>>> Then the old (to few partition topic) can go away.  Remember
>> the
>> > >>>>>>>> list
>> > >>>>>>>> of
>> > >>>>>>>> steps in the beginning of this thread. If one has broker
>> support
>> > for
>> > >>>>>>>> all
>> > >>>>>>>> where its required and streams support for those that aren’t
>> > >>>>>>>> necessarily.
>> > >>>>>>>> Then one has solved the problem.
>> > >>>>>>>> I repeat it because I think its important. I am really happy
>> that
>> > >>>>>>>> you
>> > >>>>>>>> brought that up! because its 100% what I want just with the
>> > >>>>>>>> differences
>> > >>>>>>>> to
>> > >>>>>>>> have an option to discard the to small topic later (after all
>> > >>>>>>>> consumers
>> > >>>>>>>> adapted). And to have order correct there. I need broker
>> support
>> > >>>>>>>> managing
>> > >>>>>>>> the copy process + the produces and fence them against each
>> > other. I
>> > >>>>>>>> also
>> > >>>>>>>> repeat. the copy process can run for weeks in the worst case.
>> > >>>>>>>> Copying
>> > >>>>>>>> the
>> > >>>>>>>> data is not the longest task migrating consumers might very
>> well
>> > be.
>> > >>>>>>>> Once all consumers switched and copying is really up to date
>> > (think
>> > >>>>>>>> ISR
>> > >>>>>>>> like up to date) only then we stop the producer, wait for the
>> copy
>> > >>>>>>>> to
>> > >>>>>>>> finish and use the new topic for producing.
>> > >>>>>>>>
>> > >>>>>>>> After this the topic is perfect in shape. and no one needs to
>> > worry
>> > >>>>>>>> about
>> > >>>>>>>> complicated stuff. (old keys hanging around might arrive in
>> some
>> > >>>>>>>> other
>> > >>>>>>>> topic later.....). can only imagine how many tricky bugs gonna
>> > >>>>>>>> arrive
>> > >>>>>>>> after
>> > >>>>>>>> someone had grown and shrunken is topic 10 times.
>> > >>>>>>>>
>> > >>>>>>>>
>> > >>>>>>>>
>> > >>>>>>>>
>> > >>>>>>>>
>> > >>>>>>>>
>> > >>>>>>>> 54. "The other thing I wanted to mention is that I believe the
>> > >>>>>>>> current
>> > >>>>>>>>
>> > >>>>>>>> suggestion (without copying data over) can be implemented in
>> pure
>> > >>>>>>>>> userland
>> > >>>>>>>>> with a custom partitioner and a small feedbackloop from
>> > >>>>>>>>> ProduceResponse
>> > >>>>>>>>> =>
>> > >>>>>>>>> Partitionier in coorporation with a change management
>> system." I
>> > am
>> > >>>>>>>>> not
>> > >>>>>>>>> sure a customized partitioner itself solves the problem. We
>> > >>>>>>>>> probably
>> > >>>>>>>>> need
>> > >>>>>>>>> some broker side support to enforce when the new partitions
>> can
>> > be
>> > >>>>>>>>> used.
>> > >>>>>>>>> We
>> > >>>>>>>>> also need some support on the consumer/kstream side to
>> preserve
>> > the
>> > >>>>>>>>> per
>> > >>>>>>>>> key
>> > >>>>>>>>> ordering and potentially migrate the processing state. This is
>> > not
>> > >>>>>>>>> trivial
>> > >>>>>>>>> and I am not sure if it's ideal to fully push to the
>> application
>> > >>>>>>>>> space.
>> > >>>>>>>>>
>> > >>>>>>>>> Broker support is defenitly the preferred way here. I have
>> > nothing
>> > >>>>>>>>>
>> > >>>>>>>>> against
>> > >>>>>>>> broker support.
>> > >>>>>>>> I tried to say that for what I would preffer - copying the data
>> > >>>>>>>> over,
>> > >>>>>>>> at
>> > >>>>>>>> least for log compacted topics -
>> > >>>>>>>> I would require more broker support than the KIP currently
>> offers.
>> > >>>>>>>>
>> > >>>>>>>>
>> > >>>>>>>>
>> > >>>>>>>> Jun
>> > >>>>>>>>
>> > >>>>>>>> On Tue, Mar 6, 2018 at 10:33 PM, Jan Filipiak <
>> > >>>>>>>>> Jan.Filipiak@trivago.com
>> > >>>>>>>>> wrote:
>> > >>>>>>>>>
>> > >>>>>>>>> Hi Dong,
>> > >>>>>>>>>
>> > >>>>>>>>> are you actually reading my emails, or are you just using the
>> > >>>>>>>>> thread I
>> > >>>>>>>>>
>> > >>>>>>>>>> started for general announcements regarding the KIP?
>> > >>>>>>>>>>
>> > >>>>>>>>>> I tried to argue really hard against linear hashing. Growing
>> the
>> > >>>>>>>>>> topic
>> > >>>>>>>>>> by
>> > >>>>>>>>>> an integer factor does not require any state redistribution
>> at
>> > >>>>>>>>>> all. I
>> > >>>>>>>>>> fail
>> > >>>>>>>>>> to see completely where linear hashing helps on log compacted
>> > >>>>>>>>>> topics.
>> > >>>>>>>>>>
>> > >>>>>>>>>> If you are not willing to explain to me what I might be
>> > >>>>>>>>>> overlooking:
>> > >>>>>>>>>> that
>> > >>>>>>>>>> is fine.
>> > >>>>>>>>>> But I ask you to not reply to my emails then. Please
>> understand
>> > my
>> > >>>>>>>>>> frustration with this.
>> > >>>>>>>>>>
>> > >>>>>>>>>> Best Jan
>> > >>>>>>>>>>
>> > >>>>>>>>>>
>> > >>>>>>>>>>
>> > >>>>>>>>>> On 06.03.2018 19:38, Dong Lin wrote:
>> > >>>>>>>>>>
>> > >>>>>>>>>> Hi everyone,
>> > >>>>>>>>>>
>> > >>>>>>>>>> Thanks for all the comments! It appears that everyone prefers
>> > >>>>>>>>>> linear
>> > >>>>>>>>>>
>> > >>>>>>>>>>> hashing because it reduces the amount of state that needs
>> to be
>> > >>>>>>>>>>> moved
>> > >>>>>>>>>>> between consumers (for stream processing). The KIP has been
>> > >>>>>>>>>>> updated
>> > >>>>>>>>>>> to
>> > >>>>>>>>>>> use
>> > >>>>>>>>>>> linear hashing.
>> > >>>>>>>>>>>
>> > >>>>>>>>>>> Regarding the migration endeavor: it seems that migrating
>> > >>>>>>>>>>> producer
>> > >>>>>>>>>>> library
>> > >>>>>>>>>>> to use linear hashing should be pretty straightforward
>> without
>> > >>>>>>>>>>> much operational endeavor. If we don't upgrade client
>> library
>> > to
>> > >>>>>>>>>>> use
>> > >>>>>>>>>>> this
>> > >>>>>>>>>>> KIP, we can not support in-order delivery after partition is
>> > >>>>>>>>>>> changed
>> > >>>>>>>>>>> anyway. Suppose we upgrade client library to use this KIP,
>> if
>> > >>>>>>>>>>> partition
>> > >>>>>>>>>>> number is not changed, the key -> partition mapping will be
>> > >>>>>>>>>>> exactly
>> > >>>>>>>>>>> the
>> > >>>>>>>>>>> same as it is now because it is still determined using
>> > >>>>>>>>>>> murmur_hash(key)
>> > >>>>>>>>>>> %
>> > >>>>>>>>>>> original_partition_num. In other words, this change is
>> backward
>> > >>>>>>>>>>> compatible.
>> > >>>>>>>>>>>
>> > >>>>>>>>>>> Regarding the load distribution: if we use linear hashing,
>> the
>> > >>>>>>>>>>> load
>> > >>>>>>>>>>> may
>> > >>>>>>>>>>> be
>> > >>>>>>>>>>> unevenly distributed because those partitions which are not
>> > split
>> > >>>>>>>>>>> may
>> > >>>>>>>>>>> receive twice as much traffic as other partitions that are
>> > split.
>> > >>>>>>>>>>> This
>> > >>>>>>>>>>> issue can be mitigated by creating topic with partitions
>> that
>> > are
>> > >>>>>>>>>>> several
>> > >>>>>>>>>>> times the number of consumers. And there will be no
>> imbalance
>> > if
>> > >>>>>>>>>>> the
>> > >>>>>>>>>>> partition number is always doubled. So this imbalance seems
>> > >>>>>>>>>>> acceptable.
>> > >>>>>>>>>>>
>> > >>>>>>>>>>> Regarding storing the partition strategy as per-topic
>> config:
>> > It
>> > >>>>>>>>>>> seems
>> > >>>>>>>>>>> not
>> > >>>>>>>>>>> necessary since we can still use murmur_hash as the default
>> > hash
>> > >>>>>>>>>>> function
>> > >>>>>>>>>>> and additionally apply the linear hashing algorithm if the
>> > >>>>>>>>>>> partition
>> > >>>>>>>>>>> number
>> > >>>>>>>>>>> has increased. Not sure if there is any use-case for
>> producer
>> > to
>> > >>>>>>>>>>> use a
>> > >>>>>>>>>>> different hash function. Jason, can you check if there is
>> some
>> > >>>>>>>>>>> use-case
>> > >>>>>>>>>>> that I missed for using the per-topic partition strategy?
>> > >>>>>>>>>>>
>> > >>>>>>>>>>> Regarding how to reduce latency (due to state store/load) in
>> > >>>>>>>>>>> stream
>> > >>>>>>>>>>> processing consumer when partition number changes: I need to
>> > read
>> > >>>>>>>>>>> the
>> > >>>>>>>>>>> Kafka
>> > >>>>>>>>>>> Stream code to understand how Kafka Stream currently migrate
>> > >>>>>>>>>>> state
>> > >>>>>>>>>>> between
>> > >>>>>>>>>>> consumers when the application is added/removed for a given
>> > job.
>> > >>>>>>>>>>> I
>> > >>>>>>>>>>> will
>> > >>>>>>>>>>> reply after I finish reading the documentation and code.
>> > >>>>>>>>>>>
>> > >>>>>>>>>>>
>> > >>>>>>>>>>> Thanks,
>> > >>>>>>>>>>> Dong
>> > >>>>>>>>>>>
>> > >>>>>>>>>>>
>> > >>>>>>>>>>> On Mon, Mar 5, 2018 at 10:43 AM, Jason Gustafson <
>> > >>>>>>>>>>> jason@confluent.io>
>> > >>>>>>>>>>> wrote:
>> > >>>>>>>>>>>
>> > >>>>>>>>>>> Great discussion. I think I'm wondering whether we can
>> continue
>> > >>>>>>>>>>> to
>> > >>>>>>>>>>> leave
>> > >>>>>>>>>>>
>> > >>>>>>>>>>> Kafka agnostic to the partitioning strategy. The challenge
>> is
>> > >>>>>>>>>>>
>> > >>>>>>>>>>> communicating
>> > >>>>>>>>>>>> the partitioning logic from producers to consumers so that
>> the
>> > >>>>>>>>>>>> dependencies
>> > >>>>>>>>>>>> between each epoch can be determined. For the sake of
>> > >>>>>>>>>>>> discussion,
>> > >>>>>>>>>>>> imagine
>> > >>>>>>>>>>>> you did something like the following:
>> > >>>>>>>>>>>>
>> > >>>>>>>>>>>> 1. The name (and perhaps version) of a partitioning
>> strategy
>> > is
>> > >>>>>>>>>>>> stored
>> > >>>>>>>>>>>> in
>> > >>>>>>>>>>>> topic configuration when a topic is created.
>> > >>>>>>>>>>>> 2. The producer looks up the partitioning strategy before
>> > >>>>>>>>>>>> writing
>> > >>>>>>>>>>>> to
>> > >>>>>>>>>>>> a
>> > >>>>>>>>>>>> topic and includes it in the produce request (for
>> fencing). If
>> > >>>>>>>>>>>> it
>> > >>>>>>>>>>>> doesn't
>> > >>>>>>>>>>>> have an implementation for the configured strategy, it
>> fails.
>> > >>>>>>>>>>>> 3. The consumer also looks up the partitioning strategy and
>> > >>>>>>>>>>>> uses it
>> > >>>>>>>>>>>> to
>> > >>>>>>>>>>>> determine dependencies when reading a new epoch. It could
>> > either
>> > >>>>>>>>>>>> fail
>> > >>>>>>>>>>>> or
>> > >>>>>>>>>>>> make the most conservative dependency assumptions if it
>> > doesn't
>> > >>>>>>>>>>>> know
>> > >>>>>>>>>>>> how
>> > >>>>>>>>>>>> to
>> > >>>>>>>>>>>> implement the partitioning strategy. For the consumer, the
>> new
>> > >>>>>>>>>>>> interface
>> > >>>>>>>>>>>> might look something like this:
>> > >>>>>>>>>>>>
>> > >>>>>>>>>>>> // Return the partition dependencies following an epoch
>> bump
>> > >>>>>>>>>>>> Map<Integer, List<Integer>> dependencies(int
>> > >>>>>>>>>>>> numPartitionsBeforeEpochBump,
>> > >>>>>>>>>>>> int numPartitionsAfterEpochBump)
>> > >>>>>>>>>>>>
>> > >>>>>>>>>>>> The unordered case then is just a particular implementation
>> > >>>>>>>>>>>> which
>> > >>>>>>>>>>>> never
>> > >>>>>>>>>>>> has
>> > >>>>>>>>>>>> any epoch dependencies. To implement this, we would need
>> some
>> > >>>>>>>>>>>> way
>> > >>>>>>>>>>>> for
>> > >>>>>>>>>>>> the
>> > >>>>>>>>>>>> consumer to find out how many partitions there were in each
>> > >>>>>>>>>>>> epoch,
>> > >>>>>>>>>>>> but
>> > >>>>>>>>>>>> maybe that's not too unreasonable.
>> > >>>>>>>>>>>>
>> > >>>>>>>>>>>> Thanks,
>> > >>>>>>>>>>>> Jason
>> > >>>>>>>>>>>>
>> > >>>>>>>>>>>>
>> > >>>>>>>>>>>> On Mon, Mar 5, 2018 at 4:51 AM, Jan Filipiak <
>> > >>>>>>>>>>>> Jan.Filipiak@trivago.com
>> > >>>>>>>>>>>> wrote:
>> > >>>>>>>>>>>>
>> > >>>>>>>>>>>> Hi Dong
>> > >>>>>>>>>>>>
>> > >>>>>>>>>>>> thank you very much for your questions.
>> > >>>>>>>>>>>>
>> > >>>>>>>>>>>> regarding the time spend copying data across:
>> > >>>>>>>>>>>>> It is correct that copying data from a topic with one
>> > partition
>> > >>>>>>>>>>>>> mapping
>> > >>>>>>>>>>>>>
>> > >>>>>>>>>>>>> to
>> > >>>>>>>>>>>>>
>> > >>>>>>>>>>>>> a topic with a different partition mapping takes way
>> longer
>> > >>>>>>>>>>>>> than
>> > >>>>>>>>>>>>>
>> > >>>>>>>>>>>> we
>> > >>>>>>>>>>>> can
>> > >>>>>>>>>>>>
>> > >>>>>>>>>>>> stop producers. Tens of minutes is a very optimistic
>> estimate
>> > >>>>>>>>>>>> here.
>> > >>>>>>>>>>>>
>> > >>>>>>>>>>>>> Many
>> > >>>>>>>>>>>>> people can not afford copy full steam and therefore will
>> have
>> > >>>>>>>>>>>>> some
>> > >>>>>>>>>>>>> rate
>> > >>>>>>>>>>>>> limiting in place, this can bump the timespan into the
>> day's.
>> > >>>>>>>>>>>>> The
>> > >>>>>>>>>>>>> good
>> > >>>>>>>>>>>>>
>> > >>>>>>>>>>>>> part
>> > >>>>>>>>>>>>>
>> > >>>>>>>>>>>>> is that the vast majority of the data can be copied while
>> the
>> > >>>>>>>>>>>>>
>> > >>>>>>>>>>>> producers
>> > >>>>>>>>>>>>
>> > >>>>>>>>>>>> are
>> > >>>>>>>>>>>>
>> > >>>>>>>>>>>>> still going. One can then, piggyback the consumers ontop
>> of
>> > >>>>>>>>>>>>> this
>> > >>>>>>>>>>>>>
>> > >>>>>>>>>>>> timeframe,
>> > >>>>>>>>>>>>
>> > >>>>>>>>>>>>> by the method mentioned (provide them an mapping from
>> their
>> > old
>> > >>>>>>>>>>>>>
>> > >>>>>>>>>>>> offsets
>> > >>>>>>>>>>>>
>> > >>>>>>>>>>>> to
>> > >>>>>>>>>>>>
>> > >>>>>>>>>>>>> new offsets in their repartitioned topics. In that way we
>> > >>>>>>>>>>>>> separate
>> > >>>>>>>>>>>>>
>> > >>>>>>>>>>>> migration of consumers from migration of producers
>> (decoupling
>> > >>>>>>>>>>>>
>> > >>>>>>>>>>>>> these
>> > >>>>>>>>>>>>> is
>> > >>>>>>>>>>>>> what kafka is strongest at). The time to actually swap
>> over
>> > the
>> > >>>>>>>>>>>>> producers
>> > >>>>>>>>>>>>> should be kept minimal by ensuring that when a swap
>> attempt
>> > is
>> > >>>>>>>>>>>>> started
>> > >>>>>>>>>>>>>
>> > >>>>>>>>>>>>> the
>> > >>>>>>>>>>>>>
>> > >>>>>>>>>>>>> consumer copying over should be very close to the log end
>> and
>> > >>>>>>>>>>>>> is
>> > >>>>>>>>>>>>>
>> > >>>>>>>>>>>> expected
>> > >>>>>>>>>>>>
>> > >>>>>>>>>>>>> to finish within the next fetch. The operation should
>> have a
>> > >>>>>>>>>>>>> time-out
>> > >>>>>>>>>>>>> and
>> > >>>>>>>>>>>>> should be "reattemtable".
>> > >>>>>>>>>>>>>
>> > >>>>>>>>>>>>> Importance of logcompaction:
>> > >>>>>>>>>>>>> If a producer produces key A, to partiton 0, its forever
>> > gonna
>> > >>>>>>>>>>>>> be
>> > >>>>>>>>>>>>> there,
>> > >>>>>>>>>>>>> unless it gets deleted. The record might sit in there for
>> > >>>>>>>>>>>>> years. A
>> > >>>>>>>>>>>>> new
>> > >>>>>>>>>>>>> producer started with the new partitions will fail to
>> delete
>> > >>>>>>>>>>>>> the
>> > >>>>>>>>>>>>> record
>> > >>>>>>>>>>>>>
>> > >>>>>>>>>>>>> in
>> > >>>>>>>>>>>>>
>> > >>>>>>>>>>>>> the correct partition. Th record will be there forever and
>> > one
>> > >>>>>>>>>>>>> can
>> > >>>>>>>>>>>>>
>> > >>>>>>>>>>>> not
>> > >>>>>>>>>>>>
>> > >>>>>>>>>>>> reliable bootstrap new consumers. I cannot see how linear
>> > >>>>>>>>>>>> hashing
>> > >>>>>>>>>>>>
>> > >>>>>>>>>>>>> can
>> > >>>>>>>>>>>>>
>> > >>>>>>>>>>>>> solve
>> > >>>>>>>>>>>>>
>> > >>>>>>>>>>>>> this.
>> > >>>>>>>>>>>>>
>> > >>>>>>>>>>>> Regarding your skipping of userland copying:
>> > >>>>>>>>>>>>
>> > >>>>>>>>>>>>> 100%, copying the data across in userland is, as far as i
>> can
>> > >>>>>>>>>>>>> see,
>> > >>>>>>>>>>>>> only
>> > >>>>>>>>>>>>> a
>> > >>>>>>>>>>>>> usecase for log compacted topics. Even for logcompaction +
>> > >>>>>>>>>>>>> retentions
>> > >>>>>>>>>>>>> it
>> > >>>>>>>>>>>>> should only be opt-in. Why did I bring it up? I think log
>> > >>>>>>>>>>>>> compaction
>> > >>>>>>>>>>>>> is
>> > >>>>>>>>>>>>> a
>> > >>>>>>>>>>>>> very important feature to really embrace kafka as a "data
>> > >>>>>>>>>>>>> plattform".
>> > >>>>>>>>>>>>> The
>> > >>>>>>>>>>>>> point I also want to make is that copying data this way is
>> > >>>>>>>>>>>>> completely
>> > >>>>>>>>>>>>> inline with the kafka architecture. it only consists of
>> > reading
>> > >>>>>>>>>>>>> and
>> > >>>>>>>>>>>>>
>> > >>>>>>>>>>>>> writing
>> > >>>>>>>>>>>>>
>> > >>>>>>>>>>>>> to topics.
>> > >>>>>>>>>>>>>
>> > >>>>>>>>>>>> I hope it clarifies more why I think we should aim for more
>> > than
>> > >>>>>>>>>>>>
>> > >>>>>>>>>>>>> the
>> > >>>>>>>>>>>>> current KIP. I fear that once the KIP is done not much
>> more
>> > >>>>>>>>>>>>> effort
>> > >>>>>>>>>>>>> will
>> > >>>>>>>>>>>>>
>> > >>>>>>>>>>>>> be
>> > >>>>>>>>>>>>>
>> > >>>>>>>>>>>>> taken.
>> > >>>>>>>>>>>>>
>> > >>>>>>>>>>>>
>> > >>>>>>>>>>>> On 04.03.2018 02:28, Dong Lin wrote:
>> > >>>>>>>>>>>>>
>> > >>>>>>>>>>>>> Hey Jan,
>> > >>>>>>>>>>>>>
>> > >>>>>>>>>>>>> In the current proposal, the consumer will be blocked on
>> > >>>>>>>>>>>>> waiting
>> > >>>>>>>>>>>>> for
>> > >>>>>>>>>>>>>
>> > >>>>>>>>>>>>> other
>> > >>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>> consumers of the group to consume up to a given offset.
>> In
>> > >>>>>>>>>>>>>> most
>> > >>>>>>>>>>>>>>
>> > >>>>>>>>>>>>> cases,
>> > >>>>>>>>>>>>> all
>> > >>>>>>>>>>>>> consumers should be close to the LEO of the partitions
>> when
>> > the
>> > >>>>>>>>>>>>> partition
>> > >>>>>>>>>>>>> expansion happens. Thus the time waiting should not be
>> long
>> > >>>>>>>>>>>>> e.g.
>> > >>>>>>>>>>>>> on
>> > >>>>>>>>>>>>> the
>> > >>>>>>>>>>>>>
>> > >>>>>>>>>>>>> order of seconds. On the other hand, it may take a long
>> time
>> > to
>> > >>>>>>>>>>>>> wait
>> > >>>>>>>>>>>>>
>> > >>>>>>>>>>>>> for
>> > >>>>>>>>>>>>>> the entire partition to be copied -- the amount of time
>> is
>> > >>>>>>>>>>>>>> proportional
>> > >>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>> to
>> > >>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>> the amount of existing data in the partition, which can
>> take
>> > >>>>>>>>>>>>>>
>> > >>>>>>>>>>>>> tens of
>> > >>>>>>>>>>>>>
>> > >>>>>>>>>>>>> minutes. So the amount of time that we stop consumers may
>> not
>> > >>>>>>>>>>>>> be
>> > >>>>>>>>>>>>> on
>> > >>>>>>>>>>>>>
>> > >>>>>>>>>>>>> the
>> > >>>>>>>>>>>>>> same order of magnitude.
>> > >>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>> If we can implement this suggestion without copying data
>> > over
>> > >>>>>>>>>>>>>> in
>> > >>>>>>>>>>>>>> purse
>> > >>>>>>>>>>>>>> userland, it will be much more valuable. Do you have
>> ideas
>> > on
>> > >>>>>>>>>>>>>> how
>> > >>>>>>>>>>>>>> this
>> > >>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>> can
>> > >>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>> be done?
>> > >>>>>>>>>>>>>>
>> > >>>>>>>>>>>>> Not sure why the current KIP not help people who depend on
>> > log
>> > >>>>>>>>>>>>>
>> > >>>>>>>>>>>>> compaction.
>> > >>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>> Could you elaborate more on this point?
>> > >>>>>>>>>>>>>>
>> > >>>>>>>>>>>>> Thanks,
>> > >>>>>>>>>>>>>
>> > >>>>>>>>>>>>> Dong
>> > >>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>> On Wed, Feb 28, 2018 at 10:55 PM, Jan
>> > >>>>>>>>>>>>>> Filipiak<Jan.Filipiak@trivago.
>> > >>>>>>>>>>>>>> com
>> > >>>>>>>>>>>>>> wrote:
>> > >>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>> Hi Dong,
>> > >>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>> I tried to focus on what the steps are one can currently
>> > >>>>>>>>>>>>>> perform
>> > >>>>>>>>>>>>>> to
>> > >>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>> expand
>> > >>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>>> or shrink a keyed topic while maintaining a top notch
>> > >>>>>>>>>>>>>>> semantics.
>> > >>>>>>>>>>>>>>> I can understand that there might be confusion about
>> > >>>>>>>>>>>>>>> "stopping
>> > >>>>>>>>>>>>>>> the
>> > >>>>>>>>>>>>>>> consumer". It is exactly the same as proposed in the
>> KIP.
>> > >>>>>>>>>>>>>>> there
>> > >>>>>>>>>>>>>>> needs
>> > >>>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>>> to
>> > >>>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>>> be
>> > >>>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>> a time the producers agree on the new partitioning. The
>> > extra
>> > >>>>>>>>>>>>>
>> > >>>>>>>>>>>>> semantics I
>> > >>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>>> want to put in there is that we have a possibility to
>> wait
>> > >>>>>>>>>>>>>>> until
>> > >>>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>> all
>> > >>>>>>>>>>>>>
>> > >>>>>>>>>>>>> the
>> > >>>>>>>>>>>>>
>> > >>>>>>>>>>>>> existing data
>> > >>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>> is copied over into the new partitioning scheme. When I
>> say
>> > >>>>>>>>>>>>> stopping
>> > >>>>>>>>>>>>>
>> > >>>>>>>>>>>>> I
>> > >>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>>> think more of having a memory barrier that ensures the
>> > >>>>>>>>>>>>>>> ordering. I
>> > >>>>>>>>>>>>>>> am
>> > >>>>>>>>>>>>>>> still
>> > >>>>>>>>>>>>>>> aming for latencies  on the scale of leader failovers.
>> > >>>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>>> Consumers have to explicitly adapt the new partitioning
>> > >>>>>>>>>>>>>>> scheme
>> > >>>>>>>>>>>>>>> in
>> > >>>>>>>>>>>>>>> the
>> > >>>>>>>>>>>>>>> above scenario. The reason is that in these cases where
>> you
>> > >>>>>>>>>>>>>>> are
>> > >>>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>>> dependent
>> > >>>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>>> on a particular partitioning scheme, you also have other
>> > >>>>>>>>>>>>>>> topics
>> > >>>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>> that
>> > >>>>>>>>>>>>>
>> > >>>>>>>>>>>>> have
>> > >>>>>>>>>>>>>
>> > >>>>>>>>>>>>> co-partition enforcements or the kind -frequently.
>> Therefore
>> > >>>>>>>>>>>>>> all
>> > >>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>> your
>> > >>>>>>>>>>>>>
>> > >>>>>>>>>>>>> other
>> > >>>>>>>>>>>>>
>> > >>>>>>>>>>>>> input topics might need to grow accordingly.
>> > >>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>>> What I was suggesting was to streamline all these
>> > operations
>> > >>>>>>>>>>>>>>> as
>> > >>>>>>>>>>>>>>> best
>> > >>>>>>>>>>>>>>> as
>> > >>>>>>>>>>>>>>> possible to have "real" partition grow and shrinkage
>> going
>> > >>>>>>>>>>>>>>> on.
>> > >>>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>>> Migrating
>> > >>>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>>> the producers to a new partitioning scheme can be much
>> more
>> > >>>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>> streamlined
>> > >>>>>>>>>>>>>
>> > >>>>>>>>>>>>> with proper broker support for this. Migrating consumer
>> is a
>> > >>>>>>>>>>>>> step
>> > >>>>>>>>>>>>>
>> > >>>>>>>>>>>>> that
>> > >>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>>> might be made completly unnecessary if - for example
>> > streams
>> > >>>>>>>>>>>>>>> -
>> > >>>>>>>>>>>>>>> takes
>> > >>>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>>> the
>> > >>>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>>> gcd as partitioning scheme instead of enforcing 1 to 1.
>> > >>>>>>>>>>>>>>> Connect
>> > >>>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>> consumers
>> > >>>>>>>>>>>>>
>> > >>>>>>>>>>>>> and other consumers should be fine anyways.
>> > >>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>> I hope this makes more clear where I was aiming at. The
>> rest
>> > >>>>>>>>>>>>> needs
>> > >>>>>>>>>>>>>
>> > >>>>>>>>>>>>> to
>> > >>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>> be
>> > >>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>>> figured out. The only danger i see is that when we are
>> > >>>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>> introducing
>> > >>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>> this
>> > >>>>>>>>>>>>>
>> > >>>>>>>>>>>>> feature as supposed in the KIP, it wont help any people
>> > >>>>>>>>>>>>> depending
>> > >>>>>>>>>>>>> on
>> > >>>>>>>>>>>>>
>> > >>>>>>>>>>>>> log
>> > >>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>>> compaction.
>> > >>>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>> The other thing I wanted to mention is that I believe the
>> > >>>>>>>>>>>>> current
>> > >>>>>>>>>>>>>
>> > >>>>>>>>>>>>> suggestion (without copying data over) can be implemented
>> in
>> > >>>>>>>>>>>>>> pure
>> > >>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>>> userland
>> > >>>>>>>>>>>>>>> with a custom partitioner and a small feedbackloop from
>> > >>>>>>>>>>>>>>> ProduceResponse
>> > >>>>>>>>>>>>>>> =>
>> > >>>>>>>>>>>>>>> Partitionier in coorporation with a change management
>> > system.
>> > >>>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>>> Best Jan
>> > >>>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>>> On 28.02.2018 07:13, Dong Lin wrote:
>> > >>>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>>> Hey Jan,
>> > >>>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>>> I am not sure if it is acceptable for producer to be
>> > stopped
>> > >>>>>>>>>>>>>>> for a
>> > >>>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>>> while,
>> > >>>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>>>> particularly for online application which requires low
>> > >>>>>>>>>>>>>>>> latency. I
>> > >>>>>>>>>>>>>>>> am
>> > >>>>>>>>>>>>>>>> also
>> > >>>>>>>>>>>>>>>> not sure how consumers can switch to a new topic. Does
>> > user
>> > >>>>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>>>> application
>> > >>>>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>>>> needs to explicitly specify a different topic for
>> > >>>>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>>> producer/consumer
>> > >>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>> to
>> > >>>>>>>>>>>>>>
>> > >>>>>>>>>>>>> subscribe to? It will be helpful for discussion if you can
>> > >>>>>>>>>>>>> provide
>> > >>>>>>>>>>>>>
>> > >>>>>>>>>>>>> more
>> > >>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>>> detail on the interface change for this solution.
>> > >>>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>>> Thanks,
>> > >>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>> Dong
>> > >>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>>> On Mon, Feb 26, 2018 at 12:48 AM, Jan
>> > >>>>>>>>>>>>>>>> Filipiak<Jan.Filipiak@trivago.
>> > >>>>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>>>> com
>> > >>>>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>>>> wrote:
>> > >>>>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>>> Hi,
>> > >>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>> just want to throw my though in. In general the
>> > functionality
>> > >>>>>>>>>>>>>> is
>> > >>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>>> very
>> > >>>>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>>>> usefull, we should though not try to find the
>> architecture
>> > >>>>>>>>>>>>>>>> to
>> > >>>>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>>>> hard
>> > >>>>>>>>>>>>>>>>> while
>> > >>>>>>>>>>>>>>>>> implementing.
>> > >>>>>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>>>>> The manual steps would be to
>> > >>>>>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>>>>> create a new topic
>> > >>>>>>>>>>>>>>>>> the mirrormake from the new old topic to the new topic
>> > >>>>>>>>>>>>>>>>> wait for mirror making to catch up.
>> > >>>>>>>>>>>>>>>>> then put the consumers onto the new topic
>> > >>>>>>>>>>>>>>>>>            (having mirrormaker spit out a mapping from
>> > old
>> > >>>>>>>>>>>>>>>>> offsets to
>> > >>>>>>>>>>>>>>>>> new
>> > >>>>>>>>>>>>>>>>> offsets:
>> > >>>>>>>>>>>>>>>>>                if topic is increased by factor X
>> there is
>> > >>>>>>>>>>>>>>>>> gonna
>> > >>>>>>>>>>>>>>>>> be a
>> > >>>>>>>>>>>>>>>>> clean
>> > >>>>>>>>>>>>>>>>> mapping from 1 offset in the old topic to X offsets in
>> > the
>> > >>>>>>>>>>>>>>>>> new
>> > >>>>>>>>>>>>>>>>> topic,
>> > >>>>>>>>>>>>>>>>>                if there is no factor then there is no
>> > >>>>>>>>>>>>>>>>> chance to
>> > >>>>>>>>>>>>>>>>> generate a
>> > >>>>>>>>>>>>>>>>> mapping that can be reasonable used for continuing)
>> > >>>>>>>>>>>>>>>>>            make consumers stop at appropriate points
>> and
>> > >>>>>>>>>>>>>>>>> continue
>> > >>>>>>>>>>>>>>>>> consumption
>> > >>>>>>>>>>>>>>>>> with offsets from the mapping.
>> > >>>>>>>>>>>>>>>>> have the producers stop for a minimal time.
>> > >>>>>>>>>>>>>>>>> wait for mirrormaker to finish
>> > >>>>>>>>>>>>>>>>> let producer produce with the new metadata.
>> > >>>>>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>>>>> Instead of implementing the approach suggest in the
>> KIP
>> > >>>>>>>>>>>>>>>>> which
>> > >>>>>>>>>>>>>>>>> will
>> > >>>>>>>>>>>>>>>>> leave
>> > >>>>>>>>>>>>>>>>> log compacted topic completely crumbled and unusable.
>> > >>>>>>>>>>>>>>>>> I would much rather try to build infrastructure to
>> > support
>> > >>>>>>>>>>>>>>>>> the
>> > >>>>>>>>>>>>>>>>> mentioned
>> > >>>>>>>>>>>>>>>>> above operations more smoothly.
>> > >>>>>>>>>>>>>>>>> Especially having producers stop and use another
>> topic is
>> > >>>>>>>>>>>>>>>>> difficult
>> > >>>>>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>>>>> and
>> > >>>>>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>>>>> it would be nice if one can trigger "invalid metadata"
>> > >>>>>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>>>> exceptions
>> > >>>>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>>>> for
>> > >>>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>> them
>> > >>>>>>>>>>>>>
>> > >>>>>>>>>>>>> and
>> > >>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>>> if one could give topics aliases so that their produces
>> > with
>> > >>>>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>>>>> the
>> > >>>>>>>>>>>>>>>>> old
>> > >>>>>>>>>>>>>>>>> topic
>> > >>>>>>>>>>>>>>>>> will arrive in the new topic.
>> > >>>>>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>>>>> The downsides are obvious I guess ( having the same
>> data
>> > >>>>>>>>>>>>>>>>> twice
>> > >>>>>>>>>>>>>>>>> for
>> > >>>>>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>>>>> the
>> > >>>>>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>>>>> transition period, but kafka tends to scale well with
>> > >>>>>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>>>> datasize).
>> > >>>>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>>>> So
>> > >>>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>>> its a
>> > >>>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>> nicer fit into the architecture.
>> > >>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>>> I further want to argument that the functionality by the
>> > KIP
>> > >>>>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>>>>> can
>> > >>>>>>>>>>>>>>>>> completely be implementing in "userland" with a custom
>> > >>>>>>>>>>>>>>>>> partitioner
>> > >>>>>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>>>>> that
>> > >>>>>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>>>>> handles the transition as needed. I would appreciate
>> if
>> > >>>>>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>>>> someone
>> > >>>>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>>>> could
>> > >>>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>> point
>> > >>>>>>>>>>>>>
>> > >>>>>>>>>>>>> out what a custom partitioner couldn't handle in this
>> case?
>> > >>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>>> With the above approach, shrinking a topic becomes the
>> same
>> > >>>>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>>>>> steps.
>> > >>>>>>>>>>>>>>>>> Without
>> > >>>>>>>>>>>>>>>>> loosing keys in the discontinued partitions.
>> > >>>>>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>>>>> Would love to hear what everyone thinks.
>> > >>>>>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>>>>> Best Jan
>> > >>>>>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>>>>> On 11.02.2018 00:35, Dong Lin wrote:
>> > >>>>>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>>>>> Hi all,
>> > >>>>>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>>>>> I have created KIP-253: Support in-order message
>> delivery
>> > >>>>>>>>>>>>>>>>> with
>> > >>>>>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>>>>> partition
>> > >>>>>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>>>>> expansion. See
>> > >>>>>>>>>>>>>>>>>> https://cwiki.apache.org/confl
>> > >>>>>>>>>>>>>>>>>> uence/display/KAFKA/KIP-253%
>> > >>>>>>>>>>>>>>>>>> 3A+Support+in-order+message+de
>> > >>>>>>>>>>>>>>>>>> livery+with+partition+expansio
>> > >>>>>>>>>>>>>>>>>> n
>> > >>>>>>>>>>>>>>>>>> .
>> > >>>>>>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>>>>>> This KIP provides a way to allow messages of the same
>> > key
>> > >>>>>>>>>>>>>>>>>> from
>> > >>>>>>>>>>>>>>>>>> the
>> > >>>>>>>>>>>>>>>>>> same
>> > >>>>>>>>>>>>>>>>>> producer to be consumed in the same order they are
>> > >>>>>>>>>>>>>>>>>> produced
>> > >>>>>>>>>>>>>>>>>> even
>> > >>>>>>>>>>>>>>>>>> if
>> > >>>>>>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>>>>>> we
>> > >>>>>>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>>>>>> expand partition of the topic.
>> > >>>>>>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>>>>> Thanks,
>> > >>>>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>>> Dong
>> > >>>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>>>>>>
>> > >>>>>>>>>>>>>>>>>>
>> > >>>>
>> > >>
>> > >>
>> > >
>> >
>>
>
>

Re: [DISCUSS] KIP-253: Support in-order message delivery with partition expansion

Posted by Dong Lin <li...@gmail.com>.
Hey John,

Thanks much for the detailed comments. Here are my thoughts:

- The need to delete messages from log compacted topics is mainly for
performance (e.g. storage space) optimization than for correctness for this
KIP. I agree that we probably don't need to focus on this in our discussion
since it is mostly for performance optimization.

- "Asking producers and consumers, or even two different producers, to
share code like the partition function is a pretty huge ask. What if they
are using different languages?". It seems that today we already require
different producer's to use the same hash function -- otherwise messages
with the same key will go to different partitions of the same topic which
may cause problem for downstream consumption. So not sure if it adds any
more constraint by assuming consumers know the hash function of producer.
Could you explain more why user would want to use a cusmtom partition
function? Maybe we can check if this is something that can be supported in
the default Kafka hash function. Also, can you explain more why it is
difficuilt to implement the same hash function in different languages?

- Besides the assumption that consumer needs to share the hash function of
producer, is there other organization overhead of the proposal in the
current KIP?

- Currently producer can forget about the message that has been
acknowledged by the broker. Thus the producer probably does not know most
of the exiting messages in topic, including those messages produced by
other producers. We can have the owner of the producer to split+backfill.
In my opion it will be a new program that wraps around the existing
producer and consumer classes.

- Regarding point 5. The argument is in favor of the split+backfill but for
changelog topic. And it intends to address the problem for stream use-case
in general. In this KIP we will provide interface (i.e.
PartitionKeyRebalanceListener in the KIP) to be used by sream use-case and
the goal is that user can flush/re-consume the state as part of the
interface implementation regardless of whether there is change log topic.

Maybe you are suggesting that the main reason to do split+backfill of input
topic is to support log compacted topics? You mentioned in Point 1 that log
compacted topics is out of the scope of this KIP. Maybe I could understand
your position better. Regarding Jan's proposal to split partitions with
backfill, do you think this should replace the proposal in the existing
KIP, or do you think this is something that we should do in addition to the
existing KIP?

- Regarding point 6. I guess we can agree that it is better not to have the
performance overhread of copying the input data. Before we discuss more on
whether the performance overhead is acceptable or not, I am trying to
figure out what is the benefit of introducing this overhread. You mentioned
that the benefit is the loose organizational coupling. By "organizational
coupling", are you referring to the requirement that consumer needs to know
the hash function of producer? If so, maybe we can discuss the use-case of
custom partiton function and see whether we can find a way to support such
use-case without having to copy the input data.

Thanks,
Dong


On Tue, Mar 27, 2018 at 11:34 AM, John Roesler <jo...@confluent.io> wrote:

> Hey Dong and Jun,
>
> Thanks for the thoughtful responses. If you don't mind, I'll mix my replies
> together to try for a coherent response. I'm not too familiar with
> mailing-list etiquette, though.
>
> I'm going to keep numbering my points because it makes it easy for you all
> to respond.
>
> Point 1:
> As I read it, KIP-253 is *just* about properly fencing the producers and
> consumers so that you preserve the correct ordering of records during
> partition expansion. This is clearly necessary regardless of anything else
> we discuss. I think this whole discussion about backfill, consumers,
> streams, etc., is beyond the scope of KIP-253. But it would be cumbersome
> to start a new thread at this point.
>
> I had missed KIP-253's Proposed Change #9 among all the details... I think
> this is a nice addition to the proposal. One thought is that it's actually
> irrelevant whether the hash function is linear. This is simply an algorithm
> for moving a key from one partition to another, so the type of hash
> function need not be a precondition. In fact, it also doesn't matter
> whether the topic is compacted or not, the algorithm works regardless.
>
> I think this is a good algorithm to keep in mind, as it might solve a
> variety of problems, but it does have a downside: that the producer won't
> know whether or not K1 was actually in P1, it just knows that K1 was in
> P1's keyspace before the new epoch. Therefore, it will have to
> pessimistically send (K1,null) to P1 just in case. But the next time K1
> comes along, the producer *also* won't remember that it already retracted
> K1 from P1, so it will have to send (K1,null) *again*. By extension, every
> time the producer sends to P2, it will also have to send a tombstone to P1,
> which is a pretty big burden. To make the situation worse, if there is a
> second split, say P2 becomes P2 and P3, then any key Kx belonging to P3
> will also have to be retracted from P2 *and* P1, since the producer can't
> know whether Kx had been last written to P2 or P1. Over a long period of
> time, this clearly becomes a issue, as the producer must send an arbitrary
> number of retractions along with every update.
>
> In contrast, the proposed backfill operation has an end, and after it ends,
> everyone can afford to forget that there ever was a different partition
> layout.
>
> Really, though, figuring out how to split compacted topics is beyond the
> scope of KIP-253, so I'm not sure #9 really even needs to be in this KIP...
> We do need in-order delivery during partition expansion. It would be fine
> by me to say that you *cannot* expand partitions of a log-compacted topic
> and call it a day. I think it would be better to tackle that in another
> KIP.
>
>
> Point 2:
> Regarding whether the consumer re-shuffles its inputs, this is always on
> the table; any consumer who wants to re-shuffle its input is free to do so.
> But this is currently not required. It's just that the current high-level
> story with Kafka encourages the use of partitions as a unit of concurrency.
> As long as consumers are single-threaded, they can happily consume a single
> partition without concurrency control of any kind. This is a key aspect to
> this system that lets folks design high-throughput systems on top of it
> surprisingly easily. If all consumers were instead encouraged/required to
> implement a repartition of their own, then the consumer becomes
> significantly more complex, requiring either the consumer to first produce
> to its own intermediate repartition topic or to ensure that consumer
> threads have a reliable, high-bandwith channel of communication with every
> other consumer thread.
>
> Either of those tradeoffs may be reasonable for a particular user of Kafka,
> but I don't know if we're in a position to say that they are reasonable for
> *every* user of Kafka.
>
>
> Point 3:
> Regarding Jun's point about this use case, "(3) stateful and maintaining
> the
> states in a local store", I agree that they may use a framework *like*
> Kafka Streams, but that is not the same as using Kafka Streams. This is why
> I think it's better to solve it in Core: because it is then solved for
> KStreams and also for everything else that facilitates local state
> maintenance. To me, Streams is a member of the category of "stream
> processing frameworks", which is itself a subcategory of "things requiring
> local state maintenence". I'm not sure if it makes sense to assert that
> Streams is a sufficient and practical replacement for everything in "things
> requiring local state maintenence".
>
> But, yes, I do agree that per-key ordering is an absolute requirement,
> therefore I think that KIP-253 itself is a necessary step. Regarding the
> coupling of the state store partitioning to the topic partitioning, yes,
> this is an issue we are discussing solutions to right now. We may go ahead
> and introduce an overpartition layer on our inputs to solve it, but then
> again, if we get the ability to split partitions with backfill, we may not
> need to!
>
>
> Point 4:
> On this:
>
> > Regarding thought 2: If we don't care about the stream use-case, then the
> > current KIP probably has already addressed problem without requiring
> > consumer to know the partition function. If we care about the stream
> > use-case, we already need coordination across producers of different
> > topics, i.e. the same partition function needs to be used by producers of
> > topics A and B in order to join topics A and B. Thus, it might be
> > reasonable to extend coordination a bit and say we need coordination
> across
> > clients (i.e. producer and consumer), such that consumer knows the
> > partition function used by producer. If we do so, then we can let
> consumer
> > re-copy data for the change log topic using the same partition function
> as
> > producer. This approach has lower overhead as compared to having producer
> > re-copy data of the input topic.
> > Also, producer currently does not need to know the data already produced
> to
> > the topic. If we let producer split/merge partition, it would require
> > producer to consume the existing data, which intuitively is the task of
> > consumer.
>
>
> I think we do care about use cases *like* Streams, I just don't think we
> should rely on Streams to implement a feature of Core like partition
> expansion.
>
> Note, though, that we (Streams) do not require coordination across
> producers. If two topics are certified to be co-partitioned, then Streams
> apps can make use of that knowledge to optimize their topology (skipping a
> repartition). But if they don't know whether they are co-partitioned, then
> they'd better go ahead and repartition within the topology. This is the
> current state.
>
> A huge selling point of Kafka is enabling different parts of loosely
> coupled organizations to produce and consume data independently. Some
> coordination between producers and consumers is necessary, like
> coordinating on the names of topics and their schemas. But Kafka's value
> proposition w.r.t. ESBs, etc. is inversely proportional to the amount of
> coordination required. I think it behooves us to be extremely skeptical
> about introducing any coordination beyond correctness protocols.
>
> Asking producers and consumers, or even two different producers, to share
> code like the partition function is a pretty huge ask. What if they are
> using different languages?
>
> Comparing organizational overhead vs computational overhead, there are
> maybe two orders of magnitude difference between them. In other words, I
> would happily take on the (linear) overhead of having the producer re-copy
> the data once during a re-partition in order to save the organizational
> overhead of tying all the producers and consumers together across multiple
> boundaries.
>
> On that last paragraph: note that the producer *did* know the data it
> already produced. It handled it the first time around. Asking it to
> re-produce it into a new partition layout is squarely within its scope of
> capabilities. Contrast this with the alternative, asking the consumer to
> re-partition the data. I think this is even less intuitive, when the
> partition function belongs to the producer.
>
>
> Point 5:
> Dong asked this:
>
> > For stream use-case that needs to increase consumer number, the
> > existing consumer can backfill the existing data in the change log topic
> to
> > the same change log topic with the new partition number, before the new
> set
> > of consumers bootstrap state from the new partitions of the change log
> > topic, right?
>
>
> In this sense, the "consumer" is actually the producer of the changelog
> topic, so if we support partition expansion + backfill as a producer/broker
> operation, then it would be very straightforward for Streams to split a
> state store. As you say, they would simply instruct the broker to split the
> changelog topic's partitions, then backfill. Once the backfill is ready,
> they can create a new crop of StandbyTasks to bootstrap the more granular
> state stores and finally switch over to them when they are ready.
>
> But this actually seems to be an argument in favor of split+backfill, so
> maybe I missed the point.
>
> You also asked me to explain why copying the "input" topic is better than
> copying the "changelog" topic. I think they are totally independent,
> actually. For one thing, you can't depend on the existence of a "changelog"
> topic in general, only within Streams, but Kafka's user base clearly
> exceeds Streams's user base. Plus, you actually also can't depend on the
> existence of a changelog topic within Streams, since that is an optional
> feature of *some* state store implementations. Even in the situation where
> you do have a changelog topic in Streams, there may be use cases where it
> makes sense to expand the partitions of just the input, or just the
> changelog.
>
> The ask for a Core feature of split+backfill is really about supporting the
> use case of splitting partitions in log-compacted topics, regardless of
> whether that topic is an "input" or a "changelog" or anything else for that
> matter.
>
>
> Point 6:
> On the concern about the performance overhead of copying data between the
> brokers, I think it's actually a bit overestimated. Splitting a topic's
> partition is probably rare, certainly rarer in general than bootstrapping
> new consumers on that topic. If "bootstrapping new consumers" means that
> they have to re-shuffle the data before they consume it, then you wind up
> copying the same record multiple times:
>
> (broker: input topic) -> (initial consumer) -> (broker: repartition topic)
> -> (real consumer)
>
> That's 3x, and it's also 3x for every new record after the split as well,
> since you don't get to stop repartitioning/reshuffling once you start.
>
> Whereas if you do a backfill in something like the procedure I outlined,
> you only copy the prefix of the partition before the split, and you send it
> once to the producer and then once to the new generation partition. Plus,
> assuming we're splitting the partition for the benefit of consumers,
> there's no reason we can't co-locate the post-split partitions on the same
> host as the pre-split partition, making the second copy a local filesystem
> operation.
>
> Even if you follow these two copies up with bootstrapping a new consumer,
> it's still rare for this to occur, so you get to amortize these copies over
> the lifetime of the topic, whereas a reshuffle just keeps making copies for
> every new event.
>
> And finally, I really do think that regardless of any performance concerns
> about this operation, if it preserves loose organizational coupling, it is
> certainly worth it.
>
>
> In conclusion:
> It might actually be a good idea for us to clarify the scope of KIP-253. If
> we're all agreed that it's a good algorithm for allowing in-order message
> delivery during partition expansion, then we can continue this discussion
> as a new KIP, something like "backfill with partition expansion". This
> would let Dong proceed with KIP-253. On the other hand, if it seems like
> this conversation may alter the design of KIP-253, then maybe we *should*
> just finish working it out.
>
> For my part, my only concern about KIP-253 is the one I raised earlier.
>
> Thanks again, all, for considering these points,
> -John
>
>
> On Tue, Mar 27, 2018 at 2:10 AM, Dong Lin <li...@gmail.com> wrote:
>
> > On Tue, Mar 27, 2018 at 12:04 AM, Dong Lin <li...@gmail.com> wrote:
> >
> > > Hey Jan,
> > >
> > > Thanks for the enthusiasm in improving Kafka's design. Now that I have
> > > read through your discussion with Jun, here are my thoughts:
> > >
> > > - The latest proposal should with log compacted topics by properly
> > > deleting old messages after a new message with the same key is
> produced.
> > So
> > > it is probably not a concern anymore. Could you comment if there is
> still
> > > issue?
> > >
> > > - I wrote the SEP-5 and I am pretty familiar with the motivation and
> the
> > > design of SEP-5. SEP-5 is probably orthornal to the motivation of this
> > KIP.
> > > The goal of SEP-5 is to allow user to increase task number of an
> existing
> > > Samza job. But if we increase the partition number of input topics,
> > > messages may still be consumed out-of-order by tasks in Samza which
> cause
> > > incorrect result. Similarly, the approach you proposed does not seem to
> > > ensure that the messages can be delivered in order, even if we can make
> > > sure that each consumer instance is assigned the set of new partitions
> > > covering the same set of keys.
> > >
> >
> > Let me correct this comment. The approach of copying data to a new topic
> > can ensure in-order message delivery suppose we properly migrate offsets
> > from old topic to new topic.
> >
> >
> > > - I am trying to understand why it is better to copy the data instead
> of
> > > copying the change log topic for streaming use-case. For core Kafka
> > > use-case, and for the stream use-case that does not need to increase
> > > consumers, the current KIP already supports in-order delivery without
> the
> > > overhead of copying the data. For stream use-case that needs to
> increase
> > > consumer number, the existing consumer can backfill the existing data
> in
> > > the change log topic to the same change log topic with the new
> partition
> > > number, before the new set of consumers bootstrap state from the new
> > > partitions of the change log topic. If this solution works, then could
> > you
> > > summarize the advantage of copying the data of input topic as compared
> to
> > > copying the change log topic? For example, does it enable more
> use-case,
> > > simplify the implementation of Kafka library, or reduce the operation
> > > overhead etc?
> > >
> > > Thanks,
> > > Dong
> > >
> > >
> > > On Wed, Mar 21, 2018 at 6:57 AM, Jan Filipiak <
> Jan.Filipiak@trivago.com>
> > > wrote:
> > >
> > >> Hi Jun,
> > >>
> > >> I was really seeing progress in our conversation but your latest reply
> > is
> > >> just devastating.
> > >> I though we were getting close being on the same page now it feels
> like
> > >> we are in different libraries.
> > >>
> > >> I just quickly slam my answers in here. If they are to brief I am
> sorry
> > >> give me a ping and try to go into details more.
> > >> Just want to show that your pro/cons listing is broken.
> > >>
> > >> Best Jan
> > >>
> > >> and want to get rid of this horrible compromise
> > >>
> > >>
> > >> On 19.03.2018 05:48, Jun Rao wrote:
> > >>
> > >>> Hi, Jan,
> > >>>
> > >>> Thanks for the discussion. Great points.
> > >>>
> > >>> Let me try to summarize the approach that you are proposing. On the
> > >>> broker
> > >>> side, we reshuffle the existing data in a topic from current
> partitions
> > >>> to
> > >>> the new partitions. Once the reshuffle fully catches up, switch the
> > >>> consumers to start consuming from the new partitions. If a consumer
> > needs
> > >>> to rebuild its local state (due to partition changes), let the
> consumer
> > >>> rebuild its state by reading all existing data from the new
> partitions.
> > >>> Once all consumers have switches over, cut over the producer to the
> new
> > >>> partitions.
> > >>>
> > >>> The pros for this approach are that :
> > >>> 1. There is just one way to rebuild the local state, which is
> simpler.
> > >>>
> > >> true thanks
> > >>
> > >>>
> > >>> The cons for this approach are:
> > >>> 1. Need to copy existing data.
> > >>>
> > >> Very unfair and not correct. It does not require you to copy over
> > >> existing data. It _allows_ you to copy all existing data.
> > >>
> > >> 2. The cutover of the producer is a bit complicated since it needs to
> > >>> coordinate with all consumer groups.
> > >>>
> > >> Also not true. I explicitly tried to make clear that there is only one
> > >> special consumer (in the case of actually copying data) coordination
> is
> > >> required.
> > >>
> > >>> 3. The rebuilding of the state in the consumer is from the input
> topic,
> > >>> which can be more expensive than rebuilding from the existing state.
> > >>>
> > >> true, but rebuilding state is only required if you want to increase
> > >> processing power, so we assume this is at hand.
> > >>
> > >>> 4. The broker potentially has to know the partitioning function. If
> > this
> > >>> needs to be customized at the topic level, it can be a bit messy.
> > >>>
> > >> I would argue against having the operation being performed by the
> > broker.
> > >> This was not discussed yet but if you see my original email i
> suggested
> > >> otherwise from the beginning.
> > >>
> > >>>
> > >>> Here is an alternative approach by applying your idea not in the
> > broker,
> > >>> but in the consumer. When new partitions are added, we don't move
> > >>> existing
> > >>> data. In KStreams, we first reshuffle the new input data to a new
> topic
> > >>> T1
> > >>> with the old number of partitions and feed T1's data to the rest of
> the
> > >>> pipeline. In the meantime, KStreams reshuffles all existing data of
> the
> > >>> change capture topic to another topic C1 with the new number of
> > >>> partitions.
> > >>> We can then build the state of the new tasks from C1. Once the new
> > states
> > >>> have been fully built, we can cut over the consumption to the input
> > topic
> > >>> and delete T1. This approach works with compacted topic too. If an
> > >>> application reads from the beginning of a compacted topic, the
> consumer
> > >>> will reshuffle the portion of the input when the number of partitions
> > >>> doesn't match the number of tasks.
> > >>>
> > >> We all wipe this idea from our heads instantly. Mixing Ideas from an
> > >> argument is not a resolution strategy
> > >> just leads to horrible horrible software.
> > >>
> > >>
> > >>> The pros of this approach are:
> > >>> 1. No need to copy existing data.
> > >>> 2. Each consumer group can cut over to the new partitions
> > independently.
> > >>> 3. The state is rebuilt from the change capture topic, which is
> cheaper
> > >>> than rebuilding from the input topic.
> > >>> 4. Only the KStreams job needs to know the partitioning function.
> > >>>
> > >>> The cons of this approach are:
> > >>> 1. Potentially the same input topic needs to be reshuffled more than
> > once
> > >>> in different consumer groups during the transition phase.
> > >>>
> > >>> What do you think?
> > >>>
> > >>> Thanks,
> > >>>
> > >>> Jun
> > >>>
> > >>>
> > >>>
> > >>> On Thu, Mar 15, 2018 at 1:04 AM, Jan Filipiak <
> > Jan.Filipiak@trivago.com>
> > >>> wrote:
> > >>>
> > >>> Hi Jun,
> > >>>>
> > >>>> thank you for following me on these thoughts. It was important to me
> > to
> > >>>> feel that kind of understanding for my arguments.
> > >>>>
> > >>>> What I was hoping for (I mentioned this earlier) is that we can
> model
> > >>>> the
> > >>>> case where we do not want to copy the data the exact same way as the
> > >>>> case
> > >>>> when we do copy the data. Maybe you can peek into the mails before
> to
> > >>>> see
> > >>>> more details for this.
> > >>>>
> > >>>> This means we have the same mechanism to transfer consumer groups to
> > >>>> switch topic. The offset mapping that would be generated would even
> be
> > >>>> simpler End Offset of the Old topic => offset 0 off all the
> partitions
> > >>>> of
> > >>>> the new topic. Then we could model the transition of a non-copy
> > >>>> expansion
> > >>>> the exact same way as a copy-expansion.
> > >>>>
> > >>>> I know this only works when topic growth by a factor. But the
> benefits
> > >>>> of
> > >>>> only growing by a factor are to strong anyways. See Clemens's hint
> and
> > >>>> remember that state reshuffling is entirely not needed if one
> doesn't
> > >>>> want
> > >>>> to grow processing power.
> > >>>>
> > >>>> I think these benefits should be clear, and that there is basically
> no
> > >>>> downside to what is currently at hand but just makes everything
> easy.
> > >>>>
> > >>>> One thing you need to know is. that if you do not offer rebuilding a
> > log
> > >>>> compacted topic like i suggest that even if you have consumer state
> > >>>> reshuffling. The topic is broken and can not be used to bootstrap
> new
> > >>>> consumers. They don't know if they need to apply a key from and old
> > >>>> partition or not. This is a horrible downside I haven't seen a
> > solution
> > >>>> for
> > >>>> in the email conversation.
> > >>>>
> > >>>> I argue to:
> > >>>>
> > >>>> Only grow topic by a factor always.
> > >>>> Have the "no copy consumer" transition as the trivial case of the
> > "copy
> > >>>> consumer transition".
> > >>>> If processors needs to be scaled, let them rebuild from the new
> topic
> > >>>> and
> > >>>> leave the old running in the mean time.
> > >>>> Do not implement key shuffling in streams.
> > >>>>
> > >>>> I hope I can convince you especially with the fact how I want to
> > handle
> > >>>> consumer transition. I think
> > >>>> you didn't quite understood me there before. I think the term "new
> > >>>> topic"
> > >>>> intimidated you a little.
> > >>>> How we solve this on disc doesn't really matter, If the data goes
> into
> > >>>> the
> > >>>> same Dir or a different Dir or anything. I do think that it needs to
> > >>>> involve at least rolling a new segment for the existing partitions.
> > >>>> But most of the transitions should work without restarting
> consumers.
> > >>>> (newer consumers with support for this). But with new topic i just
> > meant
> > >>>> the topic that now has a different partition count. Plenty of ways
> to
> > >>>> handle that (versions, aliases)
> > >>>>
> > >>>> Hope I can further get my idea across.
> > >>>>
> > >>>> Best Jan
> > >>>>
> > >>>>
> > >>>>
> > >>>>
> > >>>>
> > >>>>
> > >>>> On 14.03.2018 02:45, Jun Rao wrote:
> > >>>>
> > >>>> Hi, Jan,
> > >>>>>
> > >>>>> Thanks for sharing your view.
> > >>>>>
> > >>>>> I agree with you that recopying the data potentially makes the
> state
> > >>>>> management easier since the consumer can just rebuild its state
> from
> > >>>>> scratch (i.e., no need for state reshuffling).
> > >>>>>
> > >>>>> On the flip slide, I saw a few disadvantages of the approach that
> you
> > >>>>> suggested. (1) Building the state from the input topic from scratch
> > is
> > >>>>> in
> > >>>>> general less efficient than state reshuffling. Let's say one
> > computes a
> > >>>>> count per key from an input topic. The former requires reading all
> > >>>>> existing
> > >>>>> records in the input topic whereas the latter only requires reading
> > >>>>> data
> > >>>>> proportional to the number of unique keys. (2) The switching of the
> > >>>>> topic
> > >>>>> needs modification to the application. If there are many
> applications
> > >>>>> on a
> > >>>>> topic, coordinating such an effort may not be easy. Also, it's not
> > >>>>> clear
> > >>>>> how to enforce exactly-once semantic during the switch. (3) If a
> > topic
> > >>>>> doesn't need any state management, recopying the data seems
> wasteful.
> > >>>>> In
> > >>>>> that case, in place partition expansion seems more desirable.
> > >>>>>
> > >>>>> I understand your concern about adding complexity in KStreams. But,
> > >>>>> perhaps
> > >>>>> we could iterate on that a bit more to see if it can be simplified.
> > >>>>>
> > >>>>> Jun
> > >>>>>
> > >>>>>
> > >>>>> On Mon, Mar 12, 2018 at 11:21 PM, Jan Filipiak <
> > >>>>> Jan.Filipiak@trivago.com>
> > >>>>> wrote:
> > >>>>>
> > >>>>> Hi Jun,
> > >>>>>
> > >>>>>> I will focus on point 61 as I think its _the_ fundamental part
> that
> > I
> > >>>>>> cant
> > >>>>>> get across at the moment.
> > >>>>>>
> > >>>>>> Kafka is the platform to have state materialized multiple times
> from
> > >>>>>> one
> > >>>>>> input. I emphasize this: It is the building block in architectures
> > >>>>>> that
> > >>>>>> allow you to
> > >>>>>> have your state maintained multiple times. You put a message in
> > once,
> > >>>>>> and
> > >>>>>> you have it pop out as often as you like. I believe you understand
> > >>>>>> this.
> > >>>>>>
> > >>>>>> Now! The path of thinking goes the following: I am using apache
> > kafka
> > >>>>>> and
> > >>>>>> I _want_ my state multiple times. What am I going todo?
> > >>>>>>
> > >>>>>> A) Am I going to take my state that I build up, plunge some sort
> of
> > >>>>>> RPC
> > >>>>>> layer ontop of it, use that RPC layer to throw my records across
> > >>>>>> instances?
> > >>>>>> B) Am I just going to read the damn message twice?
> > >>>>>>
> > >>>>>> Approach A is fundamentally flawed and a violation of all that is
> > good
> > >>>>>> and
> > >>>>>> holy in kafka deployments. I can not understand how this Idea can
> > >>>>>> come in
> > >>>>>> the first place.
> > >>>>>> (I do understand: IQ in streams, they polluted the kafka streams
> > >>>>>> codebase
> > >>>>>> really bad already. It is not funny! I think they are equally
> flawed
> > >>>>>> as
> > >>>>>> A)
> > >>>>>>
> > >>>>>> I say, we do what Kafka is good at. We repartition the topic once.
> > We
> > >>>>>> switch the consumers.
> > >>>>>> (Those that need more partitions are going to rebuild their state
> in
> > >>>>>> multiple partitions by reading the new topic, those that don't
> just
> > >>>>>> assign
> > >>>>>> the new partitions properly)
> > >>>>>> We switch producers. Done!
> > >>>>>>
> > >>>>>> The best thing! It is trivial, hipster stream processor will have
> an
> > >>>>>> easy
> > >>>>>> time with that aswell. Its so super simple. And simple IS good!
> > >>>>>> It is what kafka was build todo. It is how we do it today. All I
> am
> > >>>>>> saying
> > >>>>>> is that a little broker help doing the producer swap is super
> > useful.
> > >>>>>>
> > >>>>>> For everyone interested in why kafka is so powerful with approach
> B,
> > >>>>>> please watch https://youtu.be/bEbeZPVo98c?t=1633
> > >>>>>> I already looked up a good point in time, I think after 5 minutes
> > the
> > >>>>>> "state" topic is handled and you should be able to understand me
> > >>>>>> and inch better.
> > >>>>>>
> > >>>>>> Please do not do A to the project, it deserves better!
> > >>>>>>
> > >>>>>> Best Jan
> > >>>>>>
> > >>>>>>
> > >>>>>>
> > >>>>>> On 13.03.2018 02:40, Jun Rao wrote:
> > >>>>>>
> > >>>>>> Hi, Jan,
> > >>>>>>
> > >>>>>>> Thanks for the reply. A few more comments below.
> > >>>>>>>
> > >>>>>>> 50. Ok, we can think a bit harder for supporting compacted
> topics.
> > >>>>>>>
> > >>>>>>> 51. This is a fundamental design question. In the more common
> case,
> > >>>>>>> the
> > >>>>>>> reason why someone wants to increase the number of partitions is
> > that
> > >>>>>>> the
> > >>>>>>> consumer application is slow and one wants to run more consumer
> > >>>>>>> instances
> > >>>>>>> to increase the degree of parallelism. So, fixing the number of
> > >>>>>>> running
> > >>>>>>> consumer instances when expanding the partitions won't help this
> > >>>>>>> case.
> > >>>>>>> If
> > >>>>>>> we do need to increase the number of consumer instances, we need
> to
> > >>>>>>> somehow
> > >>>>>>> reshuffle the state of the consumer across instances. What we
> have
> > >>>>>>> been
> > >>>>>>> discussing in this KIP is whether we can do this more effectively
> > >>>>>>> through
> > >>>>>>> the KStream library (e.g. through a 2-phase partition expansion).
> > >>>>>>> This
> > >>>>>>> will
> > >>>>>>> add some complexity, but it's probably better than everyone doing
> > >>>>>>> this
> > >>>>>>> in
> > >>>>>>> the application space. The recopying approach that you mentioned
> > >>>>>>> doesn't
> > >>>>>>> seem to address the consumer state management issue when the
> > consumer
> > >>>>>>> switches from an old to a new topic.
> > >>>>>>>
> > >>>>>>> 52. As for your example, it depends on whether the join key is
> the
> > >>>>>>> same
> > >>>>>>> between (A,B) and (B,C). If the join key is the same, we can do a
> > >>>>>>> 2-phase
> > >>>>>>> partition expansion of A, B, and C together. If the join keys are
> > >>>>>>> different, one would need to repartition the data on a different
> > key
> > >>>>>>> for
> > >>>>>>> the second join, then the partition expansion can be done
> > >>>>>>> independently
> > >>>>>>> between (A,B) and (B,C).
> > >>>>>>>
> > >>>>>>> 53. If you always fix the number of consumer instances, we you
> > >>>>>>> described
> > >>>>>>> works. However, as I mentioned in #51, I am not sure how your
> > >>>>>>> proposal
> > >>>>>>> deals with consumer states when the number of consumer instances
> > >>>>>>> grows.
> > >>>>>>> Also, it just seems that it's better to avoid re-copying the
> > existing
> > >>>>>>> data.
> > >>>>>>>
> > >>>>>>> 60. "just want to throw in my question from the longer email in
> the
> > >>>>>>> other
> > >>>>>>> Thread here. How will the bloom filter help a new consumer to
> > decide
> > >>>>>>> to
> > >>>>>>> apply the key or not?" Not sure that I fully understood your
> > >>>>>>> question.
> > >>>>>>> The
> > >>>>>>> consumer just reads whatever key is in the log. The bloom filter
> > just
> > >>>>>>> helps
> > >>>>>>> clean up the old keys.
> > >>>>>>>
> > >>>>>>> 61. "Why can we afford having a topic where its apparently not
> > >>>>>>> possible
> > >>>>>>> to
> > >>>>>>> start a new application on? I think this is an overall flaw of
> the
> > >>>>>>> discussed idea here. Not playing attention to the overall
> > >>>>>>> architecture."
> > >>>>>>> Could you explain a bit more when one can't start a new
> > application?
> > >>>>>>>
> > >>>>>>> Jun
> > >>>>>>>
> > >>>>>>>
> > >>>>>>>
> > >>>>>>> On Sat, Mar 10, 2018 at 1:40 AM, Jan Filipiak <
> > >>>>>>> Jan.Filipiak@trivago.com
> > >>>>>>> wrote:
> > >>>>>>>
> > >>>>>>> Hi Jun, thanks for your mail.
> > >>>>>>>
> > >>>>>>> Thank you for your questions!
> > >>>>>>>> I think they are really good and tackle the core of the problem
> I
> > >>>>>>>> see.
> > >>>>>>>>
> > >>>>>>>> I will answer inline, mostly but still want to set the tone
> here.
> > >>>>>>>>
> > >>>>>>>> The core strength of kafka is what Martin once called the
> > >>>>>>>> kappa-Architecture. How does this work?
> > >>>>>>>> You have everything as a log as in kafka. When you need to
> change
> > >>>>>>>> something.
> > >>>>>>>> You create the new version of your application and leave it
> > running
> > >>>>>>>> in
> > >>>>>>>> parallel.
> > >>>>>>>> Once the new version is good you switch your users to use the
> new
> > >>>>>>>> application.
> > >>>>>>>>
> > >>>>>>>> The online reshuffling effectively breaks this architecture and
> I
> > >>>>>>>> think
> > >>>>>>>> the switch in thinking here is more harmful
> > >>>>>>>> than any details about the partitioning function to allow such a
> > >>>>>>>> change.
> > >>>>>>>> I
> > >>>>>>>> feel with my suggestion we are the closest to
> > >>>>>>>> the original and battle proven architecture and I can only warn
> to
> > >>>>>>>> move
> > >>>>>>>> away from it.
> > >>>>>>>>
> > >>>>>>>> I might have forgotten something, sometimes its hard for me to
> > >>>>>>>> getting
> > >>>>>>>> all
> > >>>>>>>> the thoughts captured in a mail, but I hope the comments inline
> > will
> > >>>>>>>> further make my concern clear, and put some emphasis on why I
> > >>>>>>>> prefer my
> > >>>>>>>> solution ;)
> > >>>>>>>>
> > >>>>>>>> One thing we should all be aware of when discussing this, and I
> > >>>>>>>> think
> > >>>>>>>> Dong
> > >>>>>>>> should have mentioned it (maybe he did).
> > >>>>>>>> We are not discussing all of this out of thin air but there is
> an
> > >>>>>>>> effort
> > >>>>>>>> in the Samza project.
> > >>>>>>>>
> > >>>>>>>> https://cwiki.apache.org/confluence/display/SAMZA/SEP-5%3A+
> > >>>>>>>> Enable+partition+expansion+of+input+streams
> > >>>>>>>> https://issues.apache.org/jira/browse/SAMZA-1293
> > >>>>>>>>
> > >>>>>>>> To be clear. I think SEP-5 (state of last week, dont know if it
> > >>>>>>>> adapted
> > >>>>>>>> to
> > >>>>>>>> this discussion) is on a way better path than KIP-253, and I
> can't
> > >>>>>>>> really
> > >>>>>>>> explain why.
> > >>>>>>>>
> > >>>>>>>> Best Jan,
> > >>>>>>>>
> > >>>>>>>> nice weekend everyone
> > >>>>>>>>
> > >>>>>>>>
> > >>>>>>>> On 09.03.2018 03:36, Jun Rao wrote:
> > >>>>>>>>
> > >>>>>>>> Hi, Jan,
> > >>>>>>>>
> > >>>>>>>> Thanks for the feedback. Just some comments on the earlier
> points
> > >>>>>>>>> that
> > >>>>>>>>> you
> > >>>>>>>>> mentioned.
> > >>>>>>>>>
> > >>>>>>>>> 50. You brought up the question of whether existing data needs
> to
> > >>>>>>>>> be
> > >>>>>>>>> copied
> > >>>>>>>>> during partition expansion. My understand of your view is that
> > >>>>>>>>> avoid
> > >>>>>>>>> copying existing data will be more efficient, but it doesn't
> work
> > >>>>>>>>> well
> > >>>>>>>>> with
> > >>>>>>>>> compacted topics since some keys in the original partitions
> will
> > >>>>>>>>> never
> > >>>>>>>>> be
> > >>>>>>>>> cleaned. It would be useful to understand your use case of
> > >>>>>>>>> compacted
> > >>>>>>>>> topics
> > >>>>>>>>> a bit more. In the common use case, the data volume in a
> > compacted
> > >>>>>>>>> topic
> > >>>>>>>>> may not be large. So, I am not sure if there is a strong need
> to
> > >>>>>>>>> expand
> > >>>>>>>>> partitions in a compacted topic, at least initially.
> > >>>>>>>>>
> > >>>>>>>>> I do agree. State is usually smaller. Update rates might be
> also
> > >>>>>>>>>
> > >>>>>>>>> competitively high.
> > >>>>>>>> Doing Log-compaction (even beeing very efficient and
> configurable)
> > >>>>>>>> is
> > >>>>>>>> also
> > >>>>>>>> a more expensive operation than
> > >>>>>>>> just discarding old segments. Further if you want to use more
> > >>>>>>>> consumers
> > >>>>>>>> processing the events
> > >>>>>>>> you also have to grow the number of partitions. Especially for
> > >>>>>>>> use-cases
> > >>>>>>>> we do (KIP-213) a tiny state full
> > >>>>>>>> table might be very expensive to process if it joins against a
> > huge
> > >>>>>>>> table.
> > >>>>>>>>
> > >>>>>>>> I can just say we have been in the spot of needing to grow log
> > >>>>>>>> compacted
> > >>>>>>>> topics. Mainly for processing power we can bring to the table.
> > >>>>>>>>
> > >>>>>>>> Further i am not at all concerned about the extra spaced used by
> > >>>>>>>> "garbage
> > >>>>>>>> keys". I am more concerned about the correctness of innocent
> > >>>>>>>> consumers.
> > >>>>>>>> The
> > >>>>>>>> logic becomes complicated. Say for streams one would need to
> load
> > >>>>>>>> the
> > >>>>>>>> record into state but not forward it the topology ( to have it
> > >>>>>>>> available
> > >>>>>>>> for shuffeling). I rather have it simple and a topic clean
> > >>>>>>>> regardless
> > >>>>>>>> if
> > >>>>>>>> it
> > >>>>>>>> still has its old partition count. Especially with multiple
> > >>>>>>>> partitions
> > >>>>>>>> growth's I think it becomes insanely hard to to this shuffle
> > >>>>>>>> correct.
> > >>>>>>>> Maybe
> > >>>>>>>> Streams and Samza can do it. Especially if you do "hipster
> stream
> > >>>>>>>> processing" <https://www.confluent.io/blog
> > >>>>>>>> /introducing-kafka-streams-
> > >>>>>>>> stream-processing-made-simple/>. This makes kafka way to
> > >>>>>>>> complicated.
> > >>>>>>>> With my approach I think its way simpler because the topic has
> no
> > >>>>>>>> "history"
> > >>>>>>>> in terms of partitioning but is always clean.
> > >>>>>>>>
> > >>>>>>>>
> > >>>>>>>> 51. "Growing the topic by an integer factor does not require any
> > >>>>>>>> state
> > >>>>>>>>
> > >>>>>>>> redistribution at all." Could you clarify this a bit more? Let's
> > say
> > >>>>>>>>> you
> > >>>>>>>>> have a consumer app that computes the windowed count per key.
> If
> > >>>>>>>>> you
> > >>>>>>>>> double
> > >>>>>>>>> the number of partitions from 1 to 2 and grow the consumer
> > >>>>>>>>> instances
> > >>>>>>>>> from
> > >>>>>>>>> 1
> > >>>>>>>>> to 2, we would need to redistribute some of the counts to the
> new
> > >>>>>>>>> consumer
> > >>>>>>>>> instance. Regarding to linear hashing, it's true that it won't
> > >>>>>>>>> solve
> > >>>>>>>>> the
> > >>>>>>>>> problem with compacted topics. The main benefit is that it
> > >>>>>>>>> redistributes
> > >>>>>>>>> the keys in one partition to no more than two partitions, which
> > >>>>>>>>> could
> > >>>>>>>>> help
> > >>>>>>>>> redistribute the state.
> > >>>>>>>>>
> > >>>>>>>>> You don't need to spin up a new consumer in this case. every
> > >>>>>>>>> consumer
> > >>>>>>>>>
> > >>>>>>>>> would just read every partition with the (partition % num_task)
> > >>>>>>>> task.
> > >>>>>>>> it
> > >>>>>>>> will still have the previous data right there and can go on.
> > >>>>>>>>
> > >>>>>>>> This sounds contradictory to what I said before, but please bear
> > >>>>>>>> with
> > >>>>>>>> me.
> > >>>>>>>>
> > >>>>>>>> 52. Good point on coordinating the expansion of 2 topics that
> need
> > >>>>>>>> to
> > >>>>>>>> be
> > >>>>>>>>
> > >>>>>>>> joined together. This is where the 2-phase partition expansion
> > could
> > >>>>>>>>> potentially help. In the first phase, we could add new
> partitions
> > >>>>>>>>> to
> > >>>>>>>>> the 2
> > >>>>>>>>> topics one at a time but without publishing to the new
> patitions.
> > >>>>>>>>> Then,
> > >>>>>>>>> we
> > >>>>>>>>> can add new consumer instances to pick up the new partitions.
> In
> > >>>>>>>>> this
> > >>>>>>>>> transition phase, no reshuffling is needed since no data is
> > coming
> > >>>>>>>>> from
> > >>>>>>>>> the
> > >>>>>>>>> new partitions. Finally, we can enable the publishing to the
> new
> > >>>>>>>>> partitions.
> > >>>>>>>>>
> > >>>>>>>>> I think its even worse than you think. I would like to
> introduce
> > >>>>>>>>> the
> > >>>>>>>>>
> > >>>>>>>>> Term
> > >>>>>>>> transitive copartitioning. Imagine
> > >>>>>>>> 2 streams application. One joins (A,B) the other (B,C) then
> there
> > >>>>>>>> is a
> > >>>>>>>> transitive copartition requirement for
> > >>>>>>>> (A,C) to be copartitioned aswell. This can spread significantly
> > and
> > >>>>>>>> require many consumers to adapt at the same time.
> > >>>>>>>>
> > >>>>>>>> It is also not entirely clear to me how you not need reshuffling
> > in
> > >>>>>>>> this
> > >>>>>>>> case. If A has a record that never gets updated after the
> > expansion
> > >>>>>>>> and
> > >>>>>>>> the
> > >>>>>>>> coresponding B record moves to a new partition. How shall they
> > meet
> > >>>>>>>> w/o
> > >>>>>>>> shuffle?
> > >>>>>>>>
> > >>>>>>>> 53. "Migrating consumer is a step that might be made completly
> > >>>>>>>>
> > >>>>>>>> unnecessary
> > >>>>>>>>> if - for example streams - takes the gcd as partitioning scheme
> > >>>>>>>>> instead
> > >>>>>>>>> of
> > >>>>>>>>> enforcing 1 to 1." Not sure that I fully understand this. I
> think
> > >>>>>>>>> you
> > >>>>>>>>> mean
> > >>>>>>>>> that a consumer application can run more instances than the
> > number
> > >>>>>>>>> of
> > >>>>>>>>> partitions. In that case, the consumer can just repartitioning
> > the
> > >>>>>>>>> input
> > >>>>>>>>> data according to the number of instances. This is possible,
> but
> > >>>>>>>>> just
> > >>>>>>>>> has
> > >>>>>>>>> the overhead of reshuffling the data.
> > >>>>>>>>>
> > >>>>>>>>> No what I meant is ( that is also your question i think
> Mathias)
> > >>>>>>>>> that
> > >>>>>>>>> if
> > >>>>>>>>>
> > >>>>>>>>> you grow a topic by a factor.
> > >>>>>>>> Even if your processor is statefull you can can just assign all
> > the
> > >>>>>>>> multiples of the previous partition to
> > >>>>>>>> this consumer and the state to keep processing correctly will be
> > >>>>>>>> present
> > >>>>>>>> w/o any shuffling.
> > >>>>>>>>
> > >>>>>>>> Say you have an assignment
> > >>>>>>>> Statefull consumer => partition
> > >>>>>>>> 0 => 0
> > >>>>>>>> 1 => 1
> > >>>>>>>> 2 => 2
> > >>>>>>>>
> > >>>>>>>> and you grow you topic by 4 you get,
> > >>>>>>>>
> > >>>>>>>> 0 => 0,3,6,9
> > >>>>>>>> 1 => 1,4,7,10
> > >>>>>>>> 2 => 2,5,8,11
> > >>>>>>>>
> > >>>>>>>> Say your hashcode is 8. 8%3 => 2  before so consumer for
> > partition 2
> > >>>>>>>> has
> > >>>>>>>> it.
> > >>>>>>>> Now you you have 12 partitions so 8%12 => 8, so it goes into
> > >>>>>>>> partition
> > >>>>>>>> 8
> > >>>>>>>> which is assigned to the same consumer
> > >>>>>>>> who had 2 before and therefore knows the key.
> > >>>>>>>>
> > >>>>>>>> Userland reshuffeling is there as an options. And it does
> exactly
> > >>>>>>>> what
> > >>>>>>>> I
> > >>>>>>>> suggest. And I think its the perfect strategie. All I am
> > suggestion
> > >>>>>>>> is
> > >>>>>>>> broker side support to switch the producers to the newly
> > partitioned
> > >>>>>>>> topic.
> > >>>>>>>> Then the old (to few partition topic) can go away.  Remember the
> > >>>>>>>> list
> > >>>>>>>> of
> > >>>>>>>> steps in the beginning of this thread. If one has broker support
> > for
> > >>>>>>>> all
> > >>>>>>>> where its required and streams support for those that aren’t
> > >>>>>>>> necessarily.
> > >>>>>>>> Then one has solved the problem.
> > >>>>>>>> I repeat it because I think its important. I am really happy
> that
> > >>>>>>>> you
> > >>>>>>>> brought that up! because its 100% what I want just with the
> > >>>>>>>> differences
> > >>>>>>>> to
> > >>>>>>>> have an option to discard the to small topic later (after all
> > >>>>>>>> consumers
> > >>>>>>>> adapted). And to have order correct there. I need broker support
> > >>>>>>>> managing
> > >>>>>>>> the copy process + the produces and fence them against each
> > other. I
> > >>>>>>>> also
> > >>>>>>>> repeat. the copy process can run for weeks in the worst case.
> > >>>>>>>> Copying
> > >>>>>>>> the
> > >>>>>>>> data is not the longest task migrating consumers might very well
> > be.
> > >>>>>>>> Once all consumers switched and copying is really up to date
> > (think
> > >>>>>>>> ISR
> > >>>>>>>> like up to date) only then we stop the producer, wait for the
> copy
> > >>>>>>>> to
> > >>>>>>>> finish and use the new topic for producing.
> > >>>>>>>>
> > >>>>>>>> After this the topic is perfect in shape. and no one needs to
> > worry
> > >>>>>>>> about
> > >>>>>>>> complicated stuff. (old keys hanging around might arrive in some
> > >>>>>>>> other
> > >>>>>>>> topic later.....). can only imagine how many tricky bugs gonna
> > >>>>>>>> arrive
> > >>>>>>>> after
> > >>>>>>>> someone had grown and shrunken is topic 10 times.
> > >>>>>>>>
> > >>>>>>>>
> > >>>>>>>>
> > >>>>>>>>
> > >>>>>>>>
> > >>>>>>>>
> > >>>>>>>> 54. "The other thing I wanted to mention is that I believe the
> > >>>>>>>> current
> > >>>>>>>>
> > >>>>>>>> suggestion (without copying data over) can be implemented in
> pure
> > >>>>>>>>> userland
> > >>>>>>>>> with a custom partitioner and a small feedbackloop from
> > >>>>>>>>> ProduceResponse
> > >>>>>>>>> =>
> > >>>>>>>>> Partitionier in coorporation with a change management system."
> I
> > am
> > >>>>>>>>> not
> > >>>>>>>>> sure a customized partitioner itself solves the problem. We
> > >>>>>>>>> probably
> > >>>>>>>>> need
> > >>>>>>>>> some broker side support to enforce when the new partitions can
> > be
> > >>>>>>>>> used.
> > >>>>>>>>> We
> > >>>>>>>>> also need some support on the consumer/kstream side to preserve
> > the
> > >>>>>>>>> per
> > >>>>>>>>> key
> > >>>>>>>>> ordering and potentially migrate the processing state. This is
> > not
> > >>>>>>>>> trivial
> > >>>>>>>>> and I am not sure if it's ideal to fully push to the
> application
> > >>>>>>>>> space.
> > >>>>>>>>>
> > >>>>>>>>> Broker support is defenitly the preferred way here. I have
> > nothing
> > >>>>>>>>>
> > >>>>>>>>> against
> > >>>>>>>> broker support.
> > >>>>>>>> I tried to say that for what I would preffer - copying the data
> > >>>>>>>> over,
> > >>>>>>>> at
> > >>>>>>>> least for log compacted topics -
> > >>>>>>>> I would require more broker support than the KIP currently
> offers.
> > >>>>>>>>
> > >>>>>>>>
> > >>>>>>>>
> > >>>>>>>> Jun
> > >>>>>>>>
> > >>>>>>>> On Tue, Mar 6, 2018 at 10:33 PM, Jan Filipiak <
> > >>>>>>>>> Jan.Filipiak@trivago.com
> > >>>>>>>>> wrote:
> > >>>>>>>>>
> > >>>>>>>>> Hi Dong,
> > >>>>>>>>>
> > >>>>>>>>> are you actually reading my emails, or are you just using the
> > >>>>>>>>> thread I
> > >>>>>>>>>
> > >>>>>>>>>> started for general announcements regarding the KIP?
> > >>>>>>>>>>
> > >>>>>>>>>> I tried to argue really hard against linear hashing. Growing
> the
> > >>>>>>>>>> topic
> > >>>>>>>>>> by
> > >>>>>>>>>> an integer factor does not require any state redistribution at
> > >>>>>>>>>> all. I
> > >>>>>>>>>> fail
> > >>>>>>>>>> to see completely where linear hashing helps on log compacted
> > >>>>>>>>>> topics.
> > >>>>>>>>>>
> > >>>>>>>>>> If you are not willing to explain to me what I might be
> > >>>>>>>>>> overlooking:
> > >>>>>>>>>> that
> > >>>>>>>>>> is fine.
> > >>>>>>>>>> But I ask you to not reply to my emails then. Please
> understand
> > my
> > >>>>>>>>>> frustration with this.
> > >>>>>>>>>>
> > >>>>>>>>>> Best Jan
> > >>>>>>>>>>
> > >>>>>>>>>>
> > >>>>>>>>>>
> > >>>>>>>>>> On 06.03.2018 19:38, Dong Lin wrote:
> > >>>>>>>>>>
> > >>>>>>>>>> Hi everyone,
> > >>>>>>>>>>
> > >>>>>>>>>> Thanks for all the comments! It appears that everyone prefers
> > >>>>>>>>>> linear
> > >>>>>>>>>>
> > >>>>>>>>>>> hashing because it reduces the amount of state that needs to
> be
> > >>>>>>>>>>> moved
> > >>>>>>>>>>> between consumers (for stream processing). The KIP has been
> > >>>>>>>>>>> updated
> > >>>>>>>>>>> to
> > >>>>>>>>>>> use
> > >>>>>>>>>>> linear hashing.
> > >>>>>>>>>>>
> > >>>>>>>>>>> Regarding the migration endeavor: it seems that migrating
> > >>>>>>>>>>> producer
> > >>>>>>>>>>> library
> > >>>>>>>>>>> to use linear hashing should be pretty straightforward
> without
> > >>>>>>>>>>> much operational endeavor. If we don't upgrade client library
> > to
> > >>>>>>>>>>> use
> > >>>>>>>>>>> this
> > >>>>>>>>>>> KIP, we can not support in-order delivery after partition is
> > >>>>>>>>>>> changed
> > >>>>>>>>>>> anyway. Suppose we upgrade client library to use this KIP, if
> > >>>>>>>>>>> partition
> > >>>>>>>>>>> number is not changed, the key -> partition mapping will be
> > >>>>>>>>>>> exactly
> > >>>>>>>>>>> the
> > >>>>>>>>>>> same as it is now because it is still determined using
> > >>>>>>>>>>> murmur_hash(key)
> > >>>>>>>>>>> %
> > >>>>>>>>>>> original_partition_num. In other words, this change is
> backward
> > >>>>>>>>>>> compatible.
> > >>>>>>>>>>>
> > >>>>>>>>>>> Regarding the load distribution: if we use linear hashing,
> the
> > >>>>>>>>>>> load
> > >>>>>>>>>>> may
> > >>>>>>>>>>> be
> > >>>>>>>>>>> unevenly distributed because those partitions which are not
> > split
> > >>>>>>>>>>> may
> > >>>>>>>>>>> receive twice as much traffic as other partitions that are
> > split.
> > >>>>>>>>>>> This
> > >>>>>>>>>>> issue can be mitigated by creating topic with partitions that
> > are
> > >>>>>>>>>>> several
> > >>>>>>>>>>> times the number of consumers. And there will be no imbalance
> > if
> > >>>>>>>>>>> the
> > >>>>>>>>>>> partition number is always doubled. So this imbalance seems
> > >>>>>>>>>>> acceptable.
> > >>>>>>>>>>>
> > >>>>>>>>>>> Regarding storing the partition strategy as per-topic config:
> > It
> > >>>>>>>>>>> seems
> > >>>>>>>>>>> not
> > >>>>>>>>>>> necessary since we can still use murmur_hash as the default
> > hash
> > >>>>>>>>>>> function
> > >>>>>>>>>>> and additionally apply the linear hashing algorithm if the
> > >>>>>>>>>>> partition
> > >>>>>>>>>>> number
> > >>>>>>>>>>> has increased. Not sure if there is any use-case for producer
> > to
> > >>>>>>>>>>> use a
> > >>>>>>>>>>> different hash function. Jason, can you check if there is
> some
> > >>>>>>>>>>> use-case
> > >>>>>>>>>>> that I missed for using the per-topic partition strategy?
> > >>>>>>>>>>>
> > >>>>>>>>>>> Regarding how to reduce latency (due to state store/load) in
> > >>>>>>>>>>> stream
> > >>>>>>>>>>> processing consumer when partition number changes: I need to
> > read
> > >>>>>>>>>>> the
> > >>>>>>>>>>> Kafka
> > >>>>>>>>>>> Stream code to understand how Kafka Stream currently migrate
> > >>>>>>>>>>> state
> > >>>>>>>>>>> between
> > >>>>>>>>>>> consumers when the application is added/removed for a given
> > job.
> > >>>>>>>>>>> I
> > >>>>>>>>>>> will
> > >>>>>>>>>>> reply after I finish reading the documentation and code.
> > >>>>>>>>>>>
> > >>>>>>>>>>>
> > >>>>>>>>>>> Thanks,
> > >>>>>>>>>>> Dong
> > >>>>>>>>>>>
> > >>>>>>>>>>>
> > >>>>>>>>>>> On Mon, Mar 5, 2018 at 10:43 AM, Jason Gustafson <
> > >>>>>>>>>>> jason@confluent.io>
> > >>>>>>>>>>> wrote:
> > >>>>>>>>>>>
> > >>>>>>>>>>> Great discussion. I think I'm wondering whether we can
> continue
> > >>>>>>>>>>> to
> > >>>>>>>>>>> leave
> > >>>>>>>>>>>
> > >>>>>>>>>>> Kafka agnostic to the partitioning strategy. The challenge is
> > >>>>>>>>>>>
> > >>>>>>>>>>> communicating
> > >>>>>>>>>>>> the partitioning logic from producers to consumers so that
> the
> > >>>>>>>>>>>> dependencies
> > >>>>>>>>>>>> between each epoch can be determined. For the sake of
> > >>>>>>>>>>>> discussion,
> > >>>>>>>>>>>> imagine
> > >>>>>>>>>>>> you did something like the following:
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> 1. The name (and perhaps version) of a partitioning strategy
> > is
> > >>>>>>>>>>>> stored
> > >>>>>>>>>>>> in
> > >>>>>>>>>>>> topic configuration when a topic is created.
> > >>>>>>>>>>>> 2. The producer looks up the partitioning strategy before
> > >>>>>>>>>>>> writing
> > >>>>>>>>>>>> to
> > >>>>>>>>>>>> a
> > >>>>>>>>>>>> topic and includes it in the produce request (for fencing).
> If
> > >>>>>>>>>>>> it
> > >>>>>>>>>>>> doesn't
> > >>>>>>>>>>>> have an implementation for the configured strategy, it
> fails.
> > >>>>>>>>>>>> 3. The consumer also looks up the partitioning strategy and
> > >>>>>>>>>>>> uses it
> > >>>>>>>>>>>> to
> > >>>>>>>>>>>> determine dependencies when reading a new epoch. It could
> > either
> > >>>>>>>>>>>> fail
> > >>>>>>>>>>>> or
> > >>>>>>>>>>>> make the most conservative dependency assumptions if it
> > doesn't
> > >>>>>>>>>>>> know
> > >>>>>>>>>>>> how
> > >>>>>>>>>>>> to
> > >>>>>>>>>>>> implement the partitioning strategy. For the consumer, the
> new
> > >>>>>>>>>>>> interface
> > >>>>>>>>>>>> might look something like this:
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> // Return the partition dependencies following an epoch bump
> > >>>>>>>>>>>> Map<Integer, List<Integer>> dependencies(int
> > >>>>>>>>>>>> numPartitionsBeforeEpochBump,
> > >>>>>>>>>>>> int numPartitionsAfterEpochBump)
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> The unordered case then is just a particular implementation
> > >>>>>>>>>>>> which
> > >>>>>>>>>>>> never
> > >>>>>>>>>>>> has
> > >>>>>>>>>>>> any epoch dependencies. To implement this, we would need
> some
> > >>>>>>>>>>>> way
> > >>>>>>>>>>>> for
> > >>>>>>>>>>>> the
> > >>>>>>>>>>>> consumer to find out how many partitions there were in each
> > >>>>>>>>>>>> epoch,
> > >>>>>>>>>>>> but
> > >>>>>>>>>>>> maybe that's not too unreasonable.
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> Thanks,
> > >>>>>>>>>>>> Jason
> > >>>>>>>>>>>>
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> On Mon, Mar 5, 2018 at 4:51 AM, Jan Filipiak <
> > >>>>>>>>>>>> Jan.Filipiak@trivago.com
> > >>>>>>>>>>>> wrote:
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> Hi Dong
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> thank you very much for your questions.
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> regarding the time spend copying data across:
> > >>>>>>>>>>>>> It is correct that copying data from a topic with one
> > partition
> > >>>>>>>>>>>>> mapping
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>>> to
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>>> a topic with a different partition mapping takes way longer
> > >>>>>>>>>>>>> than
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>> we
> > >>>>>>>>>>>> can
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> stop producers. Tens of minutes is a very optimistic
> estimate
> > >>>>>>>>>>>> here.
> > >>>>>>>>>>>>
> > >>>>>>>>>>>>> Many
> > >>>>>>>>>>>>> people can not afford copy full steam and therefore will
> have
> > >>>>>>>>>>>>> some
> > >>>>>>>>>>>>> rate
> > >>>>>>>>>>>>> limiting in place, this can bump the timespan into the
> day's.
> > >>>>>>>>>>>>> The
> > >>>>>>>>>>>>> good
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>>> part
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>>> is that the vast majority of the data can be copied while
> the
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>> producers
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> are
> > >>>>>>>>>>>>
> > >>>>>>>>>>>>> still going. One can then, piggyback the consumers ontop of
> > >>>>>>>>>>>>> this
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>> timeframe,
> > >>>>>>>>>>>>
> > >>>>>>>>>>>>> by the method mentioned (provide them an mapping from their
> > old
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>> offsets
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> to
> > >>>>>>>>>>>>
> > >>>>>>>>>>>>> new offsets in their repartitioned topics. In that way we
> > >>>>>>>>>>>>> separate
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>> migration of consumers from migration of producers
> (decoupling
> > >>>>>>>>>>>>
> > >>>>>>>>>>>>> these
> > >>>>>>>>>>>>> is
> > >>>>>>>>>>>>> what kafka is strongest at). The time to actually swap over
> > the
> > >>>>>>>>>>>>> producers
> > >>>>>>>>>>>>> should be kept minimal by ensuring that when a swap attempt
> > is
> > >>>>>>>>>>>>> started
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>>> the
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>>> consumer copying over should be very close to the log end
> and
> > >>>>>>>>>>>>> is
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>> expected
> > >>>>>>>>>>>>
> > >>>>>>>>>>>>> to finish within the next fetch. The operation should have
> a
> > >>>>>>>>>>>>> time-out
> > >>>>>>>>>>>>> and
> > >>>>>>>>>>>>> should be "reattemtable".
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>>> Importance of logcompaction:
> > >>>>>>>>>>>>> If a producer produces key A, to partiton 0, its forever
> > gonna
> > >>>>>>>>>>>>> be
> > >>>>>>>>>>>>> there,
> > >>>>>>>>>>>>> unless it gets deleted. The record might sit in there for
> > >>>>>>>>>>>>> years. A
> > >>>>>>>>>>>>> new
> > >>>>>>>>>>>>> producer started with the new partitions will fail to
> delete
> > >>>>>>>>>>>>> the
> > >>>>>>>>>>>>> record
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>>> in
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>>> the correct partition. Th record will be there forever and
> > one
> > >>>>>>>>>>>>> can
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>> not
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> reliable bootstrap new consumers. I cannot see how linear
> > >>>>>>>>>>>> hashing
> > >>>>>>>>>>>>
> > >>>>>>>>>>>>> can
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>>> solve
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>>> this.
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>> Regarding your skipping of userland copying:
> > >>>>>>>>>>>>
> > >>>>>>>>>>>>> 100%, copying the data across in userland is, as far as i
> can
> > >>>>>>>>>>>>> see,
> > >>>>>>>>>>>>> only
> > >>>>>>>>>>>>> a
> > >>>>>>>>>>>>> usecase for log compacted topics. Even for logcompaction +
> > >>>>>>>>>>>>> retentions
> > >>>>>>>>>>>>> it
> > >>>>>>>>>>>>> should only be opt-in. Why did I bring it up? I think log
> > >>>>>>>>>>>>> compaction
> > >>>>>>>>>>>>> is
> > >>>>>>>>>>>>> a
> > >>>>>>>>>>>>> very important feature to really embrace kafka as a "data
> > >>>>>>>>>>>>> plattform".
> > >>>>>>>>>>>>> The
> > >>>>>>>>>>>>> point I also want to make is that copying data this way is
> > >>>>>>>>>>>>> completely
> > >>>>>>>>>>>>> inline with the kafka architecture. it only consists of
> > reading
> > >>>>>>>>>>>>> and
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>>> writing
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>>> to topics.
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>> I hope it clarifies more why I think we should aim for more
> > than
> > >>>>>>>>>>>>
> > >>>>>>>>>>>>> the
> > >>>>>>>>>>>>> current KIP. I fear that once the KIP is done not much more
> > >>>>>>>>>>>>> effort
> > >>>>>>>>>>>>> will
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>>> be
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>>> taken.
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> On 04.03.2018 02:28, Dong Lin wrote:
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>>> Hey Jan,
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>>> In the current proposal, the consumer will be blocked on
> > >>>>>>>>>>>>> waiting
> > >>>>>>>>>>>>> for
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>>> other
> > >>>>>>>>>>>>>>
> > >>>>>>>>>>>>>> consumers of the group to consume up to a given offset. In
> > >>>>>>>>>>>>>> most
> > >>>>>>>>>>>>>>
> > >>>>>>>>>>>>> cases,
> > >>>>>>>>>>>>> all
> > >>>>>>>>>>>>> consumers should be close to the LEO of the partitions when
> > the
> > >>>>>>>>>>>>> partition
> > >>>>>>>>>>>>> expansion happens. Thus the time waiting should not be long
> > >>>>>>>>>>>>> e.g.
> > >>>>>>>>>>>>> on
> > >>>>>>>>>>>>> the
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>>> order of seconds. On the other hand, it may take a long
> time
> > to
> > >>>>>>>>>>>>> wait
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>>> for
> > >>>>>>>>>>>>>> the entire partition to be copied -- the amount of time is
> > >>>>>>>>>>>>>> proportional
> > >>>>>>>>>>>>>>
> > >>>>>>>>>>>>>> to
> > >>>>>>>>>>>>>>
> > >>>>>>>>>>>>>> the amount of existing data in the partition, which can
> take
> > >>>>>>>>>>>>>>
> > >>>>>>>>>>>>> tens of
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>>> minutes. So the amount of time that we stop consumers may
> not
> > >>>>>>>>>>>>> be
> > >>>>>>>>>>>>> on
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>>> the
> > >>>>>>>>>>>>>> same order of magnitude.
> > >>>>>>>>>>>>>>
> > >>>>>>>>>>>>>> If we can implement this suggestion without copying data
> > over
> > >>>>>>>>>>>>>> in
> > >>>>>>>>>>>>>> purse
> > >>>>>>>>>>>>>> userland, it will be much more valuable. Do you have ideas
> > on
> > >>>>>>>>>>>>>> how
> > >>>>>>>>>>>>>> this
> > >>>>>>>>>>>>>>
> > >>>>>>>>>>>>>> can
> > >>>>>>>>>>>>>>
> > >>>>>>>>>>>>>> be done?
> > >>>>>>>>>>>>>>
> > >>>>>>>>>>>>> Not sure why the current KIP not help people who depend on
> > log
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>>> compaction.
> > >>>>>>>>>>>>>>
> > >>>>>>>>>>>>>> Could you elaborate more on this point?
> > >>>>>>>>>>>>>>
> > >>>>>>>>>>>>> Thanks,
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>>> Dong
> > >>>>>>>>>>>>>>
> > >>>>>>>>>>>>>> On Wed, Feb 28, 2018 at 10:55 PM, Jan
> > >>>>>>>>>>>>>> Filipiak<Jan.Filipiak@trivago.
> > >>>>>>>>>>>>>> com
> > >>>>>>>>>>>>>> wrote:
> > >>>>>>>>>>>>>>
> > >>>>>>>>>>>>>> Hi Dong,
> > >>>>>>>>>>>>>>
> > >>>>>>>>>>>>>> I tried to focus on what the steps are one can currently
> > >>>>>>>>>>>>>> perform
> > >>>>>>>>>>>>>> to
> > >>>>>>>>>>>>>>
> > >>>>>>>>>>>>>> expand
> > >>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>> or shrink a keyed topic while maintaining a top notch
> > >>>>>>>>>>>>>>> semantics.
> > >>>>>>>>>>>>>>> I can understand that there might be confusion about
> > >>>>>>>>>>>>>>> "stopping
> > >>>>>>>>>>>>>>> the
> > >>>>>>>>>>>>>>> consumer". It is exactly the same as proposed in the KIP.
> > >>>>>>>>>>>>>>> there
> > >>>>>>>>>>>>>>> needs
> > >>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>> to
> > >>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>> be
> > >>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>> a time the producers agree on the new partitioning. The
> > extra
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>>> semantics I
> > >>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>> want to put in there is that we have a possibility to
> wait
> > >>>>>>>>>>>>>>> until
> > >>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>> all
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>>> the
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>>> existing data
> > >>>>>>>>>>>>>>
> > >>>>>>>>>>>>>> is copied over into the new partitioning scheme. When I
> say
> > >>>>>>>>>>>>> stopping
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>>> I
> > >>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>> think more of having a memory barrier that ensures the
> > >>>>>>>>>>>>>>> ordering. I
> > >>>>>>>>>>>>>>> am
> > >>>>>>>>>>>>>>> still
> > >>>>>>>>>>>>>>> aming for latencies  on the scale of leader failovers.
> > >>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>> Consumers have to explicitly adapt the new partitioning
> > >>>>>>>>>>>>>>> scheme
> > >>>>>>>>>>>>>>> in
> > >>>>>>>>>>>>>>> the
> > >>>>>>>>>>>>>>> above scenario. The reason is that in these cases where
> you
> > >>>>>>>>>>>>>>> are
> > >>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>> dependent
> > >>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>> on a particular partitioning scheme, you also have other
> > >>>>>>>>>>>>>>> topics
> > >>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>> that
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>>> have
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>>> co-partition enforcements or the kind -frequently.
> Therefore
> > >>>>>>>>>>>>>> all
> > >>>>>>>>>>>>>>
> > >>>>>>>>>>>>>> your
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>>> other
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>>> input topics might need to grow accordingly.
> > >>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>> What I was suggesting was to streamline all these
> > operations
> > >>>>>>>>>>>>>>> as
> > >>>>>>>>>>>>>>> best
> > >>>>>>>>>>>>>>> as
> > >>>>>>>>>>>>>>> possible to have "real" partition grow and shrinkage
> going
> > >>>>>>>>>>>>>>> on.
> > >>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>> Migrating
> > >>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>> the producers to a new partitioning scheme can be much
> more
> > >>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>> streamlined
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>>> with proper broker support for this. Migrating consumer is
> a
> > >>>>>>>>>>>>> step
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>>> that
> > >>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>> might be made completly unnecessary if - for example
> > streams
> > >>>>>>>>>>>>>>> -
> > >>>>>>>>>>>>>>> takes
> > >>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>> the
> > >>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>> gcd as partitioning scheme instead of enforcing 1 to 1.
> > >>>>>>>>>>>>>>> Connect
> > >>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>> consumers
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>>> and other consumers should be fine anyways.
> > >>>>>>>>>>>>>>
> > >>>>>>>>>>>>>> I hope this makes more clear where I was aiming at. The
> rest
> > >>>>>>>>>>>>> needs
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>>> to
> > >>>>>>>>>>>>>>
> > >>>>>>>>>>>>>> be
> > >>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>> figured out. The only danger i see is that when we are
> > >>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>> introducing
> > >>>>>>>>>>>>>>
> > >>>>>>>>>>>>>> this
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>>> feature as supposed in the KIP, it wont help any people
> > >>>>>>>>>>>>> depending
> > >>>>>>>>>>>>> on
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>>> log
> > >>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>> compaction.
> > >>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>> The other thing I wanted to mention is that I believe the
> > >>>>>>>>>>>>> current
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>>> suggestion (without copying data over) can be implemented
> in
> > >>>>>>>>>>>>>> pure
> > >>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>> userland
> > >>>>>>>>>>>>>>> with a custom partitioner and a small feedbackloop from
> > >>>>>>>>>>>>>>> ProduceResponse
> > >>>>>>>>>>>>>>> =>
> > >>>>>>>>>>>>>>> Partitionier in coorporation with a change management
> > system.
> > >>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>> Best Jan
> > >>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>> On 28.02.2018 07:13, Dong Lin wrote:
> > >>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>> Hey Jan,
> > >>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>> I am not sure if it is acceptable for producer to be
> > stopped
> > >>>>>>>>>>>>>>> for a
> > >>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>> while,
> > >>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>> particularly for online application which requires low
> > >>>>>>>>>>>>>>>> latency. I
> > >>>>>>>>>>>>>>>> am
> > >>>>>>>>>>>>>>>> also
> > >>>>>>>>>>>>>>>> not sure how consumers can switch to a new topic. Does
> > user
> > >>>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>> application
> > >>>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>> needs to explicitly specify a different topic for
> > >>>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>> producer/consumer
> > >>>>>>>>>>>>>>
> > >>>>>>>>>>>>>> to
> > >>>>>>>>>>>>>>
> > >>>>>>>>>>>>> subscribe to? It will be helpful for discussion if you can
> > >>>>>>>>>>>>> provide
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>>> more
> > >>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>> detail on the interface change for this solution.
> > >>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>> Thanks,
> > >>>>>>>>>>>>>>
> > >>>>>>>>>>>>>> Dong
> > >>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>> On Mon, Feb 26, 2018 at 12:48 AM, Jan
> > >>>>>>>>>>>>>>>> Filipiak<Jan.Filipiak@trivago.
> > >>>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>> com
> > >>>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>> wrote:
> > >>>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>> Hi,
> > >>>>>>>>>>>>>>
> > >>>>>>>>>>>>>> just want to throw my though in. In general the
> > functionality
> > >>>>>>>>>>>>>> is
> > >>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>> very
> > >>>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>> usefull, we should though not try to find the
> architecture
> > >>>>>>>>>>>>>>>> to
> > >>>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>> hard
> > >>>>>>>>>>>>>>>>> while
> > >>>>>>>>>>>>>>>>> implementing.
> > >>>>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>>> The manual steps would be to
> > >>>>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>>> create a new topic
> > >>>>>>>>>>>>>>>>> the mirrormake from the new old topic to the new topic
> > >>>>>>>>>>>>>>>>> wait for mirror making to catch up.
> > >>>>>>>>>>>>>>>>> then put the consumers onto the new topic
> > >>>>>>>>>>>>>>>>>            (having mirrormaker spit out a mapping from
> > old
> > >>>>>>>>>>>>>>>>> offsets to
> > >>>>>>>>>>>>>>>>> new
> > >>>>>>>>>>>>>>>>> offsets:
> > >>>>>>>>>>>>>>>>>                if topic is increased by factor X there
> is
> > >>>>>>>>>>>>>>>>> gonna
> > >>>>>>>>>>>>>>>>> be a
> > >>>>>>>>>>>>>>>>> clean
> > >>>>>>>>>>>>>>>>> mapping from 1 offset in the old topic to X offsets in
> > the
> > >>>>>>>>>>>>>>>>> new
> > >>>>>>>>>>>>>>>>> topic,
> > >>>>>>>>>>>>>>>>>                if there is no factor then there is no
> > >>>>>>>>>>>>>>>>> chance to
> > >>>>>>>>>>>>>>>>> generate a
> > >>>>>>>>>>>>>>>>> mapping that can be reasonable used for continuing)
> > >>>>>>>>>>>>>>>>>            make consumers stop at appropriate points
> and
> > >>>>>>>>>>>>>>>>> continue
> > >>>>>>>>>>>>>>>>> consumption
> > >>>>>>>>>>>>>>>>> with offsets from the mapping.
> > >>>>>>>>>>>>>>>>> have the producers stop for a minimal time.
> > >>>>>>>>>>>>>>>>> wait for mirrormaker to finish
> > >>>>>>>>>>>>>>>>> let producer produce with the new metadata.
> > >>>>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>>> Instead of implementing the approach suggest in the KIP
> > >>>>>>>>>>>>>>>>> which
> > >>>>>>>>>>>>>>>>> will
> > >>>>>>>>>>>>>>>>> leave
> > >>>>>>>>>>>>>>>>> log compacted topic completely crumbled and unusable.
> > >>>>>>>>>>>>>>>>> I would much rather try to build infrastructure to
> > support
> > >>>>>>>>>>>>>>>>> the
> > >>>>>>>>>>>>>>>>> mentioned
> > >>>>>>>>>>>>>>>>> above operations more smoothly.
> > >>>>>>>>>>>>>>>>> Especially having producers stop and use another topic
> is
> > >>>>>>>>>>>>>>>>> difficult
> > >>>>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>>> and
> > >>>>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>>> it would be nice if one can trigger "invalid metadata"
> > >>>>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>> exceptions
> > >>>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>> for
> > >>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>> them
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>>> and
> > >>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>> if one could give topics aliases so that their produces
> > with
> > >>>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>>> the
> > >>>>>>>>>>>>>>>>> old
> > >>>>>>>>>>>>>>>>> topic
> > >>>>>>>>>>>>>>>>> will arrive in the new topic.
> > >>>>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>>> The downsides are obvious I guess ( having the same
> data
> > >>>>>>>>>>>>>>>>> twice
> > >>>>>>>>>>>>>>>>> for
> > >>>>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>>> the
> > >>>>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>>> transition period, but kafka tends to scale well with
> > >>>>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>> datasize).
> > >>>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>> So
> > >>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>> its a
> > >>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>> nicer fit into the architecture.
> > >>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>> I further want to argument that the functionality by the
> > KIP
> > >>>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>>> can
> > >>>>>>>>>>>>>>>>> completely be implementing in "userland" with a custom
> > >>>>>>>>>>>>>>>>> partitioner
> > >>>>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>>> that
> > >>>>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>>> handles the transition as needed. I would appreciate if
> > >>>>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>> someone
> > >>>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>> could
> > >>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>> point
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>>> out what a custom partitioner couldn't handle in this case?
> > >>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>> With the above approach, shrinking a topic becomes the
> same
> > >>>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>>> steps.
> > >>>>>>>>>>>>>>>>> Without
> > >>>>>>>>>>>>>>>>> loosing keys in the discontinued partitions.
> > >>>>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>>> Would love to hear what everyone thinks.
> > >>>>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>>> Best Jan
> > >>>>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>>> On 11.02.2018 00:35, Dong Lin wrote:
> > >>>>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>>> Hi all,
> > >>>>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>>> I have created KIP-253: Support in-order message
> delivery
> > >>>>>>>>>>>>>>>>> with
> > >>>>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>>> partition
> > >>>>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>>> expansion. See
> > >>>>>>>>>>>>>>>>>> https://cwiki.apache.org/confl
> > >>>>>>>>>>>>>>>>>> uence/display/KAFKA/KIP-253%
> > >>>>>>>>>>>>>>>>>> 3A+Support+in-order+message+de
> > >>>>>>>>>>>>>>>>>> livery+with+partition+expansio
> > >>>>>>>>>>>>>>>>>> n
> > >>>>>>>>>>>>>>>>>> .
> > >>>>>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>>>> This KIP provides a way to allow messages of the same
> > key
> > >>>>>>>>>>>>>>>>>> from
> > >>>>>>>>>>>>>>>>>> the
> > >>>>>>>>>>>>>>>>>> same
> > >>>>>>>>>>>>>>>>>> producer to be consumed in the same order they are
> > >>>>>>>>>>>>>>>>>> produced
> > >>>>>>>>>>>>>>>>>> even
> > >>>>>>>>>>>>>>>>>> if
> > >>>>>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>>>> we
> > >>>>>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>>>> expand partition of the topic.
> > >>>>>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>>> Thanks,
> > >>>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>> Dong
> > >>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>>>>>
> > >>>>
> > >>
> > >>
> > >
> >
>

Re: [DISCUSS] KIP-253: Support in-order message delivery with partition expansion

Posted by John Roesler <jo...@confluent.io>.
Hey Dong and Jun,

Thanks for the thoughtful responses. If you don't mind, I'll mix my replies
together to try for a coherent response. I'm not too familiar with
mailing-list etiquette, though.

I'm going to keep numbering my points because it makes it easy for you all
to respond.

Point 1:
As I read it, KIP-253 is *just* about properly fencing the producers and
consumers so that you preserve the correct ordering of records during
partition expansion. This is clearly necessary regardless of anything else
we discuss. I think this whole discussion about backfill, consumers,
streams, etc., is beyond the scope of KIP-253. But it would be cumbersome
to start a new thread at this point.

I had missed KIP-253's Proposed Change #9 among all the details... I think
this is a nice addition to the proposal. One thought is that it's actually
irrelevant whether the hash function is linear. This is simply an algorithm
for moving a key from one partition to another, so the type of hash
function need not be a precondition. In fact, it also doesn't matter
whether the topic is compacted or not, the algorithm works regardless.

I think this is a good algorithm to keep in mind, as it might solve a
variety of problems, but it does have a downside: that the producer won't
know whether or not K1 was actually in P1, it just knows that K1 was in
P1's keyspace before the new epoch. Therefore, it will have to
pessimistically send (K1,null) to P1 just in case. But the next time K1
comes along, the producer *also* won't remember that it already retracted
K1 from P1, so it will have to send (K1,null) *again*. By extension, every
time the producer sends to P2, it will also have to send a tombstone to P1,
which is a pretty big burden. To make the situation worse, if there is a
second split, say P2 becomes P2 and P3, then any key Kx belonging to P3
will also have to be retracted from P2 *and* P1, since the producer can't
know whether Kx had been last written to P2 or P1. Over a long period of
time, this clearly becomes a issue, as the producer must send an arbitrary
number of retractions along with every update.

In contrast, the proposed backfill operation has an end, and after it ends,
everyone can afford to forget that there ever was a different partition
layout.

Really, though, figuring out how to split compacted topics is beyond the
scope of KIP-253, so I'm not sure #9 really even needs to be in this KIP...
We do need in-order delivery during partition expansion. It would be fine
by me to say that you *cannot* expand partitions of a log-compacted topic
and call it a day. I think it would be better to tackle that in another KIP.


Point 2:
Regarding whether the consumer re-shuffles its inputs, this is always on
the table; any consumer who wants to re-shuffle its input is free to do so.
But this is currently not required. It's just that the current high-level
story with Kafka encourages the use of partitions as a unit of concurrency.
As long as consumers are single-threaded, they can happily consume a single
partition without concurrency control of any kind. This is a key aspect to
this system that lets folks design high-throughput systems on top of it
surprisingly easily. If all consumers were instead encouraged/required to
implement a repartition of their own, then the consumer becomes
significantly more complex, requiring either the consumer to first produce
to its own intermediate repartition topic or to ensure that consumer
threads have a reliable, high-bandwith channel of communication with every
other consumer thread.

Either of those tradeoffs may be reasonable for a particular user of Kafka,
but I don't know if we're in a position to say that they are reasonable for
*every* user of Kafka.


Point 3:
Regarding Jun's point about this use case, "(3) stateful and maintaining the
states in a local store", I agree that they may use a framework *like*
Kafka Streams, but that is not the same as using Kafka Streams. This is why
I think it's better to solve it in Core: because it is then solved for
KStreams and also for everything else that facilitates local state
maintenance. To me, Streams is a member of the category of "stream
processing frameworks", which is itself a subcategory of "things requiring
local state maintenence". I'm not sure if it makes sense to assert that
Streams is a sufficient and practical replacement for everything in "things
requiring local state maintenence".

But, yes, I do agree that per-key ordering is an absolute requirement,
therefore I think that KIP-253 itself is a necessary step. Regarding the
coupling of the state store partitioning to the topic partitioning, yes,
this is an issue we are discussing solutions to right now. We may go ahead
and introduce an overpartition layer on our inputs to solve it, but then
again, if we get the ability to split partitions with backfill, we may not
need to!


Point 4:
On this:

> Regarding thought 2: If we don't care about the stream use-case, then the
> current KIP probably has already addressed problem without requiring
> consumer to know the partition function. If we care about the stream
> use-case, we already need coordination across producers of different
> topics, i.e. the same partition function needs to be used by producers of
> topics A and B in order to join topics A and B. Thus, it might be
> reasonable to extend coordination a bit and say we need coordination across
> clients (i.e. producer and consumer), such that consumer knows the
> partition function used by producer. If we do so, then we can let consumer
> re-copy data for the change log topic using the same partition function as
> producer. This approach has lower overhead as compared to having producer
> re-copy data of the input topic.
> Also, producer currently does not need to know the data already produced to
> the topic. If we let producer split/merge partition, it would require
> producer to consume the existing data, which intuitively is the task of
> consumer.


I think we do care about use cases *like* Streams, I just don't think we
should rely on Streams to implement a feature of Core like partition
expansion.

Note, though, that we (Streams) do not require coordination across
producers. If two topics are certified to be co-partitioned, then Streams
apps can make use of that knowledge to optimize their topology (skipping a
repartition). But if they don't know whether they are co-partitioned, then
they'd better go ahead and repartition within the topology. This is the
current state.

A huge selling point of Kafka is enabling different parts of loosely
coupled organizations to produce and consume data independently. Some
coordination between producers and consumers is necessary, like
coordinating on the names of topics and their schemas. But Kafka's value
proposition w.r.t. ESBs, etc. is inversely proportional to the amount of
coordination required. I think it behooves us to be extremely skeptical
about introducing any coordination beyond correctness protocols.

Asking producers and consumers, or even two different producers, to share
code like the partition function is a pretty huge ask. What if they are
using different languages?

Comparing organizational overhead vs computational overhead, there are
maybe two orders of magnitude difference between them. In other words, I
would happily take on the (linear) overhead of having the producer re-copy
the data once during a re-partition in order to save the organizational
overhead of tying all the producers and consumers together across multiple
boundaries.

On that last paragraph: note that the producer *did* know the data it
already produced. It handled it the first time around. Asking it to
re-produce it into a new partition layout is squarely within its scope of
capabilities. Contrast this with the alternative, asking the consumer to
re-partition the data. I think this is even less intuitive, when the
partition function belongs to the producer.


Point 5:
Dong asked this:

> For stream use-case that needs to increase consumer number, the
> existing consumer can backfill the existing data in the change log topic to
> the same change log topic with the new partition number, before the new set
> of consumers bootstrap state from the new partitions of the change log
> topic, right?


In this sense, the "consumer" is actually the producer of the changelog
topic, so if we support partition expansion + backfill as a producer/broker
operation, then it would be very straightforward for Streams to split a
state store. As you say, they would simply instruct the broker to split the
changelog topic's partitions, then backfill. Once the backfill is ready,
they can create a new crop of StandbyTasks to bootstrap the more granular
state stores and finally switch over to them when they are ready.

But this actually seems to be an argument in favor of split+backfill, so
maybe I missed the point.

You also asked me to explain why copying the "input" topic is better than
copying the "changelog" topic. I think they are totally independent,
actually. For one thing, you can't depend on the existence of a "changelog"
topic in general, only within Streams, but Kafka's user base clearly
exceeds Streams's user base. Plus, you actually also can't depend on the
existence of a changelog topic within Streams, since that is an optional
feature of *some* state store implementations. Even in the situation where
you do have a changelog topic in Streams, there may be use cases where it
makes sense to expand the partitions of just the input, or just the
changelog.

The ask for a Core feature of split+backfill is really about supporting the
use case of splitting partitions in log-compacted topics, regardless of
whether that topic is an "input" or a "changelog" or anything else for that
matter.


Point 6:
On the concern about the performance overhead of copying data between the
brokers, I think it's actually a bit overestimated. Splitting a topic's
partition is probably rare, certainly rarer in general than bootstrapping
new consumers on that topic. If "bootstrapping new consumers" means that
they have to re-shuffle the data before they consume it, then you wind up
copying the same record multiple times:

(broker: input topic) -> (initial consumer) -> (broker: repartition topic)
-> (real consumer)

That's 3x, and it's also 3x for every new record after the split as well,
since you don't get to stop repartitioning/reshuffling once you start.

Whereas if you do a backfill in something like the procedure I outlined,
you only copy the prefix of the partition before the split, and you send it
once to the producer and then once to the new generation partition. Plus,
assuming we're splitting the partition for the benefit of consumers,
there's no reason we can't co-locate the post-split partitions on the same
host as the pre-split partition, making the second copy a local filesystem
operation.

Even if you follow these two copies up with bootstrapping a new consumer,
it's still rare for this to occur, so you get to amortize these copies over
the lifetime of the topic, whereas a reshuffle just keeps making copies for
every new event.

And finally, I really do think that regardless of any performance concerns
about this operation, if it preserves loose organizational coupling, it is
certainly worth it.


In conclusion:
It might actually be a good idea for us to clarify the scope of KIP-253. If
we're all agreed that it's a good algorithm for allowing in-order message
delivery during partition expansion, then we can continue this discussion
as a new KIP, something like "backfill with partition expansion". This
would let Dong proceed with KIP-253. On the other hand, if it seems like
this conversation may alter the design of KIP-253, then maybe we *should*
just finish working it out.

For my part, my only concern about KIP-253 is the one I raised earlier.

Thanks again, all, for considering these points,
-John


On Tue, Mar 27, 2018 at 2:10 AM, Dong Lin <li...@gmail.com> wrote:

> On Tue, Mar 27, 2018 at 12:04 AM, Dong Lin <li...@gmail.com> wrote:
>
> > Hey Jan,
> >
> > Thanks for the enthusiasm in improving Kafka's design. Now that I have
> > read through your discussion with Jun, here are my thoughts:
> >
> > - The latest proposal should with log compacted topics by properly
> > deleting old messages after a new message with the same key is produced.
> So
> > it is probably not a concern anymore. Could you comment if there is still
> > issue?
> >
> > - I wrote the SEP-5 and I am pretty familiar with the motivation and the
> > design of SEP-5. SEP-5 is probably orthornal to the motivation of this
> KIP.
> > The goal of SEP-5 is to allow user to increase task number of an existing
> > Samza job. But if we increase the partition number of input topics,
> > messages may still be consumed out-of-order by tasks in Samza which cause
> > incorrect result. Similarly, the approach you proposed does not seem to
> > ensure that the messages can be delivered in order, even if we can make
> > sure that each consumer instance is assigned the set of new partitions
> > covering the same set of keys.
> >
>
> Let me correct this comment. The approach of copying data to a new topic
> can ensure in-order message delivery suppose we properly migrate offsets
> from old topic to new topic.
>
>
> > - I am trying to understand why it is better to copy the data instead of
> > copying the change log topic for streaming use-case. For core Kafka
> > use-case, and for the stream use-case that does not need to increase
> > consumers, the current KIP already supports in-order delivery without the
> > overhead of copying the data. For stream use-case that needs to increase
> > consumer number, the existing consumer can backfill the existing data in
> > the change log topic to the same change log topic with the new partition
> > number, before the new set of consumers bootstrap state from the new
> > partitions of the change log topic. If this solution works, then could
> you
> > summarize the advantage of copying the data of input topic as compared to
> > copying the change log topic? For example, does it enable more use-case,
> > simplify the implementation of Kafka library, or reduce the operation
> > overhead etc?
> >
> > Thanks,
> > Dong
> >
> >
> > On Wed, Mar 21, 2018 at 6:57 AM, Jan Filipiak <Ja...@trivago.com>
> > wrote:
> >
> >> Hi Jun,
> >>
> >> I was really seeing progress in our conversation but your latest reply
> is
> >> just devastating.
> >> I though we were getting close being on the same page now it feels like
> >> we are in different libraries.
> >>
> >> I just quickly slam my answers in here. If they are to brief I am sorry
> >> give me a ping and try to go into details more.
> >> Just want to show that your pro/cons listing is broken.
> >>
> >> Best Jan
> >>
> >> and want to get rid of this horrible compromise
> >>
> >>
> >> On 19.03.2018 05:48, Jun Rao wrote:
> >>
> >>> Hi, Jan,
> >>>
> >>> Thanks for the discussion. Great points.
> >>>
> >>> Let me try to summarize the approach that you are proposing. On the
> >>> broker
> >>> side, we reshuffle the existing data in a topic from current partitions
> >>> to
> >>> the new partitions. Once the reshuffle fully catches up, switch the
> >>> consumers to start consuming from the new partitions. If a consumer
> needs
> >>> to rebuild its local state (due to partition changes), let the consumer
> >>> rebuild its state by reading all existing data from the new partitions.
> >>> Once all consumers have switches over, cut over the producer to the new
> >>> partitions.
> >>>
> >>> The pros for this approach are that :
> >>> 1. There is just one way to rebuild the local state, which is simpler.
> >>>
> >> true thanks
> >>
> >>>
> >>> The cons for this approach are:
> >>> 1. Need to copy existing data.
> >>>
> >> Very unfair and not correct. It does not require you to copy over
> >> existing data. It _allows_ you to copy all existing data.
> >>
> >> 2. The cutover of the producer is a bit complicated since it needs to
> >>> coordinate with all consumer groups.
> >>>
> >> Also not true. I explicitly tried to make clear that there is only one
> >> special consumer (in the case of actually copying data) coordination is
> >> required.
> >>
> >>> 3. The rebuilding of the state in the consumer is from the input topic,
> >>> which can be more expensive than rebuilding from the existing state.
> >>>
> >> true, but rebuilding state is only required if you want to increase
> >> processing power, so we assume this is at hand.
> >>
> >>> 4. The broker potentially has to know the partitioning function. If
> this
> >>> needs to be customized at the topic level, it can be a bit messy.
> >>>
> >> I would argue against having the operation being performed by the
> broker.
> >> This was not discussed yet but if you see my original email i suggested
> >> otherwise from the beginning.
> >>
> >>>
> >>> Here is an alternative approach by applying your idea not in the
> broker,
> >>> but in the consumer. When new partitions are added, we don't move
> >>> existing
> >>> data. In KStreams, we first reshuffle the new input data to a new topic
> >>> T1
> >>> with the old number of partitions and feed T1's data to the rest of the
> >>> pipeline. In the meantime, KStreams reshuffles all existing data of the
> >>> change capture topic to another topic C1 with the new number of
> >>> partitions.
> >>> We can then build the state of the new tasks from C1. Once the new
> states
> >>> have been fully built, we can cut over the consumption to the input
> topic
> >>> and delete T1. This approach works with compacted topic too. If an
> >>> application reads from the beginning of a compacted topic, the consumer
> >>> will reshuffle the portion of the input when the number of partitions
> >>> doesn't match the number of tasks.
> >>>
> >> We all wipe this idea from our heads instantly. Mixing Ideas from an
> >> argument is not a resolution strategy
> >> just leads to horrible horrible software.
> >>
> >>
> >>> The pros of this approach are:
> >>> 1. No need to copy existing data.
> >>> 2. Each consumer group can cut over to the new partitions
> independently.
> >>> 3. The state is rebuilt from the change capture topic, which is cheaper
> >>> than rebuilding from the input topic.
> >>> 4. Only the KStreams job needs to know the partitioning function.
> >>>
> >>> The cons of this approach are:
> >>> 1. Potentially the same input topic needs to be reshuffled more than
> once
> >>> in different consumer groups during the transition phase.
> >>>
> >>> What do you think?
> >>>
> >>> Thanks,
> >>>
> >>> Jun
> >>>
> >>>
> >>>
> >>> On Thu, Mar 15, 2018 at 1:04 AM, Jan Filipiak <
> Jan.Filipiak@trivago.com>
> >>> wrote:
> >>>
> >>> Hi Jun,
> >>>>
> >>>> thank you for following me on these thoughts. It was important to me
> to
> >>>> feel that kind of understanding for my arguments.
> >>>>
> >>>> What I was hoping for (I mentioned this earlier) is that we can model
> >>>> the
> >>>> case where we do not want to copy the data the exact same way as the
> >>>> case
> >>>> when we do copy the data. Maybe you can peek into the mails before to
> >>>> see
> >>>> more details for this.
> >>>>
> >>>> This means we have the same mechanism to transfer consumer groups to
> >>>> switch topic. The offset mapping that would be generated would even be
> >>>> simpler End Offset of the Old topic => offset 0 off all the partitions
> >>>> of
> >>>> the new topic. Then we could model the transition of a non-copy
> >>>> expansion
> >>>> the exact same way as a copy-expansion.
> >>>>
> >>>> I know this only works when topic growth by a factor. But the benefits
> >>>> of
> >>>> only growing by a factor are to strong anyways. See Clemens's hint and
> >>>> remember that state reshuffling is entirely not needed if one doesn't
> >>>> want
> >>>> to grow processing power.
> >>>>
> >>>> I think these benefits should be clear, and that there is basically no
> >>>> downside to what is currently at hand but just makes everything easy.
> >>>>
> >>>> One thing you need to know is. that if you do not offer rebuilding a
> log
> >>>> compacted topic like i suggest that even if you have consumer state
> >>>> reshuffling. The topic is broken and can not be used to bootstrap new
> >>>> consumers. They don't know if they need to apply a key from and old
> >>>> partition or not. This is a horrible downside I haven't seen a
> solution
> >>>> for
> >>>> in the email conversation.
> >>>>
> >>>> I argue to:
> >>>>
> >>>> Only grow topic by a factor always.
> >>>> Have the "no copy consumer" transition as the trivial case of the
> "copy
> >>>> consumer transition".
> >>>> If processors needs to be scaled, let them rebuild from the new topic
> >>>> and
> >>>> leave the old running in the mean time.
> >>>> Do not implement key shuffling in streams.
> >>>>
> >>>> I hope I can convince you especially with the fact how I want to
> handle
> >>>> consumer transition. I think
> >>>> you didn't quite understood me there before. I think the term "new
> >>>> topic"
> >>>> intimidated you a little.
> >>>> How we solve this on disc doesn't really matter, If the data goes into
> >>>> the
> >>>> same Dir or a different Dir or anything. I do think that it needs to
> >>>> involve at least rolling a new segment for the existing partitions.
> >>>> But most of the transitions should work without restarting consumers.
> >>>> (newer consumers with support for this). But with new topic i just
> meant
> >>>> the topic that now has a different partition count. Plenty of ways to
> >>>> handle that (versions, aliases)
> >>>>
> >>>> Hope I can further get my idea across.
> >>>>
> >>>> Best Jan
> >>>>
> >>>>
> >>>>
> >>>>
> >>>>
> >>>>
> >>>> On 14.03.2018 02:45, Jun Rao wrote:
> >>>>
> >>>> Hi, Jan,
> >>>>>
> >>>>> Thanks for sharing your view.
> >>>>>
> >>>>> I agree with you that recopying the data potentially makes the state
> >>>>> management easier since the consumer can just rebuild its state from
> >>>>> scratch (i.e., no need for state reshuffling).
> >>>>>
> >>>>> On the flip slide, I saw a few disadvantages of the approach that you
> >>>>> suggested. (1) Building the state from the input topic from scratch
> is
> >>>>> in
> >>>>> general less efficient than state reshuffling. Let's say one
> computes a
> >>>>> count per key from an input topic. The former requires reading all
> >>>>> existing
> >>>>> records in the input topic whereas the latter only requires reading
> >>>>> data
> >>>>> proportional to the number of unique keys. (2) The switching of the
> >>>>> topic
> >>>>> needs modification to the application. If there are many applications
> >>>>> on a
> >>>>> topic, coordinating such an effort may not be easy. Also, it's not
> >>>>> clear
> >>>>> how to enforce exactly-once semantic during the switch. (3) If a
> topic
> >>>>> doesn't need any state management, recopying the data seems wasteful.
> >>>>> In
> >>>>> that case, in place partition expansion seems more desirable.
> >>>>>
> >>>>> I understand your concern about adding complexity in KStreams. But,
> >>>>> perhaps
> >>>>> we could iterate on that a bit more to see if it can be simplified.
> >>>>>
> >>>>> Jun
> >>>>>
> >>>>>
> >>>>> On Mon, Mar 12, 2018 at 11:21 PM, Jan Filipiak <
> >>>>> Jan.Filipiak@trivago.com>
> >>>>> wrote:
> >>>>>
> >>>>> Hi Jun,
> >>>>>
> >>>>>> I will focus on point 61 as I think its _the_ fundamental part that
> I
> >>>>>> cant
> >>>>>> get across at the moment.
> >>>>>>
> >>>>>> Kafka is the platform to have state materialized multiple times from
> >>>>>> one
> >>>>>> input. I emphasize this: It is the building block in architectures
> >>>>>> that
> >>>>>> allow you to
> >>>>>> have your state maintained multiple times. You put a message in
> once,
> >>>>>> and
> >>>>>> you have it pop out as often as you like. I believe you understand
> >>>>>> this.
> >>>>>>
> >>>>>> Now! The path of thinking goes the following: I am using apache
> kafka
> >>>>>> and
> >>>>>> I _want_ my state multiple times. What am I going todo?
> >>>>>>
> >>>>>> A) Am I going to take my state that I build up, plunge some sort of
> >>>>>> RPC
> >>>>>> layer ontop of it, use that RPC layer to throw my records across
> >>>>>> instances?
> >>>>>> B) Am I just going to read the damn message twice?
> >>>>>>
> >>>>>> Approach A is fundamentally flawed and a violation of all that is
> good
> >>>>>> and
> >>>>>> holy in kafka deployments. I can not understand how this Idea can
> >>>>>> come in
> >>>>>> the first place.
> >>>>>> (I do understand: IQ in streams, they polluted the kafka streams
> >>>>>> codebase
> >>>>>> really bad already. It is not funny! I think they are equally flawed
> >>>>>> as
> >>>>>> A)
> >>>>>>
> >>>>>> I say, we do what Kafka is good at. We repartition the topic once.
> We
> >>>>>> switch the consumers.
> >>>>>> (Those that need more partitions are going to rebuild their state in
> >>>>>> multiple partitions by reading the new topic, those that don't just
> >>>>>> assign
> >>>>>> the new partitions properly)
> >>>>>> We switch producers. Done!
> >>>>>>
> >>>>>> The best thing! It is trivial, hipster stream processor will have an
> >>>>>> easy
> >>>>>> time with that aswell. Its so super simple. And simple IS good!
> >>>>>> It is what kafka was build todo. It is how we do it today. All I am
> >>>>>> saying
> >>>>>> is that a little broker help doing the producer swap is super
> useful.
> >>>>>>
> >>>>>> For everyone interested in why kafka is so powerful with approach B,
> >>>>>> please watch https://youtu.be/bEbeZPVo98c?t=1633
> >>>>>> I already looked up a good point in time, I think after 5 minutes
> the
> >>>>>> "state" topic is handled and you should be able to understand me
> >>>>>> and inch better.
> >>>>>>
> >>>>>> Please do not do A to the project, it deserves better!
> >>>>>>
> >>>>>> Best Jan
> >>>>>>
> >>>>>>
> >>>>>>
> >>>>>> On 13.03.2018 02:40, Jun Rao wrote:
> >>>>>>
> >>>>>> Hi, Jan,
> >>>>>>
> >>>>>>> Thanks for the reply. A few more comments below.
> >>>>>>>
> >>>>>>> 50. Ok, we can think a bit harder for supporting compacted topics.
> >>>>>>>
> >>>>>>> 51. This is a fundamental design question. In the more common case,
> >>>>>>> the
> >>>>>>> reason why someone wants to increase the number of partitions is
> that
> >>>>>>> the
> >>>>>>> consumer application is slow and one wants to run more consumer
> >>>>>>> instances
> >>>>>>> to increase the degree of parallelism. So, fixing the number of
> >>>>>>> running
> >>>>>>> consumer instances when expanding the partitions won't help this
> >>>>>>> case.
> >>>>>>> If
> >>>>>>> we do need to increase the number of consumer instances, we need to
> >>>>>>> somehow
> >>>>>>> reshuffle the state of the consumer across instances. What we have
> >>>>>>> been
> >>>>>>> discussing in this KIP is whether we can do this more effectively
> >>>>>>> through
> >>>>>>> the KStream library (e.g. through a 2-phase partition expansion).
> >>>>>>> This
> >>>>>>> will
> >>>>>>> add some complexity, but it's probably better than everyone doing
> >>>>>>> this
> >>>>>>> in
> >>>>>>> the application space. The recopying approach that you mentioned
> >>>>>>> doesn't
> >>>>>>> seem to address the consumer state management issue when the
> consumer
> >>>>>>> switches from an old to a new topic.
> >>>>>>>
> >>>>>>> 52. As for your example, it depends on whether the join key is the
> >>>>>>> same
> >>>>>>> between (A,B) and (B,C). If the join key is the same, we can do a
> >>>>>>> 2-phase
> >>>>>>> partition expansion of A, B, and C together. If the join keys are
> >>>>>>> different, one would need to repartition the data on a different
> key
> >>>>>>> for
> >>>>>>> the second join, then the partition expansion can be done
> >>>>>>> independently
> >>>>>>> between (A,B) and (B,C).
> >>>>>>>
> >>>>>>> 53. If you always fix the number of consumer instances, we you
> >>>>>>> described
> >>>>>>> works. However, as I mentioned in #51, I am not sure how your
> >>>>>>> proposal
> >>>>>>> deals with consumer states when the number of consumer instances
> >>>>>>> grows.
> >>>>>>> Also, it just seems that it's better to avoid re-copying the
> existing
> >>>>>>> data.
> >>>>>>>
> >>>>>>> 60. "just want to throw in my question from the longer email in the
> >>>>>>> other
> >>>>>>> Thread here. How will the bloom filter help a new consumer to
> decide
> >>>>>>> to
> >>>>>>> apply the key or not?" Not sure that I fully understood your
> >>>>>>> question.
> >>>>>>> The
> >>>>>>> consumer just reads whatever key is in the log. The bloom filter
> just
> >>>>>>> helps
> >>>>>>> clean up the old keys.
> >>>>>>>
> >>>>>>> 61. "Why can we afford having a topic where its apparently not
> >>>>>>> possible
> >>>>>>> to
> >>>>>>> start a new application on? I think this is an overall flaw of the
> >>>>>>> discussed idea here. Not playing attention to the overall
> >>>>>>> architecture."
> >>>>>>> Could you explain a bit more when one can't start a new
> application?
> >>>>>>>
> >>>>>>> Jun
> >>>>>>>
> >>>>>>>
> >>>>>>>
> >>>>>>> On Sat, Mar 10, 2018 at 1:40 AM, Jan Filipiak <
> >>>>>>> Jan.Filipiak@trivago.com
> >>>>>>> wrote:
> >>>>>>>
> >>>>>>> Hi Jun, thanks for your mail.
> >>>>>>>
> >>>>>>> Thank you for your questions!
> >>>>>>>> I think they are really good and tackle the core of the problem I
> >>>>>>>> see.
> >>>>>>>>
> >>>>>>>> I will answer inline, mostly but still want to set the tone here.
> >>>>>>>>
> >>>>>>>> The core strength of kafka is what Martin once called the
> >>>>>>>> kappa-Architecture. How does this work?
> >>>>>>>> You have everything as a log as in kafka. When you need to change
> >>>>>>>> something.
> >>>>>>>> You create the new version of your application and leave it
> running
> >>>>>>>> in
> >>>>>>>> parallel.
> >>>>>>>> Once the new version is good you switch your users to use the new
> >>>>>>>> application.
> >>>>>>>>
> >>>>>>>> The online reshuffling effectively breaks this architecture and I
> >>>>>>>> think
> >>>>>>>> the switch in thinking here is more harmful
> >>>>>>>> than any details about the partitioning function to allow such a
> >>>>>>>> change.
> >>>>>>>> I
> >>>>>>>> feel with my suggestion we are the closest to
> >>>>>>>> the original and battle proven architecture and I can only warn to
> >>>>>>>> move
> >>>>>>>> away from it.
> >>>>>>>>
> >>>>>>>> I might have forgotten something, sometimes its hard for me to
> >>>>>>>> getting
> >>>>>>>> all
> >>>>>>>> the thoughts captured in a mail, but I hope the comments inline
> will
> >>>>>>>> further make my concern clear, and put some emphasis on why I
> >>>>>>>> prefer my
> >>>>>>>> solution ;)
> >>>>>>>>
> >>>>>>>> One thing we should all be aware of when discussing this, and I
> >>>>>>>> think
> >>>>>>>> Dong
> >>>>>>>> should have mentioned it (maybe he did).
> >>>>>>>> We are not discussing all of this out of thin air but there is an
> >>>>>>>> effort
> >>>>>>>> in the Samza project.
> >>>>>>>>
> >>>>>>>> https://cwiki.apache.org/confluence/display/SAMZA/SEP-5%3A+
> >>>>>>>> Enable+partition+expansion+of+input+streams
> >>>>>>>> https://issues.apache.org/jira/browse/SAMZA-1293
> >>>>>>>>
> >>>>>>>> To be clear. I think SEP-5 (state of last week, dont know if it
> >>>>>>>> adapted
> >>>>>>>> to
> >>>>>>>> this discussion) is on a way better path than KIP-253, and I can't
> >>>>>>>> really
> >>>>>>>> explain why.
> >>>>>>>>
> >>>>>>>> Best Jan,
> >>>>>>>>
> >>>>>>>> nice weekend everyone
> >>>>>>>>
> >>>>>>>>
> >>>>>>>> On 09.03.2018 03:36, Jun Rao wrote:
> >>>>>>>>
> >>>>>>>> Hi, Jan,
> >>>>>>>>
> >>>>>>>> Thanks for the feedback. Just some comments on the earlier points
> >>>>>>>>> that
> >>>>>>>>> you
> >>>>>>>>> mentioned.
> >>>>>>>>>
> >>>>>>>>> 50. You brought up the question of whether existing data needs to
> >>>>>>>>> be
> >>>>>>>>> copied
> >>>>>>>>> during partition expansion. My understand of your view is that
> >>>>>>>>> avoid
> >>>>>>>>> copying existing data will be more efficient, but it doesn't work
> >>>>>>>>> well
> >>>>>>>>> with
> >>>>>>>>> compacted topics since some keys in the original partitions will
> >>>>>>>>> never
> >>>>>>>>> be
> >>>>>>>>> cleaned. It would be useful to understand your use case of
> >>>>>>>>> compacted
> >>>>>>>>> topics
> >>>>>>>>> a bit more. In the common use case, the data volume in a
> compacted
> >>>>>>>>> topic
> >>>>>>>>> may not be large. So, I am not sure if there is a strong need to
> >>>>>>>>> expand
> >>>>>>>>> partitions in a compacted topic, at least initially.
> >>>>>>>>>
> >>>>>>>>> I do agree. State is usually smaller. Update rates might be also
> >>>>>>>>>
> >>>>>>>>> competitively high.
> >>>>>>>> Doing Log-compaction (even beeing very efficient and configurable)
> >>>>>>>> is
> >>>>>>>> also
> >>>>>>>> a more expensive operation than
> >>>>>>>> just discarding old segments. Further if you want to use more
> >>>>>>>> consumers
> >>>>>>>> processing the events
> >>>>>>>> you also have to grow the number of partitions. Especially for
> >>>>>>>> use-cases
> >>>>>>>> we do (KIP-213) a tiny state full
> >>>>>>>> table might be very expensive to process if it joins against a
> huge
> >>>>>>>> table.
> >>>>>>>>
> >>>>>>>> I can just say we have been in the spot of needing to grow log
> >>>>>>>> compacted
> >>>>>>>> topics. Mainly for processing power we can bring to the table.
> >>>>>>>>
> >>>>>>>> Further i am not at all concerned about the extra spaced used by
> >>>>>>>> "garbage
> >>>>>>>> keys". I am more concerned about the correctness of innocent
> >>>>>>>> consumers.
> >>>>>>>> The
> >>>>>>>> logic becomes complicated. Say for streams one would need to load
> >>>>>>>> the
> >>>>>>>> record into state but not forward it the topology ( to have it
> >>>>>>>> available
> >>>>>>>> for shuffeling). I rather have it simple and a topic clean
> >>>>>>>> regardless
> >>>>>>>> if
> >>>>>>>> it
> >>>>>>>> still has its old partition count. Especially with multiple
> >>>>>>>> partitions
> >>>>>>>> growth's I think it becomes insanely hard to to this shuffle
> >>>>>>>> correct.
> >>>>>>>> Maybe
> >>>>>>>> Streams and Samza can do it. Especially if you do "hipster stream
> >>>>>>>> processing" <https://www.confluent.io/blog
> >>>>>>>> /introducing-kafka-streams-
> >>>>>>>> stream-processing-made-simple/>. This makes kafka way to
> >>>>>>>> complicated.
> >>>>>>>> With my approach I think its way simpler because the topic has no
> >>>>>>>> "history"
> >>>>>>>> in terms of partitioning but is always clean.
> >>>>>>>>
> >>>>>>>>
> >>>>>>>> 51. "Growing the topic by an integer factor does not require any
> >>>>>>>> state
> >>>>>>>>
> >>>>>>>> redistribution at all." Could you clarify this a bit more? Let's
> say
> >>>>>>>>> you
> >>>>>>>>> have a consumer app that computes the windowed count per key. If
> >>>>>>>>> you
> >>>>>>>>> double
> >>>>>>>>> the number of partitions from 1 to 2 and grow the consumer
> >>>>>>>>> instances
> >>>>>>>>> from
> >>>>>>>>> 1
> >>>>>>>>> to 2, we would need to redistribute some of the counts to the new
> >>>>>>>>> consumer
> >>>>>>>>> instance. Regarding to linear hashing, it's true that it won't
> >>>>>>>>> solve
> >>>>>>>>> the
> >>>>>>>>> problem with compacted topics. The main benefit is that it
> >>>>>>>>> redistributes
> >>>>>>>>> the keys in one partition to no more than two partitions, which
> >>>>>>>>> could
> >>>>>>>>> help
> >>>>>>>>> redistribute the state.
> >>>>>>>>>
> >>>>>>>>> You don't need to spin up a new consumer in this case. every
> >>>>>>>>> consumer
> >>>>>>>>>
> >>>>>>>>> would just read every partition with the (partition % num_task)
> >>>>>>>> task.
> >>>>>>>> it
> >>>>>>>> will still have the previous data right there and can go on.
> >>>>>>>>
> >>>>>>>> This sounds contradictory to what I said before, but please bear
> >>>>>>>> with
> >>>>>>>> me.
> >>>>>>>>
> >>>>>>>> 52. Good point on coordinating the expansion of 2 topics that need
> >>>>>>>> to
> >>>>>>>> be
> >>>>>>>>
> >>>>>>>> joined together. This is where the 2-phase partition expansion
> could
> >>>>>>>>> potentially help. In the first phase, we could add new partitions
> >>>>>>>>> to
> >>>>>>>>> the 2
> >>>>>>>>> topics one at a time but without publishing to the new patitions.
> >>>>>>>>> Then,
> >>>>>>>>> we
> >>>>>>>>> can add new consumer instances to pick up the new partitions. In
> >>>>>>>>> this
> >>>>>>>>> transition phase, no reshuffling is needed since no data is
> coming
> >>>>>>>>> from
> >>>>>>>>> the
> >>>>>>>>> new partitions. Finally, we can enable the publishing to the new
> >>>>>>>>> partitions.
> >>>>>>>>>
> >>>>>>>>> I think its even worse than you think. I would like to introduce
> >>>>>>>>> the
> >>>>>>>>>
> >>>>>>>>> Term
> >>>>>>>> transitive copartitioning. Imagine
> >>>>>>>> 2 streams application. One joins (A,B) the other (B,C) then there
> >>>>>>>> is a
> >>>>>>>> transitive copartition requirement for
> >>>>>>>> (A,C) to be copartitioned aswell. This can spread significantly
> and
> >>>>>>>> require many consumers to adapt at the same time.
> >>>>>>>>
> >>>>>>>> It is also not entirely clear to me how you not need reshuffling
> in
> >>>>>>>> this
> >>>>>>>> case. If A has a record that never gets updated after the
> expansion
> >>>>>>>> and
> >>>>>>>> the
> >>>>>>>> coresponding B record moves to a new partition. How shall they
> meet
> >>>>>>>> w/o
> >>>>>>>> shuffle?
> >>>>>>>>
> >>>>>>>> 53. "Migrating consumer is a step that might be made completly
> >>>>>>>>
> >>>>>>>> unnecessary
> >>>>>>>>> if - for example streams - takes the gcd as partitioning scheme
> >>>>>>>>> instead
> >>>>>>>>> of
> >>>>>>>>> enforcing 1 to 1." Not sure that I fully understand this. I think
> >>>>>>>>> you
> >>>>>>>>> mean
> >>>>>>>>> that a consumer application can run more instances than the
> number
> >>>>>>>>> of
> >>>>>>>>> partitions. In that case, the consumer can just repartitioning
> the
> >>>>>>>>> input
> >>>>>>>>> data according to the number of instances. This is possible, but
> >>>>>>>>> just
> >>>>>>>>> has
> >>>>>>>>> the overhead of reshuffling the data.
> >>>>>>>>>
> >>>>>>>>> No what I meant is ( that is also your question i think Mathias)
> >>>>>>>>> that
> >>>>>>>>> if
> >>>>>>>>>
> >>>>>>>>> you grow a topic by a factor.
> >>>>>>>> Even if your processor is statefull you can can just assign all
> the
> >>>>>>>> multiples of the previous partition to
> >>>>>>>> this consumer and the state to keep processing correctly will be
> >>>>>>>> present
> >>>>>>>> w/o any shuffling.
> >>>>>>>>
> >>>>>>>> Say you have an assignment
> >>>>>>>> Statefull consumer => partition
> >>>>>>>> 0 => 0
> >>>>>>>> 1 => 1
> >>>>>>>> 2 => 2
> >>>>>>>>
> >>>>>>>> and you grow you topic by 4 you get,
> >>>>>>>>
> >>>>>>>> 0 => 0,3,6,9
> >>>>>>>> 1 => 1,4,7,10
> >>>>>>>> 2 => 2,5,8,11
> >>>>>>>>
> >>>>>>>> Say your hashcode is 8. 8%3 => 2  before so consumer for
> partition 2
> >>>>>>>> has
> >>>>>>>> it.
> >>>>>>>> Now you you have 12 partitions so 8%12 => 8, so it goes into
> >>>>>>>> partition
> >>>>>>>> 8
> >>>>>>>> which is assigned to the same consumer
> >>>>>>>> who had 2 before and therefore knows the key.
> >>>>>>>>
> >>>>>>>> Userland reshuffeling is there as an options. And it does exactly
> >>>>>>>> what
> >>>>>>>> I
> >>>>>>>> suggest. And I think its the perfect strategie. All I am
> suggestion
> >>>>>>>> is
> >>>>>>>> broker side support to switch the producers to the newly
> partitioned
> >>>>>>>> topic.
> >>>>>>>> Then the old (to few partition topic) can go away.  Remember the
> >>>>>>>> list
> >>>>>>>> of
> >>>>>>>> steps in the beginning of this thread. If one has broker support
> for
> >>>>>>>> all
> >>>>>>>> where its required and streams support for those that aren’t
> >>>>>>>> necessarily.
> >>>>>>>> Then one has solved the problem.
> >>>>>>>> I repeat it because I think its important. I am really happy that
> >>>>>>>> you
> >>>>>>>> brought that up! because its 100% what I want just with the
> >>>>>>>> differences
> >>>>>>>> to
> >>>>>>>> have an option to discard the to small topic later (after all
> >>>>>>>> consumers
> >>>>>>>> adapted). And to have order correct there. I need broker support
> >>>>>>>> managing
> >>>>>>>> the copy process + the produces and fence them against each
> other. I
> >>>>>>>> also
> >>>>>>>> repeat. the copy process can run for weeks in the worst case.
> >>>>>>>> Copying
> >>>>>>>> the
> >>>>>>>> data is not the longest task migrating consumers might very well
> be.
> >>>>>>>> Once all consumers switched and copying is really up to date
> (think
> >>>>>>>> ISR
> >>>>>>>> like up to date) only then we stop the producer, wait for the copy
> >>>>>>>> to
> >>>>>>>> finish and use the new topic for producing.
> >>>>>>>>
> >>>>>>>> After this the topic is perfect in shape. and no one needs to
> worry
> >>>>>>>> about
> >>>>>>>> complicated stuff. (old keys hanging around might arrive in some
> >>>>>>>> other
> >>>>>>>> topic later.....). can only imagine how many tricky bugs gonna
> >>>>>>>> arrive
> >>>>>>>> after
> >>>>>>>> someone had grown and shrunken is topic 10 times.
> >>>>>>>>
> >>>>>>>>
> >>>>>>>>
> >>>>>>>>
> >>>>>>>>
> >>>>>>>>
> >>>>>>>> 54. "The other thing I wanted to mention is that I believe the
> >>>>>>>> current
> >>>>>>>>
> >>>>>>>> suggestion (without copying data over) can be implemented in pure
> >>>>>>>>> userland
> >>>>>>>>> with a custom partitioner and a small feedbackloop from
> >>>>>>>>> ProduceResponse
> >>>>>>>>> =>
> >>>>>>>>> Partitionier in coorporation with a change management system." I
> am
> >>>>>>>>> not
> >>>>>>>>> sure a customized partitioner itself solves the problem. We
> >>>>>>>>> probably
> >>>>>>>>> need
> >>>>>>>>> some broker side support to enforce when the new partitions can
> be
> >>>>>>>>> used.
> >>>>>>>>> We
> >>>>>>>>> also need some support on the consumer/kstream side to preserve
> the
> >>>>>>>>> per
> >>>>>>>>> key
> >>>>>>>>> ordering and potentially migrate the processing state. This is
> not
> >>>>>>>>> trivial
> >>>>>>>>> and I am not sure if it's ideal to fully push to the application
> >>>>>>>>> space.
> >>>>>>>>>
> >>>>>>>>> Broker support is defenitly the preferred way here. I have
> nothing
> >>>>>>>>>
> >>>>>>>>> against
> >>>>>>>> broker support.
> >>>>>>>> I tried to say that for what I would preffer - copying the data
> >>>>>>>> over,
> >>>>>>>> at
> >>>>>>>> least for log compacted topics -
> >>>>>>>> I would require more broker support than the KIP currently offers.
> >>>>>>>>
> >>>>>>>>
> >>>>>>>>
> >>>>>>>> Jun
> >>>>>>>>
> >>>>>>>> On Tue, Mar 6, 2018 at 10:33 PM, Jan Filipiak <
> >>>>>>>>> Jan.Filipiak@trivago.com
> >>>>>>>>> wrote:
> >>>>>>>>>
> >>>>>>>>> Hi Dong,
> >>>>>>>>>
> >>>>>>>>> are you actually reading my emails, or are you just using the
> >>>>>>>>> thread I
> >>>>>>>>>
> >>>>>>>>>> started for general announcements regarding the KIP?
> >>>>>>>>>>
> >>>>>>>>>> I tried to argue really hard against linear hashing. Growing the
> >>>>>>>>>> topic
> >>>>>>>>>> by
> >>>>>>>>>> an integer factor does not require any state redistribution at
> >>>>>>>>>> all. I
> >>>>>>>>>> fail
> >>>>>>>>>> to see completely where linear hashing helps on log compacted
> >>>>>>>>>> topics.
> >>>>>>>>>>
> >>>>>>>>>> If you are not willing to explain to me what I might be
> >>>>>>>>>> overlooking:
> >>>>>>>>>> that
> >>>>>>>>>> is fine.
> >>>>>>>>>> But I ask you to not reply to my emails then. Please understand
> my
> >>>>>>>>>> frustration with this.
> >>>>>>>>>>
> >>>>>>>>>> Best Jan
> >>>>>>>>>>
> >>>>>>>>>>
> >>>>>>>>>>
> >>>>>>>>>> On 06.03.2018 19:38, Dong Lin wrote:
> >>>>>>>>>>
> >>>>>>>>>> Hi everyone,
> >>>>>>>>>>
> >>>>>>>>>> Thanks for all the comments! It appears that everyone prefers
> >>>>>>>>>> linear
> >>>>>>>>>>
> >>>>>>>>>>> hashing because it reduces the amount of state that needs to be
> >>>>>>>>>>> moved
> >>>>>>>>>>> between consumers (for stream processing). The KIP has been
> >>>>>>>>>>> updated
> >>>>>>>>>>> to
> >>>>>>>>>>> use
> >>>>>>>>>>> linear hashing.
> >>>>>>>>>>>
> >>>>>>>>>>> Regarding the migration endeavor: it seems that migrating
> >>>>>>>>>>> producer
> >>>>>>>>>>> library
> >>>>>>>>>>> to use linear hashing should be pretty straightforward without
> >>>>>>>>>>> much operational endeavor. If we don't upgrade client library
> to
> >>>>>>>>>>> use
> >>>>>>>>>>> this
> >>>>>>>>>>> KIP, we can not support in-order delivery after partition is
> >>>>>>>>>>> changed
> >>>>>>>>>>> anyway. Suppose we upgrade client library to use this KIP, if
> >>>>>>>>>>> partition
> >>>>>>>>>>> number is not changed, the key -> partition mapping will be
> >>>>>>>>>>> exactly
> >>>>>>>>>>> the
> >>>>>>>>>>> same as it is now because it is still determined using
> >>>>>>>>>>> murmur_hash(key)
> >>>>>>>>>>> %
> >>>>>>>>>>> original_partition_num. In other words, this change is backward
> >>>>>>>>>>> compatible.
> >>>>>>>>>>>
> >>>>>>>>>>> Regarding the load distribution: if we use linear hashing, the
> >>>>>>>>>>> load
> >>>>>>>>>>> may
> >>>>>>>>>>> be
> >>>>>>>>>>> unevenly distributed because those partitions which are not
> split
> >>>>>>>>>>> may
> >>>>>>>>>>> receive twice as much traffic as other partitions that are
> split.
> >>>>>>>>>>> This
> >>>>>>>>>>> issue can be mitigated by creating topic with partitions that
> are
> >>>>>>>>>>> several
> >>>>>>>>>>> times the number of consumers. And there will be no imbalance
> if
> >>>>>>>>>>> the
> >>>>>>>>>>> partition number is always doubled. So this imbalance seems
> >>>>>>>>>>> acceptable.
> >>>>>>>>>>>
> >>>>>>>>>>> Regarding storing the partition strategy as per-topic config:
> It
> >>>>>>>>>>> seems
> >>>>>>>>>>> not
> >>>>>>>>>>> necessary since we can still use murmur_hash as the default
> hash
> >>>>>>>>>>> function
> >>>>>>>>>>> and additionally apply the linear hashing algorithm if the
> >>>>>>>>>>> partition
> >>>>>>>>>>> number
> >>>>>>>>>>> has increased. Not sure if there is any use-case for producer
> to
> >>>>>>>>>>> use a
> >>>>>>>>>>> different hash function. Jason, can you check if there is some
> >>>>>>>>>>> use-case
> >>>>>>>>>>> that I missed for using the per-topic partition strategy?
> >>>>>>>>>>>
> >>>>>>>>>>> Regarding how to reduce latency (due to state store/load) in
> >>>>>>>>>>> stream
> >>>>>>>>>>> processing consumer when partition number changes: I need to
> read
> >>>>>>>>>>> the
> >>>>>>>>>>> Kafka
> >>>>>>>>>>> Stream code to understand how Kafka Stream currently migrate
> >>>>>>>>>>> state
> >>>>>>>>>>> between
> >>>>>>>>>>> consumers when the application is added/removed for a given
> job.
> >>>>>>>>>>> I
> >>>>>>>>>>> will
> >>>>>>>>>>> reply after I finish reading the documentation and code.
> >>>>>>>>>>>
> >>>>>>>>>>>
> >>>>>>>>>>> Thanks,
> >>>>>>>>>>> Dong
> >>>>>>>>>>>
> >>>>>>>>>>>
> >>>>>>>>>>> On Mon, Mar 5, 2018 at 10:43 AM, Jason Gustafson <
> >>>>>>>>>>> jason@confluent.io>
> >>>>>>>>>>> wrote:
> >>>>>>>>>>>
> >>>>>>>>>>> Great discussion. I think I'm wondering whether we can continue
> >>>>>>>>>>> to
> >>>>>>>>>>> leave
> >>>>>>>>>>>
> >>>>>>>>>>> Kafka agnostic to the partitioning strategy. The challenge is
> >>>>>>>>>>>
> >>>>>>>>>>> communicating
> >>>>>>>>>>>> the partitioning logic from producers to consumers so that the
> >>>>>>>>>>>> dependencies
> >>>>>>>>>>>> between each epoch can be determined. For the sake of
> >>>>>>>>>>>> discussion,
> >>>>>>>>>>>> imagine
> >>>>>>>>>>>> you did something like the following:
> >>>>>>>>>>>>
> >>>>>>>>>>>> 1. The name (and perhaps version) of a partitioning strategy
> is
> >>>>>>>>>>>> stored
> >>>>>>>>>>>> in
> >>>>>>>>>>>> topic configuration when a topic is created.
> >>>>>>>>>>>> 2. The producer looks up the partitioning strategy before
> >>>>>>>>>>>> writing
> >>>>>>>>>>>> to
> >>>>>>>>>>>> a
> >>>>>>>>>>>> topic and includes it in the produce request (for fencing). If
> >>>>>>>>>>>> it
> >>>>>>>>>>>> doesn't
> >>>>>>>>>>>> have an implementation for the configured strategy, it fails.
> >>>>>>>>>>>> 3. The consumer also looks up the partitioning strategy and
> >>>>>>>>>>>> uses it
> >>>>>>>>>>>> to
> >>>>>>>>>>>> determine dependencies when reading a new epoch. It could
> either
> >>>>>>>>>>>> fail
> >>>>>>>>>>>> or
> >>>>>>>>>>>> make the most conservative dependency assumptions if it
> doesn't
> >>>>>>>>>>>> know
> >>>>>>>>>>>> how
> >>>>>>>>>>>> to
> >>>>>>>>>>>> implement the partitioning strategy. For the consumer, the new
> >>>>>>>>>>>> interface
> >>>>>>>>>>>> might look something like this:
> >>>>>>>>>>>>
> >>>>>>>>>>>> // Return the partition dependencies following an epoch bump
> >>>>>>>>>>>> Map<Integer, List<Integer>> dependencies(int
> >>>>>>>>>>>> numPartitionsBeforeEpochBump,
> >>>>>>>>>>>> int numPartitionsAfterEpochBump)
> >>>>>>>>>>>>
> >>>>>>>>>>>> The unordered case then is just a particular implementation
> >>>>>>>>>>>> which
> >>>>>>>>>>>> never
> >>>>>>>>>>>> has
> >>>>>>>>>>>> any epoch dependencies. To implement this, we would need some
> >>>>>>>>>>>> way
> >>>>>>>>>>>> for
> >>>>>>>>>>>> the
> >>>>>>>>>>>> consumer to find out how many partitions there were in each
> >>>>>>>>>>>> epoch,
> >>>>>>>>>>>> but
> >>>>>>>>>>>> maybe that's not too unreasonable.
> >>>>>>>>>>>>
> >>>>>>>>>>>> Thanks,
> >>>>>>>>>>>> Jason
> >>>>>>>>>>>>
> >>>>>>>>>>>>
> >>>>>>>>>>>> On Mon, Mar 5, 2018 at 4:51 AM, Jan Filipiak <
> >>>>>>>>>>>> Jan.Filipiak@trivago.com
> >>>>>>>>>>>> wrote:
> >>>>>>>>>>>>
> >>>>>>>>>>>> Hi Dong
> >>>>>>>>>>>>
> >>>>>>>>>>>> thank you very much for your questions.
> >>>>>>>>>>>>
> >>>>>>>>>>>> regarding the time spend copying data across:
> >>>>>>>>>>>>> It is correct that copying data from a topic with one
> partition
> >>>>>>>>>>>>> mapping
> >>>>>>>>>>>>>
> >>>>>>>>>>>>> to
> >>>>>>>>>>>>>
> >>>>>>>>>>>>> a topic with a different partition mapping takes way longer
> >>>>>>>>>>>>> than
> >>>>>>>>>>>>>
> >>>>>>>>>>>> we
> >>>>>>>>>>>> can
> >>>>>>>>>>>>
> >>>>>>>>>>>> stop producers. Tens of minutes is a very optimistic estimate
> >>>>>>>>>>>> here.
> >>>>>>>>>>>>
> >>>>>>>>>>>>> Many
> >>>>>>>>>>>>> people can not afford copy full steam and therefore will have
> >>>>>>>>>>>>> some
> >>>>>>>>>>>>> rate
> >>>>>>>>>>>>> limiting in place, this can bump the timespan into the day's.
> >>>>>>>>>>>>> The
> >>>>>>>>>>>>> good
> >>>>>>>>>>>>>
> >>>>>>>>>>>>> part
> >>>>>>>>>>>>>
> >>>>>>>>>>>>> is that the vast majority of the data can be copied while the
> >>>>>>>>>>>>>
> >>>>>>>>>>>> producers
> >>>>>>>>>>>>
> >>>>>>>>>>>> are
> >>>>>>>>>>>>
> >>>>>>>>>>>>> still going. One can then, piggyback the consumers ontop of
> >>>>>>>>>>>>> this
> >>>>>>>>>>>>>
> >>>>>>>>>>>> timeframe,
> >>>>>>>>>>>>
> >>>>>>>>>>>>> by the method mentioned (provide them an mapping from their
> old
> >>>>>>>>>>>>>
> >>>>>>>>>>>> offsets
> >>>>>>>>>>>>
> >>>>>>>>>>>> to
> >>>>>>>>>>>>
> >>>>>>>>>>>>> new offsets in their repartitioned topics. In that way we
> >>>>>>>>>>>>> separate
> >>>>>>>>>>>>>
> >>>>>>>>>>>> migration of consumers from migration of producers (decoupling
> >>>>>>>>>>>>
> >>>>>>>>>>>>> these
> >>>>>>>>>>>>> is
> >>>>>>>>>>>>> what kafka is strongest at). The time to actually swap over
> the
> >>>>>>>>>>>>> producers
> >>>>>>>>>>>>> should be kept minimal by ensuring that when a swap attempt
> is
> >>>>>>>>>>>>> started
> >>>>>>>>>>>>>
> >>>>>>>>>>>>> the
> >>>>>>>>>>>>>
> >>>>>>>>>>>>> consumer copying over should be very close to the log end and
> >>>>>>>>>>>>> is
> >>>>>>>>>>>>>
> >>>>>>>>>>>> expected
> >>>>>>>>>>>>
> >>>>>>>>>>>>> to finish within the next fetch. The operation should have a
> >>>>>>>>>>>>> time-out
> >>>>>>>>>>>>> and
> >>>>>>>>>>>>> should be "reattemtable".
> >>>>>>>>>>>>>
> >>>>>>>>>>>>> Importance of logcompaction:
> >>>>>>>>>>>>> If a producer produces key A, to partiton 0, its forever
> gonna
> >>>>>>>>>>>>> be
> >>>>>>>>>>>>> there,
> >>>>>>>>>>>>> unless it gets deleted. The record might sit in there for
> >>>>>>>>>>>>> years. A
> >>>>>>>>>>>>> new
> >>>>>>>>>>>>> producer started with the new partitions will fail to delete
> >>>>>>>>>>>>> the
> >>>>>>>>>>>>> record
> >>>>>>>>>>>>>
> >>>>>>>>>>>>> in
> >>>>>>>>>>>>>
> >>>>>>>>>>>>> the correct partition. Th record will be there forever and
> one
> >>>>>>>>>>>>> can
> >>>>>>>>>>>>>
> >>>>>>>>>>>> not
> >>>>>>>>>>>>
> >>>>>>>>>>>> reliable bootstrap new consumers. I cannot see how linear
> >>>>>>>>>>>> hashing
> >>>>>>>>>>>>
> >>>>>>>>>>>>> can
> >>>>>>>>>>>>>
> >>>>>>>>>>>>> solve
> >>>>>>>>>>>>>
> >>>>>>>>>>>>> this.
> >>>>>>>>>>>>>
> >>>>>>>>>>>> Regarding your skipping of userland copying:
> >>>>>>>>>>>>
> >>>>>>>>>>>>> 100%, copying the data across in userland is, as far as i can
> >>>>>>>>>>>>> see,
> >>>>>>>>>>>>> only
> >>>>>>>>>>>>> a
> >>>>>>>>>>>>> usecase for log compacted topics. Even for logcompaction +
> >>>>>>>>>>>>> retentions
> >>>>>>>>>>>>> it
> >>>>>>>>>>>>> should only be opt-in. Why did I bring it up? I think log
> >>>>>>>>>>>>> compaction
> >>>>>>>>>>>>> is
> >>>>>>>>>>>>> a
> >>>>>>>>>>>>> very important feature to really embrace kafka as a "data
> >>>>>>>>>>>>> plattform".
> >>>>>>>>>>>>> The
> >>>>>>>>>>>>> point I also want to make is that copying data this way is
> >>>>>>>>>>>>> completely
> >>>>>>>>>>>>> inline with the kafka architecture. it only consists of
> reading
> >>>>>>>>>>>>> and
> >>>>>>>>>>>>>
> >>>>>>>>>>>>> writing
> >>>>>>>>>>>>>
> >>>>>>>>>>>>> to topics.
> >>>>>>>>>>>>>
> >>>>>>>>>>>> I hope it clarifies more why I think we should aim for more
> than
> >>>>>>>>>>>>
> >>>>>>>>>>>>> the
> >>>>>>>>>>>>> current KIP. I fear that once the KIP is done not much more
> >>>>>>>>>>>>> effort
> >>>>>>>>>>>>> will
> >>>>>>>>>>>>>
> >>>>>>>>>>>>> be
> >>>>>>>>>>>>>
> >>>>>>>>>>>>> taken.
> >>>>>>>>>>>>>
> >>>>>>>>>>>>
> >>>>>>>>>>>> On 04.03.2018 02:28, Dong Lin wrote:
> >>>>>>>>>>>>>
> >>>>>>>>>>>>> Hey Jan,
> >>>>>>>>>>>>>
> >>>>>>>>>>>>> In the current proposal, the consumer will be blocked on
> >>>>>>>>>>>>> waiting
> >>>>>>>>>>>>> for
> >>>>>>>>>>>>>
> >>>>>>>>>>>>> other
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>> consumers of the group to consume up to a given offset. In
> >>>>>>>>>>>>>> most
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>> cases,
> >>>>>>>>>>>>> all
> >>>>>>>>>>>>> consumers should be close to the LEO of the partitions when
> the
> >>>>>>>>>>>>> partition
> >>>>>>>>>>>>> expansion happens. Thus the time waiting should not be long
> >>>>>>>>>>>>> e.g.
> >>>>>>>>>>>>> on
> >>>>>>>>>>>>> the
> >>>>>>>>>>>>>
> >>>>>>>>>>>>> order of seconds. On the other hand, it may take a long time
> to
> >>>>>>>>>>>>> wait
> >>>>>>>>>>>>>
> >>>>>>>>>>>>> for
> >>>>>>>>>>>>>> the entire partition to be copied -- the amount of time is
> >>>>>>>>>>>>>> proportional
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>> to
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>> the amount of existing data in the partition, which can take
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>> tens of
> >>>>>>>>>>>>>
> >>>>>>>>>>>>> minutes. So the amount of time that we stop consumers may not
> >>>>>>>>>>>>> be
> >>>>>>>>>>>>> on
> >>>>>>>>>>>>>
> >>>>>>>>>>>>> the
> >>>>>>>>>>>>>> same order of magnitude.
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>> If we can implement this suggestion without copying data
> over
> >>>>>>>>>>>>>> in
> >>>>>>>>>>>>>> purse
> >>>>>>>>>>>>>> userland, it will be much more valuable. Do you have ideas
> on
> >>>>>>>>>>>>>> how
> >>>>>>>>>>>>>> this
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>> can
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>> be done?
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>> Not sure why the current KIP not help people who depend on
> log
> >>>>>>>>>>>>>
> >>>>>>>>>>>>> compaction.
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>> Could you elaborate more on this point?
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>> Thanks,
> >>>>>>>>>>>>>
> >>>>>>>>>>>>> Dong
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>> On Wed, Feb 28, 2018 at 10:55 PM, Jan
> >>>>>>>>>>>>>> Filipiak<Jan.Filipiak@trivago.
> >>>>>>>>>>>>>> com
> >>>>>>>>>>>>>> wrote:
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>> Hi Dong,
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>> I tried to focus on what the steps are one can currently
> >>>>>>>>>>>>>> perform
> >>>>>>>>>>>>>> to
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>> expand
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>>> or shrink a keyed topic while maintaining a top notch
> >>>>>>>>>>>>>>> semantics.
> >>>>>>>>>>>>>>> I can understand that there might be confusion about
> >>>>>>>>>>>>>>> "stopping
> >>>>>>>>>>>>>>> the
> >>>>>>>>>>>>>>> consumer". It is exactly the same as proposed in the KIP.
> >>>>>>>>>>>>>>> there
> >>>>>>>>>>>>>>> needs
> >>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>> to
> >>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>> be
> >>>>>>>>>>>>>>>
> >>>>>>>>>>>>>> a time the producers agree on the new partitioning. The
> extra
> >>>>>>>>>>>>>
> >>>>>>>>>>>>> semantics I
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>>> want to put in there is that we have a possibility to wait
> >>>>>>>>>>>>>>> until
> >>>>>>>>>>>>>>>
> >>>>>>>>>>>>>> all
> >>>>>>>>>>>>>
> >>>>>>>>>>>>> the
> >>>>>>>>>>>>>
> >>>>>>>>>>>>> existing data
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>> is copied over into the new partitioning scheme. When I say
> >>>>>>>>>>>>> stopping
> >>>>>>>>>>>>>
> >>>>>>>>>>>>> I
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>>> think more of having a memory barrier that ensures the
> >>>>>>>>>>>>>>> ordering. I
> >>>>>>>>>>>>>>> am
> >>>>>>>>>>>>>>> still
> >>>>>>>>>>>>>>> aming for latencies  on the scale of leader failovers.
> >>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>> Consumers have to explicitly adapt the new partitioning
> >>>>>>>>>>>>>>> scheme
> >>>>>>>>>>>>>>> in
> >>>>>>>>>>>>>>> the
> >>>>>>>>>>>>>>> above scenario. The reason is that in these cases where you
> >>>>>>>>>>>>>>> are
> >>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>> dependent
> >>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>> on a particular partitioning scheme, you also have other
> >>>>>>>>>>>>>>> topics
> >>>>>>>>>>>>>>>
> >>>>>>>>>>>>>> that
> >>>>>>>>>>>>>
> >>>>>>>>>>>>> have
> >>>>>>>>>>>>>
> >>>>>>>>>>>>> co-partition enforcements or the kind -frequently. Therefore
> >>>>>>>>>>>>>> all
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>> your
> >>>>>>>>>>>>>
> >>>>>>>>>>>>> other
> >>>>>>>>>>>>>
> >>>>>>>>>>>>> input topics might need to grow accordingly.
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>> What I was suggesting was to streamline all these
> operations
> >>>>>>>>>>>>>>> as
> >>>>>>>>>>>>>>> best
> >>>>>>>>>>>>>>> as
> >>>>>>>>>>>>>>> possible to have "real" partition grow and shrinkage going
> >>>>>>>>>>>>>>> on.
> >>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>> Migrating
> >>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>> the producers to a new partitioning scheme can be much more
> >>>>>>>>>>>>>>>
> >>>>>>>>>>>>>> streamlined
> >>>>>>>>>>>>>
> >>>>>>>>>>>>> with proper broker support for this. Migrating consumer is a
> >>>>>>>>>>>>> step
> >>>>>>>>>>>>>
> >>>>>>>>>>>>> that
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>>> might be made completly unnecessary if - for example
> streams
> >>>>>>>>>>>>>>> -
> >>>>>>>>>>>>>>> takes
> >>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>> the
> >>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>> gcd as partitioning scheme instead of enforcing 1 to 1.
> >>>>>>>>>>>>>>> Connect
> >>>>>>>>>>>>>>>
> >>>>>>>>>>>>>> consumers
> >>>>>>>>>>>>>
> >>>>>>>>>>>>> and other consumers should be fine anyways.
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>> I hope this makes more clear where I was aiming at. The rest
> >>>>>>>>>>>>> needs
> >>>>>>>>>>>>>
> >>>>>>>>>>>>> to
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>> be
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>>> figured out. The only danger i see is that when we are
> >>>>>>>>>>>>>>>
> >>>>>>>>>>>>>> introducing
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>> this
> >>>>>>>>>>>>>
> >>>>>>>>>>>>> feature as supposed in the KIP, it wont help any people
> >>>>>>>>>>>>> depending
> >>>>>>>>>>>>> on
> >>>>>>>>>>>>>
> >>>>>>>>>>>>> log
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>>> compaction.
> >>>>>>>>>>>>>>>
> >>>>>>>>>>>>>> The other thing I wanted to mention is that I believe the
> >>>>>>>>>>>>> current
> >>>>>>>>>>>>>
> >>>>>>>>>>>>> suggestion (without copying data over) can be implemented in
> >>>>>>>>>>>>>> pure
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>>> userland
> >>>>>>>>>>>>>>> with a custom partitioner and a small feedbackloop from
> >>>>>>>>>>>>>>> ProduceResponse
> >>>>>>>>>>>>>>> =>
> >>>>>>>>>>>>>>> Partitionier in coorporation with a change management
> system.
> >>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>> Best Jan
> >>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>> On 28.02.2018 07:13, Dong Lin wrote:
> >>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>> Hey Jan,
> >>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>> I am not sure if it is acceptable for producer to be
> stopped
> >>>>>>>>>>>>>>> for a
> >>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>> while,
> >>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>> particularly for online application which requires low
> >>>>>>>>>>>>>>>> latency. I
> >>>>>>>>>>>>>>>> am
> >>>>>>>>>>>>>>>> also
> >>>>>>>>>>>>>>>> not sure how consumers can switch to a new topic. Does
> user
> >>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>> application
> >>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>> needs to explicitly specify a different topic for
> >>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>> producer/consumer
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>> to
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>> subscribe to? It will be helpful for discussion if you can
> >>>>>>>>>>>>> provide
> >>>>>>>>>>>>>
> >>>>>>>>>>>>> more
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>>> detail on the interface change for this solution.
> >>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>> Thanks,
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>> Dong
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>>> On Mon, Feb 26, 2018 at 12:48 AM, Jan
> >>>>>>>>>>>>>>>> Filipiak<Jan.Filipiak@trivago.
> >>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>> com
> >>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>> wrote:
> >>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>> Hi,
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>> just want to throw my though in. In general the
> functionality
> >>>>>>>>>>>>>> is
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>>> very
> >>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>> usefull, we should though not try to find the architecture
> >>>>>>>>>>>>>>>> to
> >>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>> hard
> >>>>>>>>>>>>>>>>> while
> >>>>>>>>>>>>>>>>> implementing.
> >>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>> The manual steps would be to
> >>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>> create a new topic
> >>>>>>>>>>>>>>>>> the mirrormake from the new old topic to the new topic
> >>>>>>>>>>>>>>>>> wait for mirror making to catch up.
> >>>>>>>>>>>>>>>>> then put the consumers onto the new topic
> >>>>>>>>>>>>>>>>>            (having mirrormaker spit out a mapping from
> old
> >>>>>>>>>>>>>>>>> offsets to
> >>>>>>>>>>>>>>>>> new
> >>>>>>>>>>>>>>>>> offsets:
> >>>>>>>>>>>>>>>>>                if topic is increased by factor X there is
> >>>>>>>>>>>>>>>>> gonna
> >>>>>>>>>>>>>>>>> be a
> >>>>>>>>>>>>>>>>> clean
> >>>>>>>>>>>>>>>>> mapping from 1 offset in the old topic to X offsets in
> the
> >>>>>>>>>>>>>>>>> new
> >>>>>>>>>>>>>>>>> topic,
> >>>>>>>>>>>>>>>>>                if there is no factor then there is no
> >>>>>>>>>>>>>>>>> chance to
> >>>>>>>>>>>>>>>>> generate a
> >>>>>>>>>>>>>>>>> mapping that can be reasonable used for continuing)
> >>>>>>>>>>>>>>>>>            make consumers stop at appropriate points and
> >>>>>>>>>>>>>>>>> continue
> >>>>>>>>>>>>>>>>> consumption
> >>>>>>>>>>>>>>>>> with offsets from the mapping.
> >>>>>>>>>>>>>>>>> have the producers stop for a minimal time.
> >>>>>>>>>>>>>>>>> wait for mirrormaker to finish
> >>>>>>>>>>>>>>>>> let producer produce with the new metadata.
> >>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>> Instead of implementing the approach suggest in the KIP
> >>>>>>>>>>>>>>>>> which
> >>>>>>>>>>>>>>>>> will
> >>>>>>>>>>>>>>>>> leave
> >>>>>>>>>>>>>>>>> log compacted topic completely crumbled and unusable.
> >>>>>>>>>>>>>>>>> I would much rather try to build infrastructure to
> support
> >>>>>>>>>>>>>>>>> the
> >>>>>>>>>>>>>>>>> mentioned
> >>>>>>>>>>>>>>>>> above operations more smoothly.
> >>>>>>>>>>>>>>>>> Especially having producers stop and use another topic is
> >>>>>>>>>>>>>>>>> difficult
> >>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>> and
> >>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>> it would be nice if one can trigger "invalid metadata"
> >>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>> exceptions
> >>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>> for
> >>>>>>>>>>>>>>>
> >>>>>>>>>>>>>> them
> >>>>>>>>>>>>>
> >>>>>>>>>>>>> and
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>>> if one could give topics aliases so that their produces
> with
> >>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>> the
> >>>>>>>>>>>>>>>>> old
> >>>>>>>>>>>>>>>>> topic
> >>>>>>>>>>>>>>>>> will arrive in the new topic.
> >>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>> The downsides are obvious I guess ( having the same data
> >>>>>>>>>>>>>>>>> twice
> >>>>>>>>>>>>>>>>> for
> >>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>> the
> >>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>> transition period, but kafka tends to scale well with
> >>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>> datasize).
> >>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>> So
> >>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>> its a
> >>>>>>>>>>>>>>>
> >>>>>>>>>>>>>> nicer fit into the architecture.
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>>> I further want to argument that the functionality by the
> KIP
> >>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>> can
> >>>>>>>>>>>>>>>>> completely be implementing in "userland" with a custom
> >>>>>>>>>>>>>>>>> partitioner
> >>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>> that
> >>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>> handles the transition as needed. I would appreciate if
> >>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>> someone
> >>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>> could
> >>>>>>>>>>>>>>>
> >>>>>>>>>>>>>> point
> >>>>>>>>>>>>>
> >>>>>>>>>>>>> out what a custom partitioner couldn't handle in this case?
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>>> With the above approach, shrinking a topic becomes the same
> >>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>> steps.
> >>>>>>>>>>>>>>>>> Without
> >>>>>>>>>>>>>>>>> loosing keys in the discontinued partitions.
> >>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>> Would love to hear what everyone thinks.
> >>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>> Best Jan
> >>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>> On 11.02.2018 00:35, Dong Lin wrote:
> >>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>> Hi all,
> >>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>> I have created KIP-253: Support in-order message delivery
> >>>>>>>>>>>>>>>>> with
> >>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>> partition
> >>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>> expansion. See
> >>>>>>>>>>>>>>>>>> https://cwiki.apache.org/confl
> >>>>>>>>>>>>>>>>>> uence/display/KAFKA/KIP-253%
> >>>>>>>>>>>>>>>>>> 3A+Support+in-order+message+de
> >>>>>>>>>>>>>>>>>> livery+with+partition+expansio
> >>>>>>>>>>>>>>>>>> n
> >>>>>>>>>>>>>>>>>> .
> >>>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>>> This KIP provides a way to allow messages of the same
> key
> >>>>>>>>>>>>>>>>>> from
> >>>>>>>>>>>>>>>>>> the
> >>>>>>>>>>>>>>>>>> same
> >>>>>>>>>>>>>>>>>> producer to be consumed in the same order they are
> >>>>>>>>>>>>>>>>>> produced
> >>>>>>>>>>>>>>>>>> even
> >>>>>>>>>>>>>>>>>> if
> >>>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>>> we
> >>>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>>> expand partition of the topic.
> >>>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>> Thanks,
> >>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>> Dong
> >>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>>>
> >>>>>>>>>>>>>>>>>>
> >>>>
> >>
> >>
> >
>

Re: [DISCUSS] KIP-253: Support in-order message delivery with partition expansion

Posted by Dong Lin <li...@gmail.com>.
On Tue, Mar 27, 2018 at 12:04 AM, Dong Lin <li...@gmail.com> wrote:

> Hey Jan,
>
> Thanks for the enthusiasm in improving Kafka's design. Now that I have
> read through your discussion with Jun, here are my thoughts:
>
> - The latest proposal should with log compacted topics by properly
> deleting old messages after a new message with the same key is produced. So
> it is probably not a concern anymore. Could you comment if there is still
> issue?
>
> - I wrote the SEP-5 and I am pretty familiar with the motivation and the
> design of SEP-5. SEP-5 is probably orthornal to the motivation of this KIP.
> The goal of SEP-5 is to allow user to increase task number of an existing
> Samza job. But if we increase the partition number of input topics,
> messages may still be consumed out-of-order by tasks in Samza which cause
> incorrect result. Similarly, the approach you proposed does not seem to
> ensure that the messages can be delivered in order, even if we can make
> sure that each consumer instance is assigned the set of new partitions
> covering the same set of keys.
>

Let me correct this comment. The approach of copying data to a new topic
can ensure in-order message delivery suppose we properly migrate offsets
from old topic to new topic.


> - I am trying to understand why it is better to copy the data instead of
> copying the change log topic for streaming use-case. For core Kafka
> use-case, and for the stream use-case that does not need to increase
> consumers, the current KIP already supports in-order delivery without the
> overhead of copying the data. For stream use-case that needs to increase
> consumer number, the existing consumer can backfill the existing data in
> the change log topic to the same change log topic with the new partition
> number, before the new set of consumers bootstrap state from the new
> partitions of the change log topic. If this solution works, then could you
> summarize the advantage of copying the data of input topic as compared to
> copying the change log topic? For example, does it enable more use-case,
> simplify the implementation of Kafka library, or reduce the operation
> overhead etc?
>
> Thanks,
> Dong
>
>
> On Wed, Mar 21, 2018 at 6:57 AM, Jan Filipiak <Ja...@trivago.com>
> wrote:
>
>> Hi Jun,
>>
>> I was really seeing progress in our conversation but your latest reply is
>> just devastating.
>> I though we were getting close being on the same page now it feels like
>> we are in different libraries.
>>
>> I just quickly slam my answers in here. If they are to brief I am sorry
>> give me a ping and try to go into details more.
>> Just want to show that your pro/cons listing is broken.
>>
>> Best Jan
>>
>> and want to get rid of this horrible compromise
>>
>>
>> On 19.03.2018 05:48, Jun Rao wrote:
>>
>>> Hi, Jan,
>>>
>>> Thanks for the discussion. Great points.
>>>
>>> Let me try to summarize the approach that you are proposing. On the
>>> broker
>>> side, we reshuffle the existing data in a topic from current partitions
>>> to
>>> the new partitions. Once the reshuffle fully catches up, switch the
>>> consumers to start consuming from the new partitions. If a consumer needs
>>> to rebuild its local state (due to partition changes), let the consumer
>>> rebuild its state by reading all existing data from the new partitions.
>>> Once all consumers have switches over, cut over the producer to the new
>>> partitions.
>>>
>>> The pros for this approach are that :
>>> 1. There is just one way to rebuild the local state, which is simpler.
>>>
>> true thanks
>>
>>>
>>> The cons for this approach are:
>>> 1. Need to copy existing data.
>>>
>> Very unfair and not correct. It does not require you to copy over
>> existing data. It _allows_ you to copy all existing data.
>>
>> 2. The cutover of the producer is a bit complicated since it needs to
>>> coordinate with all consumer groups.
>>>
>> Also not true. I explicitly tried to make clear that there is only one
>> special consumer (in the case of actually copying data) coordination is
>> required.
>>
>>> 3. The rebuilding of the state in the consumer is from the input topic,
>>> which can be more expensive than rebuilding from the existing state.
>>>
>> true, but rebuilding state is only required if you want to increase
>> processing power, so we assume this is at hand.
>>
>>> 4. The broker potentially has to know the partitioning function. If this
>>> needs to be customized at the topic level, it can be a bit messy.
>>>
>> I would argue against having the operation being performed by the broker.
>> This was not discussed yet but if you see my original email i suggested
>> otherwise from the beginning.
>>
>>>
>>> Here is an alternative approach by applying your idea not in the broker,
>>> but in the consumer. When new partitions are added, we don't move
>>> existing
>>> data. In KStreams, we first reshuffle the new input data to a new topic
>>> T1
>>> with the old number of partitions and feed T1's data to the rest of the
>>> pipeline. In the meantime, KStreams reshuffles all existing data of the
>>> change capture topic to another topic C1 with the new number of
>>> partitions.
>>> We can then build the state of the new tasks from C1. Once the new states
>>> have been fully built, we can cut over the consumption to the input topic
>>> and delete T1. This approach works with compacted topic too. If an
>>> application reads from the beginning of a compacted topic, the consumer
>>> will reshuffle the portion of the input when the number of partitions
>>> doesn't match the number of tasks.
>>>
>> We all wipe this idea from our heads instantly. Mixing Ideas from an
>> argument is not a resolution strategy
>> just leads to horrible horrible software.
>>
>>
>>> The pros of this approach are:
>>> 1. No need to copy existing data.
>>> 2. Each consumer group can cut over to the new partitions independently.
>>> 3. The state is rebuilt from the change capture topic, which is cheaper
>>> than rebuilding from the input topic.
>>> 4. Only the KStreams job needs to know the partitioning function.
>>>
>>> The cons of this approach are:
>>> 1. Potentially the same input topic needs to be reshuffled more than once
>>> in different consumer groups during the transition phase.
>>>
>>> What do you think?
>>>
>>> Thanks,
>>>
>>> Jun
>>>
>>>
>>>
>>> On Thu, Mar 15, 2018 at 1:04 AM, Jan Filipiak <Ja...@trivago.com>
>>> wrote:
>>>
>>> Hi Jun,
>>>>
>>>> thank you for following me on these thoughts. It was important to me to
>>>> feel that kind of understanding for my arguments.
>>>>
>>>> What I was hoping for (I mentioned this earlier) is that we can model
>>>> the
>>>> case where we do not want to copy the data the exact same way as the
>>>> case
>>>> when we do copy the data. Maybe you can peek into the mails before to
>>>> see
>>>> more details for this.
>>>>
>>>> This means we have the same mechanism to transfer consumer groups to
>>>> switch topic. The offset mapping that would be generated would even be
>>>> simpler End Offset of the Old topic => offset 0 off all the partitions
>>>> of
>>>> the new topic. Then we could model the transition of a non-copy
>>>> expansion
>>>> the exact same way as a copy-expansion.
>>>>
>>>> I know this only works when topic growth by a factor. But the benefits
>>>> of
>>>> only growing by a factor are to strong anyways. See Clemens's hint and
>>>> remember that state reshuffling is entirely not needed if one doesn't
>>>> want
>>>> to grow processing power.
>>>>
>>>> I think these benefits should be clear, and that there is basically no
>>>> downside to what is currently at hand but just makes everything easy.
>>>>
>>>> One thing you need to know is. that if you do not offer rebuilding a log
>>>> compacted topic like i suggest that even if you have consumer state
>>>> reshuffling. The topic is broken and can not be used to bootstrap new
>>>> consumers. They don't know if they need to apply a key from and old
>>>> partition or not. This is a horrible downside I haven't seen a solution
>>>> for
>>>> in the email conversation.
>>>>
>>>> I argue to:
>>>>
>>>> Only grow topic by a factor always.
>>>> Have the "no copy consumer" transition as the trivial case of the "copy
>>>> consumer transition".
>>>> If processors needs to be scaled, let them rebuild from the new topic
>>>> and
>>>> leave the old running in the mean time.
>>>> Do not implement key shuffling in streams.
>>>>
>>>> I hope I can convince you especially with the fact how I want to handle
>>>> consumer transition. I think
>>>> you didn't quite understood me there before. I think the term "new
>>>> topic"
>>>> intimidated you a little.
>>>> How we solve this on disc doesn't really matter, If the data goes into
>>>> the
>>>> same Dir or a different Dir or anything. I do think that it needs to
>>>> involve at least rolling a new segment for the existing partitions.
>>>> But most of the transitions should work without restarting consumers.
>>>> (newer consumers with support for this). But with new topic i just meant
>>>> the topic that now has a different partition count. Plenty of ways to
>>>> handle that (versions, aliases)
>>>>
>>>> Hope I can further get my idea across.
>>>>
>>>> Best Jan
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> On 14.03.2018 02:45, Jun Rao wrote:
>>>>
>>>> Hi, Jan,
>>>>>
>>>>> Thanks for sharing your view.
>>>>>
>>>>> I agree with you that recopying the data potentially makes the state
>>>>> management easier since the consumer can just rebuild its state from
>>>>> scratch (i.e., no need for state reshuffling).
>>>>>
>>>>> On the flip slide, I saw a few disadvantages of the approach that you
>>>>> suggested. (1) Building the state from the input topic from scratch is
>>>>> in
>>>>> general less efficient than state reshuffling. Let's say one computes a
>>>>> count per key from an input topic. The former requires reading all
>>>>> existing
>>>>> records in the input topic whereas the latter only requires reading
>>>>> data
>>>>> proportional to the number of unique keys. (2) The switching of the
>>>>> topic
>>>>> needs modification to the application. If there are many applications
>>>>> on a
>>>>> topic, coordinating such an effort may not be easy. Also, it's not
>>>>> clear
>>>>> how to enforce exactly-once semantic during the switch. (3) If a topic
>>>>> doesn't need any state management, recopying the data seems wasteful.
>>>>> In
>>>>> that case, in place partition expansion seems more desirable.
>>>>>
>>>>> I understand your concern about adding complexity in KStreams. But,
>>>>> perhaps
>>>>> we could iterate on that a bit more to see if it can be simplified.
>>>>>
>>>>> Jun
>>>>>
>>>>>
>>>>> On Mon, Mar 12, 2018 at 11:21 PM, Jan Filipiak <
>>>>> Jan.Filipiak@trivago.com>
>>>>> wrote:
>>>>>
>>>>> Hi Jun,
>>>>>
>>>>>> I will focus on point 61 as I think its _the_ fundamental part that I
>>>>>> cant
>>>>>> get across at the moment.
>>>>>>
>>>>>> Kafka is the platform to have state materialized multiple times from
>>>>>> one
>>>>>> input. I emphasize this: It is the building block in architectures
>>>>>> that
>>>>>> allow you to
>>>>>> have your state maintained multiple times. You put a message in once,
>>>>>> and
>>>>>> you have it pop out as often as you like. I believe you understand
>>>>>> this.
>>>>>>
>>>>>> Now! The path of thinking goes the following: I am using apache kafka
>>>>>> and
>>>>>> I _want_ my state multiple times. What am I going todo?
>>>>>>
>>>>>> A) Am I going to take my state that I build up, plunge some sort of
>>>>>> RPC
>>>>>> layer ontop of it, use that RPC layer to throw my records across
>>>>>> instances?
>>>>>> B) Am I just going to read the damn message twice?
>>>>>>
>>>>>> Approach A is fundamentally flawed and a violation of all that is good
>>>>>> and
>>>>>> holy in kafka deployments. I can not understand how this Idea can
>>>>>> come in
>>>>>> the first place.
>>>>>> (I do understand: IQ in streams, they polluted the kafka streams
>>>>>> codebase
>>>>>> really bad already. It is not funny! I think they are equally flawed
>>>>>> as
>>>>>> A)
>>>>>>
>>>>>> I say, we do what Kafka is good at. We repartition the topic once. We
>>>>>> switch the consumers.
>>>>>> (Those that need more partitions are going to rebuild their state in
>>>>>> multiple partitions by reading the new topic, those that don't just
>>>>>> assign
>>>>>> the new partitions properly)
>>>>>> We switch producers. Done!
>>>>>>
>>>>>> The best thing! It is trivial, hipster stream processor will have an
>>>>>> easy
>>>>>> time with that aswell. Its so super simple. And simple IS good!
>>>>>> It is what kafka was build todo. It is how we do it today. All I am
>>>>>> saying
>>>>>> is that a little broker help doing the producer swap is super useful.
>>>>>>
>>>>>> For everyone interested in why kafka is so powerful with approach B,
>>>>>> please watch https://youtu.be/bEbeZPVo98c?t=1633
>>>>>> I already looked up a good point in time, I think after 5 minutes the
>>>>>> "state" topic is handled and you should be able to understand me
>>>>>> and inch better.
>>>>>>
>>>>>> Please do not do A to the project, it deserves better!
>>>>>>
>>>>>> Best Jan
>>>>>>
>>>>>>
>>>>>>
>>>>>> On 13.03.2018 02:40, Jun Rao wrote:
>>>>>>
>>>>>> Hi, Jan,
>>>>>>
>>>>>>> Thanks for the reply. A few more comments below.
>>>>>>>
>>>>>>> 50. Ok, we can think a bit harder for supporting compacted topics.
>>>>>>>
>>>>>>> 51. This is a fundamental design question. In the more common case,
>>>>>>> the
>>>>>>> reason why someone wants to increase the number of partitions is that
>>>>>>> the
>>>>>>> consumer application is slow and one wants to run more consumer
>>>>>>> instances
>>>>>>> to increase the degree of parallelism. So, fixing the number of
>>>>>>> running
>>>>>>> consumer instances when expanding the partitions won't help this
>>>>>>> case.
>>>>>>> If
>>>>>>> we do need to increase the number of consumer instances, we need to
>>>>>>> somehow
>>>>>>> reshuffle the state of the consumer across instances. What we have
>>>>>>> been
>>>>>>> discussing in this KIP is whether we can do this more effectively
>>>>>>> through
>>>>>>> the KStream library (e.g. through a 2-phase partition expansion).
>>>>>>> This
>>>>>>> will
>>>>>>> add some complexity, but it's probably better than everyone doing
>>>>>>> this
>>>>>>> in
>>>>>>> the application space. The recopying approach that you mentioned
>>>>>>> doesn't
>>>>>>> seem to address the consumer state management issue when the consumer
>>>>>>> switches from an old to a new topic.
>>>>>>>
>>>>>>> 52. As for your example, it depends on whether the join key is the
>>>>>>> same
>>>>>>> between (A,B) and (B,C). If the join key is the same, we can do a
>>>>>>> 2-phase
>>>>>>> partition expansion of A, B, and C together. If the join keys are
>>>>>>> different, one would need to repartition the data on a different key
>>>>>>> for
>>>>>>> the second join, then the partition expansion can be done
>>>>>>> independently
>>>>>>> between (A,B) and (B,C).
>>>>>>>
>>>>>>> 53. If you always fix the number of consumer instances, we you
>>>>>>> described
>>>>>>> works. However, as I mentioned in #51, I am not sure how your
>>>>>>> proposal
>>>>>>> deals with consumer states when the number of consumer instances
>>>>>>> grows.
>>>>>>> Also, it just seems that it's better to avoid re-copying the existing
>>>>>>> data.
>>>>>>>
>>>>>>> 60. "just want to throw in my question from the longer email in the
>>>>>>> other
>>>>>>> Thread here. How will the bloom filter help a new consumer to decide
>>>>>>> to
>>>>>>> apply the key or not?" Not sure that I fully understood your
>>>>>>> question.
>>>>>>> The
>>>>>>> consumer just reads whatever key is in the log. The bloom filter just
>>>>>>> helps
>>>>>>> clean up the old keys.
>>>>>>>
>>>>>>> 61. "Why can we afford having a topic where its apparently not
>>>>>>> possible
>>>>>>> to
>>>>>>> start a new application on? I think this is an overall flaw of the
>>>>>>> discussed idea here. Not playing attention to the overall
>>>>>>> architecture."
>>>>>>> Could you explain a bit more when one can't start a new application?
>>>>>>>
>>>>>>> Jun
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> On Sat, Mar 10, 2018 at 1:40 AM, Jan Filipiak <
>>>>>>> Jan.Filipiak@trivago.com
>>>>>>> wrote:
>>>>>>>
>>>>>>> Hi Jun, thanks for your mail.
>>>>>>>
>>>>>>> Thank you for your questions!
>>>>>>>> I think they are really good and tackle the core of the problem I
>>>>>>>> see.
>>>>>>>>
>>>>>>>> I will answer inline, mostly but still want to set the tone here.
>>>>>>>>
>>>>>>>> The core strength of kafka is what Martin once called the
>>>>>>>> kappa-Architecture. How does this work?
>>>>>>>> You have everything as a log as in kafka. When you need to change
>>>>>>>> something.
>>>>>>>> You create the new version of your application and leave it running
>>>>>>>> in
>>>>>>>> parallel.
>>>>>>>> Once the new version is good you switch your users to use the new
>>>>>>>> application.
>>>>>>>>
>>>>>>>> The online reshuffling effectively breaks this architecture and I
>>>>>>>> think
>>>>>>>> the switch in thinking here is more harmful
>>>>>>>> than any details about the partitioning function to allow such a
>>>>>>>> change.
>>>>>>>> I
>>>>>>>> feel with my suggestion we are the closest to
>>>>>>>> the original and battle proven architecture and I can only warn to
>>>>>>>> move
>>>>>>>> away from it.
>>>>>>>>
>>>>>>>> I might have forgotten something, sometimes its hard for me to
>>>>>>>> getting
>>>>>>>> all
>>>>>>>> the thoughts captured in a mail, but I hope the comments inline will
>>>>>>>> further make my concern clear, and put some emphasis on why I
>>>>>>>> prefer my
>>>>>>>> solution ;)
>>>>>>>>
>>>>>>>> One thing we should all be aware of when discussing this, and I
>>>>>>>> think
>>>>>>>> Dong
>>>>>>>> should have mentioned it (maybe he did).
>>>>>>>> We are not discussing all of this out of thin air but there is an
>>>>>>>> effort
>>>>>>>> in the Samza project.
>>>>>>>>
>>>>>>>> https://cwiki.apache.org/confluence/display/SAMZA/SEP-5%3A+
>>>>>>>> Enable+partition+expansion+of+input+streams
>>>>>>>> https://issues.apache.org/jira/browse/SAMZA-1293
>>>>>>>>
>>>>>>>> To be clear. I think SEP-5 (state of last week, dont know if it
>>>>>>>> adapted
>>>>>>>> to
>>>>>>>> this discussion) is on a way better path than KIP-253, and I can't
>>>>>>>> really
>>>>>>>> explain why.
>>>>>>>>
>>>>>>>> Best Jan,
>>>>>>>>
>>>>>>>> nice weekend everyone
>>>>>>>>
>>>>>>>>
>>>>>>>> On 09.03.2018 03:36, Jun Rao wrote:
>>>>>>>>
>>>>>>>> Hi, Jan,
>>>>>>>>
>>>>>>>> Thanks for the feedback. Just some comments on the earlier points
>>>>>>>>> that
>>>>>>>>> you
>>>>>>>>> mentioned.
>>>>>>>>>
>>>>>>>>> 50. You brought up the question of whether existing data needs to
>>>>>>>>> be
>>>>>>>>> copied
>>>>>>>>> during partition expansion. My understand of your view is that
>>>>>>>>> avoid
>>>>>>>>> copying existing data will be more efficient, but it doesn't work
>>>>>>>>> well
>>>>>>>>> with
>>>>>>>>> compacted topics since some keys in the original partitions will
>>>>>>>>> never
>>>>>>>>> be
>>>>>>>>> cleaned. It would be useful to understand your use case of
>>>>>>>>> compacted
>>>>>>>>> topics
>>>>>>>>> a bit more. In the common use case, the data volume in a compacted
>>>>>>>>> topic
>>>>>>>>> may not be large. So, I am not sure if there is a strong need to
>>>>>>>>> expand
>>>>>>>>> partitions in a compacted topic, at least initially.
>>>>>>>>>
>>>>>>>>> I do agree. State is usually smaller. Update rates might be also
>>>>>>>>>
>>>>>>>>> competitively high.
>>>>>>>> Doing Log-compaction (even beeing very efficient and configurable)
>>>>>>>> is
>>>>>>>> also
>>>>>>>> a more expensive operation than
>>>>>>>> just discarding old segments. Further if you want to use more
>>>>>>>> consumers
>>>>>>>> processing the events
>>>>>>>> you also have to grow the number of partitions. Especially for
>>>>>>>> use-cases
>>>>>>>> we do (KIP-213) a tiny state full
>>>>>>>> table might be very expensive to process if it joins against a huge
>>>>>>>> table.
>>>>>>>>
>>>>>>>> I can just say we have been in the spot of needing to grow log
>>>>>>>> compacted
>>>>>>>> topics. Mainly for processing power we can bring to the table.
>>>>>>>>
>>>>>>>> Further i am not at all concerned about the extra spaced used by
>>>>>>>> "garbage
>>>>>>>> keys". I am more concerned about the correctness of innocent
>>>>>>>> consumers.
>>>>>>>> The
>>>>>>>> logic becomes complicated. Say for streams one would need to load
>>>>>>>> the
>>>>>>>> record into state but not forward it the topology ( to have it
>>>>>>>> available
>>>>>>>> for shuffeling). I rather have it simple and a topic clean
>>>>>>>> regardless
>>>>>>>> if
>>>>>>>> it
>>>>>>>> still has its old partition count. Especially with multiple
>>>>>>>> partitions
>>>>>>>> growth's I think it becomes insanely hard to to this shuffle
>>>>>>>> correct.
>>>>>>>> Maybe
>>>>>>>> Streams and Samza can do it. Especially if you do "hipster stream
>>>>>>>> processing" <https://www.confluent.io/blog
>>>>>>>> /introducing-kafka-streams-
>>>>>>>> stream-processing-made-simple/>. This makes kafka way to
>>>>>>>> complicated.
>>>>>>>> With my approach I think its way simpler because the topic has no
>>>>>>>> "history"
>>>>>>>> in terms of partitioning but is always clean.
>>>>>>>>
>>>>>>>>
>>>>>>>> 51. "Growing the topic by an integer factor does not require any
>>>>>>>> state
>>>>>>>>
>>>>>>>> redistribution at all." Could you clarify this a bit more? Let's say
>>>>>>>>> you
>>>>>>>>> have a consumer app that computes the windowed count per key. If
>>>>>>>>> you
>>>>>>>>> double
>>>>>>>>> the number of partitions from 1 to 2 and grow the consumer
>>>>>>>>> instances
>>>>>>>>> from
>>>>>>>>> 1
>>>>>>>>> to 2, we would need to redistribute some of the counts to the new
>>>>>>>>> consumer
>>>>>>>>> instance. Regarding to linear hashing, it's true that it won't
>>>>>>>>> solve
>>>>>>>>> the
>>>>>>>>> problem with compacted topics. The main benefit is that it
>>>>>>>>> redistributes
>>>>>>>>> the keys in one partition to no more than two partitions, which
>>>>>>>>> could
>>>>>>>>> help
>>>>>>>>> redistribute the state.
>>>>>>>>>
>>>>>>>>> You don't need to spin up a new consumer in this case. every
>>>>>>>>> consumer
>>>>>>>>>
>>>>>>>>> would just read every partition with the (partition % num_task)
>>>>>>>> task.
>>>>>>>> it
>>>>>>>> will still have the previous data right there and can go on.
>>>>>>>>
>>>>>>>> This sounds contradictory to what I said before, but please bear
>>>>>>>> with
>>>>>>>> me.
>>>>>>>>
>>>>>>>> 52. Good point on coordinating the expansion of 2 topics that need
>>>>>>>> to
>>>>>>>> be
>>>>>>>>
>>>>>>>> joined together. This is where the 2-phase partition expansion could
>>>>>>>>> potentially help. In the first phase, we could add new partitions
>>>>>>>>> to
>>>>>>>>> the 2
>>>>>>>>> topics one at a time but without publishing to the new patitions.
>>>>>>>>> Then,
>>>>>>>>> we
>>>>>>>>> can add new consumer instances to pick up the new partitions. In
>>>>>>>>> this
>>>>>>>>> transition phase, no reshuffling is needed since no data is coming
>>>>>>>>> from
>>>>>>>>> the
>>>>>>>>> new partitions. Finally, we can enable the publishing to the new
>>>>>>>>> partitions.
>>>>>>>>>
>>>>>>>>> I think its even worse than you think. I would like to introduce
>>>>>>>>> the
>>>>>>>>>
>>>>>>>>> Term
>>>>>>>> transitive copartitioning. Imagine
>>>>>>>> 2 streams application. One joins (A,B) the other (B,C) then there
>>>>>>>> is a
>>>>>>>> transitive copartition requirement for
>>>>>>>> (A,C) to be copartitioned aswell. This can spread significantly and
>>>>>>>> require many consumers to adapt at the same time.
>>>>>>>>
>>>>>>>> It is also not entirely clear to me how you not need reshuffling in
>>>>>>>> this
>>>>>>>> case. If A has a record that never gets updated after the expansion
>>>>>>>> and
>>>>>>>> the
>>>>>>>> coresponding B record moves to a new partition. How shall they meet
>>>>>>>> w/o
>>>>>>>> shuffle?
>>>>>>>>
>>>>>>>> 53. "Migrating consumer is a step that might be made completly
>>>>>>>>
>>>>>>>> unnecessary
>>>>>>>>> if - for example streams - takes the gcd as partitioning scheme
>>>>>>>>> instead
>>>>>>>>> of
>>>>>>>>> enforcing 1 to 1." Not sure that I fully understand this. I think
>>>>>>>>> you
>>>>>>>>> mean
>>>>>>>>> that a consumer application can run more instances than the number
>>>>>>>>> of
>>>>>>>>> partitions. In that case, the consumer can just repartitioning the
>>>>>>>>> input
>>>>>>>>> data according to the number of instances. This is possible, but
>>>>>>>>> just
>>>>>>>>> has
>>>>>>>>> the overhead of reshuffling the data.
>>>>>>>>>
>>>>>>>>> No what I meant is ( that is also your question i think Mathias)
>>>>>>>>> that
>>>>>>>>> if
>>>>>>>>>
>>>>>>>>> you grow a topic by a factor.
>>>>>>>> Even if your processor is statefull you can can just assign all the
>>>>>>>> multiples of the previous partition to
>>>>>>>> this consumer and the state to keep processing correctly will be
>>>>>>>> present
>>>>>>>> w/o any shuffling.
>>>>>>>>
>>>>>>>> Say you have an assignment
>>>>>>>> Statefull consumer => partition
>>>>>>>> 0 => 0
>>>>>>>> 1 => 1
>>>>>>>> 2 => 2
>>>>>>>>
>>>>>>>> and you grow you topic by 4 you get,
>>>>>>>>
>>>>>>>> 0 => 0,3,6,9
>>>>>>>> 1 => 1,4,7,10
>>>>>>>> 2 => 2,5,8,11
>>>>>>>>
>>>>>>>> Say your hashcode is 8. 8%3 => 2  before so consumer for partition 2
>>>>>>>> has
>>>>>>>> it.
>>>>>>>> Now you you have 12 partitions so 8%12 => 8, so it goes into
>>>>>>>> partition
>>>>>>>> 8
>>>>>>>> which is assigned to the same consumer
>>>>>>>> who had 2 before and therefore knows the key.
>>>>>>>>
>>>>>>>> Userland reshuffeling is there as an options. And it does exactly
>>>>>>>> what
>>>>>>>> I
>>>>>>>> suggest. And I think its the perfect strategie. All I am suggestion
>>>>>>>> is
>>>>>>>> broker side support to switch the producers to the newly partitioned
>>>>>>>> topic.
>>>>>>>> Then the old (to few partition topic) can go away.  Remember the
>>>>>>>> list
>>>>>>>> of
>>>>>>>> steps in the beginning of this thread. If one has broker support for
>>>>>>>> all
>>>>>>>> where its required and streams support for those that aren’t
>>>>>>>> necessarily.
>>>>>>>> Then one has solved the problem.
>>>>>>>> I repeat it because I think its important. I am really happy that
>>>>>>>> you
>>>>>>>> brought that up! because its 100% what I want just with the
>>>>>>>> differences
>>>>>>>> to
>>>>>>>> have an option to discard the to small topic later (after all
>>>>>>>> consumers
>>>>>>>> adapted). And to have order correct there. I need broker support
>>>>>>>> managing
>>>>>>>> the copy process + the produces and fence them against each other. I
>>>>>>>> also
>>>>>>>> repeat. the copy process can run for weeks in the worst case.
>>>>>>>> Copying
>>>>>>>> the
>>>>>>>> data is not the longest task migrating consumers might very well be.
>>>>>>>> Once all consumers switched and copying is really up to date (think
>>>>>>>> ISR
>>>>>>>> like up to date) only then we stop the producer, wait for the copy
>>>>>>>> to
>>>>>>>> finish and use the new topic for producing.
>>>>>>>>
>>>>>>>> After this the topic is perfect in shape. and no one needs to worry
>>>>>>>> about
>>>>>>>> complicated stuff. (old keys hanging around might arrive in some
>>>>>>>> other
>>>>>>>> topic later.....). can only imagine how many tricky bugs gonna
>>>>>>>> arrive
>>>>>>>> after
>>>>>>>> someone had grown and shrunken is topic 10 times.
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> 54. "The other thing I wanted to mention is that I believe the
>>>>>>>> current
>>>>>>>>
>>>>>>>> suggestion (without copying data over) can be implemented in pure
>>>>>>>>> userland
>>>>>>>>> with a custom partitioner and a small feedbackloop from
>>>>>>>>> ProduceResponse
>>>>>>>>> =>
>>>>>>>>> Partitionier in coorporation with a change management system." I am
>>>>>>>>> not
>>>>>>>>> sure a customized partitioner itself solves the problem. We
>>>>>>>>> probably
>>>>>>>>> need
>>>>>>>>> some broker side support to enforce when the new partitions can be
>>>>>>>>> used.
>>>>>>>>> We
>>>>>>>>> also need some support on the consumer/kstream side to preserve the
>>>>>>>>> per
>>>>>>>>> key
>>>>>>>>> ordering and potentially migrate the processing state. This is not
>>>>>>>>> trivial
>>>>>>>>> and I am not sure if it's ideal to fully push to the application
>>>>>>>>> space.
>>>>>>>>>
>>>>>>>>> Broker support is defenitly the preferred way here. I have nothing
>>>>>>>>>
>>>>>>>>> against
>>>>>>>> broker support.
>>>>>>>> I tried to say that for what I would preffer - copying the data
>>>>>>>> over,
>>>>>>>> at
>>>>>>>> least for log compacted topics -
>>>>>>>> I would require more broker support than the KIP currently offers.
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> Jun
>>>>>>>>
>>>>>>>> On Tue, Mar 6, 2018 at 10:33 PM, Jan Filipiak <
>>>>>>>>> Jan.Filipiak@trivago.com
>>>>>>>>> wrote:
>>>>>>>>>
>>>>>>>>> Hi Dong,
>>>>>>>>>
>>>>>>>>> are you actually reading my emails, or are you just using the
>>>>>>>>> thread I
>>>>>>>>>
>>>>>>>>>> started for general announcements regarding the KIP?
>>>>>>>>>>
>>>>>>>>>> I tried to argue really hard against linear hashing. Growing the
>>>>>>>>>> topic
>>>>>>>>>> by
>>>>>>>>>> an integer factor does not require any state redistribution at
>>>>>>>>>> all. I
>>>>>>>>>> fail
>>>>>>>>>> to see completely where linear hashing helps on log compacted
>>>>>>>>>> topics.
>>>>>>>>>>
>>>>>>>>>> If you are not willing to explain to me what I might be
>>>>>>>>>> overlooking:
>>>>>>>>>> that
>>>>>>>>>> is fine.
>>>>>>>>>> But I ask you to not reply to my emails then. Please understand my
>>>>>>>>>> frustration with this.
>>>>>>>>>>
>>>>>>>>>> Best Jan
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> On 06.03.2018 19:38, Dong Lin wrote:
>>>>>>>>>>
>>>>>>>>>> Hi everyone,
>>>>>>>>>>
>>>>>>>>>> Thanks for all the comments! It appears that everyone prefers
>>>>>>>>>> linear
>>>>>>>>>>
>>>>>>>>>>> hashing because it reduces the amount of state that needs to be
>>>>>>>>>>> moved
>>>>>>>>>>> between consumers (for stream processing). The KIP has been
>>>>>>>>>>> updated
>>>>>>>>>>> to
>>>>>>>>>>> use
>>>>>>>>>>> linear hashing.
>>>>>>>>>>>
>>>>>>>>>>> Regarding the migration endeavor: it seems that migrating
>>>>>>>>>>> producer
>>>>>>>>>>> library
>>>>>>>>>>> to use linear hashing should be pretty straightforward without
>>>>>>>>>>> much operational endeavor. If we don't upgrade client library to
>>>>>>>>>>> use
>>>>>>>>>>> this
>>>>>>>>>>> KIP, we can not support in-order delivery after partition is
>>>>>>>>>>> changed
>>>>>>>>>>> anyway. Suppose we upgrade client library to use this KIP, if
>>>>>>>>>>> partition
>>>>>>>>>>> number is not changed, the key -> partition mapping will be
>>>>>>>>>>> exactly
>>>>>>>>>>> the
>>>>>>>>>>> same as it is now because it is still determined using
>>>>>>>>>>> murmur_hash(key)
>>>>>>>>>>> %
>>>>>>>>>>> original_partition_num. In other words, this change is backward
>>>>>>>>>>> compatible.
>>>>>>>>>>>
>>>>>>>>>>> Regarding the load distribution: if we use linear hashing, the
>>>>>>>>>>> load
>>>>>>>>>>> may
>>>>>>>>>>> be
>>>>>>>>>>> unevenly distributed because those partitions which are not split
>>>>>>>>>>> may
>>>>>>>>>>> receive twice as much traffic as other partitions that are split.
>>>>>>>>>>> This
>>>>>>>>>>> issue can be mitigated by creating topic with partitions that are
>>>>>>>>>>> several
>>>>>>>>>>> times the number of consumers. And there will be no imbalance if
>>>>>>>>>>> the
>>>>>>>>>>> partition number is always doubled. So this imbalance seems
>>>>>>>>>>> acceptable.
>>>>>>>>>>>
>>>>>>>>>>> Regarding storing the partition strategy as per-topic config: It
>>>>>>>>>>> seems
>>>>>>>>>>> not
>>>>>>>>>>> necessary since we can still use murmur_hash as the default hash
>>>>>>>>>>> function
>>>>>>>>>>> and additionally apply the linear hashing algorithm if the
>>>>>>>>>>> partition
>>>>>>>>>>> number
>>>>>>>>>>> has increased. Not sure if there is any use-case for producer to
>>>>>>>>>>> use a
>>>>>>>>>>> different hash function. Jason, can you check if there is some
>>>>>>>>>>> use-case
>>>>>>>>>>> that I missed for using the per-topic partition strategy?
>>>>>>>>>>>
>>>>>>>>>>> Regarding how to reduce latency (due to state store/load) in
>>>>>>>>>>> stream
>>>>>>>>>>> processing consumer when partition number changes: I need to read
>>>>>>>>>>> the
>>>>>>>>>>> Kafka
>>>>>>>>>>> Stream code to understand how Kafka Stream currently migrate
>>>>>>>>>>> state
>>>>>>>>>>> between
>>>>>>>>>>> consumers when the application is added/removed for a given job.
>>>>>>>>>>> I
>>>>>>>>>>> will
>>>>>>>>>>> reply after I finish reading the documentation and code.
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> Thanks,
>>>>>>>>>>> Dong
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> On Mon, Mar 5, 2018 at 10:43 AM, Jason Gustafson <
>>>>>>>>>>> jason@confluent.io>
>>>>>>>>>>> wrote:
>>>>>>>>>>>
>>>>>>>>>>> Great discussion. I think I'm wondering whether we can continue
>>>>>>>>>>> to
>>>>>>>>>>> leave
>>>>>>>>>>>
>>>>>>>>>>> Kafka agnostic to the partitioning strategy. The challenge is
>>>>>>>>>>>
>>>>>>>>>>> communicating
>>>>>>>>>>>> the partitioning logic from producers to consumers so that the
>>>>>>>>>>>> dependencies
>>>>>>>>>>>> between each epoch can be determined. For the sake of
>>>>>>>>>>>> discussion,
>>>>>>>>>>>> imagine
>>>>>>>>>>>> you did something like the following:
>>>>>>>>>>>>
>>>>>>>>>>>> 1. The name (and perhaps version) of a partitioning strategy is
>>>>>>>>>>>> stored
>>>>>>>>>>>> in
>>>>>>>>>>>> topic configuration when a topic is created.
>>>>>>>>>>>> 2. The producer looks up the partitioning strategy before
>>>>>>>>>>>> writing
>>>>>>>>>>>> to
>>>>>>>>>>>> a
>>>>>>>>>>>> topic and includes it in the produce request (for fencing). If
>>>>>>>>>>>> it
>>>>>>>>>>>> doesn't
>>>>>>>>>>>> have an implementation for the configured strategy, it fails.
>>>>>>>>>>>> 3. The consumer also looks up the partitioning strategy and
>>>>>>>>>>>> uses it
>>>>>>>>>>>> to
>>>>>>>>>>>> determine dependencies when reading a new epoch. It could either
>>>>>>>>>>>> fail
>>>>>>>>>>>> or
>>>>>>>>>>>> make the most conservative dependency assumptions if it doesn't
>>>>>>>>>>>> know
>>>>>>>>>>>> how
>>>>>>>>>>>> to
>>>>>>>>>>>> implement the partitioning strategy. For the consumer, the new
>>>>>>>>>>>> interface
>>>>>>>>>>>> might look something like this:
>>>>>>>>>>>>
>>>>>>>>>>>> // Return the partition dependencies following an epoch bump
>>>>>>>>>>>> Map<Integer, List<Integer>> dependencies(int
>>>>>>>>>>>> numPartitionsBeforeEpochBump,
>>>>>>>>>>>> int numPartitionsAfterEpochBump)
>>>>>>>>>>>>
>>>>>>>>>>>> The unordered case then is just a particular implementation
>>>>>>>>>>>> which
>>>>>>>>>>>> never
>>>>>>>>>>>> has
>>>>>>>>>>>> any epoch dependencies. To implement this, we would need some
>>>>>>>>>>>> way
>>>>>>>>>>>> for
>>>>>>>>>>>> the
>>>>>>>>>>>> consumer to find out how many partitions there were in each
>>>>>>>>>>>> epoch,
>>>>>>>>>>>> but
>>>>>>>>>>>> maybe that's not too unreasonable.
>>>>>>>>>>>>
>>>>>>>>>>>> Thanks,
>>>>>>>>>>>> Jason
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>> On Mon, Mar 5, 2018 at 4:51 AM, Jan Filipiak <
>>>>>>>>>>>> Jan.Filipiak@trivago.com
>>>>>>>>>>>> wrote:
>>>>>>>>>>>>
>>>>>>>>>>>> Hi Dong
>>>>>>>>>>>>
>>>>>>>>>>>> thank you very much for your questions.
>>>>>>>>>>>>
>>>>>>>>>>>> regarding the time spend copying data across:
>>>>>>>>>>>>> It is correct that copying data from a topic with one partition
>>>>>>>>>>>>> mapping
>>>>>>>>>>>>>
>>>>>>>>>>>>> to
>>>>>>>>>>>>>
>>>>>>>>>>>>> a topic with a different partition mapping takes way longer
>>>>>>>>>>>>> than
>>>>>>>>>>>>>
>>>>>>>>>>>> we
>>>>>>>>>>>> can
>>>>>>>>>>>>
>>>>>>>>>>>> stop producers. Tens of minutes is a very optimistic estimate
>>>>>>>>>>>> here.
>>>>>>>>>>>>
>>>>>>>>>>>>> Many
>>>>>>>>>>>>> people can not afford copy full steam and therefore will have
>>>>>>>>>>>>> some
>>>>>>>>>>>>> rate
>>>>>>>>>>>>> limiting in place, this can bump the timespan into the day's.
>>>>>>>>>>>>> The
>>>>>>>>>>>>> good
>>>>>>>>>>>>>
>>>>>>>>>>>>> part
>>>>>>>>>>>>>
>>>>>>>>>>>>> is that the vast majority of the data can be copied while the
>>>>>>>>>>>>>
>>>>>>>>>>>> producers
>>>>>>>>>>>>
>>>>>>>>>>>> are
>>>>>>>>>>>>
>>>>>>>>>>>>> still going. One can then, piggyback the consumers ontop of
>>>>>>>>>>>>> this
>>>>>>>>>>>>>
>>>>>>>>>>>> timeframe,
>>>>>>>>>>>>
>>>>>>>>>>>>> by the method mentioned (provide them an mapping from their old
>>>>>>>>>>>>>
>>>>>>>>>>>> offsets
>>>>>>>>>>>>
>>>>>>>>>>>> to
>>>>>>>>>>>>
>>>>>>>>>>>>> new offsets in their repartitioned topics. In that way we
>>>>>>>>>>>>> separate
>>>>>>>>>>>>>
>>>>>>>>>>>> migration of consumers from migration of producers (decoupling
>>>>>>>>>>>>
>>>>>>>>>>>>> these
>>>>>>>>>>>>> is
>>>>>>>>>>>>> what kafka is strongest at). The time to actually swap over the
>>>>>>>>>>>>> producers
>>>>>>>>>>>>> should be kept minimal by ensuring that when a swap attempt is
>>>>>>>>>>>>> started
>>>>>>>>>>>>>
>>>>>>>>>>>>> the
>>>>>>>>>>>>>
>>>>>>>>>>>>> consumer copying over should be very close to the log end and
>>>>>>>>>>>>> is
>>>>>>>>>>>>>
>>>>>>>>>>>> expected
>>>>>>>>>>>>
>>>>>>>>>>>>> to finish within the next fetch. The operation should have a
>>>>>>>>>>>>> time-out
>>>>>>>>>>>>> and
>>>>>>>>>>>>> should be "reattemtable".
>>>>>>>>>>>>>
>>>>>>>>>>>>> Importance of logcompaction:
>>>>>>>>>>>>> If a producer produces key A, to partiton 0, its forever gonna
>>>>>>>>>>>>> be
>>>>>>>>>>>>> there,
>>>>>>>>>>>>> unless it gets deleted. The record might sit in there for
>>>>>>>>>>>>> years. A
>>>>>>>>>>>>> new
>>>>>>>>>>>>> producer started with the new partitions will fail to delete
>>>>>>>>>>>>> the
>>>>>>>>>>>>> record
>>>>>>>>>>>>>
>>>>>>>>>>>>> in
>>>>>>>>>>>>>
>>>>>>>>>>>>> the correct partition. Th record will be there forever and one
>>>>>>>>>>>>> can
>>>>>>>>>>>>>
>>>>>>>>>>>> not
>>>>>>>>>>>>
>>>>>>>>>>>> reliable bootstrap new consumers. I cannot see how linear
>>>>>>>>>>>> hashing
>>>>>>>>>>>>
>>>>>>>>>>>>> can
>>>>>>>>>>>>>
>>>>>>>>>>>>> solve
>>>>>>>>>>>>>
>>>>>>>>>>>>> this.
>>>>>>>>>>>>>
>>>>>>>>>>>> Regarding your skipping of userland copying:
>>>>>>>>>>>>
>>>>>>>>>>>>> 100%, copying the data across in userland is, as far as i can
>>>>>>>>>>>>> see,
>>>>>>>>>>>>> only
>>>>>>>>>>>>> a
>>>>>>>>>>>>> usecase for log compacted topics. Even for logcompaction +
>>>>>>>>>>>>> retentions
>>>>>>>>>>>>> it
>>>>>>>>>>>>> should only be opt-in. Why did I bring it up? I think log
>>>>>>>>>>>>> compaction
>>>>>>>>>>>>> is
>>>>>>>>>>>>> a
>>>>>>>>>>>>> very important feature to really embrace kafka as a "data
>>>>>>>>>>>>> plattform".
>>>>>>>>>>>>> The
>>>>>>>>>>>>> point I also want to make is that copying data this way is
>>>>>>>>>>>>> completely
>>>>>>>>>>>>> inline with the kafka architecture. it only consists of reading
>>>>>>>>>>>>> and
>>>>>>>>>>>>>
>>>>>>>>>>>>> writing
>>>>>>>>>>>>>
>>>>>>>>>>>>> to topics.
>>>>>>>>>>>>>
>>>>>>>>>>>> I hope it clarifies more why I think we should aim for more than
>>>>>>>>>>>>
>>>>>>>>>>>>> the
>>>>>>>>>>>>> current KIP. I fear that once the KIP is done not much more
>>>>>>>>>>>>> effort
>>>>>>>>>>>>> will
>>>>>>>>>>>>>
>>>>>>>>>>>>> be
>>>>>>>>>>>>>
>>>>>>>>>>>>> taken.
>>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>> On 04.03.2018 02:28, Dong Lin wrote:
>>>>>>>>>>>>>
>>>>>>>>>>>>> Hey Jan,
>>>>>>>>>>>>>
>>>>>>>>>>>>> In the current proposal, the consumer will be blocked on
>>>>>>>>>>>>> waiting
>>>>>>>>>>>>> for
>>>>>>>>>>>>>
>>>>>>>>>>>>> other
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> consumers of the group to consume up to a given offset. In
>>>>>>>>>>>>>> most
>>>>>>>>>>>>>>
>>>>>>>>>>>>> cases,
>>>>>>>>>>>>> all
>>>>>>>>>>>>> consumers should be close to the LEO of the partitions when the
>>>>>>>>>>>>> partition
>>>>>>>>>>>>> expansion happens. Thus the time waiting should not be long
>>>>>>>>>>>>> e.g.
>>>>>>>>>>>>> on
>>>>>>>>>>>>> the
>>>>>>>>>>>>>
>>>>>>>>>>>>> order of seconds. On the other hand, it may take a long time to
>>>>>>>>>>>>> wait
>>>>>>>>>>>>>
>>>>>>>>>>>>> for
>>>>>>>>>>>>>> the entire partition to be copied -- the amount of time is
>>>>>>>>>>>>>> proportional
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> to
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> the amount of existing data in the partition, which can take
>>>>>>>>>>>>>>
>>>>>>>>>>>>> tens of
>>>>>>>>>>>>>
>>>>>>>>>>>>> minutes. So the amount of time that we stop consumers may not
>>>>>>>>>>>>> be
>>>>>>>>>>>>> on
>>>>>>>>>>>>>
>>>>>>>>>>>>> the
>>>>>>>>>>>>>> same order of magnitude.
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> If we can implement this suggestion without copying data over
>>>>>>>>>>>>>> in
>>>>>>>>>>>>>> purse
>>>>>>>>>>>>>> userland, it will be much more valuable. Do you have ideas on
>>>>>>>>>>>>>> how
>>>>>>>>>>>>>> this
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> can
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> be done?
>>>>>>>>>>>>>>
>>>>>>>>>>>>> Not sure why the current KIP not help people who depend on log
>>>>>>>>>>>>>
>>>>>>>>>>>>> compaction.
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> Could you elaborate more on this point?
>>>>>>>>>>>>>>
>>>>>>>>>>>>> Thanks,
>>>>>>>>>>>>>
>>>>>>>>>>>>> Dong
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> On Wed, Feb 28, 2018 at 10:55 PM, Jan
>>>>>>>>>>>>>> Filipiak<Jan.Filipiak@trivago.
>>>>>>>>>>>>>> com
>>>>>>>>>>>>>> wrote:
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> Hi Dong,
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> I tried to focus on what the steps are one can currently
>>>>>>>>>>>>>> perform
>>>>>>>>>>>>>> to
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> expand
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> or shrink a keyed topic while maintaining a top notch
>>>>>>>>>>>>>>> semantics.
>>>>>>>>>>>>>>> I can understand that there might be confusion about
>>>>>>>>>>>>>>> "stopping
>>>>>>>>>>>>>>> the
>>>>>>>>>>>>>>> consumer". It is exactly the same as proposed in the KIP.
>>>>>>>>>>>>>>> there
>>>>>>>>>>>>>>> needs
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> to
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> be
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>> a time the producers agree on the new partitioning. The extra
>>>>>>>>>>>>>
>>>>>>>>>>>>> semantics I
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> want to put in there is that we have a possibility to wait
>>>>>>>>>>>>>>> until
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>> all
>>>>>>>>>>>>>
>>>>>>>>>>>>> the
>>>>>>>>>>>>>
>>>>>>>>>>>>> existing data
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> is copied over into the new partitioning scheme. When I say
>>>>>>>>>>>>> stopping
>>>>>>>>>>>>>
>>>>>>>>>>>>> I
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> think more of having a memory barrier that ensures the
>>>>>>>>>>>>>>> ordering. I
>>>>>>>>>>>>>>> am
>>>>>>>>>>>>>>> still
>>>>>>>>>>>>>>> aming for latencies  on the scale of leader failovers.
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> Consumers have to explicitly adapt the new partitioning
>>>>>>>>>>>>>>> scheme
>>>>>>>>>>>>>>> in
>>>>>>>>>>>>>>> the
>>>>>>>>>>>>>>> above scenario. The reason is that in these cases where you
>>>>>>>>>>>>>>> are
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> dependent
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> on a particular partitioning scheme, you also have other
>>>>>>>>>>>>>>> topics
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>> that
>>>>>>>>>>>>>
>>>>>>>>>>>>> have
>>>>>>>>>>>>>
>>>>>>>>>>>>> co-partition enforcements or the kind -frequently. Therefore
>>>>>>>>>>>>>> all
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> your
>>>>>>>>>>>>>
>>>>>>>>>>>>> other
>>>>>>>>>>>>>
>>>>>>>>>>>>> input topics might need to grow accordingly.
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> What I was suggesting was to streamline all these operations
>>>>>>>>>>>>>>> as
>>>>>>>>>>>>>>> best
>>>>>>>>>>>>>>> as
>>>>>>>>>>>>>>> possible to have "real" partition grow and shrinkage going
>>>>>>>>>>>>>>> on.
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> Migrating
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> the producers to a new partitioning scheme can be much more
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>> streamlined
>>>>>>>>>>>>>
>>>>>>>>>>>>> with proper broker support for this. Migrating consumer is a
>>>>>>>>>>>>> step
>>>>>>>>>>>>>
>>>>>>>>>>>>> that
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> might be made completly unnecessary if - for example streams
>>>>>>>>>>>>>>> -
>>>>>>>>>>>>>>> takes
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> the
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> gcd as partitioning scheme instead of enforcing 1 to 1.
>>>>>>>>>>>>>>> Connect
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>> consumers
>>>>>>>>>>>>>
>>>>>>>>>>>>> and other consumers should be fine anyways.
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> I hope this makes more clear where I was aiming at. The rest
>>>>>>>>>>>>> needs
>>>>>>>>>>>>>
>>>>>>>>>>>>> to
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> be
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> figured out. The only danger i see is that when we are
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>> introducing
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> this
>>>>>>>>>>>>>
>>>>>>>>>>>>> feature as supposed in the KIP, it wont help any people
>>>>>>>>>>>>> depending
>>>>>>>>>>>>> on
>>>>>>>>>>>>>
>>>>>>>>>>>>> log
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> compaction.
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>> The other thing I wanted to mention is that I believe the
>>>>>>>>>>>>> current
>>>>>>>>>>>>>
>>>>>>>>>>>>> suggestion (without copying data over) can be implemented in
>>>>>>>>>>>>>> pure
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> userland
>>>>>>>>>>>>>>> with a custom partitioner and a small feedbackloop from
>>>>>>>>>>>>>>> ProduceResponse
>>>>>>>>>>>>>>> =>
>>>>>>>>>>>>>>> Partitionier in coorporation with a change management system.
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> Best Jan
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> On 28.02.2018 07:13, Dong Lin wrote:
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> Hey Jan,
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> I am not sure if it is acceptable for producer to be stopped
>>>>>>>>>>>>>>> for a
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> while,
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> particularly for online application which requires low
>>>>>>>>>>>>>>>> latency. I
>>>>>>>>>>>>>>>> am
>>>>>>>>>>>>>>>> also
>>>>>>>>>>>>>>>> not sure how consumers can switch to a new topic. Does user
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> application
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> needs to explicitly specify a different topic for
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> producer/consumer
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> to
>>>>>>>>>>>>>>
>>>>>>>>>>>>> subscribe to? It will be helpful for discussion if you can
>>>>>>>>>>>>> provide
>>>>>>>>>>>>>
>>>>>>>>>>>>> more
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> detail on the interface change for this solution.
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> Thanks,
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> Dong
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> On Mon, Feb 26, 2018 at 12:48 AM, Jan
>>>>>>>>>>>>>>>> Filipiak<Jan.Filipiak@trivago.
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> com
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> wrote:
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> Hi,
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> just want to throw my though in. In general the functionality
>>>>>>>>>>>>>> is
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> very
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> usefull, we should though not try to find the architecture
>>>>>>>>>>>>>>>> to
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> hard
>>>>>>>>>>>>>>>>> while
>>>>>>>>>>>>>>>>> implementing.
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> The manual steps would be to
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> create a new topic
>>>>>>>>>>>>>>>>> the mirrormake from the new old topic to the new topic
>>>>>>>>>>>>>>>>> wait for mirror making to catch up.
>>>>>>>>>>>>>>>>> then put the consumers onto the new topic
>>>>>>>>>>>>>>>>>            (having mirrormaker spit out a mapping from old
>>>>>>>>>>>>>>>>> offsets to
>>>>>>>>>>>>>>>>> new
>>>>>>>>>>>>>>>>> offsets:
>>>>>>>>>>>>>>>>>                if topic is increased by factor X there is
>>>>>>>>>>>>>>>>> gonna
>>>>>>>>>>>>>>>>> be a
>>>>>>>>>>>>>>>>> clean
>>>>>>>>>>>>>>>>> mapping from 1 offset in the old topic to X offsets in the
>>>>>>>>>>>>>>>>> new
>>>>>>>>>>>>>>>>> topic,
>>>>>>>>>>>>>>>>>                if there is no factor then there is no
>>>>>>>>>>>>>>>>> chance to
>>>>>>>>>>>>>>>>> generate a
>>>>>>>>>>>>>>>>> mapping that can be reasonable used for continuing)
>>>>>>>>>>>>>>>>>            make consumers stop at appropriate points and
>>>>>>>>>>>>>>>>> continue
>>>>>>>>>>>>>>>>> consumption
>>>>>>>>>>>>>>>>> with offsets from the mapping.
>>>>>>>>>>>>>>>>> have the producers stop for a minimal time.
>>>>>>>>>>>>>>>>> wait for mirrormaker to finish
>>>>>>>>>>>>>>>>> let producer produce with the new metadata.
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> Instead of implementing the approach suggest in the KIP
>>>>>>>>>>>>>>>>> which
>>>>>>>>>>>>>>>>> will
>>>>>>>>>>>>>>>>> leave
>>>>>>>>>>>>>>>>> log compacted topic completely crumbled and unusable.
>>>>>>>>>>>>>>>>> I would much rather try to build infrastructure to support
>>>>>>>>>>>>>>>>> the
>>>>>>>>>>>>>>>>> mentioned
>>>>>>>>>>>>>>>>> above operations more smoothly.
>>>>>>>>>>>>>>>>> Especially having producers stop and use another topic is
>>>>>>>>>>>>>>>>> difficult
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> and
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> it would be nice if one can trigger "invalid metadata"
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> exceptions
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> for
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>> them
>>>>>>>>>>>>>
>>>>>>>>>>>>> and
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> if one could give topics aliases so that their produces with
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> the
>>>>>>>>>>>>>>>>> old
>>>>>>>>>>>>>>>>> topic
>>>>>>>>>>>>>>>>> will arrive in the new topic.
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> The downsides are obvious I guess ( having the same data
>>>>>>>>>>>>>>>>> twice
>>>>>>>>>>>>>>>>> for
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> the
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> transition period, but kafka tends to scale well with
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> datasize).
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> So
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> its a
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>> nicer fit into the architecture.
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> I further want to argument that the functionality by the KIP
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> can
>>>>>>>>>>>>>>>>> completely be implementing in "userland" with a custom
>>>>>>>>>>>>>>>>> partitioner
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> that
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> handles the transition as needed. I would appreciate if
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> someone
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> could
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>> point
>>>>>>>>>>>>>
>>>>>>>>>>>>> out what a custom partitioner couldn't handle in this case?
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> With the above approach, shrinking a topic becomes the same
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> steps.
>>>>>>>>>>>>>>>>> Without
>>>>>>>>>>>>>>>>> loosing keys in the discontinued partitions.
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> Would love to hear what everyone thinks.
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> Best Jan
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> On 11.02.2018 00:35, Dong Lin wrote:
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> Hi all,
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> I have created KIP-253: Support in-order message delivery
>>>>>>>>>>>>>>>>> with
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> partition
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> expansion. See
>>>>>>>>>>>>>>>>>> https://cwiki.apache.org/confl
>>>>>>>>>>>>>>>>>> uence/display/KAFKA/KIP-253%
>>>>>>>>>>>>>>>>>> 3A+Support+in-order+message+de
>>>>>>>>>>>>>>>>>> livery+with+partition+expansio
>>>>>>>>>>>>>>>>>> n
>>>>>>>>>>>>>>>>>> .
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> This KIP provides a way to allow messages of the same key
>>>>>>>>>>>>>>>>>> from
>>>>>>>>>>>>>>>>>> the
>>>>>>>>>>>>>>>>>> same
>>>>>>>>>>>>>>>>>> producer to be consumed in the same order they are
>>>>>>>>>>>>>>>>>> produced
>>>>>>>>>>>>>>>>>> even
>>>>>>>>>>>>>>>>>> if
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> we
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> expand partition of the topic.
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> Thanks,
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> Dong
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>
>>>>
>>
>>
>

Re: [DISCUSS] KIP-253: Support in-order message delivery with partition expansion

Posted by Dong Lin <li...@gmail.com>.
Hey Jan,

Thanks for the enthusiasm in improving Kafka's design. Now that I have read
through your discussion with Jun, here are my thoughts:

- The latest proposal should with log compacted topics by properly deleting
old messages after a new message with the same key is produced. So it is
probably not a concern anymore. Could you comment if there is still issue?

- I wrote the SEP-5 and I am pretty familiar with the motivation and the
design of SEP-5. SEP-5 is probably orthornal to the motivation of this KIP.
The goal of SEP-5 is to allow user to increase task number of an existing
Samza job. But if we increase the partition number of input topics,
messages may still be consumed out-of-order by tasks in Samza which cause
incorrect result. Similarly, the approach you proposed does not seem to
ensure that the messages can be delivered in order, even if we can make
sure that each consumer instance is assigned the set of new partitions
covering the same set of keys.

- I am trying to understand why it is better to copy the data instead of
copying the change log topic for streaming use-case. For core Kafka
use-case, and for the stream use-case that does not need to increase
consumers, the current KIP already supports in-order delivery without the
overhead of copying the data. For stream use-case that needs to increase
consumer number, the existing consumer can backfill the existing data in
the change log topic to the same change log topic with the new partition
number, before the new set of consumers bootstrap state from the new
partitions of the change log topic. If this solution works, then could you
summarize the advantage of copying the data of input topic as compared to
copying the change log topic? For example, does it enable more use-case,
simplify the implementation of Kafka library, or reduce the operation
overhead etc?

Thanks,
Dong


On Wed, Mar 21, 2018 at 6:57 AM, Jan Filipiak <Ja...@trivago.com>
wrote:

> Hi Jun,
>
> I was really seeing progress in our conversation but your latest reply is
> just devastating.
> I though we were getting close being on the same page now it feels like we
> are in different libraries.
>
> I just quickly slam my answers in here. If they are to brief I am sorry
> give me a ping and try to go into details more.
> Just want to show that your pro/cons listing is broken.
>
> Best Jan
>
> and want to get rid of this horrible compromise
>
>
> On 19.03.2018 05:48, Jun Rao wrote:
>
>> Hi, Jan,
>>
>> Thanks for the discussion. Great points.
>>
>> Let me try to summarize the approach that you are proposing. On the broker
>> side, we reshuffle the existing data in a topic from current partitions to
>> the new partitions. Once the reshuffle fully catches up, switch the
>> consumers to start consuming from the new partitions. If a consumer needs
>> to rebuild its local state (due to partition changes), let the consumer
>> rebuild its state by reading all existing data from the new partitions.
>> Once all consumers have switches over, cut over the producer to the new
>> partitions.
>>
>> The pros for this approach are that :
>> 1. There is just one way to rebuild the local state, which is simpler.
>>
> true thanks
>
>>
>> The cons for this approach are:
>> 1. Need to copy existing data.
>>
> Very unfair and not correct. It does not require you to copy over existing
> data. It _allows_ you to copy all existing data.
>
> 2. The cutover of the producer is a bit complicated since it needs to
>> coordinate with all consumer groups.
>>
> Also not true. I explicitly tried to make clear that there is only one
> special consumer (in the case of actually copying data) coordination is
> required.
>
>> 3. The rebuilding of the state in the consumer is from the input topic,
>> which can be more expensive than rebuilding from the existing state.
>>
> true, but rebuilding state is only required if you want to increase
> processing power, so we assume this is at hand.
>
>> 4. The broker potentially has to know the partitioning function. If this
>> needs to be customized at the topic level, it can be a bit messy.
>>
> I would argue against having the operation being performed by the broker.
> This was not discussed yet but if you see my original email i suggested
> otherwise from the beginning.
>
>>
>> Here is an alternative approach by applying your idea not in the broker,
>> but in the consumer. When new partitions are added, we don't move existing
>> data. In KStreams, we first reshuffle the new input data to a new topic T1
>> with the old number of partitions and feed T1's data to the rest of the
>> pipeline. In the meantime, KStreams reshuffles all existing data of the
>> change capture topic to another topic C1 with the new number of
>> partitions.
>> We can then build the state of the new tasks from C1. Once the new states
>> have been fully built, we can cut over the consumption to the input topic
>> and delete T1. This approach works with compacted topic too. If an
>> application reads from the beginning of a compacted topic, the consumer
>> will reshuffle the portion of the input when the number of partitions
>> doesn't match the number of tasks.
>>
> We all wipe this idea from our heads instantly. Mixing Ideas from an
> argument is not a resolution strategy
> just leads to horrible horrible software.
>
>
>> The pros of this approach are:
>> 1. No need to copy existing data.
>> 2. Each consumer group can cut over to the new partitions independently.
>> 3. The state is rebuilt from the change capture topic, which is cheaper
>> than rebuilding from the input topic.
>> 4. Only the KStreams job needs to know the partitioning function.
>>
>> The cons of this approach are:
>> 1. Potentially the same input topic needs to be reshuffled more than once
>> in different consumer groups during the transition phase.
>>
>> What do you think?
>>
>> Thanks,
>>
>> Jun
>>
>>
>>
>> On Thu, Mar 15, 2018 at 1:04 AM, Jan Filipiak <Ja...@trivago.com>
>> wrote:
>>
>> Hi Jun,
>>>
>>> thank you for following me on these thoughts. It was important to me to
>>> feel that kind of understanding for my arguments.
>>>
>>> What I was hoping for (I mentioned this earlier) is that we can model the
>>> case where we do not want to copy the data the exact same way as the case
>>> when we do copy the data. Maybe you can peek into the mails before to see
>>> more details for this.
>>>
>>> This means we have the same mechanism to transfer consumer groups to
>>> switch topic. The offset mapping that would be generated would even be
>>> simpler End Offset of the Old topic => offset 0 off all the partitions of
>>> the new topic. Then we could model the transition of a non-copy expansion
>>> the exact same way as a copy-expansion.
>>>
>>> I know this only works when topic growth by a factor. But the benefits of
>>> only growing by a factor are to strong anyways. See Clemens's hint and
>>> remember that state reshuffling is entirely not needed if one doesn't
>>> want
>>> to grow processing power.
>>>
>>> I think these benefits should be clear, and that there is basically no
>>> downside to what is currently at hand but just makes everything easy.
>>>
>>> One thing you need to know is. that if you do not offer rebuilding a log
>>> compacted topic like i suggest that even if you have consumer state
>>> reshuffling. The topic is broken and can not be used to bootstrap new
>>> consumers. They don't know if they need to apply a key from and old
>>> partition or not. This is a horrible downside I haven't seen a solution
>>> for
>>> in the email conversation.
>>>
>>> I argue to:
>>>
>>> Only grow topic by a factor always.
>>> Have the "no copy consumer" transition as the trivial case of the "copy
>>> consumer transition".
>>> If processors needs to be scaled, let them rebuild from the new topic and
>>> leave the old running in the mean time.
>>> Do not implement key shuffling in streams.
>>>
>>> I hope I can convince you especially with the fact how I want to handle
>>> consumer transition. I think
>>> you didn't quite understood me there before. I think the term "new topic"
>>> intimidated you a little.
>>> How we solve this on disc doesn't really matter, If the data goes into
>>> the
>>> same Dir or a different Dir or anything. I do think that it needs to
>>> involve at least rolling a new segment for the existing partitions.
>>> But most of the transitions should work without restarting consumers.
>>> (newer consumers with support for this). But with new topic i just meant
>>> the topic that now has a different partition count. Plenty of ways to
>>> handle that (versions, aliases)
>>>
>>> Hope I can further get my idea across.
>>>
>>> Best Jan
>>>
>>>
>>>
>>>
>>>
>>>
>>> On 14.03.2018 02:45, Jun Rao wrote:
>>>
>>> Hi, Jan,
>>>>
>>>> Thanks for sharing your view.
>>>>
>>>> I agree with you that recopying the data potentially makes the state
>>>> management easier since the consumer can just rebuild its state from
>>>> scratch (i.e., no need for state reshuffling).
>>>>
>>>> On the flip slide, I saw a few disadvantages of the approach that you
>>>> suggested. (1) Building the state from the input topic from scratch is
>>>> in
>>>> general less efficient than state reshuffling. Let's say one computes a
>>>> count per key from an input topic. The former requires reading all
>>>> existing
>>>> records in the input topic whereas the latter only requires reading data
>>>> proportional to the number of unique keys. (2) The switching of the
>>>> topic
>>>> needs modification to the application. If there are many applications
>>>> on a
>>>> topic, coordinating such an effort may not be easy. Also, it's not clear
>>>> how to enforce exactly-once semantic during the switch. (3) If a topic
>>>> doesn't need any state management, recopying the data seems wasteful. In
>>>> that case, in place partition expansion seems more desirable.
>>>>
>>>> I understand your concern about adding complexity in KStreams. But,
>>>> perhaps
>>>> we could iterate on that a bit more to see if it can be simplified.
>>>>
>>>> Jun
>>>>
>>>>
>>>> On Mon, Mar 12, 2018 at 11:21 PM, Jan Filipiak <
>>>> Jan.Filipiak@trivago.com>
>>>> wrote:
>>>>
>>>> Hi Jun,
>>>>
>>>>> I will focus on point 61 as I think its _the_ fundamental part that I
>>>>> cant
>>>>> get across at the moment.
>>>>>
>>>>> Kafka is the platform to have state materialized multiple times from
>>>>> one
>>>>> input. I emphasize this: It is the building block in architectures that
>>>>> allow you to
>>>>> have your state maintained multiple times. You put a message in once,
>>>>> and
>>>>> you have it pop out as often as you like. I believe you understand
>>>>> this.
>>>>>
>>>>> Now! The path of thinking goes the following: I am using apache kafka
>>>>> and
>>>>> I _want_ my state multiple times. What am I going todo?
>>>>>
>>>>> A) Am I going to take my state that I build up, plunge some sort of RPC
>>>>> layer ontop of it, use that RPC layer to throw my records across
>>>>> instances?
>>>>> B) Am I just going to read the damn message twice?
>>>>>
>>>>> Approach A is fundamentally flawed and a violation of all that is good
>>>>> and
>>>>> holy in kafka deployments. I can not understand how this Idea can come
>>>>> in
>>>>> the first place.
>>>>> (I do understand: IQ in streams, they polluted the kafka streams
>>>>> codebase
>>>>> really bad already. It is not funny! I think they are equally flawed as
>>>>> A)
>>>>>
>>>>> I say, we do what Kafka is good at. We repartition the topic once. We
>>>>> switch the consumers.
>>>>> (Those that need more partitions are going to rebuild their state in
>>>>> multiple partitions by reading the new topic, those that don't just
>>>>> assign
>>>>> the new partitions properly)
>>>>> We switch producers. Done!
>>>>>
>>>>> The best thing! It is trivial, hipster stream processor will have an
>>>>> easy
>>>>> time with that aswell. Its so super simple. And simple IS good!
>>>>> It is what kafka was build todo. It is how we do it today. All I am
>>>>> saying
>>>>> is that a little broker help doing the producer swap is super useful.
>>>>>
>>>>> For everyone interested in why kafka is so powerful with approach B,
>>>>> please watch https://youtu.be/bEbeZPVo98c?t=1633
>>>>> I already looked up a good point in time, I think after 5 minutes the
>>>>> "state" topic is handled and you should be able to understand me
>>>>> and inch better.
>>>>>
>>>>> Please do not do A to the project, it deserves better!
>>>>>
>>>>> Best Jan
>>>>>
>>>>>
>>>>>
>>>>> On 13.03.2018 02:40, Jun Rao wrote:
>>>>>
>>>>> Hi, Jan,
>>>>>
>>>>>> Thanks for the reply. A few more comments below.
>>>>>>
>>>>>> 50. Ok, we can think a bit harder for supporting compacted topics.
>>>>>>
>>>>>> 51. This is a fundamental design question. In the more common case,
>>>>>> the
>>>>>> reason why someone wants to increase the number of partitions is that
>>>>>> the
>>>>>> consumer application is slow and one wants to run more consumer
>>>>>> instances
>>>>>> to increase the degree of parallelism. So, fixing the number of
>>>>>> running
>>>>>> consumer instances when expanding the partitions won't help this case.
>>>>>> If
>>>>>> we do need to increase the number of consumer instances, we need to
>>>>>> somehow
>>>>>> reshuffle the state of the consumer across instances. What we have
>>>>>> been
>>>>>> discussing in this KIP is whether we can do this more effectively
>>>>>> through
>>>>>> the KStream library (e.g. through a 2-phase partition expansion). This
>>>>>> will
>>>>>> add some complexity, but it's probably better than everyone doing this
>>>>>> in
>>>>>> the application space. The recopying approach that you mentioned
>>>>>> doesn't
>>>>>> seem to address the consumer state management issue when the consumer
>>>>>> switches from an old to a new topic.
>>>>>>
>>>>>> 52. As for your example, it depends on whether the join key is the
>>>>>> same
>>>>>> between (A,B) and (B,C). If the join key is the same, we can do a
>>>>>> 2-phase
>>>>>> partition expansion of A, B, and C together. If the join keys are
>>>>>> different, one would need to repartition the data on a different key
>>>>>> for
>>>>>> the second join, then the partition expansion can be done
>>>>>> independently
>>>>>> between (A,B) and (B,C).
>>>>>>
>>>>>> 53. If you always fix the number of consumer instances, we you
>>>>>> described
>>>>>> works. However, as I mentioned in #51, I am not sure how your proposal
>>>>>> deals with consumer states when the number of consumer instances
>>>>>> grows.
>>>>>> Also, it just seems that it's better to avoid re-copying the existing
>>>>>> data.
>>>>>>
>>>>>> 60. "just want to throw in my question from the longer email in the
>>>>>> other
>>>>>> Thread here. How will the bloom filter help a new consumer to decide
>>>>>> to
>>>>>> apply the key or not?" Not sure that I fully understood your question.
>>>>>> The
>>>>>> consumer just reads whatever key is in the log. The bloom filter just
>>>>>> helps
>>>>>> clean up the old keys.
>>>>>>
>>>>>> 61. "Why can we afford having a topic where its apparently not
>>>>>> possible
>>>>>> to
>>>>>> start a new application on? I think this is an overall flaw of the
>>>>>> discussed idea here. Not playing attention to the overall
>>>>>> architecture."
>>>>>> Could you explain a bit more when one can't start a new application?
>>>>>>
>>>>>> Jun
>>>>>>
>>>>>>
>>>>>>
>>>>>> On Sat, Mar 10, 2018 at 1:40 AM, Jan Filipiak <
>>>>>> Jan.Filipiak@trivago.com
>>>>>> wrote:
>>>>>>
>>>>>> Hi Jun, thanks for your mail.
>>>>>>
>>>>>> Thank you for your questions!
>>>>>>> I think they are really good and tackle the core of the problem I
>>>>>>> see.
>>>>>>>
>>>>>>> I will answer inline, mostly but still want to set the tone here.
>>>>>>>
>>>>>>> The core strength of kafka is what Martin once called the
>>>>>>> kappa-Architecture. How does this work?
>>>>>>> You have everything as a log as in kafka. When you need to change
>>>>>>> something.
>>>>>>> You create the new version of your application and leave it running
>>>>>>> in
>>>>>>> parallel.
>>>>>>> Once the new version is good you switch your users to use the new
>>>>>>> application.
>>>>>>>
>>>>>>> The online reshuffling effectively breaks this architecture and I
>>>>>>> think
>>>>>>> the switch in thinking here is more harmful
>>>>>>> than any details about the partitioning function to allow such a
>>>>>>> change.
>>>>>>> I
>>>>>>> feel with my suggestion we are the closest to
>>>>>>> the original and battle proven architecture and I can only warn to
>>>>>>> move
>>>>>>> away from it.
>>>>>>>
>>>>>>> I might have forgotten something, sometimes its hard for me to
>>>>>>> getting
>>>>>>> all
>>>>>>> the thoughts captured in a mail, but I hope the comments inline will
>>>>>>> further make my concern clear, and put some emphasis on why I prefer
>>>>>>> my
>>>>>>> solution ;)
>>>>>>>
>>>>>>> One thing we should all be aware of when discussing this, and I think
>>>>>>> Dong
>>>>>>> should have mentioned it (maybe he did).
>>>>>>> We are not discussing all of this out of thin air but there is an
>>>>>>> effort
>>>>>>> in the Samza project.
>>>>>>>
>>>>>>> https://cwiki.apache.org/confluence/display/SAMZA/SEP-5%3A+
>>>>>>> Enable+partition+expansion+of+input+streams
>>>>>>> https://issues.apache.org/jira/browse/SAMZA-1293
>>>>>>>
>>>>>>> To be clear. I think SEP-5 (state of last week, dont know if it
>>>>>>> adapted
>>>>>>> to
>>>>>>> this discussion) is on a way better path than KIP-253, and I can't
>>>>>>> really
>>>>>>> explain why.
>>>>>>>
>>>>>>> Best Jan,
>>>>>>>
>>>>>>> nice weekend everyone
>>>>>>>
>>>>>>>
>>>>>>> On 09.03.2018 03:36, Jun Rao wrote:
>>>>>>>
>>>>>>> Hi, Jan,
>>>>>>>
>>>>>>> Thanks for the feedback. Just some comments on the earlier points
>>>>>>>> that
>>>>>>>> you
>>>>>>>> mentioned.
>>>>>>>>
>>>>>>>> 50. You brought up the question of whether existing data needs to be
>>>>>>>> copied
>>>>>>>> during partition expansion. My understand of your view is that avoid
>>>>>>>> copying existing data will be more efficient, but it doesn't work
>>>>>>>> well
>>>>>>>> with
>>>>>>>> compacted topics since some keys in the original partitions will
>>>>>>>> never
>>>>>>>> be
>>>>>>>> cleaned. It would be useful to understand your use case of compacted
>>>>>>>> topics
>>>>>>>> a bit more. In the common use case, the data volume in a compacted
>>>>>>>> topic
>>>>>>>> may not be large. So, I am not sure if there is a strong need to
>>>>>>>> expand
>>>>>>>> partitions in a compacted topic, at least initially.
>>>>>>>>
>>>>>>>> I do agree. State is usually smaller. Update rates might be also
>>>>>>>>
>>>>>>>> competitively high.
>>>>>>> Doing Log-compaction (even beeing very efficient and configurable) is
>>>>>>> also
>>>>>>> a more expensive operation than
>>>>>>> just discarding old segments. Further if you want to use more
>>>>>>> consumers
>>>>>>> processing the events
>>>>>>> you also have to grow the number of partitions. Especially for
>>>>>>> use-cases
>>>>>>> we do (KIP-213) a tiny state full
>>>>>>> table might be very expensive to process if it joins against a huge
>>>>>>> table.
>>>>>>>
>>>>>>> I can just say we have been in the spot of needing to grow log
>>>>>>> compacted
>>>>>>> topics. Mainly for processing power we can bring to the table.
>>>>>>>
>>>>>>> Further i am not at all concerned about the extra spaced used by
>>>>>>> "garbage
>>>>>>> keys". I am more concerned about the correctness of innocent
>>>>>>> consumers.
>>>>>>> The
>>>>>>> logic becomes complicated. Say for streams one would need to load the
>>>>>>> record into state but not forward it the topology ( to have it
>>>>>>> available
>>>>>>> for shuffeling). I rather have it simple and a topic clean regardless
>>>>>>> if
>>>>>>> it
>>>>>>> still has its old partition count. Especially with multiple
>>>>>>> partitions
>>>>>>> growth's I think it becomes insanely hard to to this shuffle correct.
>>>>>>> Maybe
>>>>>>> Streams and Samza can do it. Especially if you do "hipster stream
>>>>>>> processing" <https://www.confluent.io/blog
>>>>>>> /introducing-kafka-streams-
>>>>>>> stream-processing-made-simple/>. This makes kafka way to
>>>>>>> complicated.
>>>>>>> With my approach I think its way simpler because the topic has no
>>>>>>> "history"
>>>>>>> in terms of partitioning but is always clean.
>>>>>>>
>>>>>>>
>>>>>>> 51. "Growing the topic by an integer factor does not require any
>>>>>>> state
>>>>>>>
>>>>>>> redistribution at all." Could you clarify this a bit more? Let's say
>>>>>>>> you
>>>>>>>> have a consumer app that computes the windowed count per key. If you
>>>>>>>> double
>>>>>>>> the number of partitions from 1 to 2 and grow the consumer instances
>>>>>>>> from
>>>>>>>> 1
>>>>>>>> to 2, we would need to redistribute some of the counts to the new
>>>>>>>> consumer
>>>>>>>> instance. Regarding to linear hashing, it's true that it won't solve
>>>>>>>> the
>>>>>>>> problem with compacted topics. The main benefit is that it
>>>>>>>> redistributes
>>>>>>>> the keys in one partition to no more than two partitions, which
>>>>>>>> could
>>>>>>>> help
>>>>>>>> redistribute the state.
>>>>>>>>
>>>>>>>> You don't need to spin up a new consumer in this case. every
>>>>>>>> consumer
>>>>>>>>
>>>>>>>> would just read every partition with the (partition % num_task)
>>>>>>> task.
>>>>>>> it
>>>>>>> will still have the previous data right there and can go on.
>>>>>>>
>>>>>>> This sounds contradictory to what I said before, but please bear with
>>>>>>> me.
>>>>>>>
>>>>>>> 52. Good point on coordinating the expansion of 2 topics that need to
>>>>>>> be
>>>>>>>
>>>>>>> joined together. This is where the 2-phase partition expansion could
>>>>>>>> potentially help. In the first phase, we could add new partitions to
>>>>>>>> the 2
>>>>>>>> topics one at a time but without publishing to the new patitions.
>>>>>>>> Then,
>>>>>>>> we
>>>>>>>> can add new consumer instances to pick up the new partitions. In
>>>>>>>> this
>>>>>>>> transition phase, no reshuffling is needed since no data is coming
>>>>>>>> from
>>>>>>>> the
>>>>>>>> new partitions. Finally, we can enable the publishing to the new
>>>>>>>> partitions.
>>>>>>>>
>>>>>>>> I think its even worse than you think. I would like to introduce the
>>>>>>>>
>>>>>>>> Term
>>>>>>> transitive copartitioning. Imagine
>>>>>>> 2 streams application. One joins (A,B) the other (B,C) then there is
>>>>>>> a
>>>>>>> transitive copartition requirement for
>>>>>>> (A,C) to be copartitioned aswell. This can spread significantly and
>>>>>>> require many consumers to adapt at the same time.
>>>>>>>
>>>>>>> It is also not entirely clear to me how you not need reshuffling in
>>>>>>> this
>>>>>>> case. If A has a record that never gets updated after the expansion
>>>>>>> and
>>>>>>> the
>>>>>>> coresponding B record moves to a new partition. How shall they meet
>>>>>>> w/o
>>>>>>> shuffle?
>>>>>>>
>>>>>>> 53. "Migrating consumer is a step that might be made completly
>>>>>>>
>>>>>>> unnecessary
>>>>>>>> if - for example streams - takes the gcd as partitioning scheme
>>>>>>>> instead
>>>>>>>> of
>>>>>>>> enforcing 1 to 1." Not sure that I fully understand this. I think
>>>>>>>> you
>>>>>>>> mean
>>>>>>>> that a consumer application can run more instances than the number
>>>>>>>> of
>>>>>>>> partitions. In that case, the consumer can just repartitioning the
>>>>>>>> input
>>>>>>>> data according to the number of instances. This is possible, but
>>>>>>>> just
>>>>>>>> has
>>>>>>>> the overhead of reshuffling the data.
>>>>>>>>
>>>>>>>> No what I meant is ( that is also your question i think Mathias)
>>>>>>>> that
>>>>>>>> if
>>>>>>>>
>>>>>>>> you grow a topic by a factor.
>>>>>>> Even if your processor is statefull you can can just assign all the
>>>>>>> multiples of the previous partition to
>>>>>>> this consumer and the state to keep processing correctly will be
>>>>>>> present
>>>>>>> w/o any shuffling.
>>>>>>>
>>>>>>> Say you have an assignment
>>>>>>> Statefull consumer => partition
>>>>>>> 0 => 0
>>>>>>> 1 => 1
>>>>>>> 2 => 2
>>>>>>>
>>>>>>> and you grow you topic by 4 you get,
>>>>>>>
>>>>>>> 0 => 0,3,6,9
>>>>>>> 1 => 1,4,7,10
>>>>>>> 2 => 2,5,8,11
>>>>>>>
>>>>>>> Say your hashcode is 8. 8%3 => 2  before so consumer for partition 2
>>>>>>> has
>>>>>>> it.
>>>>>>> Now you you have 12 partitions so 8%12 => 8, so it goes into
>>>>>>> partition
>>>>>>> 8
>>>>>>> which is assigned to the same consumer
>>>>>>> who had 2 before and therefore knows the key.
>>>>>>>
>>>>>>> Userland reshuffeling is there as an options. And it does exactly
>>>>>>> what
>>>>>>> I
>>>>>>> suggest. And I think its the perfect strategie. All I am suggestion
>>>>>>> is
>>>>>>> broker side support to switch the producers to the newly partitioned
>>>>>>> topic.
>>>>>>> Then the old (to few partition topic) can go away.  Remember the list
>>>>>>> of
>>>>>>> steps in the beginning of this thread. If one has broker support for
>>>>>>> all
>>>>>>> where its required and streams support for those that aren’t
>>>>>>> necessarily.
>>>>>>> Then one has solved the problem.
>>>>>>> I repeat it because I think its important. I am really happy that you
>>>>>>> brought that up! because its 100% what I want just with the
>>>>>>> differences
>>>>>>> to
>>>>>>> have an option to discard the to small topic later (after all
>>>>>>> consumers
>>>>>>> adapted). And to have order correct there. I need broker support
>>>>>>> managing
>>>>>>> the copy process + the produces and fence them against each other. I
>>>>>>> also
>>>>>>> repeat. the copy process can run for weeks in the worst case. Copying
>>>>>>> the
>>>>>>> data is not the longest task migrating consumers might very well be.
>>>>>>> Once all consumers switched and copying is really up to date (think
>>>>>>> ISR
>>>>>>> like up to date) only then we stop the producer, wait for the copy to
>>>>>>> finish and use the new topic for producing.
>>>>>>>
>>>>>>> After this the topic is perfect in shape. and no one needs to worry
>>>>>>> about
>>>>>>> complicated stuff. (old keys hanging around might arrive in some
>>>>>>> other
>>>>>>> topic later.....). can only imagine how many tricky bugs gonna arrive
>>>>>>> after
>>>>>>> someone had grown and shrunken is topic 10 times.
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> 54. "The other thing I wanted to mention is that I believe the
>>>>>>> current
>>>>>>>
>>>>>>> suggestion (without copying data over) can be implemented in pure
>>>>>>>> userland
>>>>>>>> with a custom partitioner and a small feedbackloop from
>>>>>>>> ProduceResponse
>>>>>>>> =>
>>>>>>>> Partitionier in coorporation with a change management system." I am
>>>>>>>> not
>>>>>>>> sure a customized partitioner itself solves the problem. We probably
>>>>>>>> need
>>>>>>>> some broker side support to enforce when the new partitions can be
>>>>>>>> used.
>>>>>>>> We
>>>>>>>> also need some support on the consumer/kstream side to preserve the
>>>>>>>> per
>>>>>>>> key
>>>>>>>> ordering and potentially migrate the processing state. This is not
>>>>>>>> trivial
>>>>>>>> and I am not sure if it's ideal to fully push to the application
>>>>>>>> space.
>>>>>>>>
>>>>>>>> Broker support is defenitly the preferred way here. I have nothing
>>>>>>>>
>>>>>>>> against
>>>>>>> broker support.
>>>>>>> I tried to say that for what I would preffer - copying the data over,
>>>>>>> at
>>>>>>> least for log compacted topics -
>>>>>>> I would require more broker support than the KIP currently offers.
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> Jun
>>>>>>>
>>>>>>> On Tue, Mar 6, 2018 at 10:33 PM, Jan Filipiak <
>>>>>>>> Jan.Filipiak@trivago.com
>>>>>>>> wrote:
>>>>>>>>
>>>>>>>> Hi Dong,
>>>>>>>>
>>>>>>>> are you actually reading my emails, or are you just using the
>>>>>>>> thread I
>>>>>>>>
>>>>>>>>> started for general announcements regarding the KIP?
>>>>>>>>>
>>>>>>>>> I tried to argue really hard against linear hashing. Growing the
>>>>>>>>> topic
>>>>>>>>> by
>>>>>>>>> an integer factor does not require any state redistribution at
>>>>>>>>> all. I
>>>>>>>>> fail
>>>>>>>>> to see completely where linear hashing helps on log compacted
>>>>>>>>> topics.
>>>>>>>>>
>>>>>>>>> If you are not willing to explain to me what I might be
>>>>>>>>> overlooking:
>>>>>>>>> that
>>>>>>>>> is fine.
>>>>>>>>> But I ask you to not reply to my emails then. Please understand my
>>>>>>>>> frustration with this.
>>>>>>>>>
>>>>>>>>> Best Jan
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> On 06.03.2018 19:38, Dong Lin wrote:
>>>>>>>>>
>>>>>>>>> Hi everyone,
>>>>>>>>>
>>>>>>>>> Thanks for all the comments! It appears that everyone prefers
>>>>>>>>> linear
>>>>>>>>>
>>>>>>>>>> hashing because it reduces the amount of state that needs to be
>>>>>>>>>> moved
>>>>>>>>>> between consumers (for stream processing). The KIP has been
>>>>>>>>>> updated
>>>>>>>>>> to
>>>>>>>>>> use
>>>>>>>>>> linear hashing.
>>>>>>>>>>
>>>>>>>>>> Regarding the migration endeavor: it seems that migrating producer
>>>>>>>>>> library
>>>>>>>>>> to use linear hashing should be pretty straightforward without
>>>>>>>>>> much operational endeavor. If we don't upgrade client library to
>>>>>>>>>> use
>>>>>>>>>> this
>>>>>>>>>> KIP, we can not support in-order delivery after partition is
>>>>>>>>>> changed
>>>>>>>>>> anyway. Suppose we upgrade client library to use this KIP, if
>>>>>>>>>> partition
>>>>>>>>>> number is not changed, the key -> partition mapping will be
>>>>>>>>>> exactly
>>>>>>>>>> the
>>>>>>>>>> same as it is now because it is still determined using
>>>>>>>>>> murmur_hash(key)
>>>>>>>>>> %
>>>>>>>>>> original_partition_num. In other words, this change is backward
>>>>>>>>>> compatible.
>>>>>>>>>>
>>>>>>>>>> Regarding the load distribution: if we use linear hashing, the
>>>>>>>>>> load
>>>>>>>>>> may
>>>>>>>>>> be
>>>>>>>>>> unevenly distributed because those partitions which are not split
>>>>>>>>>> may
>>>>>>>>>> receive twice as much traffic as other partitions that are split.
>>>>>>>>>> This
>>>>>>>>>> issue can be mitigated by creating topic with partitions that are
>>>>>>>>>> several
>>>>>>>>>> times the number of consumers. And there will be no imbalance if
>>>>>>>>>> the
>>>>>>>>>> partition number is always doubled. So this imbalance seems
>>>>>>>>>> acceptable.
>>>>>>>>>>
>>>>>>>>>> Regarding storing the partition strategy as per-topic config: It
>>>>>>>>>> seems
>>>>>>>>>> not
>>>>>>>>>> necessary since we can still use murmur_hash as the default hash
>>>>>>>>>> function
>>>>>>>>>> and additionally apply the linear hashing algorithm if the
>>>>>>>>>> partition
>>>>>>>>>> number
>>>>>>>>>> has increased. Not sure if there is any use-case for producer to
>>>>>>>>>> use a
>>>>>>>>>> different hash function. Jason, can you check if there is some
>>>>>>>>>> use-case
>>>>>>>>>> that I missed for using the per-topic partition strategy?
>>>>>>>>>>
>>>>>>>>>> Regarding how to reduce latency (due to state store/load) in
>>>>>>>>>> stream
>>>>>>>>>> processing consumer when partition number changes: I need to read
>>>>>>>>>> the
>>>>>>>>>> Kafka
>>>>>>>>>> Stream code to understand how Kafka Stream currently migrate state
>>>>>>>>>> between
>>>>>>>>>> consumers when the application is added/removed for a given job. I
>>>>>>>>>> will
>>>>>>>>>> reply after I finish reading the documentation and code.
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> Thanks,
>>>>>>>>>> Dong
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> On Mon, Mar 5, 2018 at 10:43 AM, Jason Gustafson <
>>>>>>>>>> jason@confluent.io>
>>>>>>>>>> wrote:
>>>>>>>>>>
>>>>>>>>>> Great discussion. I think I'm wondering whether we can continue to
>>>>>>>>>> leave
>>>>>>>>>>
>>>>>>>>>> Kafka agnostic to the partitioning strategy. The challenge is
>>>>>>>>>>
>>>>>>>>>> communicating
>>>>>>>>>>> the partitioning logic from producers to consumers so that the
>>>>>>>>>>> dependencies
>>>>>>>>>>> between each epoch can be determined. For the sake of discussion,
>>>>>>>>>>> imagine
>>>>>>>>>>> you did something like the following:
>>>>>>>>>>>
>>>>>>>>>>> 1. The name (and perhaps version) of a partitioning strategy is
>>>>>>>>>>> stored
>>>>>>>>>>> in
>>>>>>>>>>> topic configuration when a topic is created.
>>>>>>>>>>> 2. The producer looks up the partitioning strategy before writing
>>>>>>>>>>> to
>>>>>>>>>>> a
>>>>>>>>>>> topic and includes it in the produce request (for fencing). If it
>>>>>>>>>>> doesn't
>>>>>>>>>>> have an implementation for the configured strategy, it fails.
>>>>>>>>>>> 3. The consumer also looks up the partitioning strategy and uses
>>>>>>>>>>> it
>>>>>>>>>>> to
>>>>>>>>>>> determine dependencies when reading a new epoch. It could either
>>>>>>>>>>> fail
>>>>>>>>>>> or
>>>>>>>>>>> make the most conservative dependency assumptions if it doesn't
>>>>>>>>>>> know
>>>>>>>>>>> how
>>>>>>>>>>> to
>>>>>>>>>>> implement the partitioning strategy. For the consumer, the new
>>>>>>>>>>> interface
>>>>>>>>>>> might look something like this:
>>>>>>>>>>>
>>>>>>>>>>> // Return the partition dependencies following an epoch bump
>>>>>>>>>>> Map<Integer, List<Integer>> dependencies(int
>>>>>>>>>>> numPartitionsBeforeEpochBump,
>>>>>>>>>>> int numPartitionsAfterEpochBump)
>>>>>>>>>>>
>>>>>>>>>>> The unordered case then is just a particular implementation which
>>>>>>>>>>> never
>>>>>>>>>>> has
>>>>>>>>>>> any epoch dependencies. To implement this, we would need some way
>>>>>>>>>>> for
>>>>>>>>>>> the
>>>>>>>>>>> consumer to find out how many partitions there were in each
>>>>>>>>>>> epoch,
>>>>>>>>>>> but
>>>>>>>>>>> maybe that's not too unreasonable.
>>>>>>>>>>>
>>>>>>>>>>> Thanks,
>>>>>>>>>>> Jason
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> On Mon, Mar 5, 2018 at 4:51 AM, Jan Filipiak <
>>>>>>>>>>> Jan.Filipiak@trivago.com
>>>>>>>>>>> wrote:
>>>>>>>>>>>
>>>>>>>>>>> Hi Dong
>>>>>>>>>>>
>>>>>>>>>>> thank you very much for your questions.
>>>>>>>>>>>
>>>>>>>>>>> regarding the time spend copying data across:
>>>>>>>>>>>> It is correct that copying data from a topic with one partition
>>>>>>>>>>>> mapping
>>>>>>>>>>>>
>>>>>>>>>>>> to
>>>>>>>>>>>>
>>>>>>>>>>>> a topic with a different partition mapping takes way longer than
>>>>>>>>>>>>
>>>>>>>>>>> we
>>>>>>>>>>> can
>>>>>>>>>>>
>>>>>>>>>>> stop producers. Tens of minutes is a very optimistic estimate
>>>>>>>>>>> here.
>>>>>>>>>>>
>>>>>>>>>>>> Many
>>>>>>>>>>>> people can not afford copy full steam and therefore will have
>>>>>>>>>>>> some
>>>>>>>>>>>> rate
>>>>>>>>>>>> limiting in place, this can bump the timespan into the day's.
>>>>>>>>>>>> The
>>>>>>>>>>>> good
>>>>>>>>>>>>
>>>>>>>>>>>> part
>>>>>>>>>>>>
>>>>>>>>>>>> is that the vast majority of the data can be copied while the
>>>>>>>>>>>>
>>>>>>>>>>> producers
>>>>>>>>>>>
>>>>>>>>>>> are
>>>>>>>>>>>
>>>>>>>>>>>> still going. One can then, piggyback the consumers ontop of this
>>>>>>>>>>>>
>>>>>>>>>>> timeframe,
>>>>>>>>>>>
>>>>>>>>>>>> by the method mentioned (provide them an mapping from their old
>>>>>>>>>>>>
>>>>>>>>>>> offsets
>>>>>>>>>>>
>>>>>>>>>>> to
>>>>>>>>>>>
>>>>>>>>>>>> new offsets in their repartitioned topics. In that way we
>>>>>>>>>>>> separate
>>>>>>>>>>>>
>>>>>>>>>>> migration of consumers from migration of producers (decoupling
>>>>>>>>>>>
>>>>>>>>>>>> these
>>>>>>>>>>>> is
>>>>>>>>>>>> what kafka is strongest at). The time to actually swap over the
>>>>>>>>>>>> producers
>>>>>>>>>>>> should be kept minimal by ensuring that when a swap attempt is
>>>>>>>>>>>> started
>>>>>>>>>>>>
>>>>>>>>>>>> the
>>>>>>>>>>>>
>>>>>>>>>>>> consumer copying over should be very close to the log end and is
>>>>>>>>>>>>
>>>>>>>>>>> expected
>>>>>>>>>>>
>>>>>>>>>>>> to finish within the next fetch. The operation should have a
>>>>>>>>>>>> time-out
>>>>>>>>>>>> and
>>>>>>>>>>>> should be "reattemtable".
>>>>>>>>>>>>
>>>>>>>>>>>> Importance of logcompaction:
>>>>>>>>>>>> If a producer produces key A, to partiton 0, its forever gonna
>>>>>>>>>>>> be
>>>>>>>>>>>> there,
>>>>>>>>>>>> unless it gets deleted. The record might sit in there for
>>>>>>>>>>>> years. A
>>>>>>>>>>>> new
>>>>>>>>>>>> producer started with the new partitions will fail to delete the
>>>>>>>>>>>> record
>>>>>>>>>>>>
>>>>>>>>>>>> in
>>>>>>>>>>>>
>>>>>>>>>>>> the correct partition. Th record will be there forever and one
>>>>>>>>>>>> can
>>>>>>>>>>>>
>>>>>>>>>>> not
>>>>>>>>>>>
>>>>>>>>>>> reliable bootstrap new consumers. I cannot see how linear hashing
>>>>>>>>>>>
>>>>>>>>>>>> can
>>>>>>>>>>>>
>>>>>>>>>>>> solve
>>>>>>>>>>>>
>>>>>>>>>>>> this.
>>>>>>>>>>>>
>>>>>>>>>>> Regarding your skipping of userland copying:
>>>>>>>>>>>
>>>>>>>>>>>> 100%, copying the data across in userland is, as far as i can
>>>>>>>>>>>> see,
>>>>>>>>>>>> only
>>>>>>>>>>>> a
>>>>>>>>>>>> usecase for log compacted topics. Even for logcompaction +
>>>>>>>>>>>> retentions
>>>>>>>>>>>> it
>>>>>>>>>>>> should only be opt-in. Why did I bring it up? I think log
>>>>>>>>>>>> compaction
>>>>>>>>>>>> is
>>>>>>>>>>>> a
>>>>>>>>>>>> very important feature to really embrace kafka as a "data
>>>>>>>>>>>> plattform".
>>>>>>>>>>>> The
>>>>>>>>>>>> point I also want to make is that copying data this way is
>>>>>>>>>>>> completely
>>>>>>>>>>>> inline with the kafka architecture. it only consists of reading
>>>>>>>>>>>> and
>>>>>>>>>>>>
>>>>>>>>>>>> writing
>>>>>>>>>>>>
>>>>>>>>>>>> to topics.
>>>>>>>>>>>>
>>>>>>>>>>> I hope it clarifies more why I think we should aim for more than
>>>>>>>>>>>
>>>>>>>>>>>> the
>>>>>>>>>>>> current KIP. I fear that once the KIP is done not much more
>>>>>>>>>>>> effort
>>>>>>>>>>>> will
>>>>>>>>>>>>
>>>>>>>>>>>> be
>>>>>>>>>>>>
>>>>>>>>>>>> taken.
>>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> On 04.03.2018 02:28, Dong Lin wrote:
>>>>>>>>>>>>
>>>>>>>>>>>> Hey Jan,
>>>>>>>>>>>>
>>>>>>>>>>>> In the current proposal, the consumer will be blocked on waiting
>>>>>>>>>>>> for
>>>>>>>>>>>>
>>>>>>>>>>>> other
>>>>>>>>>>>>>
>>>>>>>>>>>>> consumers of the group to consume up to a given offset. In most
>>>>>>>>>>>>>
>>>>>>>>>>>> cases,
>>>>>>>>>>>> all
>>>>>>>>>>>> consumers should be close to the LEO of the partitions when the
>>>>>>>>>>>> partition
>>>>>>>>>>>> expansion happens. Thus the time waiting should not be long e.g.
>>>>>>>>>>>> on
>>>>>>>>>>>> the
>>>>>>>>>>>>
>>>>>>>>>>>> order of seconds. On the other hand, it may take a long time to
>>>>>>>>>>>> wait
>>>>>>>>>>>>
>>>>>>>>>>>> for
>>>>>>>>>>>>> the entire partition to be copied -- the amount of time is
>>>>>>>>>>>>> proportional
>>>>>>>>>>>>>
>>>>>>>>>>>>> to
>>>>>>>>>>>>>
>>>>>>>>>>>>> the amount of existing data in the partition, which can take
>>>>>>>>>>>>>
>>>>>>>>>>>> tens of
>>>>>>>>>>>>
>>>>>>>>>>>> minutes. So the amount of time that we stop consumers may not be
>>>>>>>>>>>> on
>>>>>>>>>>>>
>>>>>>>>>>>> the
>>>>>>>>>>>>> same order of magnitude.
>>>>>>>>>>>>>
>>>>>>>>>>>>> If we can implement this suggestion without copying data over
>>>>>>>>>>>>> in
>>>>>>>>>>>>> purse
>>>>>>>>>>>>> userland, it will be much more valuable. Do you have ideas on
>>>>>>>>>>>>> how
>>>>>>>>>>>>> this
>>>>>>>>>>>>>
>>>>>>>>>>>>> can
>>>>>>>>>>>>>
>>>>>>>>>>>>> be done?
>>>>>>>>>>>>>
>>>>>>>>>>>> Not sure why the current KIP not help people who depend on log
>>>>>>>>>>>>
>>>>>>>>>>>> compaction.
>>>>>>>>>>>>>
>>>>>>>>>>>>> Could you elaborate more on this point?
>>>>>>>>>>>>>
>>>>>>>>>>>> Thanks,
>>>>>>>>>>>>
>>>>>>>>>>>> Dong
>>>>>>>>>>>>>
>>>>>>>>>>>>> On Wed, Feb 28, 2018 at 10:55 PM, Jan
>>>>>>>>>>>>> Filipiak<Jan.Filipiak@trivago.
>>>>>>>>>>>>> com
>>>>>>>>>>>>> wrote:
>>>>>>>>>>>>>
>>>>>>>>>>>>> Hi Dong,
>>>>>>>>>>>>>
>>>>>>>>>>>>> I tried to focus on what the steps are one can currently
>>>>>>>>>>>>> perform
>>>>>>>>>>>>> to
>>>>>>>>>>>>>
>>>>>>>>>>>>> expand
>>>>>>>>>>>>>
>>>>>>>>>>>>>> or shrink a keyed topic while maintaining a top notch
>>>>>>>>>>>>>> semantics.
>>>>>>>>>>>>>> I can understand that there might be confusion about "stopping
>>>>>>>>>>>>>> the
>>>>>>>>>>>>>> consumer". It is exactly the same as proposed in the KIP.
>>>>>>>>>>>>>> there
>>>>>>>>>>>>>> needs
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> to
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> be
>>>>>>>>>>>>>>
>>>>>>>>>>>>> a time the producers agree on the new partitioning. The extra
>>>>>>>>>>>>
>>>>>>>>>>>> semantics I
>>>>>>>>>>>>>
>>>>>>>>>>>>>> want to put in there is that we have a possibility to wait
>>>>>>>>>>>>>> until
>>>>>>>>>>>>>>
>>>>>>>>>>>>> all
>>>>>>>>>>>>
>>>>>>>>>>>> the
>>>>>>>>>>>>
>>>>>>>>>>>> existing data
>>>>>>>>>>>>>
>>>>>>>>>>>>> is copied over into the new partitioning scheme. When I say
>>>>>>>>>>>> stopping
>>>>>>>>>>>>
>>>>>>>>>>>> I
>>>>>>>>>>>>>
>>>>>>>>>>>>>> think more of having a memory barrier that ensures the
>>>>>>>>>>>>>> ordering. I
>>>>>>>>>>>>>> am
>>>>>>>>>>>>>> still
>>>>>>>>>>>>>> aming for latencies  on the scale of leader failovers.
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> Consumers have to explicitly adapt the new partitioning scheme
>>>>>>>>>>>>>> in
>>>>>>>>>>>>>> the
>>>>>>>>>>>>>> above scenario. The reason is that in these cases where you
>>>>>>>>>>>>>> are
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> dependent
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> on a particular partitioning scheme, you also have other
>>>>>>>>>>>>>> topics
>>>>>>>>>>>>>>
>>>>>>>>>>>>> that
>>>>>>>>>>>>
>>>>>>>>>>>> have
>>>>>>>>>>>>
>>>>>>>>>>>> co-partition enforcements or the kind -frequently. Therefore all
>>>>>>>>>>>>>
>>>>>>>>>>>>> your
>>>>>>>>>>>>
>>>>>>>>>>>> other
>>>>>>>>>>>>
>>>>>>>>>>>> input topics might need to grow accordingly.
>>>>>>>>>>>>>
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> What I was suggesting was to streamline all these operations
>>>>>>>>>>>>>> as
>>>>>>>>>>>>>> best
>>>>>>>>>>>>>> as
>>>>>>>>>>>>>> possible to have "real" partition grow and shrinkage going on.
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> Migrating
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> the producers to a new partitioning scheme can be much more
>>>>>>>>>>>>>>
>>>>>>>>>>>>> streamlined
>>>>>>>>>>>>
>>>>>>>>>>>> with proper broker support for this. Migrating consumer is a
>>>>>>>>>>>> step
>>>>>>>>>>>>
>>>>>>>>>>>> that
>>>>>>>>>>>>>
>>>>>>>>>>>>>> might be made completly unnecessary if - for example streams -
>>>>>>>>>>>>>> takes
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> the
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> gcd as partitioning scheme instead of enforcing 1 to 1.
>>>>>>>>>>>>>> Connect
>>>>>>>>>>>>>>
>>>>>>>>>>>>> consumers
>>>>>>>>>>>>
>>>>>>>>>>>> and other consumers should be fine anyways.
>>>>>>>>>>>>>
>>>>>>>>>>>>> I hope this makes more clear where I was aiming at. The rest
>>>>>>>>>>>> needs
>>>>>>>>>>>>
>>>>>>>>>>>> to
>>>>>>>>>>>>>
>>>>>>>>>>>>> be
>>>>>>>>>>>>>
>>>>>>>>>>>>>> figured out. The only danger i see is that when we are
>>>>>>>>>>>>>>
>>>>>>>>>>>>> introducing
>>>>>>>>>>>>>
>>>>>>>>>>>>> this
>>>>>>>>>>>>
>>>>>>>>>>>> feature as supposed in the KIP, it wont help any people
>>>>>>>>>>>> depending
>>>>>>>>>>>> on
>>>>>>>>>>>>
>>>>>>>>>>>> log
>>>>>>>>>>>>>
>>>>>>>>>>>>>> compaction.
>>>>>>>>>>>>>>
>>>>>>>>>>>>> The other thing I wanted to mention is that I believe the
>>>>>>>>>>>> current
>>>>>>>>>>>>
>>>>>>>>>>>> suggestion (without copying data over) can be implemented in
>>>>>>>>>>>>> pure
>>>>>>>>>>>>>
>>>>>>>>>>>>>> userland
>>>>>>>>>>>>>> with a custom partitioner and a small feedbackloop from
>>>>>>>>>>>>>> ProduceResponse
>>>>>>>>>>>>>> =>
>>>>>>>>>>>>>> Partitionier in coorporation with a change management system.
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> Best Jan
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> On 28.02.2018 07:13, Dong Lin wrote:
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> Hey Jan,
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> I am not sure if it is acceptable for producer to be stopped
>>>>>>>>>>>>>> for a
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> while,
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> particularly for online application which requires low
>>>>>>>>>>>>>>> latency. I
>>>>>>>>>>>>>>> am
>>>>>>>>>>>>>>> also
>>>>>>>>>>>>>>> not sure how consumers can switch to a new topic. Does user
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> application
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> needs to explicitly specify a different topic for
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>> producer/consumer
>>>>>>>>>>>>>
>>>>>>>>>>>>> to
>>>>>>>>>>>>>
>>>>>>>>>>>> subscribe to? It will be helpful for discussion if you can
>>>>>>>>>>>> provide
>>>>>>>>>>>>
>>>>>>>>>>>> more
>>>>>>>>>>>>>
>>>>>>>>>>>>>> detail on the interface change for this solution.
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> Thanks,
>>>>>>>>>>>>>
>>>>>>>>>>>>> Dong
>>>>>>>>>>>>>
>>>>>>>>>>>>>> On Mon, Feb 26, 2018 at 12:48 AM, Jan
>>>>>>>>>>>>>>> Filipiak<Jan.Filipiak@trivago.
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> com
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> wrote:
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>> Hi,
>>>>>>>>>>>>>
>>>>>>>>>>>>> just want to throw my though in. In general the functionality
>>>>>>>>>>>>> is
>>>>>>>>>>>>>
>>>>>>>>>>>>>> very
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> usefull, we should though not try to find the architecture to
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> hard
>>>>>>>>>>>>>>>> while
>>>>>>>>>>>>>>>> implementing.
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> The manual steps would be to
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> create a new topic
>>>>>>>>>>>>>>>> the mirrormake from the new old topic to the new topic
>>>>>>>>>>>>>>>> wait for mirror making to catch up.
>>>>>>>>>>>>>>>> then put the consumers onto the new topic
>>>>>>>>>>>>>>>>            (having mirrormaker spit out a mapping from old
>>>>>>>>>>>>>>>> offsets to
>>>>>>>>>>>>>>>> new
>>>>>>>>>>>>>>>> offsets:
>>>>>>>>>>>>>>>>                if topic is increased by factor X there is
>>>>>>>>>>>>>>>> gonna
>>>>>>>>>>>>>>>> be a
>>>>>>>>>>>>>>>> clean
>>>>>>>>>>>>>>>> mapping from 1 offset in the old topic to X offsets in the
>>>>>>>>>>>>>>>> new
>>>>>>>>>>>>>>>> topic,
>>>>>>>>>>>>>>>>                if there is no factor then there is no
>>>>>>>>>>>>>>>> chance to
>>>>>>>>>>>>>>>> generate a
>>>>>>>>>>>>>>>> mapping that can be reasonable used for continuing)
>>>>>>>>>>>>>>>>            make consumers stop at appropriate points and
>>>>>>>>>>>>>>>> continue
>>>>>>>>>>>>>>>> consumption
>>>>>>>>>>>>>>>> with offsets from the mapping.
>>>>>>>>>>>>>>>> have the producers stop for a minimal time.
>>>>>>>>>>>>>>>> wait for mirrormaker to finish
>>>>>>>>>>>>>>>> let producer produce with the new metadata.
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> Instead of implementing the approach suggest in the KIP
>>>>>>>>>>>>>>>> which
>>>>>>>>>>>>>>>> will
>>>>>>>>>>>>>>>> leave
>>>>>>>>>>>>>>>> log compacted topic completely crumbled and unusable.
>>>>>>>>>>>>>>>> I would much rather try to build infrastructure to support
>>>>>>>>>>>>>>>> the
>>>>>>>>>>>>>>>> mentioned
>>>>>>>>>>>>>>>> above operations more smoothly.
>>>>>>>>>>>>>>>> Especially having producers stop and use another topic is
>>>>>>>>>>>>>>>> difficult
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> and
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> it would be nice if one can trigger "invalid metadata"
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> exceptions
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> for
>>>>>>>>>>>>>>
>>>>>>>>>>>>> them
>>>>>>>>>>>>
>>>>>>>>>>>> and
>>>>>>>>>>>>>
>>>>>>>>>>>>>> if one could give topics aliases so that their produces with
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> the
>>>>>>>>>>>>>>>> old
>>>>>>>>>>>>>>>> topic
>>>>>>>>>>>>>>>> will arrive in the new topic.
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> The downsides are obvious I guess ( having the same data
>>>>>>>>>>>>>>>> twice
>>>>>>>>>>>>>>>> for
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> the
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> transition period, but kafka tends to scale well with
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> datasize).
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> So
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> its a
>>>>>>>>>>>>>>
>>>>>>>>>>>>> nicer fit into the architecture.
>>>>>>>>>>>>>
>>>>>>>>>>>>>> I further want to argument that the functionality by the KIP
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> can
>>>>>>>>>>>>>>>> completely be implementing in "userland" with a custom
>>>>>>>>>>>>>>>> partitioner
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> that
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> handles the transition as needed. I would appreciate if
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> someone
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> could
>>>>>>>>>>>>>>
>>>>>>>>>>>>> point
>>>>>>>>>>>>
>>>>>>>>>>>> out what a custom partitioner couldn't handle in this case?
>>>>>>>>>>>>>
>>>>>>>>>>>>>> With the above approach, shrinking a topic becomes the same
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> steps.
>>>>>>>>>>>>>>>> Without
>>>>>>>>>>>>>>>> loosing keys in the discontinued partitions.
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> Would love to hear what everyone thinks.
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> Best Jan
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> On 11.02.2018 00:35, Dong Lin wrote:
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> Hi all,
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> I have created KIP-253: Support in-order message delivery
>>>>>>>>>>>>>>>> with
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> partition
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> expansion. See
>>>>>>>>>>>>>>>>> https://cwiki.apache.org/confluence/display/KAFKA/KIP-253%
>>>>>>>>>>>>>>>>> 3A+Support+in-order+message+de
>>>>>>>>>>>>>>>>> livery+with+partition+expansio
>>>>>>>>>>>>>>>>> n
>>>>>>>>>>>>>>>>> .
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> This KIP provides a way to allow messages of the same key
>>>>>>>>>>>>>>>>> from
>>>>>>>>>>>>>>>>> the
>>>>>>>>>>>>>>>>> same
>>>>>>>>>>>>>>>>> producer to be consumed in the same order they are produced
>>>>>>>>>>>>>>>>> even
>>>>>>>>>>>>>>>>> if
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> we
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> expand partition of the topic.
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> Thanks,
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>> Dong
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>
>>>
>
>

Re: [DISCUSS] KIP-253: Support in-order message delivery with partition expansion

Posted by Jan Filipiak <Ja...@trivago.com>.
Hi Jun,

I was really seeing progress in our conversation but your latest reply 
is just devastating.
I though we were getting close being on the same page now it feels like 
we are in different libraries.

I just quickly slam my answers in here. If they are to brief I am sorry 
give me a ping and try to go into details more.
Just want to show that your pro/cons listing is broken.

Best Jan

and want to get rid of this horrible compromise


On 19.03.2018 05:48, Jun Rao wrote:
> Hi, Jan,
>
> Thanks for the discussion. Great points.
>
> Let me try to summarize the approach that you are proposing. On the broker
> side, we reshuffle the existing data in a topic from current partitions to
> the new partitions. Once the reshuffle fully catches up, switch the
> consumers to start consuming from the new partitions. If a consumer needs
> to rebuild its local state (due to partition changes), let the consumer
> rebuild its state by reading all existing data from the new partitions.
> Once all consumers have switches over, cut over the producer to the new
> partitions.
>
> The pros for this approach are that :
> 1. There is just one way to rebuild the local state, which is simpler.
true thanks
>
> The cons for this approach are:
> 1. Need to copy existing data.
Very unfair and not correct. It does not require you to copy over 
existing data. It _allows_ you to copy all existing data.

> 2. The cutover of the producer is a bit complicated since it needs to
> coordinate with all consumer groups.
Also not true. I explicitly tried to make clear that there is only one 
special consumer (in the case of actually copying data) coordination is 
required.
> 3. The rebuilding of the state in the consumer is from the input topic,
> which can be more expensive than rebuilding from the existing state.
true, but rebuilding state is only required if you want to increase 
processing power, so we assume this is at hand.
> 4. The broker potentially has to know the partitioning function. If this
> needs to be customized at the topic level, it can be a bit messy.
I would argue against having the operation being performed by the 
broker. This was not discussed yet but if you see my original email i 
suggested otherwise from the beginning.
>
> Here is an alternative approach by applying your idea not in the broker,
> but in the consumer. When new partitions are added, we don't move existing
> data. In KStreams, we first reshuffle the new input data to a new topic T1
> with the old number of partitions and feed T1's data to the rest of the
> pipeline. In the meantime, KStreams reshuffles all existing data of the
> change capture topic to another topic C1 with the new number of partitions.
> We can then build the state of the new tasks from C1. Once the new states
> have been fully built, we can cut over the consumption to the input topic
> and delete T1. This approach works with compacted topic too. If an
> application reads from the beginning of a compacted topic, the consumer
> will reshuffle the portion of the input when the number of partitions
> doesn't match the number of tasks.
We all wipe this idea from our heads instantly. Mixing Ideas from an 
argument is not a resolution strategy
just leads to horrible horrible software.
>
> The pros of this approach are:
> 1. No need to copy existing data.
> 2. Each consumer group can cut over to the new partitions independently.
> 3. The state is rebuilt from the change capture topic, which is cheaper
> than rebuilding from the input topic.
> 4. Only the KStreams job needs to know the partitioning function.
>
> The cons of this approach are:
> 1. Potentially the same input topic needs to be reshuffled more than once
> in different consumer groups during the transition phase.
>
> What do you think?
>
> Thanks,
>
> Jun
>
>
>
> On Thu, Mar 15, 2018 at 1:04 AM, Jan Filipiak <Ja...@trivago.com>
> wrote:
>
>> Hi Jun,
>>
>> thank you for following me on these thoughts. It was important to me to
>> feel that kind of understanding for my arguments.
>>
>> What I was hoping for (I mentioned this earlier) is that we can model the
>> case where we do not want to copy the data the exact same way as the case
>> when we do copy the data. Maybe you can peek into the mails before to see
>> more details for this.
>>
>> This means we have the same mechanism to transfer consumer groups to
>> switch topic. The offset mapping that would be generated would even be
>> simpler End Offset of the Old topic => offset 0 off all the partitions of
>> the new topic. Then we could model the transition of a non-copy expansion
>> the exact same way as a copy-expansion.
>>
>> I know this only works when topic growth by a factor. But the benefits of
>> only growing by a factor are to strong anyways. See Clemens's hint and
>> remember that state reshuffling is entirely not needed if one doesn't want
>> to grow processing power.
>>
>> I think these benefits should be clear, and that there is basically no
>> downside to what is currently at hand but just makes everything easy.
>>
>> One thing you need to know is. that if you do not offer rebuilding a log
>> compacted topic like i suggest that even if you have consumer state
>> reshuffling. The topic is broken and can not be used to bootstrap new
>> consumers. They don't know if they need to apply a key from and old
>> partition or not. This is a horrible downside I haven't seen a solution for
>> in the email conversation.
>>
>> I argue to:
>>
>> Only grow topic by a factor always.
>> Have the "no copy consumer" transition as the trivial case of the "copy
>> consumer transition".
>> If processors needs to be scaled, let them rebuild from the new topic and
>> leave the old running in the mean time.
>> Do not implement key shuffling in streams.
>>
>> I hope I can convince you especially with the fact how I want to handle
>> consumer transition. I think
>> you didn't quite understood me there before. I think the term "new topic"
>> intimidated you a little.
>> How we solve this on disc doesn't really matter, If the data goes into the
>> same Dir or a different Dir or anything. I do think that it needs to
>> involve at least rolling a new segment for the existing partitions.
>> But most of the transitions should work without restarting consumers.
>> (newer consumers with support for this). But with new topic i just meant
>> the topic that now has a different partition count. Plenty of ways to
>> handle that (versions, aliases)
>>
>> Hope I can further get my idea across.
>>
>> Best Jan
>>
>>
>>
>>
>>
>>
>> On 14.03.2018 02:45, Jun Rao wrote:
>>
>>> Hi, Jan,
>>>
>>> Thanks for sharing your view.
>>>
>>> I agree with you that recopying the data potentially makes the state
>>> management easier since the consumer can just rebuild its state from
>>> scratch (i.e., no need for state reshuffling).
>>>
>>> On the flip slide, I saw a few disadvantages of the approach that you
>>> suggested. (1) Building the state from the input topic from scratch is in
>>> general less efficient than state reshuffling. Let's say one computes a
>>> count per key from an input topic. The former requires reading all
>>> existing
>>> records in the input topic whereas the latter only requires reading data
>>> proportional to the number of unique keys. (2) The switching of the topic
>>> needs modification to the application. If there are many applications on a
>>> topic, coordinating such an effort may not be easy. Also, it's not clear
>>> how to enforce exactly-once semantic during the switch. (3) If a topic
>>> doesn't need any state management, recopying the data seems wasteful. In
>>> that case, in place partition expansion seems more desirable.
>>>
>>> I understand your concern about adding complexity in KStreams. But,
>>> perhaps
>>> we could iterate on that a bit more to see if it can be simplified.
>>>
>>> Jun
>>>
>>>
>>> On Mon, Mar 12, 2018 at 11:21 PM, Jan Filipiak <Ja...@trivago.com>
>>> wrote:
>>>
>>> Hi Jun,
>>>> I will focus on point 61 as I think its _the_ fundamental part that I
>>>> cant
>>>> get across at the moment.
>>>>
>>>> Kafka is the platform to have state materialized multiple times from one
>>>> input. I emphasize this: It is the building block in architectures that
>>>> allow you to
>>>> have your state maintained multiple times. You put a message in once, and
>>>> you have it pop out as often as you like. I believe you understand this.
>>>>
>>>> Now! The path of thinking goes the following: I am using apache kafka and
>>>> I _want_ my state multiple times. What am I going todo?
>>>>
>>>> A) Am I going to take my state that I build up, plunge some sort of RPC
>>>> layer ontop of it, use that RPC layer to throw my records across
>>>> instances?
>>>> B) Am I just going to read the damn message twice?
>>>>
>>>> Approach A is fundamentally flawed and a violation of all that is good
>>>> and
>>>> holy in kafka deployments. I can not understand how this Idea can come in
>>>> the first place.
>>>> (I do understand: IQ in streams, they polluted the kafka streams codebase
>>>> really bad already. It is not funny! I think they are equally flawed as
>>>> A)
>>>>
>>>> I say, we do what Kafka is good at. We repartition the topic once. We
>>>> switch the consumers.
>>>> (Those that need more partitions are going to rebuild their state in
>>>> multiple partitions by reading the new topic, those that don't just
>>>> assign
>>>> the new partitions properly)
>>>> We switch producers. Done!
>>>>
>>>> The best thing! It is trivial, hipster stream processor will have an easy
>>>> time with that aswell. Its so super simple. And simple IS good!
>>>> It is what kafka was build todo. It is how we do it today. All I am
>>>> saying
>>>> is that a little broker help doing the producer swap is super useful.
>>>>
>>>> For everyone interested in why kafka is so powerful with approach B,
>>>> please watch https://youtu.be/bEbeZPVo98c?t=1633
>>>> I already looked up a good point in time, I think after 5 minutes the
>>>> "state" topic is handled and you should be able to understand me
>>>> and inch better.
>>>>
>>>> Please do not do A to the project, it deserves better!
>>>>
>>>> Best Jan
>>>>
>>>>
>>>>
>>>> On 13.03.2018 02:40, Jun Rao wrote:
>>>>
>>>> Hi, Jan,
>>>>> Thanks for the reply. A few more comments below.
>>>>>
>>>>> 50. Ok, we can think a bit harder for supporting compacted topics.
>>>>>
>>>>> 51. This is a fundamental design question. In the more common case, the
>>>>> reason why someone wants to increase the number of partitions is that
>>>>> the
>>>>> consumer application is slow and one wants to run more consumer
>>>>> instances
>>>>> to increase the degree of parallelism. So, fixing the number of running
>>>>> consumer instances when expanding the partitions won't help this case.
>>>>> If
>>>>> we do need to increase the number of consumer instances, we need to
>>>>> somehow
>>>>> reshuffle the state of the consumer across instances. What we have been
>>>>> discussing in this KIP is whether we can do this more effectively
>>>>> through
>>>>> the KStream library (e.g. through a 2-phase partition expansion). This
>>>>> will
>>>>> add some complexity, but it's probably better than everyone doing this
>>>>> in
>>>>> the application space. The recopying approach that you mentioned doesn't
>>>>> seem to address the consumer state management issue when the consumer
>>>>> switches from an old to a new topic.
>>>>>
>>>>> 52. As for your example, it depends on whether the join key is the same
>>>>> between (A,B) and (B,C). If the join key is the same, we can do a
>>>>> 2-phase
>>>>> partition expansion of A, B, and C together. If the join keys are
>>>>> different, one would need to repartition the data on a different key for
>>>>> the second join, then the partition expansion can be done independently
>>>>> between (A,B) and (B,C).
>>>>>
>>>>> 53. If you always fix the number of consumer instances, we you described
>>>>> works. However, as I mentioned in #51, I am not sure how your proposal
>>>>> deals with consumer states when the number of consumer instances grows.
>>>>> Also, it just seems that it's better to avoid re-copying the existing
>>>>> data.
>>>>>
>>>>> 60. "just want to throw in my question from the longer email in the
>>>>> other
>>>>> Thread here. How will the bloom filter help a new consumer to decide to
>>>>> apply the key or not?" Not sure that I fully understood your question.
>>>>> The
>>>>> consumer just reads whatever key is in the log. The bloom filter just
>>>>> helps
>>>>> clean up the old keys.
>>>>>
>>>>> 61. "Why can we afford having a topic where its apparently not possible
>>>>> to
>>>>> start a new application on? I think this is an overall flaw of the
>>>>> discussed idea here. Not playing attention to the overall architecture."
>>>>> Could you explain a bit more when one can't start a new application?
>>>>>
>>>>> Jun
>>>>>
>>>>>
>>>>>
>>>>> On Sat, Mar 10, 2018 at 1:40 AM, Jan Filipiak <Jan.Filipiak@trivago.com
>>>>> wrote:
>>>>>
>>>>> Hi Jun, thanks for your mail.
>>>>>
>>>>>> Thank you for your questions!
>>>>>> I think they are really good and tackle the core of the problem I see.
>>>>>>
>>>>>> I will answer inline, mostly but still want to set the tone here.
>>>>>>
>>>>>> The core strength of kafka is what Martin once called the
>>>>>> kappa-Architecture. How does this work?
>>>>>> You have everything as a log as in kafka. When you need to change
>>>>>> something.
>>>>>> You create the new version of your application and leave it running in
>>>>>> parallel.
>>>>>> Once the new version is good you switch your users to use the new
>>>>>> application.
>>>>>>
>>>>>> The online reshuffling effectively breaks this architecture and I think
>>>>>> the switch in thinking here is more harmful
>>>>>> than any details about the partitioning function to allow such a
>>>>>> change.
>>>>>> I
>>>>>> feel with my suggestion we are the closest to
>>>>>> the original and battle proven architecture and I can only warn to move
>>>>>> away from it.
>>>>>>
>>>>>> I might have forgotten something, sometimes its hard for me to getting
>>>>>> all
>>>>>> the thoughts captured in a mail, but I hope the comments inline will
>>>>>> further make my concern clear, and put some emphasis on why I prefer my
>>>>>> solution ;)
>>>>>>
>>>>>> One thing we should all be aware of when discussing this, and I think
>>>>>> Dong
>>>>>> should have mentioned it (maybe he did).
>>>>>> We are not discussing all of this out of thin air but there is an
>>>>>> effort
>>>>>> in the Samza project.
>>>>>>
>>>>>> https://cwiki.apache.org/confluence/display/SAMZA/SEP-5%3A+
>>>>>> Enable+partition+expansion+of+input+streams
>>>>>> https://issues.apache.org/jira/browse/SAMZA-1293
>>>>>>
>>>>>> To be clear. I think SEP-5 (state of last week, dont know if it adapted
>>>>>> to
>>>>>> this discussion) is on a way better path than KIP-253, and I can't
>>>>>> really
>>>>>> explain why.
>>>>>>
>>>>>> Best Jan,
>>>>>>
>>>>>> nice weekend everyone
>>>>>>
>>>>>>
>>>>>> On 09.03.2018 03:36, Jun Rao wrote:
>>>>>>
>>>>>> Hi, Jan,
>>>>>>
>>>>>>> Thanks for the feedback. Just some comments on the earlier points that
>>>>>>> you
>>>>>>> mentioned.
>>>>>>>
>>>>>>> 50. You brought up the question of whether existing data needs to be
>>>>>>> copied
>>>>>>> during partition expansion. My understand of your view is that avoid
>>>>>>> copying existing data will be more efficient, but it doesn't work well
>>>>>>> with
>>>>>>> compacted topics since some keys in the original partitions will never
>>>>>>> be
>>>>>>> cleaned. It would be useful to understand your use case of compacted
>>>>>>> topics
>>>>>>> a bit more. In the common use case, the data volume in a compacted
>>>>>>> topic
>>>>>>> may not be large. So, I am not sure if there is a strong need to
>>>>>>> expand
>>>>>>> partitions in a compacted topic, at least initially.
>>>>>>>
>>>>>>> I do agree. State is usually smaller. Update rates might be also
>>>>>>>
>>>>>> competitively high.
>>>>>> Doing Log-compaction (even beeing very efficient and configurable) is
>>>>>> also
>>>>>> a more expensive operation than
>>>>>> just discarding old segments. Further if you want to use more consumers
>>>>>> processing the events
>>>>>> you also have to grow the number of partitions. Especially for
>>>>>> use-cases
>>>>>> we do (KIP-213) a tiny state full
>>>>>> table might be very expensive to process if it joins against a huge
>>>>>> table.
>>>>>>
>>>>>> I can just say we have been in the spot of needing to grow log
>>>>>> compacted
>>>>>> topics. Mainly for processing power we can bring to the table.
>>>>>>
>>>>>> Further i am not at all concerned about the extra spaced used by
>>>>>> "garbage
>>>>>> keys". I am more concerned about the correctness of innocent consumers.
>>>>>> The
>>>>>> logic becomes complicated. Say for streams one would need to load the
>>>>>> record into state but not forward it the topology ( to have it
>>>>>> available
>>>>>> for shuffeling). I rather have it simple and a topic clean regardless
>>>>>> if
>>>>>> it
>>>>>> still has its old partition count. Especially with multiple partitions
>>>>>> growth's I think it becomes insanely hard to to this shuffle correct.
>>>>>> Maybe
>>>>>> Streams and Samza can do it. Especially if you do "hipster stream
>>>>>> processing" <https://www.confluent.io/blog/introducing-kafka-streams-
>>>>>> stream-processing-made-simple/>. This makes kafka way to complicated.
>>>>>> With my approach I think its way simpler because the topic has no
>>>>>> "history"
>>>>>> in terms of partitioning but is always clean.
>>>>>>
>>>>>>
>>>>>> 51. "Growing the topic by an integer factor does not require any state
>>>>>>
>>>>>>> redistribution at all." Could you clarify this a bit more? Let's say
>>>>>>> you
>>>>>>> have a consumer app that computes the windowed count per key. If you
>>>>>>> double
>>>>>>> the number of partitions from 1 to 2 and grow the consumer instances
>>>>>>> from
>>>>>>> 1
>>>>>>> to 2, we would need to redistribute some of the counts to the new
>>>>>>> consumer
>>>>>>> instance. Regarding to linear hashing, it's true that it won't solve
>>>>>>> the
>>>>>>> problem with compacted topics. The main benefit is that it
>>>>>>> redistributes
>>>>>>> the keys in one partition to no more than two partitions, which could
>>>>>>> help
>>>>>>> redistribute the state.
>>>>>>>
>>>>>>> You don't need to spin up a new consumer in this case. every consumer
>>>>>>>
>>>>>> would just read every partition with the (partition % num_task) task.
>>>>>> it
>>>>>> will still have the previous data right there and can go on.
>>>>>>
>>>>>> This sounds contradictory to what I said before, but please bear with
>>>>>> me.
>>>>>>
>>>>>> 52. Good point on coordinating the expansion of 2 topics that need to
>>>>>> be
>>>>>>
>>>>>>> joined together. This is where the 2-phase partition expansion could
>>>>>>> potentially help. In the first phase, we could add new partitions to
>>>>>>> the 2
>>>>>>> topics one at a time but without publishing to the new patitions.
>>>>>>> Then,
>>>>>>> we
>>>>>>> can add new consumer instances to pick up the new partitions. In this
>>>>>>> transition phase, no reshuffling is needed since no data is coming
>>>>>>> from
>>>>>>> the
>>>>>>> new partitions. Finally, we can enable the publishing to the new
>>>>>>> partitions.
>>>>>>>
>>>>>>> I think its even worse than you think. I would like to introduce the
>>>>>>>
>>>>>> Term
>>>>>> transitive copartitioning. Imagine
>>>>>> 2 streams application. One joins (A,B) the other (B,C) then there is a
>>>>>> transitive copartition requirement for
>>>>>> (A,C) to be copartitioned aswell. This can spread significantly and
>>>>>> require many consumers to adapt at the same time.
>>>>>>
>>>>>> It is also not entirely clear to me how you not need reshuffling in
>>>>>> this
>>>>>> case. If A has a record that never gets updated after the expansion and
>>>>>> the
>>>>>> coresponding B record moves to a new partition. How shall they meet w/o
>>>>>> shuffle?
>>>>>>
>>>>>> 53. "Migrating consumer is a step that might be made completly
>>>>>>
>>>>>>> unnecessary
>>>>>>> if - for example streams - takes the gcd as partitioning scheme
>>>>>>> instead
>>>>>>> of
>>>>>>> enforcing 1 to 1." Not sure that I fully understand this. I think you
>>>>>>> mean
>>>>>>> that a consumer application can run more instances than the number of
>>>>>>> partitions. In that case, the consumer can just repartitioning the
>>>>>>> input
>>>>>>> data according to the number of instances. This is possible, but just
>>>>>>> has
>>>>>>> the overhead of reshuffling the data.
>>>>>>>
>>>>>>> No what I meant is ( that is also your question i think Mathias) that
>>>>>>> if
>>>>>>>
>>>>>> you grow a topic by a factor.
>>>>>> Even if your processor is statefull you can can just assign all the
>>>>>> multiples of the previous partition to
>>>>>> this consumer and the state to keep processing correctly will be
>>>>>> present
>>>>>> w/o any shuffling.
>>>>>>
>>>>>> Say you have an assignment
>>>>>> Statefull consumer => partition
>>>>>> 0 => 0
>>>>>> 1 => 1
>>>>>> 2 => 2
>>>>>>
>>>>>> and you grow you topic by 4 you get,
>>>>>>
>>>>>> 0 => 0,3,6,9
>>>>>> 1 => 1,4,7,10
>>>>>> 2 => 2,5,8,11
>>>>>>
>>>>>> Say your hashcode is 8. 8%3 => 2  before so consumer for partition 2
>>>>>> has
>>>>>> it.
>>>>>> Now you you have 12 partitions so 8%12 => 8, so it goes into partition
>>>>>> 8
>>>>>> which is assigned to the same consumer
>>>>>> who had 2 before and therefore knows the key.
>>>>>>
>>>>>> Userland reshuffeling is there as an options. And it does exactly what
>>>>>> I
>>>>>> suggest. And I think its the perfect strategie. All I am suggestion is
>>>>>> broker side support to switch the producers to the newly partitioned
>>>>>> topic.
>>>>>> Then the old (to few partition topic) can go away.  Remember the list
>>>>>> of
>>>>>> steps in the beginning of this thread. If one has broker support for
>>>>>> all
>>>>>> where its required and streams support for those that aren’t
>>>>>> necessarily.
>>>>>> Then one has solved the problem.
>>>>>> I repeat it because I think its important. I am really happy that you
>>>>>> brought that up! because its 100% what I want just with the differences
>>>>>> to
>>>>>> have an option to discard the to small topic later (after all consumers
>>>>>> adapted). And to have order correct there. I need broker support
>>>>>> managing
>>>>>> the copy process + the produces and fence them against each other. I
>>>>>> also
>>>>>> repeat. the copy process can run for weeks in the worst case. Copying
>>>>>> the
>>>>>> data is not the longest task migrating consumers might very well be.
>>>>>> Once all consumers switched and copying is really up to date (think ISR
>>>>>> like up to date) only then we stop the producer, wait for the copy to
>>>>>> finish and use the new topic for producing.
>>>>>>
>>>>>> After this the topic is perfect in shape. and no one needs to worry
>>>>>> about
>>>>>> complicated stuff. (old keys hanging around might arrive in some other
>>>>>> topic later.....). can only imagine how many tricky bugs gonna arrive
>>>>>> after
>>>>>> someone had grown and shrunken is topic 10 times.
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> 54. "The other thing I wanted to mention is that I believe the current
>>>>>>
>>>>>>> suggestion (without copying data over) can be implemented in pure
>>>>>>> userland
>>>>>>> with a custom partitioner and a small feedbackloop from
>>>>>>> ProduceResponse
>>>>>>> =>
>>>>>>> Partitionier in coorporation with a change management system." I am
>>>>>>> not
>>>>>>> sure a customized partitioner itself solves the problem. We probably
>>>>>>> need
>>>>>>> some broker side support to enforce when the new partitions can be
>>>>>>> used.
>>>>>>> We
>>>>>>> also need some support on the consumer/kstream side to preserve the
>>>>>>> per
>>>>>>> key
>>>>>>> ordering and potentially migrate the processing state. This is not
>>>>>>> trivial
>>>>>>> and I am not sure if it's ideal to fully push to the application
>>>>>>> space.
>>>>>>>
>>>>>>> Broker support is defenitly the preferred way here. I have nothing
>>>>>>>
>>>>>> against
>>>>>> broker support.
>>>>>> I tried to say that for what I would preffer - copying the data over,
>>>>>> at
>>>>>> least for log compacted topics -
>>>>>> I would require more broker support than the KIP currently offers.
>>>>>>
>>>>>>
>>>>>>
>>>>>> Jun
>>>>>>
>>>>>>> On Tue, Mar 6, 2018 at 10:33 PM, Jan Filipiak <
>>>>>>> Jan.Filipiak@trivago.com
>>>>>>> wrote:
>>>>>>>
>>>>>>> Hi Dong,
>>>>>>>
>>>>>>> are you actually reading my emails, or are you just using the thread I
>>>>>>>> started for general announcements regarding the KIP?
>>>>>>>>
>>>>>>>> I tried to argue really hard against linear hashing. Growing the
>>>>>>>> topic
>>>>>>>> by
>>>>>>>> an integer factor does not require any state redistribution at all. I
>>>>>>>> fail
>>>>>>>> to see completely where linear hashing helps on log compacted topics.
>>>>>>>>
>>>>>>>> If you are not willing to explain to me what I might be overlooking:
>>>>>>>> that
>>>>>>>> is fine.
>>>>>>>> But I ask you to not reply to my emails then. Please understand my
>>>>>>>> frustration with this.
>>>>>>>>
>>>>>>>> Best Jan
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> On 06.03.2018 19:38, Dong Lin wrote:
>>>>>>>>
>>>>>>>> Hi everyone,
>>>>>>>>
>>>>>>>> Thanks for all the comments! It appears that everyone prefers linear
>>>>>>>>> hashing because it reduces the amount of state that needs to be
>>>>>>>>> moved
>>>>>>>>> between consumers (for stream processing). The KIP has been updated
>>>>>>>>> to
>>>>>>>>> use
>>>>>>>>> linear hashing.
>>>>>>>>>
>>>>>>>>> Regarding the migration endeavor: it seems that migrating producer
>>>>>>>>> library
>>>>>>>>> to use linear hashing should be pretty straightforward without
>>>>>>>>> much operational endeavor. If we don't upgrade client library to use
>>>>>>>>> this
>>>>>>>>> KIP, we can not support in-order delivery after partition is changed
>>>>>>>>> anyway. Suppose we upgrade client library to use this KIP, if
>>>>>>>>> partition
>>>>>>>>> number is not changed, the key -> partition mapping will be exactly
>>>>>>>>> the
>>>>>>>>> same as it is now because it is still determined using
>>>>>>>>> murmur_hash(key)
>>>>>>>>> %
>>>>>>>>> original_partition_num. In other words, this change is backward
>>>>>>>>> compatible.
>>>>>>>>>
>>>>>>>>> Regarding the load distribution: if we use linear hashing, the load
>>>>>>>>> may
>>>>>>>>> be
>>>>>>>>> unevenly distributed because those partitions which are not split
>>>>>>>>> may
>>>>>>>>> receive twice as much traffic as other partitions that are split.
>>>>>>>>> This
>>>>>>>>> issue can be mitigated by creating topic with partitions that are
>>>>>>>>> several
>>>>>>>>> times the number of consumers. And there will be no imbalance if the
>>>>>>>>> partition number is always doubled. So this imbalance seems
>>>>>>>>> acceptable.
>>>>>>>>>
>>>>>>>>> Regarding storing the partition strategy as per-topic config: It
>>>>>>>>> seems
>>>>>>>>> not
>>>>>>>>> necessary since we can still use murmur_hash as the default hash
>>>>>>>>> function
>>>>>>>>> and additionally apply the linear hashing algorithm if the partition
>>>>>>>>> number
>>>>>>>>> has increased. Not sure if there is any use-case for producer to
>>>>>>>>> use a
>>>>>>>>> different hash function. Jason, can you check if there is some
>>>>>>>>> use-case
>>>>>>>>> that I missed for using the per-topic partition strategy?
>>>>>>>>>
>>>>>>>>> Regarding how to reduce latency (due to state store/load) in stream
>>>>>>>>> processing consumer when partition number changes: I need to read
>>>>>>>>> the
>>>>>>>>> Kafka
>>>>>>>>> Stream code to understand how Kafka Stream currently migrate state
>>>>>>>>> between
>>>>>>>>> consumers when the application is added/removed for a given job. I
>>>>>>>>> will
>>>>>>>>> reply after I finish reading the documentation and code.
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> Thanks,
>>>>>>>>> Dong
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> On Mon, Mar 5, 2018 at 10:43 AM, Jason Gustafson <
>>>>>>>>> jason@confluent.io>
>>>>>>>>> wrote:
>>>>>>>>>
>>>>>>>>> Great discussion. I think I'm wondering whether we can continue to
>>>>>>>>> leave
>>>>>>>>>
>>>>>>>>> Kafka agnostic to the partitioning strategy. The challenge is
>>>>>>>>>
>>>>>>>>>> communicating
>>>>>>>>>> the partitioning logic from producers to consumers so that the
>>>>>>>>>> dependencies
>>>>>>>>>> between each epoch can be determined. For the sake of discussion,
>>>>>>>>>> imagine
>>>>>>>>>> you did something like the following:
>>>>>>>>>>
>>>>>>>>>> 1. The name (and perhaps version) of a partitioning strategy is
>>>>>>>>>> stored
>>>>>>>>>> in
>>>>>>>>>> topic configuration when a topic is created.
>>>>>>>>>> 2. The producer looks up the partitioning strategy before writing
>>>>>>>>>> to
>>>>>>>>>> a
>>>>>>>>>> topic and includes it in the produce request (for fencing). If it
>>>>>>>>>> doesn't
>>>>>>>>>> have an implementation for the configured strategy, it fails.
>>>>>>>>>> 3. The consumer also looks up the partitioning strategy and uses it
>>>>>>>>>> to
>>>>>>>>>> determine dependencies when reading a new epoch. It could either
>>>>>>>>>> fail
>>>>>>>>>> or
>>>>>>>>>> make the most conservative dependency assumptions if it doesn't
>>>>>>>>>> know
>>>>>>>>>> how
>>>>>>>>>> to
>>>>>>>>>> implement the partitioning strategy. For the consumer, the new
>>>>>>>>>> interface
>>>>>>>>>> might look something like this:
>>>>>>>>>>
>>>>>>>>>> // Return the partition dependencies following an epoch bump
>>>>>>>>>> Map<Integer, List<Integer>> dependencies(int
>>>>>>>>>> numPartitionsBeforeEpochBump,
>>>>>>>>>> int numPartitionsAfterEpochBump)
>>>>>>>>>>
>>>>>>>>>> The unordered case then is just a particular implementation which
>>>>>>>>>> never
>>>>>>>>>> has
>>>>>>>>>> any epoch dependencies. To implement this, we would need some way
>>>>>>>>>> for
>>>>>>>>>> the
>>>>>>>>>> consumer to find out how many partitions there were in each epoch,
>>>>>>>>>> but
>>>>>>>>>> maybe that's not too unreasonable.
>>>>>>>>>>
>>>>>>>>>> Thanks,
>>>>>>>>>> Jason
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> On Mon, Mar 5, 2018 at 4:51 AM, Jan Filipiak <
>>>>>>>>>> Jan.Filipiak@trivago.com
>>>>>>>>>> wrote:
>>>>>>>>>>
>>>>>>>>>> Hi Dong
>>>>>>>>>>
>>>>>>>>>> thank you very much for your questions.
>>>>>>>>>>
>>>>>>>>>>> regarding the time spend copying data across:
>>>>>>>>>>> It is correct that copying data from a topic with one partition
>>>>>>>>>>> mapping
>>>>>>>>>>>
>>>>>>>>>>> to
>>>>>>>>>>>
>>>>>>>>>>> a topic with a different partition mapping takes way longer than
>>>>>>>>>> we
>>>>>>>>>> can
>>>>>>>>>>
>>>>>>>>>> stop producers. Tens of minutes is a very optimistic estimate here.
>>>>>>>>>>> Many
>>>>>>>>>>> people can not afford copy full steam and therefore will have some
>>>>>>>>>>> rate
>>>>>>>>>>> limiting in place, this can bump the timespan into the day's. The
>>>>>>>>>>> good
>>>>>>>>>>>
>>>>>>>>>>> part
>>>>>>>>>>>
>>>>>>>>>>> is that the vast majority of the data can be copied while the
>>>>>>>>>> producers
>>>>>>>>>>
>>>>>>>>>> are
>>>>>>>>>>> still going. One can then, piggyback the consumers ontop of this
>>>>>>>>>> timeframe,
>>>>>>>>>>> by the method mentioned (provide them an mapping from their old
>>>>>>>>>> offsets
>>>>>>>>>>
>>>>>>>>>> to
>>>>>>>>>>> new offsets in their repartitioned topics. In that way we separate
>>>>>>>>>> migration of consumers from migration of producers (decoupling
>>>>>>>>>>> these
>>>>>>>>>>> is
>>>>>>>>>>> what kafka is strongest at). The time to actually swap over the
>>>>>>>>>>> producers
>>>>>>>>>>> should be kept minimal by ensuring that when a swap attempt is
>>>>>>>>>>> started
>>>>>>>>>>>
>>>>>>>>>>> the
>>>>>>>>>>>
>>>>>>>>>>> consumer copying over should be very close to the log end and is
>>>>>>>>>> expected
>>>>>>>>>>> to finish within the next fetch. The operation should have a
>>>>>>>>>>> time-out
>>>>>>>>>>> and
>>>>>>>>>>> should be "reattemtable".
>>>>>>>>>>>
>>>>>>>>>>> Importance of logcompaction:
>>>>>>>>>>> If a producer produces key A, to partiton 0, its forever gonna be
>>>>>>>>>>> there,
>>>>>>>>>>> unless it gets deleted. The record might sit in there for years. A
>>>>>>>>>>> new
>>>>>>>>>>> producer started with the new partitions will fail to delete the
>>>>>>>>>>> record
>>>>>>>>>>>
>>>>>>>>>>> in
>>>>>>>>>>>
>>>>>>>>>>> the correct partition. Th record will be there forever and one can
>>>>>>>>>> not
>>>>>>>>>>
>>>>>>>>>> reliable bootstrap new consumers. I cannot see how linear hashing
>>>>>>>>>>> can
>>>>>>>>>>>
>>>>>>>>>>> solve
>>>>>>>>>>>
>>>>>>>>>>> this.
>>>>>>>>>> Regarding your skipping of userland copying:
>>>>>>>>>>> 100%, copying the data across in userland is, as far as i can see,
>>>>>>>>>>> only
>>>>>>>>>>> a
>>>>>>>>>>> usecase for log compacted topics. Even for logcompaction +
>>>>>>>>>>> retentions
>>>>>>>>>>> it
>>>>>>>>>>> should only be opt-in. Why did I bring it up? I think log
>>>>>>>>>>> compaction
>>>>>>>>>>> is
>>>>>>>>>>> a
>>>>>>>>>>> very important feature to really embrace kafka as a "data
>>>>>>>>>>> plattform".
>>>>>>>>>>> The
>>>>>>>>>>> point I also want to make is that copying data this way is
>>>>>>>>>>> completely
>>>>>>>>>>> inline with the kafka architecture. it only consists of reading
>>>>>>>>>>> and
>>>>>>>>>>>
>>>>>>>>>>> writing
>>>>>>>>>>>
>>>>>>>>>>> to topics.
>>>>>>>>>> I hope it clarifies more why I think we should aim for more than
>>>>>>>>>>> the
>>>>>>>>>>> current KIP. I fear that once the KIP is done not much more effort
>>>>>>>>>>> will
>>>>>>>>>>>
>>>>>>>>>>> be
>>>>>>>>>>>
>>>>>>>>>>> taken.
>>>>>>>>>>
>>>>>>>>>>> On 04.03.2018 02:28, Dong Lin wrote:
>>>>>>>>>>>
>>>>>>>>>>> Hey Jan,
>>>>>>>>>>>
>>>>>>>>>>> In the current proposal, the consumer will be blocked on waiting
>>>>>>>>>>> for
>>>>>>>>>>>
>>>>>>>>>>>> other
>>>>>>>>>>>>
>>>>>>>>>>>> consumers of the group to consume up to a given offset. In most
>>>>>>>>>>> cases,
>>>>>>>>>>> all
>>>>>>>>>>> consumers should be close to the LEO of the partitions when the
>>>>>>>>>>> partition
>>>>>>>>>>> expansion happens. Thus the time waiting should not be long e.g.
>>>>>>>>>>> on
>>>>>>>>>>> the
>>>>>>>>>>>
>>>>>>>>>>> order of seconds. On the other hand, it may take a long time to
>>>>>>>>>>> wait
>>>>>>>>>>>
>>>>>>>>>>>> for
>>>>>>>>>>>> the entire partition to be copied -- the amount of time is
>>>>>>>>>>>> proportional
>>>>>>>>>>>>
>>>>>>>>>>>> to
>>>>>>>>>>>>
>>>>>>>>>>>> the amount of existing data in the partition, which can take
>>>>>>>>>>> tens of
>>>>>>>>>>>
>>>>>>>>>>> minutes. So the amount of time that we stop consumers may not be
>>>>>>>>>>> on
>>>>>>>>>>>
>>>>>>>>>>>> the
>>>>>>>>>>>> same order of magnitude.
>>>>>>>>>>>>
>>>>>>>>>>>> If we can implement this suggestion without copying data over in
>>>>>>>>>>>> purse
>>>>>>>>>>>> userland, it will be much more valuable. Do you have ideas on how
>>>>>>>>>>>> this
>>>>>>>>>>>>
>>>>>>>>>>>> can
>>>>>>>>>>>>
>>>>>>>>>>>> be done?
>>>>>>>>>>> Not sure why the current KIP not help people who depend on log
>>>>>>>>>>>
>>>>>>>>>>>> compaction.
>>>>>>>>>>>>
>>>>>>>>>>>> Could you elaborate more on this point?
>>>>>>>>>>> Thanks,
>>>>>>>>>>>
>>>>>>>>>>>> Dong
>>>>>>>>>>>>
>>>>>>>>>>>> On Wed, Feb 28, 2018 at 10:55 PM, Jan
>>>>>>>>>>>> Filipiak<Jan.Filipiak@trivago.
>>>>>>>>>>>> com
>>>>>>>>>>>> wrote:
>>>>>>>>>>>>
>>>>>>>>>>>> Hi Dong,
>>>>>>>>>>>>
>>>>>>>>>>>> I tried to focus on what the steps are one can currently perform
>>>>>>>>>>>> to
>>>>>>>>>>>>
>>>>>>>>>>>> expand
>>>>>>>>>>>>> or shrink a keyed topic while maintaining a top notch semantics.
>>>>>>>>>>>>> I can understand that there might be confusion about "stopping
>>>>>>>>>>>>> the
>>>>>>>>>>>>> consumer". It is exactly the same as proposed in the KIP. there
>>>>>>>>>>>>> needs
>>>>>>>>>>>>>
>>>>>>>>>>>>> to
>>>>>>>>>>>>>
>>>>>>>>>>>>> be
>>>>>>>>>>> a time the producers agree on the new partitioning. The extra
>>>>>>>>>>>
>>>>>>>>>>>> semantics I
>>>>>>>>>>>>> want to put in there is that we have a possibility to wait until
>>>>>>>>>>> all
>>>>>>>>>>>
>>>>>>>>>>> the
>>>>>>>>>>>
>>>>>>>>>>>> existing data
>>>>>>>>>>>>
>>>>>>>>>>> is copied over into the new partitioning scheme. When I say
>>>>>>>>>>> stopping
>>>>>>>>>>>
>>>>>>>>>>>> I
>>>>>>>>>>>>> think more of having a memory barrier that ensures the
>>>>>>>>>>>>> ordering. I
>>>>>>>>>>>>> am
>>>>>>>>>>>>> still
>>>>>>>>>>>>> aming for latencies  on the scale of leader failovers.
>>>>>>>>>>>>>
>>>>>>>>>>>>> Consumers have to explicitly adapt the new partitioning scheme
>>>>>>>>>>>>> in
>>>>>>>>>>>>> the
>>>>>>>>>>>>> above scenario. The reason is that in these cases where you are
>>>>>>>>>>>>>
>>>>>>>>>>>>> dependent
>>>>>>>>>>>>>
>>>>>>>>>>>>> on a particular partitioning scheme, you also have other topics
>>>>>>>>>>> that
>>>>>>>>>>>
>>>>>>>>>>> have
>>>>>>>>>>>
>>>>>>>>>>>> co-partition enforcements or the kind -frequently. Therefore all
>>>>>>>>>>>>
>>>>>>>>>>> your
>>>>>>>>>>>
>>>>>>>>>>> other
>>>>>>>>>>>
>>>>>>>>>>>> input topics might need to grow accordingly.
>>>>>>>>>>>>>
>>>>>>>>>>>>> What I was suggesting was to streamline all these operations as
>>>>>>>>>>>>> best
>>>>>>>>>>>>> as
>>>>>>>>>>>>> possible to have "real" partition grow and shrinkage going on.
>>>>>>>>>>>>>
>>>>>>>>>>>>> Migrating
>>>>>>>>>>>>>
>>>>>>>>>>>>> the producers to a new partitioning scheme can be much more
>>>>>>>>>>> streamlined
>>>>>>>>>>>
>>>>>>>>>>> with proper broker support for this. Migrating consumer is a step
>>>>>>>>>>>
>>>>>>>>>>>> that
>>>>>>>>>>>>> might be made completly unnecessary if - for example streams -
>>>>>>>>>>>>> takes
>>>>>>>>>>>>>
>>>>>>>>>>>>> the
>>>>>>>>>>>>>
>>>>>>>>>>>>> gcd as partitioning scheme instead of enforcing 1 to 1. Connect
>>>>>>>>>>> consumers
>>>>>>>>>>>
>>>>>>>>>>>> and other consumers should be fine anyways.
>>>>>>>>>>>>
>>>>>>>>>>> I hope this makes more clear where I was aiming at. The rest needs
>>>>>>>>>>>
>>>>>>>>>>>> to
>>>>>>>>>>>>
>>>>>>>>>>>> be
>>>>>>>>>>>>> figured out. The only danger i see is that when we are
>>>>>>>>>>>> introducing
>>>>>>>>>>>>
>>>>>>>>>>> this
>>>>>>>>>>>
>>>>>>>>>>> feature as supposed in the KIP, it wont help any people depending
>>>>>>>>>>> on
>>>>>>>>>>>
>>>>>>>>>>>> log
>>>>>>>>>>>>> compaction.
>>>>>>>>>>> The other thing I wanted to mention is that I believe the current
>>>>>>>>>>>
>>>>>>>>>>>> suggestion (without copying data over) can be implemented in pure
>>>>>>>>>>>>> userland
>>>>>>>>>>>>> with a custom partitioner and a small feedbackloop from
>>>>>>>>>>>>> ProduceResponse
>>>>>>>>>>>>> =>
>>>>>>>>>>>>> Partitionier in coorporation with a change management system.
>>>>>>>>>>>>>
>>>>>>>>>>>>> Best Jan
>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>> On 28.02.2018 07:13, Dong Lin wrote:
>>>>>>>>>>>>>
>>>>>>>>>>>>> Hey Jan,
>>>>>>>>>>>>>
>>>>>>>>>>>>> I am not sure if it is acceptable for producer to be stopped
>>>>>>>>>>>>> for a
>>>>>>>>>>>>>
>>>>>>>>>>>>> while,
>>>>>>>>>>>>>> particularly for online application which requires low
>>>>>>>>>>>>>> latency. I
>>>>>>>>>>>>>> am
>>>>>>>>>>>>>> also
>>>>>>>>>>>>>> not sure how consumers can switch to a new topic. Does user
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> application
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> needs to explicitly specify a different topic for
>>>>>>>>>>>> producer/consumer
>>>>>>>>>>>>
>>>>>>>>>>>> to
>>>>>>>>>>> subscribe to? It will be helpful for discussion if you can provide
>>>>>>>>>>>
>>>>>>>>>>>> more
>>>>>>>>>>>>> detail on the interface change for this solution.
>>>>>>>>>>>>>
>>>>>>>>>>>> Thanks,
>>>>>>>>>>>>
>>>>>>>>>>>> Dong
>>>>>>>>>>>>>> On Mon, Feb 26, 2018 at 12:48 AM, Jan
>>>>>>>>>>>>>> Filipiak<Jan.Filipiak@trivago.
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> com
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> wrote:
>>>>>>>>>>>> Hi,
>>>>>>>>>>>>
>>>>>>>>>>>> just want to throw my though in. In general the functionality is
>>>>>>>>>>>>>> very
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> usefull, we should though not try to find the architecture to
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> hard
>>>>>>>>>>>>>>> while
>>>>>>>>>>>>>>> implementing.
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> The manual steps would be to
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> create a new topic
>>>>>>>>>>>>>>> the mirrormake from the new old topic to the new topic
>>>>>>>>>>>>>>> wait for mirror making to catch up.
>>>>>>>>>>>>>>> then put the consumers onto the new topic
>>>>>>>>>>>>>>>            (having mirrormaker spit out a mapping from old
>>>>>>>>>>>>>>> offsets to
>>>>>>>>>>>>>>> new
>>>>>>>>>>>>>>> offsets:
>>>>>>>>>>>>>>>                if topic is increased by factor X there is gonna
>>>>>>>>>>>>>>> be a
>>>>>>>>>>>>>>> clean
>>>>>>>>>>>>>>> mapping from 1 offset in the old topic to X offsets in the new
>>>>>>>>>>>>>>> topic,
>>>>>>>>>>>>>>>                if there is no factor then there is no chance to
>>>>>>>>>>>>>>> generate a
>>>>>>>>>>>>>>> mapping that can be reasonable used for continuing)
>>>>>>>>>>>>>>>            make consumers stop at appropriate points and
>>>>>>>>>>>>>>> continue
>>>>>>>>>>>>>>> consumption
>>>>>>>>>>>>>>> with offsets from the mapping.
>>>>>>>>>>>>>>> have the producers stop for a minimal time.
>>>>>>>>>>>>>>> wait for mirrormaker to finish
>>>>>>>>>>>>>>> let producer produce with the new metadata.
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> Instead of implementing the approach suggest in the KIP which
>>>>>>>>>>>>>>> will
>>>>>>>>>>>>>>> leave
>>>>>>>>>>>>>>> log compacted topic completely crumbled and unusable.
>>>>>>>>>>>>>>> I would much rather try to build infrastructure to support the
>>>>>>>>>>>>>>> mentioned
>>>>>>>>>>>>>>> above operations more smoothly.
>>>>>>>>>>>>>>> Especially having producers stop and use another topic is
>>>>>>>>>>>>>>> difficult
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> and
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> it would be nice if one can trigger "invalid metadata"
>>>>>>>>>>>>>> exceptions
>>>>>>>>>>>>>>
>>>>>>>>>>>>> for
>>>>>>>>>>> them
>>>>>>>>>>>
>>>>>>>>>>>> and
>>>>>>>>>>>>>> if one could give topics aliases so that their produces with
>>>>>>>>>>>>>>> the
>>>>>>>>>>>>>>> old
>>>>>>>>>>>>>>> topic
>>>>>>>>>>>>>>> will arrive in the new topic.
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> The downsides are obvious I guess ( having the same data twice
>>>>>>>>>>>>>>> for
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> the
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> transition period, but kafka tends to scale well with
>>>>>>>>>>>>>> datasize).
>>>>>>>>>>>>>>
>>>>>>>>>>>>> So
>>>>>>>>>>>>>
>>>>>>>>>>>>> its a
>>>>>>>>>>>> nicer fit into the architecture.
>>>>>>>>>>>>>> I further want to argument that the functionality by the KIP
>>>>>>>>>>>>>>> can
>>>>>>>>>>>>>>> completely be implementing in "userland" with a custom
>>>>>>>>>>>>>>> partitioner
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> that
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> handles the transition as needed. I would appreciate if
>>>>>>>>>>>>>> someone
>>>>>>>>>>>>>>
>>>>>>>>>>>>> could
>>>>>>>>>>> point
>>>>>>>>>>>
>>>>>>>>>>>> out what a custom partitioner couldn't handle in this case?
>>>>>>>>>>>>>> With the above approach, shrinking a topic becomes the same
>>>>>>>>>>>>>>> steps.
>>>>>>>>>>>>>>> Without
>>>>>>>>>>>>>>> loosing keys in the discontinued partitions.
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> Would love to hear what everyone thinks.
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> Best Jan
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> On 11.02.2018 00:35, Dong Lin wrote:
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> Hi all,
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> I have created KIP-253: Support in-order message delivery with
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> partition
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> expansion. See
>>>>>>>>>>>>>>>> https://cwiki.apache.org/confluence/display/KAFKA/KIP-253%
>>>>>>>>>>>>>>>> 3A+Support+in-order+message+delivery+with+partition+expansio
>>>>>>>>>>>>>>>> n
>>>>>>>>>>>>>>>> .
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> This KIP provides a way to allow messages of the same key
>>>>>>>>>>>>>>>> from
>>>>>>>>>>>>>>>> the
>>>>>>>>>>>>>>>> same
>>>>>>>>>>>>>>>> producer to be consumed in the same order they are produced
>>>>>>>>>>>>>>>> even
>>>>>>>>>>>>>>>> if
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> we
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> expand partition of the topic.
>>>>>>>>>>>>>> Thanks,
>>>>>>>>>>>>> Dong
>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>
>>



Re: [DISCUSS] KIP-253: Support in-order message delivery with partition expansion

Posted by Jun Rao <ju...@confluent.io>.
Hi, Jan,

Thanks for the discussion. Great points.

Let me try to summarize the approach that you are proposing. On the broker
side, we reshuffle the existing data in a topic from current partitions to
the new partitions. Once the reshuffle fully catches up, switch the
consumers to start consuming from the new partitions. If a consumer needs
to rebuild its local state (due to partition changes), let the consumer
rebuild its state by reading all existing data from the new partitions.
Once all consumers have switches over, cut over the producer to the new
partitions.

The pros for this approach are that :
1. There is just one way to rebuild the local state, which is simpler.

The cons for this approach are:
1. Need to copy existing data.
2. The cutover of the producer is a bit complicated since it needs to
coordinate with all consumer groups.
3. The rebuilding of the state in the consumer is from the input topic,
which can be more expensive than rebuilding from the existing state.
4. The broker potentially has to know the partitioning function. If this
needs to be customized at the topic level, it can be a bit messy.

Here is an alternative approach by applying your idea not in the broker,
but in the consumer. When new partitions are added, we don't move existing
data. In KStreams, we first reshuffle the new input data to a new topic T1
with the old number of partitions and feed T1's data to the rest of the
pipeline. In the meantime, KStreams reshuffles all existing data of the
change capture topic to another topic C1 with the new number of partitions.
We can then build the state of the new tasks from C1. Once the new states
have been fully built, we can cut over the consumption to the input topic
and delete T1. This approach works with compacted topic too. If an
application reads from the beginning of a compacted topic, the consumer
will reshuffle the portion of the input when the number of partitions
doesn't match the number of tasks.

The pros of this approach are:
1. No need to copy existing data.
2. Each consumer group can cut over to the new partitions independently.
3. The state is rebuilt from the change capture topic, which is cheaper
than rebuilding from the input topic.
4. Only the KStreams job needs to know the partitioning function.

The cons of this approach are:
1. Potentially the same input topic needs to be reshuffled more than once
in different consumer groups during the transition phase.

What do you think?

Thanks,

Jun



On Thu, Mar 15, 2018 at 1:04 AM, Jan Filipiak <Ja...@trivago.com>
wrote:

> Hi Jun,
>
> thank you for following me on these thoughts. It was important to me to
> feel that kind of understanding for my arguments.
>
> What I was hoping for (I mentioned this earlier) is that we can model the
> case where we do not want to copy the data the exact same way as the case
> when we do copy the data. Maybe you can peek into the mails before to see
> more details for this.
>
> This means we have the same mechanism to transfer consumer groups to
> switch topic. The offset mapping that would be generated would even be
> simpler End Offset of the Old topic => offset 0 off all the partitions of
> the new topic. Then we could model the transition of a non-copy expansion
> the exact same way as a copy-expansion.
>
> I know this only works when topic growth by a factor. But the benefits of
> only growing by a factor are to strong anyways. See Clemens's hint and
> remember that state reshuffling is entirely not needed if one doesn't want
> to grow processing power.
>
> I think these benefits should be clear, and that there is basically no
> downside to what is currently at hand but just makes everything easy.
>
> One thing you need to know is. that if you do not offer rebuilding a log
> compacted topic like i suggest that even if you have consumer state
> reshuffling. The topic is broken and can not be used to bootstrap new
> consumers. They don't know if they need to apply a key from and old
> partition or not. This is a horrible downside I haven't seen a solution for
> in the email conversation.
>
> I argue to:
>
> Only grow topic by a factor always.
> Have the "no copy consumer" transition as the trivial case of the "copy
> consumer transition".
> If processors needs to be scaled, let them rebuild from the new topic and
> leave the old running in the mean time.
> Do not implement key shuffling in streams.
>
> I hope I can convince you especially with the fact how I want to handle
> consumer transition. I think
> you didn't quite understood me there before. I think the term "new topic"
> intimidated you a little.
> How we solve this on disc doesn't really matter, If the data goes into the
> same Dir or a different Dir or anything. I do think that it needs to
> involve at least rolling a new segment for the existing partitions.
> But most of the transitions should work without restarting consumers.
> (newer consumers with support for this). But with new topic i just meant
> the topic that now has a different partition count. Plenty of ways to
> handle that (versions, aliases)
>
> Hope I can further get my idea across.
>
> Best Jan
>
>
>
>
>
>
> On 14.03.2018 02:45, Jun Rao wrote:
>
>> Hi, Jan,
>>
>> Thanks for sharing your view.
>>
>> I agree with you that recopying the data potentially makes the state
>> management easier since the consumer can just rebuild its state from
>> scratch (i.e., no need for state reshuffling).
>>
>> On the flip slide, I saw a few disadvantages of the approach that you
>> suggested. (1) Building the state from the input topic from scratch is in
>> general less efficient than state reshuffling. Let's say one computes a
>> count per key from an input topic. The former requires reading all
>> existing
>> records in the input topic whereas the latter only requires reading data
>> proportional to the number of unique keys. (2) The switching of the topic
>> needs modification to the application. If there are many applications on a
>> topic, coordinating such an effort may not be easy. Also, it's not clear
>> how to enforce exactly-once semantic during the switch. (3) If a topic
>> doesn't need any state management, recopying the data seems wasteful. In
>> that case, in place partition expansion seems more desirable.
>>
>> I understand your concern about adding complexity in KStreams. But,
>> perhaps
>> we could iterate on that a bit more to see if it can be simplified.
>>
>> Jun
>>
>>
>> On Mon, Mar 12, 2018 at 11:21 PM, Jan Filipiak <Ja...@trivago.com>
>> wrote:
>>
>> Hi Jun,
>>>
>>> I will focus on point 61 as I think its _the_ fundamental part that I
>>> cant
>>> get across at the moment.
>>>
>>> Kafka is the platform to have state materialized multiple times from one
>>> input. I emphasize this: It is the building block in architectures that
>>> allow you to
>>> have your state maintained multiple times. You put a message in once, and
>>> you have it pop out as often as you like. I believe you understand this.
>>>
>>> Now! The path of thinking goes the following: I am using apache kafka and
>>> I _want_ my state multiple times. What am I going todo?
>>>
>>> A) Am I going to take my state that I build up, plunge some sort of RPC
>>> layer ontop of it, use that RPC layer to throw my records across
>>> instances?
>>> B) Am I just going to read the damn message twice?
>>>
>>> Approach A is fundamentally flawed and a violation of all that is good
>>> and
>>> holy in kafka deployments. I can not understand how this Idea can come in
>>> the first place.
>>> (I do understand: IQ in streams, they polluted the kafka streams codebase
>>> really bad already. It is not funny! I think they are equally flawed as
>>> A)
>>>
>>> I say, we do what Kafka is good at. We repartition the topic once. We
>>> switch the consumers.
>>> (Those that need more partitions are going to rebuild their state in
>>> multiple partitions by reading the new topic, those that don't just
>>> assign
>>> the new partitions properly)
>>> We switch producers. Done!
>>>
>>> The best thing! It is trivial, hipster stream processor will have an easy
>>> time with that aswell. Its so super simple. And simple IS good!
>>> It is what kafka was build todo. It is how we do it today. All I am
>>> saying
>>> is that a little broker help doing the producer swap is super useful.
>>>
>>> For everyone interested in why kafka is so powerful with approach B,
>>> please watch https://youtu.be/bEbeZPVo98c?t=1633
>>> I already looked up a good point in time, I think after 5 minutes the
>>> "state" topic is handled and you should be able to understand me
>>> and inch better.
>>>
>>> Please do not do A to the project, it deserves better!
>>>
>>> Best Jan
>>>
>>>
>>>
>>> On 13.03.2018 02:40, Jun Rao wrote:
>>>
>>> Hi, Jan,
>>>>
>>>> Thanks for the reply. A few more comments below.
>>>>
>>>> 50. Ok, we can think a bit harder for supporting compacted topics.
>>>>
>>>> 51. This is a fundamental design question. In the more common case, the
>>>> reason why someone wants to increase the number of partitions is that
>>>> the
>>>> consumer application is slow and one wants to run more consumer
>>>> instances
>>>> to increase the degree of parallelism. So, fixing the number of running
>>>> consumer instances when expanding the partitions won't help this case.
>>>> If
>>>> we do need to increase the number of consumer instances, we need to
>>>> somehow
>>>> reshuffle the state of the consumer across instances. What we have been
>>>> discussing in this KIP is whether we can do this more effectively
>>>> through
>>>> the KStream library (e.g. through a 2-phase partition expansion). This
>>>> will
>>>> add some complexity, but it's probably better than everyone doing this
>>>> in
>>>> the application space. The recopying approach that you mentioned doesn't
>>>> seem to address the consumer state management issue when the consumer
>>>> switches from an old to a new topic.
>>>>
>>>> 52. As for your example, it depends on whether the join key is the same
>>>> between (A,B) and (B,C). If the join key is the same, we can do a
>>>> 2-phase
>>>> partition expansion of A, B, and C together. If the join keys are
>>>> different, one would need to repartition the data on a different key for
>>>> the second join, then the partition expansion can be done independently
>>>> between (A,B) and (B,C).
>>>>
>>>> 53. If you always fix the number of consumer instances, we you described
>>>> works. However, as I mentioned in #51, I am not sure how your proposal
>>>> deals with consumer states when the number of consumer instances grows.
>>>> Also, it just seems that it's better to avoid re-copying the existing
>>>> data.
>>>>
>>>> 60. "just want to throw in my question from the longer email in the
>>>> other
>>>> Thread here. How will the bloom filter help a new consumer to decide to
>>>> apply the key or not?" Not sure that I fully understood your question.
>>>> The
>>>> consumer just reads whatever key is in the log. The bloom filter just
>>>> helps
>>>> clean up the old keys.
>>>>
>>>> 61. "Why can we afford having a topic where its apparently not possible
>>>> to
>>>> start a new application on? I think this is an overall flaw of the
>>>> discussed idea here. Not playing attention to the overall architecture."
>>>> Could you explain a bit more when one can't start a new application?
>>>>
>>>> Jun
>>>>
>>>>
>>>>
>>>> On Sat, Mar 10, 2018 at 1:40 AM, Jan Filipiak <Jan.Filipiak@trivago.com
>>>> >
>>>> wrote:
>>>>
>>>> Hi Jun, thanks for your mail.
>>>>
>>>>> Thank you for your questions!
>>>>> I think they are really good and tackle the core of the problem I see.
>>>>>
>>>>> I will answer inline, mostly but still want to set the tone here.
>>>>>
>>>>> The core strength of kafka is what Martin once called the
>>>>> kappa-Architecture. How does this work?
>>>>> You have everything as a log as in kafka. When you need to change
>>>>> something.
>>>>> You create the new version of your application and leave it running in
>>>>> parallel.
>>>>> Once the new version is good you switch your users to use the new
>>>>> application.
>>>>>
>>>>> The online reshuffling effectively breaks this architecture and I think
>>>>> the switch in thinking here is more harmful
>>>>> than any details about the partitioning function to allow such a
>>>>> change.
>>>>> I
>>>>> feel with my suggestion we are the closest to
>>>>> the original and battle proven architecture and I can only warn to move
>>>>> away from it.
>>>>>
>>>>> I might have forgotten something, sometimes its hard for me to getting
>>>>> all
>>>>> the thoughts captured in a mail, but I hope the comments inline will
>>>>> further make my concern clear, and put some emphasis on why I prefer my
>>>>> solution ;)
>>>>>
>>>>> One thing we should all be aware of when discussing this, and I think
>>>>> Dong
>>>>> should have mentioned it (maybe he did).
>>>>> We are not discussing all of this out of thin air but there is an
>>>>> effort
>>>>> in the Samza project.
>>>>>
>>>>> https://cwiki.apache.org/confluence/display/SAMZA/SEP-5%3A+
>>>>> Enable+partition+expansion+of+input+streams
>>>>> https://issues.apache.org/jira/browse/SAMZA-1293
>>>>>
>>>>> To be clear. I think SEP-5 (state of last week, dont know if it adapted
>>>>> to
>>>>> this discussion) is on a way better path than KIP-253, and I can't
>>>>> really
>>>>> explain why.
>>>>>
>>>>> Best Jan,
>>>>>
>>>>> nice weekend everyone
>>>>>
>>>>>
>>>>> On 09.03.2018 03:36, Jun Rao wrote:
>>>>>
>>>>> Hi, Jan,
>>>>>
>>>>>> Thanks for the feedback. Just some comments on the earlier points that
>>>>>> you
>>>>>> mentioned.
>>>>>>
>>>>>> 50. You brought up the question of whether existing data needs to be
>>>>>> copied
>>>>>> during partition expansion. My understand of your view is that avoid
>>>>>> copying existing data will be more efficient, but it doesn't work well
>>>>>> with
>>>>>> compacted topics since some keys in the original partitions will never
>>>>>> be
>>>>>> cleaned. It would be useful to understand your use case of compacted
>>>>>> topics
>>>>>> a bit more. In the common use case, the data volume in a compacted
>>>>>> topic
>>>>>> may not be large. So, I am not sure if there is a strong need to
>>>>>> expand
>>>>>> partitions in a compacted topic, at least initially.
>>>>>>
>>>>>> I do agree. State is usually smaller. Update rates might be also
>>>>>>
>>>>> competitively high.
>>>>> Doing Log-compaction (even beeing very efficient and configurable) is
>>>>> also
>>>>> a more expensive operation than
>>>>> just discarding old segments. Further if you want to use more consumers
>>>>> processing the events
>>>>> you also have to grow the number of partitions. Especially for
>>>>> use-cases
>>>>> we do (KIP-213) a tiny state full
>>>>> table might be very expensive to process if it joins against a huge
>>>>> table.
>>>>>
>>>>> I can just say we have been in the spot of needing to grow log
>>>>> compacted
>>>>> topics. Mainly for processing power we can bring to the table.
>>>>>
>>>>> Further i am not at all concerned about the extra spaced used by
>>>>> "garbage
>>>>> keys". I am more concerned about the correctness of innocent consumers.
>>>>> The
>>>>> logic becomes complicated. Say for streams one would need to load the
>>>>> record into state but not forward it the topology ( to have it
>>>>> available
>>>>> for shuffeling). I rather have it simple and a topic clean regardless
>>>>> if
>>>>> it
>>>>> still has its old partition count. Especially with multiple partitions
>>>>> growth's I think it becomes insanely hard to to this shuffle correct.
>>>>> Maybe
>>>>> Streams and Samza can do it. Especially if you do "hipster stream
>>>>> processing" <https://www.confluent.io/blog/introducing-kafka-streams-
>>>>> stream-processing-made-simple/>. This makes kafka way to complicated.
>>>>> With my approach I think its way simpler because the topic has no
>>>>> "history"
>>>>> in terms of partitioning but is always clean.
>>>>>
>>>>>
>>>>> 51. "Growing the topic by an integer factor does not require any state
>>>>>
>>>>>> redistribution at all." Could you clarify this a bit more? Let's say
>>>>>> you
>>>>>> have a consumer app that computes the windowed count per key. If you
>>>>>> double
>>>>>> the number of partitions from 1 to 2 and grow the consumer instances
>>>>>> from
>>>>>> 1
>>>>>> to 2, we would need to redistribute some of the counts to the new
>>>>>> consumer
>>>>>> instance. Regarding to linear hashing, it's true that it won't solve
>>>>>> the
>>>>>> problem with compacted topics. The main benefit is that it
>>>>>> redistributes
>>>>>> the keys in one partition to no more than two partitions, which could
>>>>>> help
>>>>>> redistribute the state.
>>>>>>
>>>>>> You don't need to spin up a new consumer in this case. every consumer
>>>>>>
>>>>> would just read every partition with the (partition % num_task) task.
>>>>> it
>>>>> will still have the previous data right there and can go on.
>>>>>
>>>>> This sounds contradictory to what I said before, but please bear with
>>>>> me.
>>>>>
>>>>> 52. Good point on coordinating the expansion of 2 topics that need to
>>>>> be
>>>>>
>>>>>> joined together. This is where the 2-phase partition expansion could
>>>>>> potentially help. In the first phase, we could add new partitions to
>>>>>> the 2
>>>>>> topics one at a time but without publishing to the new patitions.
>>>>>> Then,
>>>>>> we
>>>>>> can add new consumer instances to pick up the new partitions. In this
>>>>>> transition phase, no reshuffling is needed since no data is coming
>>>>>> from
>>>>>> the
>>>>>> new partitions. Finally, we can enable the publishing to the new
>>>>>> partitions.
>>>>>>
>>>>>> I think its even worse than you think. I would like to introduce the
>>>>>>
>>>>> Term
>>>>> transitive copartitioning. Imagine
>>>>> 2 streams application. One joins (A,B) the other (B,C) then there is a
>>>>> transitive copartition requirement for
>>>>> (A,C) to be copartitioned aswell. This can spread significantly and
>>>>> require many consumers to adapt at the same time.
>>>>>
>>>>> It is also not entirely clear to me how you not need reshuffling in
>>>>> this
>>>>> case. If A has a record that never gets updated after the expansion and
>>>>> the
>>>>> coresponding B record moves to a new partition. How shall they meet w/o
>>>>> shuffle?
>>>>>
>>>>> 53. "Migrating consumer is a step that might be made completly
>>>>>
>>>>>> unnecessary
>>>>>> if - for example streams - takes the gcd as partitioning scheme
>>>>>> instead
>>>>>> of
>>>>>> enforcing 1 to 1." Not sure that I fully understand this. I think you
>>>>>> mean
>>>>>> that a consumer application can run more instances than the number of
>>>>>> partitions. In that case, the consumer can just repartitioning the
>>>>>> input
>>>>>> data according to the number of instances. This is possible, but just
>>>>>> has
>>>>>> the overhead of reshuffling the data.
>>>>>>
>>>>>> No what I meant is ( that is also your question i think Mathias) that
>>>>>> if
>>>>>>
>>>>> you grow a topic by a factor.
>>>>> Even if your processor is statefull you can can just assign all the
>>>>> multiples of the previous partition to
>>>>> this consumer and the state to keep processing correctly will be
>>>>> present
>>>>> w/o any shuffling.
>>>>>
>>>>> Say you have an assignment
>>>>> Statefull consumer => partition
>>>>> 0 => 0
>>>>> 1 => 1
>>>>> 2 => 2
>>>>>
>>>>> and you grow you topic by 4 you get,
>>>>>
>>>>> 0 => 0,3,6,9
>>>>> 1 => 1,4,7,10
>>>>> 2 => 2,5,8,11
>>>>>
>>>>> Say your hashcode is 8. 8%3 => 2  before so consumer for partition 2
>>>>> has
>>>>> it.
>>>>> Now you you have 12 partitions so 8%12 => 8, so it goes into partition
>>>>> 8
>>>>> which is assigned to the same consumer
>>>>> who had 2 before and therefore knows the key.
>>>>>
>>>>> Userland reshuffeling is there as an options. And it does exactly what
>>>>> I
>>>>> suggest. And I think its the perfect strategie. All I am suggestion is
>>>>> broker side support to switch the producers to the newly partitioned
>>>>> topic.
>>>>> Then the old (to few partition topic) can go away.  Remember the list
>>>>> of
>>>>> steps in the beginning of this thread. If one has broker support for
>>>>> all
>>>>> where its required and streams support for those that aren’t
>>>>> necessarily.
>>>>> Then one has solved the problem.
>>>>> I repeat it because I think its important. I am really happy that you
>>>>> brought that up! because its 100% what I want just with the differences
>>>>> to
>>>>> have an option to discard the to small topic later (after all consumers
>>>>> adapted). And to have order correct there. I need broker support
>>>>> managing
>>>>> the copy process + the produces and fence them against each other. I
>>>>> also
>>>>> repeat. the copy process can run for weeks in the worst case. Copying
>>>>> the
>>>>> data is not the longest task migrating consumers might very well be.
>>>>> Once all consumers switched and copying is really up to date (think ISR
>>>>> like up to date) only then we stop the producer, wait for the copy to
>>>>> finish and use the new topic for producing.
>>>>>
>>>>> After this the topic is perfect in shape. and no one needs to worry
>>>>> about
>>>>> complicated stuff. (old keys hanging around might arrive in some other
>>>>> topic later.....). can only imagine how many tricky bugs gonna arrive
>>>>> after
>>>>> someone had grown and shrunken is topic 10 times.
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> 54. "The other thing I wanted to mention is that I believe the current
>>>>>
>>>>>> suggestion (without copying data over) can be implemented in pure
>>>>>> userland
>>>>>> with a custom partitioner and a small feedbackloop from
>>>>>> ProduceResponse
>>>>>> =>
>>>>>> Partitionier in coorporation with a change management system." I am
>>>>>> not
>>>>>> sure a customized partitioner itself solves the problem. We probably
>>>>>> need
>>>>>> some broker side support to enforce when the new partitions can be
>>>>>> used.
>>>>>> We
>>>>>> also need some support on the consumer/kstream side to preserve the
>>>>>> per
>>>>>> key
>>>>>> ordering and potentially migrate the processing state. This is not
>>>>>> trivial
>>>>>> and I am not sure if it's ideal to fully push to the application
>>>>>> space.
>>>>>>
>>>>>> Broker support is defenitly the preferred way here. I have nothing
>>>>>>
>>>>> against
>>>>> broker support.
>>>>> I tried to say that for what I would preffer - copying the data over,
>>>>> at
>>>>> least for log compacted topics -
>>>>> I would require more broker support than the KIP currently offers.
>>>>>
>>>>>
>>>>>
>>>>> Jun
>>>>>
>>>>>>
>>>>>> On Tue, Mar 6, 2018 at 10:33 PM, Jan Filipiak <
>>>>>> Jan.Filipiak@trivago.com
>>>>>> wrote:
>>>>>>
>>>>>> Hi Dong,
>>>>>>
>>>>>> are you actually reading my emails, or are you just using the thread I
>>>>>>> started for general announcements regarding the KIP?
>>>>>>>
>>>>>>> I tried to argue really hard against linear hashing. Growing the
>>>>>>> topic
>>>>>>> by
>>>>>>> an integer factor does not require any state redistribution at all. I
>>>>>>> fail
>>>>>>> to see completely where linear hashing helps on log compacted topics.
>>>>>>>
>>>>>>> If you are not willing to explain to me what I might be overlooking:
>>>>>>> that
>>>>>>> is fine.
>>>>>>> But I ask you to not reply to my emails then. Please understand my
>>>>>>> frustration with this.
>>>>>>>
>>>>>>> Best Jan
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> On 06.03.2018 19:38, Dong Lin wrote:
>>>>>>>
>>>>>>> Hi everyone,
>>>>>>>
>>>>>>> Thanks for all the comments! It appears that everyone prefers linear
>>>>>>>> hashing because it reduces the amount of state that needs to be
>>>>>>>> moved
>>>>>>>> between consumers (for stream processing). The KIP has been updated
>>>>>>>> to
>>>>>>>> use
>>>>>>>> linear hashing.
>>>>>>>>
>>>>>>>> Regarding the migration endeavor: it seems that migrating producer
>>>>>>>> library
>>>>>>>> to use linear hashing should be pretty straightforward without
>>>>>>>> much operational endeavor. If we don't upgrade client library to use
>>>>>>>> this
>>>>>>>> KIP, we can not support in-order delivery after partition is changed
>>>>>>>> anyway. Suppose we upgrade client library to use this KIP, if
>>>>>>>> partition
>>>>>>>> number is not changed, the key -> partition mapping will be exactly
>>>>>>>> the
>>>>>>>> same as it is now because it is still determined using
>>>>>>>> murmur_hash(key)
>>>>>>>> %
>>>>>>>> original_partition_num. In other words, this change is backward
>>>>>>>> compatible.
>>>>>>>>
>>>>>>>> Regarding the load distribution: if we use linear hashing, the load
>>>>>>>> may
>>>>>>>> be
>>>>>>>> unevenly distributed because those partitions which are not split
>>>>>>>> may
>>>>>>>> receive twice as much traffic as other partitions that are split.
>>>>>>>> This
>>>>>>>> issue can be mitigated by creating topic with partitions that are
>>>>>>>> several
>>>>>>>> times the number of consumers. And there will be no imbalance if the
>>>>>>>> partition number is always doubled. So this imbalance seems
>>>>>>>> acceptable.
>>>>>>>>
>>>>>>>> Regarding storing the partition strategy as per-topic config: It
>>>>>>>> seems
>>>>>>>> not
>>>>>>>> necessary since we can still use murmur_hash as the default hash
>>>>>>>> function
>>>>>>>> and additionally apply the linear hashing algorithm if the partition
>>>>>>>> number
>>>>>>>> has increased. Not sure if there is any use-case for producer to
>>>>>>>> use a
>>>>>>>> different hash function. Jason, can you check if there is some
>>>>>>>> use-case
>>>>>>>> that I missed for using the per-topic partition strategy?
>>>>>>>>
>>>>>>>> Regarding how to reduce latency (due to state store/load) in stream
>>>>>>>> processing consumer when partition number changes: I need to read
>>>>>>>> the
>>>>>>>> Kafka
>>>>>>>> Stream code to understand how Kafka Stream currently migrate state
>>>>>>>> between
>>>>>>>> consumers when the application is added/removed for a given job. I
>>>>>>>> will
>>>>>>>> reply after I finish reading the documentation and code.
>>>>>>>>
>>>>>>>>
>>>>>>>> Thanks,
>>>>>>>> Dong
>>>>>>>>
>>>>>>>>
>>>>>>>> On Mon, Mar 5, 2018 at 10:43 AM, Jason Gustafson <
>>>>>>>> jason@confluent.io>
>>>>>>>> wrote:
>>>>>>>>
>>>>>>>> Great discussion. I think I'm wondering whether we can continue to
>>>>>>>> leave
>>>>>>>>
>>>>>>>> Kafka agnostic to the partitioning strategy. The challenge is
>>>>>>>>
>>>>>>>>> communicating
>>>>>>>>> the partitioning logic from producers to consumers so that the
>>>>>>>>> dependencies
>>>>>>>>> between each epoch can be determined. For the sake of discussion,
>>>>>>>>> imagine
>>>>>>>>> you did something like the following:
>>>>>>>>>
>>>>>>>>> 1. The name (and perhaps version) of a partitioning strategy is
>>>>>>>>> stored
>>>>>>>>> in
>>>>>>>>> topic configuration when a topic is created.
>>>>>>>>> 2. The producer looks up the partitioning strategy before writing
>>>>>>>>> to
>>>>>>>>> a
>>>>>>>>> topic and includes it in the produce request (for fencing). If it
>>>>>>>>> doesn't
>>>>>>>>> have an implementation for the configured strategy, it fails.
>>>>>>>>> 3. The consumer also looks up the partitioning strategy and uses it
>>>>>>>>> to
>>>>>>>>> determine dependencies when reading a new epoch. It could either
>>>>>>>>> fail
>>>>>>>>> or
>>>>>>>>> make the most conservative dependency assumptions if it doesn't
>>>>>>>>> know
>>>>>>>>> how
>>>>>>>>> to
>>>>>>>>> implement the partitioning strategy. For the consumer, the new
>>>>>>>>> interface
>>>>>>>>> might look something like this:
>>>>>>>>>
>>>>>>>>> // Return the partition dependencies following an epoch bump
>>>>>>>>> Map<Integer, List<Integer>> dependencies(int
>>>>>>>>> numPartitionsBeforeEpochBump,
>>>>>>>>> int numPartitionsAfterEpochBump)
>>>>>>>>>
>>>>>>>>> The unordered case then is just a particular implementation which
>>>>>>>>> never
>>>>>>>>> has
>>>>>>>>> any epoch dependencies. To implement this, we would need some way
>>>>>>>>> for
>>>>>>>>> the
>>>>>>>>> consumer to find out how many partitions there were in each epoch,
>>>>>>>>> but
>>>>>>>>> maybe that's not too unreasonable.
>>>>>>>>>
>>>>>>>>> Thanks,
>>>>>>>>> Jason
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> On Mon, Mar 5, 2018 at 4:51 AM, Jan Filipiak <
>>>>>>>>> Jan.Filipiak@trivago.com
>>>>>>>>> wrote:
>>>>>>>>>
>>>>>>>>> Hi Dong
>>>>>>>>>
>>>>>>>>> thank you very much for your questions.
>>>>>>>>>
>>>>>>>>>> regarding the time spend copying data across:
>>>>>>>>>> It is correct that copying data from a topic with one partition
>>>>>>>>>> mapping
>>>>>>>>>>
>>>>>>>>>> to
>>>>>>>>>>
>>>>>>>>>> a topic with a different partition mapping takes way longer than
>>>>>>>>> we
>>>>>>>>> can
>>>>>>>>>
>>>>>>>>> stop producers. Tens of minutes is a very optimistic estimate here.
>>>>>>>>>> Many
>>>>>>>>>> people can not afford copy full steam and therefore will have some
>>>>>>>>>> rate
>>>>>>>>>> limiting in place, this can bump the timespan into the day's. The
>>>>>>>>>> good
>>>>>>>>>>
>>>>>>>>>> part
>>>>>>>>>>
>>>>>>>>>> is that the vast majority of the data can be copied while the
>>>>>>>>> producers
>>>>>>>>>
>>>>>>>>> are
>>>>>>>>>>
>>>>>>>>>> still going. One can then, piggyback the consumers ontop of this
>>>>>>>>>
>>>>>>>>> timeframe,
>>>>>>>>>>
>>>>>>>>>> by the method mentioned (provide them an mapping from their old
>>>>>>>>> offsets
>>>>>>>>>
>>>>>>>>> to
>>>>>>>>>>
>>>>>>>>>> new offsets in their repartitioned topics. In that way we separate
>>>>>>>>>
>>>>>>>>> migration of consumers from migration of producers (decoupling
>>>>>>>>>> these
>>>>>>>>>> is
>>>>>>>>>> what kafka is strongest at). The time to actually swap over the
>>>>>>>>>> producers
>>>>>>>>>> should be kept minimal by ensuring that when a swap attempt is
>>>>>>>>>> started
>>>>>>>>>>
>>>>>>>>>> the
>>>>>>>>>>
>>>>>>>>>> consumer copying over should be very close to the log end and is
>>>>>>>>>
>>>>>>>>> expected
>>>>>>>>>> to finish within the next fetch. The operation should have a
>>>>>>>>>> time-out
>>>>>>>>>> and
>>>>>>>>>> should be "reattemtable".
>>>>>>>>>>
>>>>>>>>>> Importance of logcompaction:
>>>>>>>>>> If a producer produces key A, to partiton 0, its forever gonna be
>>>>>>>>>> there,
>>>>>>>>>> unless it gets deleted. The record might sit in there for years. A
>>>>>>>>>> new
>>>>>>>>>> producer started with the new partitions will fail to delete the
>>>>>>>>>> record
>>>>>>>>>>
>>>>>>>>>> in
>>>>>>>>>>
>>>>>>>>>> the correct partition. Th record will be there forever and one can
>>>>>>>>> not
>>>>>>>>>
>>>>>>>>> reliable bootstrap new consumers. I cannot see how linear hashing
>>>>>>>>>> can
>>>>>>>>>>
>>>>>>>>>> solve
>>>>>>>>>>
>>>>>>>>>> this.
>>>>>>>>>
>>>>>>>>> Regarding your skipping of userland copying:
>>>>>>>>>> 100%, copying the data across in userland is, as far as i can see,
>>>>>>>>>> only
>>>>>>>>>> a
>>>>>>>>>> usecase for log compacted topics. Even for logcompaction +
>>>>>>>>>> retentions
>>>>>>>>>> it
>>>>>>>>>> should only be opt-in. Why did I bring it up? I think log
>>>>>>>>>> compaction
>>>>>>>>>> is
>>>>>>>>>> a
>>>>>>>>>> very important feature to really embrace kafka as a "data
>>>>>>>>>> plattform".
>>>>>>>>>> The
>>>>>>>>>> point I also want to make is that copying data this way is
>>>>>>>>>> completely
>>>>>>>>>> inline with the kafka architecture. it only consists of reading
>>>>>>>>>> and
>>>>>>>>>>
>>>>>>>>>> writing
>>>>>>>>>>
>>>>>>>>>> to topics.
>>>>>>>>>
>>>>>>>>> I hope it clarifies more why I think we should aim for more than
>>>>>>>>>> the
>>>>>>>>>> current KIP. I fear that once the KIP is done not much more effort
>>>>>>>>>> will
>>>>>>>>>>
>>>>>>>>>> be
>>>>>>>>>>
>>>>>>>>>> taken.
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> On 04.03.2018 02:28, Dong Lin wrote:
>>>>>>>>>>
>>>>>>>>>> Hey Jan,
>>>>>>>>>>
>>>>>>>>>> In the current proposal, the consumer will be blocked on waiting
>>>>>>>>>> for
>>>>>>>>>>
>>>>>>>>>>> other
>>>>>>>>>>>
>>>>>>>>>>> consumers of the group to consume up to a given offset. In most
>>>>>>>>>> cases,
>>>>>>>>>> all
>>>>>>>>>> consumers should be close to the LEO of the partitions when the
>>>>>>>>>> partition
>>>>>>>>>> expansion happens. Thus the time waiting should not be long e.g.
>>>>>>>>>> on
>>>>>>>>>> the
>>>>>>>>>>
>>>>>>>>>> order of seconds. On the other hand, it may take a long time to
>>>>>>>>>> wait
>>>>>>>>>>
>>>>>>>>>>> for
>>>>>>>>>>> the entire partition to be copied -- the amount of time is
>>>>>>>>>>> proportional
>>>>>>>>>>>
>>>>>>>>>>> to
>>>>>>>>>>>
>>>>>>>>>>> the amount of existing data in the partition, which can take
>>>>>>>>>> tens of
>>>>>>>>>>
>>>>>>>>>> minutes. So the amount of time that we stop consumers may not be
>>>>>>>>>> on
>>>>>>>>>>
>>>>>>>>>>> the
>>>>>>>>>>> same order of magnitude.
>>>>>>>>>>>
>>>>>>>>>>> If we can implement this suggestion without copying data over in
>>>>>>>>>>> purse
>>>>>>>>>>> userland, it will be much more valuable. Do you have ideas on how
>>>>>>>>>>> this
>>>>>>>>>>>
>>>>>>>>>>> can
>>>>>>>>>>>
>>>>>>>>>>> be done?
>>>>>>>>>>
>>>>>>>>>> Not sure why the current KIP not help people who depend on log
>>>>>>>>>>
>>>>>>>>>>> compaction.
>>>>>>>>>>>
>>>>>>>>>>> Could you elaborate more on this point?
>>>>>>>>>>
>>>>>>>>>> Thanks,
>>>>>>>>>>
>>>>>>>>>>> Dong
>>>>>>>>>>>
>>>>>>>>>>> On Wed, Feb 28, 2018 at 10:55 PM, Jan
>>>>>>>>>>> Filipiak<Jan.Filipiak@trivago.
>>>>>>>>>>> com
>>>>>>>>>>> wrote:
>>>>>>>>>>>
>>>>>>>>>>> Hi Dong,
>>>>>>>>>>>
>>>>>>>>>>> I tried to focus on what the steps are one can currently perform
>>>>>>>>>>> to
>>>>>>>>>>>
>>>>>>>>>>> expand
>>>>>>>>>>>> or shrink a keyed topic while maintaining a top notch semantics.
>>>>>>>>>>>> I can understand that there might be confusion about "stopping
>>>>>>>>>>>> the
>>>>>>>>>>>> consumer". It is exactly the same as proposed in the KIP. there
>>>>>>>>>>>> needs
>>>>>>>>>>>>
>>>>>>>>>>>> to
>>>>>>>>>>>>
>>>>>>>>>>>> be
>>>>>>>>>>>
>>>>>>>>>> a time the producers agree on the new partitioning. The extra
>>>>>>>>>>
>>>>>>>>>>> semantics I
>>>>>>>>>>>>
>>>>>>>>>>>> want to put in there is that we have a possibility to wait until
>>>>>>>>>>>
>>>>>>>>>> all
>>>>>>>>>>
>>>>>>>>>> the
>>>>>>>>>>
>>>>>>>>>>> existing data
>>>>>>>>>>>
>>>>>>>>>> is copied over into the new partitioning scheme. When I say
>>>>>>>>>> stopping
>>>>>>>>>>
>>>>>>>>>>> I
>>>>>>>>>>>> think more of having a memory barrier that ensures the
>>>>>>>>>>>> ordering. I
>>>>>>>>>>>> am
>>>>>>>>>>>> still
>>>>>>>>>>>> aming for latencies  on the scale of leader failovers.
>>>>>>>>>>>>
>>>>>>>>>>>> Consumers have to explicitly adapt the new partitioning scheme
>>>>>>>>>>>> in
>>>>>>>>>>>> the
>>>>>>>>>>>> above scenario. The reason is that in these cases where you are
>>>>>>>>>>>>
>>>>>>>>>>>> dependent
>>>>>>>>>>>>
>>>>>>>>>>>> on a particular partitioning scheme, you also have other topics
>>>>>>>>>>>
>>>>>>>>>> that
>>>>>>>>>>
>>>>>>>>>> have
>>>>>>>>>>
>>>>>>>>>>> co-partition enforcements or the kind -frequently. Therefore all
>>>>>>>>>>>
>>>>>>>>>> your
>>>>>>>>>>
>>>>>>>>>> other
>>>>>>>>>>
>>>>>>>>>>> input topics might need to grow accordingly.
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>> What I was suggesting was to streamline all these operations as
>>>>>>>>>>>> best
>>>>>>>>>>>> as
>>>>>>>>>>>> possible to have "real" partition grow and shrinkage going on.
>>>>>>>>>>>>
>>>>>>>>>>>> Migrating
>>>>>>>>>>>>
>>>>>>>>>>>> the producers to a new partitioning scheme can be much more
>>>>>>>>>>>
>>>>>>>>>> streamlined
>>>>>>>>>>
>>>>>>>>>> with proper broker support for this. Migrating consumer is a step
>>>>>>>>>>
>>>>>>>>>>> that
>>>>>>>>>>>> might be made completly unnecessary if - for example streams -
>>>>>>>>>>>> takes
>>>>>>>>>>>>
>>>>>>>>>>>> the
>>>>>>>>>>>>
>>>>>>>>>>>> gcd as partitioning scheme instead of enforcing 1 to 1. Connect
>>>>>>>>>>>
>>>>>>>>>> consumers
>>>>>>>>>>
>>>>>>>>>>> and other consumers should be fine anyways.
>>>>>>>>>>>
>>>>>>>>>> I hope this makes more clear where I was aiming at. The rest needs
>>>>>>>>>>
>>>>>>>>>>> to
>>>>>>>>>>>
>>>>>>>>>>> be
>>>>>>>>>>>>
>>>>>>>>>>>> figured out. The only danger i see is that when we are
>>>>>>>>>>> introducing
>>>>>>>>>>>
>>>>>>>>>> this
>>>>>>>>>>
>>>>>>>>>> feature as supposed in the KIP, it wont help any people depending
>>>>>>>>>> on
>>>>>>>>>>
>>>>>>>>>>> log
>>>>>>>>>>>>
>>>>>>>>>>>> compaction.
>>>>>>>>>>>
>>>>>>>>>> The other thing I wanted to mention is that I believe the current
>>>>>>>>>>
>>>>>>>>>>> suggestion (without copying data over) can be implemented in pure
>>>>>>>>>>>> userland
>>>>>>>>>>>> with a custom partitioner and a small feedbackloop from
>>>>>>>>>>>> ProduceResponse
>>>>>>>>>>>> =>
>>>>>>>>>>>> Partitionier in coorporation with a change management system.
>>>>>>>>>>>>
>>>>>>>>>>>> Best Jan
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>> On 28.02.2018 07:13, Dong Lin wrote:
>>>>>>>>>>>>
>>>>>>>>>>>> Hey Jan,
>>>>>>>>>>>>
>>>>>>>>>>>> I am not sure if it is acceptable for producer to be stopped
>>>>>>>>>>>> for a
>>>>>>>>>>>>
>>>>>>>>>>>> while,
>>>>>>>>>>>>> particularly for online application which requires low
>>>>>>>>>>>>> latency. I
>>>>>>>>>>>>> am
>>>>>>>>>>>>> also
>>>>>>>>>>>>> not sure how consumers can switch to a new topic. Does user
>>>>>>>>>>>>>
>>>>>>>>>>>>> application
>>>>>>>>>>>>>
>>>>>>>>>>>>> needs to explicitly specify a different topic for
>>>>>>>>>>>>
>>>>>>>>>>> producer/consumer
>>>>>>>>>>>
>>>>>>>>>>> to
>>>>>>>>>>
>>>>>>>>>> subscribe to? It will be helpful for discussion if you can provide
>>>>>>>>>>
>>>>>>>>>>> more
>>>>>>>>>>>> detail on the interface change for this solution.
>>>>>>>>>>>>
>>>>>>>>>>> Thanks,
>>>>>>>>>>>
>>>>>>>>>>> Dong
>>>>>>>>>>>>
>>>>>>>>>>>>> On Mon, Feb 26, 2018 at 12:48 AM, Jan
>>>>>>>>>>>>> Filipiak<Jan.Filipiak@trivago.
>>>>>>>>>>>>>
>>>>>>>>>>>>> com
>>>>>>>>>>>>>
>>>>>>>>>>>>> wrote:
>>>>>>>>>>>>
>>>>>>>>>>> Hi,
>>>>>>>>>>>
>>>>>>>>>>> just want to throw my though in. In general the functionality is
>>>>>>>>>>>>
>>>>>>>>>>>>> very
>>>>>>>>>>>>>
>>>>>>>>>>>>> usefull, we should though not try to find the architecture to
>>>>>>>>>>>>>
>>>>>>>>>>>>>> hard
>>>>>>>>>>>>>> while
>>>>>>>>>>>>>> implementing.
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> The manual steps would be to
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> create a new topic
>>>>>>>>>>>>>> the mirrormake from the new old topic to the new topic
>>>>>>>>>>>>>> wait for mirror making to catch up.
>>>>>>>>>>>>>> then put the consumers onto the new topic
>>>>>>>>>>>>>>           (having mirrormaker spit out a mapping from old
>>>>>>>>>>>>>> offsets to
>>>>>>>>>>>>>> new
>>>>>>>>>>>>>> offsets:
>>>>>>>>>>>>>>               if topic is increased by factor X there is gonna
>>>>>>>>>>>>>> be a
>>>>>>>>>>>>>> clean
>>>>>>>>>>>>>> mapping from 1 offset in the old topic to X offsets in the new
>>>>>>>>>>>>>> topic,
>>>>>>>>>>>>>>               if there is no factor then there is no chance to
>>>>>>>>>>>>>> generate a
>>>>>>>>>>>>>> mapping that can be reasonable used for continuing)
>>>>>>>>>>>>>>           make consumers stop at appropriate points and
>>>>>>>>>>>>>> continue
>>>>>>>>>>>>>> consumption
>>>>>>>>>>>>>> with offsets from the mapping.
>>>>>>>>>>>>>> have the producers stop for a minimal time.
>>>>>>>>>>>>>> wait for mirrormaker to finish
>>>>>>>>>>>>>> let producer produce with the new metadata.
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> Instead of implementing the approach suggest in the KIP which
>>>>>>>>>>>>>> will
>>>>>>>>>>>>>> leave
>>>>>>>>>>>>>> log compacted topic completely crumbled and unusable.
>>>>>>>>>>>>>> I would much rather try to build infrastructure to support the
>>>>>>>>>>>>>> mentioned
>>>>>>>>>>>>>> above operations more smoothly.
>>>>>>>>>>>>>> Especially having producers stop and use another topic is
>>>>>>>>>>>>>> difficult
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> and
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> it would be nice if one can trigger "invalid metadata"
>>>>>>>>>>>>> exceptions
>>>>>>>>>>>>>
>>>>>>>>>>>> for
>>>>>>>>>>>
>>>>>>>>>> them
>>>>>>>>>>
>>>>>>>>>>> and
>>>>>>>>>>>>
>>>>>>>>>>>>> if one could give topics aliases so that their produces with
>>>>>>>>>>>>>> the
>>>>>>>>>>>>>> old
>>>>>>>>>>>>>> topic
>>>>>>>>>>>>>> will arrive in the new topic.
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> The downsides are obvious I guess ( having the same data twice
>>>>>>>>>>>>>> for
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> the
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> transition period, but kafka tends to scale well with
>>>>>>>>>>>>> datasize).
>>>>>>>>>>>>>
>>>>>>>>>>>> So
>>>>>>>>>>>>
>>>>>>>>>>>> its a
>>>>>>>>>>>
>>>>>>>>>>> nicer fit into the architecture.
>>>>>>>>>>>>
>>>>>>>>>>>>> I further want to argument that the functionality by the KIP
>>>>>>>>>>>>>> can
>>>>>>>>>>>>>> completely be implementing in "userland" with a custom
>>>>>>>>>>>>>> partitioner
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> that
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> handles the transition as needed. I would appreciate if
>>>>>>>>>>>>> someone
>>>>>>>>>>>>>
>>>>>>>>>>>> could
>>>>>>>>>>>
>>>>>>>>>> point
>>>>>>>>>>
>>>>>>>>>>> out what a custom partitioner couldn't handle in this case?
>>>>>>>>>>>>
>>>>>>>>>>>>> With the above approach, shrinking a topic becomes the same
>>>>>>>>>>>>>> steps.
>>>>>>>>>>>>>> Without
>>>>>>>>>>>>>> loosing keys in the discontinued partitions.
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> Would love to hear what everyone thinks.
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> Best Jan
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> On 11.02.2018 00:35, Dong Lin wrote:
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> Hi all,
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> I have created KIP-253: Support in-order message delivery with
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> partition
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> expansion. See
>>>>>>>>>>>>>>> https://cwiki.apache.org/confluence/display/KAFKA/KIP-253%
>>>>>>>>>>>>>>> 3A+Support+in-order+message+delivery+with+partition+expansio
>>>>>>>>>>>>>>> n
>>>>>>>>>>>>>>> .
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> This KIP provides a way to allow messages of the same key
>>>>>>>>>>>>>>> from
>>>>>>>>>>>>>>> the
>>>>>>>>>>>>>>> same
>>>>>>>>>>>>>>> producer to be consumed in the same order they are produced
>>>>>>>>>>>>>>> even
>>>>>>>>>>>>>>> if
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> we
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> expand partition of the topic.
>>>>>>>>>>>>>>
>>>>>>>>>>>>> Thanks,
>>>>>>>>>>>> Dong
>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>
>
>

Re: [DISCUSS] KIP-253: Support in-order message delivery with partition expansion

Posted by Jan Filipiak <Ja...@trivago.com>.
Hi Jun,

thank you for following me on these thoughts. It was important to me to 
feel that kind of understanding for my arguments.

What I was hoping for (I mentioned this earlier) is that we can model 
the case where we do not want to copy the data the exact same way as the 
case when we do copy the data. Maybe you can peek into the mails before 
to see more details for this.

This means we have the same mechanism to transfer consumer groups to 
switch topic. The offset mapping that would be generated would even be 
simpler End Offset of the Old topic => offset 0 off all the partitions 
of the new topic. Then we could model the transition of a non-copy 
expansion the exact same way as a copy-expansion.

I know this only works when topic growth by a factor. But the benefits 
of only growing by a factor are to strong anyways. See Clemens's hint 
and remember that state reshuffling is entirely not needed if one 
doesn't want to grow processing power.

I think these benefits should be clear, and that there is basically no 
downside to what is currently at hand but just makes everything easy.

One thing you need to know is. that if you do not offer rebuilding a log 
compacted topic like i suggest that even if you have consumer state 
reshuffling. The topic is broken and can not be used to bootstrap new 
consumers. They don't know if they need to apply a key from and old 
partition or not. This is a horrible downside I haven't seen a solution 
for in the email conversation.

I argue to:

Only grow topic by a factor always.
Have the "no copy consumer" transition as the trivial case of the "copy 
consumer transition".
If processors needs to be scaled, let them rebuild from the new topic 
and leave the old running in the mean time.
Do not implement key shuffling in streams.

I hope I can convince you especially with the fact how I want to handle 
consumer transition. I think
you didn't quite understood me there before. I think the term "new 
topic" intimidated you a little.
How we solve this on disc doesn't really matter, If the data goes into 
the same Dir or a different Dir or anything. I do think that it needs to 
involve at least rolling a new segment for the existing partitions.
But most of the transitions should work without restarting consumers. 
(newer consumers with support for this). But with new topic i just meant 
the topic that now has a different partition count. Plenty of ways to 
handle that (versions, aliases)

Hope I can further get my idea across.

Best Jan





On 14.03.2018 02:45, Jun Rao wrote:
> Hi, Jan,
>
> Thanks for sharing your view.
>
> I agree with you that recopying the data potentially makes the state
> management easier since the consumer can just rebuild its state from
> scratch (i.e., no need for state reshuffling).
>
> On the flip slide, I saw a few disadvantages of the approach that you
> suggested. (1) Building the state from the input topic from scratch is in
> general less efficient than state reshuffling. Let's say one computes a
> count per key from an input topic. The former requires reading all existing
> records in the input topic whereas the latter only requires reading data
> proportional to the number of unique keys. (2) The switching of the topic
> needs modification to the application. If there are many applications on a
> topic, coordinating such an effort may not be easy. Also, it's not clear
> how to enforce exactly-once semantic during the switch. (3) If a topic
> doesn't need any state management, recopying the data seems wasteful. In
> that case, in place partition expansion seems more desirable.
>
> I understand your concern about adding complexity in KStreams. But, perhaps
> we could iterate on that a bit more to see if it can be simplified.
>
> Jun
>
>
> On Mon, Mar 12, 2018 at 11:21 PM, Jan Filipiak <Ja...@trivago.com>
> wrote:
>
>> Hi Jun,
>>
>> I will focus on point 61 as I think its _the_ fundamental part that I cant
>> get across at the moment.
>>
>> Kafka is the platform to have state materialized multiple times from one
>> input. I emphasize this: It is the building block in architectures that
>> allow you to
>> have your state maintained multiple times. You put a message in once, and
>> you have it pop out as often as you like. I believe you understand this.
>>
>> Now! The path of thinking goes the following: I am using apache kafka and
>> I _want_ my state multiple times. What am I going todo?
>>
>> A) Am I going to take my state that I build up, plunge some sort of RPC
>> layer ontop of it, use that RPC layer to throw my records across instances?
>> B) Am I just going to read the damn message twice?
>>
>> Approach A is fundamentally flawed and a violation of all that is good and
>> holy in kafka deployments. I can not understand how this Idea can come in
>> the first place.
>> (I do understand: IQ in streams, they polluted the kafka streams codebase
>> really bad already. It is not funny! I think they are equally flawed as A)
>>
>> I say, we do what Kafka is good at. We repartition the topic once. We
>> switch the consumers.
>> (Those that need more partitions are going to rebuild their state in
>> multiple partitions by reading the new topic, those that don't just assign
>> the new partitions properly)
>> We switch producers. Done!
>>
>> The best thing! It is trivial, hipster stream processor will have an easy
>> time with that aswell. Its so super simple. And simple IS good!
>> It is what kafka was build todo. It is how we do it today. All I am saying
>> is that a little broker help doing the producer swap is super useful.
>>
>> For everyone interested in why kafka is so powerful with approach B,
>> please watch https://youtu.be/bEbeZPVo98c?t=1633
>> I already looked up a good point in time, I think after 5 minutes the
>> "state" topic is handled and you should be able to understand me
>> and inch better.
>>
>> Please do not do A to the project, it deserves better!
>>
>> Best Jan
>>
>>
>>
>> On 13.03.2018 02:40, Jun Rao wrote:
>>
>>> Hi, Jan,
>>>
>>> Thanks for the reply. A few more comments below.
>>>
>>> 50. Ok, we can think a bit harder for supporting compacted topics.
>>>
>>> 51. This is a fundamental design question. In the more common case, the
>>> reason why someone wants to increase the number of partitions is that the
>>> consumer application is slow and one wants to run more consumer instances
>>> to increase the degree of parallelism. So, fixing the number of running
>>> consumer instances when expanding the partitions won't help this case. If
>>> we do need to increase the number of consumer instances, we need to
>>> somehow
>>> reshuffle the state of the consumer across instances. What we have been
>>> discussing in this KIP is whether we can do this more effectively through
>>> the KStream library (e.g. through a 2-phase partition expansion). This
>>> will
>>> add some complexity, but it's probably better than everyone doing this in
>>> the application space. The recopying approach that you mentioned doesn't
>>> seem to address the consumer state management issue when the consumer
>>> switches from an old to a new topic.
>>>
>>> 52. As for your example, it depends on whether the join key is the same
>>> between (A,B) and (B,C). If the join key is the same, we can do a 2-phase
>>> partition expansion of A, B, and C together. If the join keys are
>>> different, one would need to repartition the data on a different key for
>>> the second join, then the partition expansion can be done independently
>>> between (A,B) and (B,C).
>>>
>>> 53. If you always fix the number of consumer instances, we you described
>>> works. However, as I mentioned in #51, I am not sure how your proposal
>>> deals with consumer states when the number of consumer instances grows.
>>> Also, it just seems that it's better to avoid re-copying the existing
>>> data.
>>>
>>> 60. "just want to throw in my question from the longer email in the other
>>> Thread here. How will the bloom filter help a new consumer to decide to
>>> apply the key or not?" Not sure that I fully understood your question. The
>>> consumer just reads whatever key is in the log. The bloom filter just
>>> helps
>>> clean up the old keys.
>>>
>>> 61. "Why can we afford having a topic where its apparently not possible to
>>> start a new application on? I think this is an overall flaw of the
>>> discussed idea here. Not playing attention to the overall architecture."
>>> Could you explain a bit more when one can't start a new application?
>>>
>>> Jun
>>>
>>>
>>>
>>> On Sat, Mar 10, 2018 at 1:40 AM, Jan Filipiak <Ja...@trivago.com>
>>> wrote:
>>>
>>> Hi Jun, thanks for your mail.
>>>> Thank you for your questions!
>>>> I think they are really good and tackle the core of the problem I see.
>>>>
>>>> I will answer inline, mostly but still want to set the tone here.
>>>>
>>>> The core strength of kafka is what Martin once called the
>>>> kappa-Architecture. How does this work?
>>>> You have everything as a log as in kafka. When you need to change
>>>> something.
>>>> You create the new version of your application and leave it running in
>>>> parallel.
>>>> Once the new version is good you switch your users to use the new
>>>> application.
>>>>
>>>> The online reshuffling effectively breaks this architecture and I think
>>>> the switch in thinking here is more harmful
>>>> than any details about the partitioning function to allow such a change.
>>>> I
>>>> feel with my suggestion we are the closest to
>>>> the original and battle proven architecture and I can only warn to move
>>>> away from it.
>>>>
>>>> I might have forgotten something, sometimes its hard for me to getting
>>>> all
>>>> the thoughts captured in a mail, but I hope the comments inline will
>>>> further make my concern clear, and put some emphasis on why I prefer my
>>>> solution ;)
>>>>
>>>> One thing we should all be aware of when discussing this, and I think
>>>> Dong
>>>> should have mentioned it (maybe he did).
>>>> We are not discussing all of this out of thin air but there is an effort
>>>> in the Samza project.
>>>>
>>>> https://cwiki.apache.org/confluence/display/SAMZA/SEP-5%3A+
>>>> Enable+partition+expansion+of+input+streams
>>>> https://issues.apache.org/jira/browse/SAMZA-1293
>>>>
>>>> To be clear. I think SEP-5 (state of last week, dont know if it adapted
>>>> to
>>>> this discussion) is on a way better path than KIP-253, and I can't really
>>>> explain why.
>>>>
>>>> Best Jan,
>>>>
>>>> nice weekend everyone
>>>>
>>>>
>>>> On 09.03.2018 03:36, Jun Rao wrote:
>>>>
>>>> Hi, Jan,
>>>>> Thanks for the feedback. Just some comments on the earlier points that
>>>>> you
>>>>> mentioned.
>>>>>
>>>>> 50. You brought up the question of whether existing data needs to be
>>>>> copied
>>>>> during partition expansion. My understand of your view is that avoid
>>>>> copying existing data will be more efficient, but it doesn't work well
>>>>> with
>>>>> compacted topics since some keys in the original partitions will never
>>>>> be
>>>>> cleaned. It would be useful to understand your use case of compacted
>>>>> topics
>>>>> a bit more. In the common use case, the data volume in a compacted topic
>>>>> may not be large. So, I am not sure if there is a strong need to expand
>>>>> partitions in a compacted topic, at least initially.
>>>>>
>>>>> I do agree. State is usually smaller. Update rates might be also
>>>> competitively high.
>>>> Doing Log-compaction (even beeing very efficient and configurable) is
>>>> also
>>>> a more expensive operation than
>>>> just discarding old segments. Further if you want to use more consumers
>>>> processing the events
>>>> you also have to grow the number of partitions. Especially for use-cases
>>>> we do (KIP-213) a tiny state full
>>>> table might be very expensive to process if it joins against a huge
>>>> table.
>>>>
>>>> I can just say we have been in the spot of needing to grow log compacted
>>>> topics. Mainly for processing power we can bring to the table.
>>>>
>>>> Further i am not at all concerned about the extra spaced used by "garbage
>>>> keys". I am more concerned about the correctness of innocent consumers.
>>>> The
>>>> logic becomes complicated. Say for streams one would need to load the
>>>> record into state but not forward it the topology ( to have it available
>>>> for shuffeling). I rather have it simple and a topic clean regardless if
>>>> it
>>>> still has its old partition count. Especially with multiple partitions
>>>> growth's I think it becomes insanely hard to to this shuffle correct.
>>>> Maybe
>>>> Streams and Samza can do it. Especially if you do "hipster stream
>>>> processing" <https://www.confluent.io/blog/introducing-kafka-streams-
>>>> stream-processing-made-simple/>. This makes kafka way to complicated.
>>>> With my approach I think its way simpler because the topic has no
>>>> "history"
>>>> in terms of partitioning but is always clean.
>>>>
>>>>
>>>> 51. "Growing the topic by an integer factor does not require any state
>>>>> redistribution at all." Could you clarify this a bit more? Let's say you
>>>>> have a consumer app that computes the windowed count per key. If you
>>>>> double
>>>>> the number of partitions from 1 to 2 and grow the consumer instances
>>>>> from
>>>>> 1
>>>>> to 2, we would need to redistribute some of the counts to the new
>>>>> consumer
>>>>> instance. Regarding to linear hashing, it's true that it won't solve the
>>>>> problem with compacted topics. The main benefit is that it redistributes
>>>>> the keys in one partition to no more than two partitions, which could
>>>>> help
>>>>> redistribute the state.
>>>>>
>>>>> You don't need to spin up a new consumer in this case. every consumer
>>>> would just read every partition with the (partition % num_task) task. it
>>>> will still have the previous data right there and can go on.
>>>>
>>>> This sounds contradictory to what I said before, but please bear with me.
>>>>
>>>> 52. Good point on coordinating the expansion of 2 topics that need to be
>>>>> joined together. This is where the 2-phase partition expansion could
>>>>> potentially help. In the first phase, we could add new partitions to
>>>>> the 2
>>>>> topics one at a time but without publishing to the new patitions. Then,
>>>>> we
>>>>> can add new consumer instances to pick up the new partitions. In this
>>>>> transition phase, no reshuffling is needed since no data is coming from
>>>>> the
>>>>> new partitions. Finally, we can enable the publishing to the new
>>>>> partitions.
>>>>>
>>>>> I think its even worse than you think. I would like to introduce the
>>>> Term
>>>> transitive copartitioning. Imagine
>>>> 2 streams application. One joins (A,B) the other (B,C) then there is a
>>>> transitive copartition requirement for
>>>> (A,C) to be copartitioned aswell. This can spread significantly and
>>>> require many consumers to adapt at the same time.
>>>>
>>>> It is also not entirely clear to me how you not need reshuffling in this
>>>> case. If A has a record that never gets updated after the expansion and
>>>> the
>>>> coresponding B record moves to a new partition. How shall they meet w/o
>>>> shuffle?
>>>>
>>>> 53. "Migrating consumer is a step that might be made completly
>>>>> unnecessary
>>>>> if - for example streams - takes the gcd as partitioning scheme instead
>>>>> of
>>>>> enforcing 1 to 1." Not sure that I fully understand this. I think you
>>>>> mean
>>>>> that a consumer application can run more instances than the number of
>>>>> partitions. In that case, the consumer can just repartitioning the input
>>>>> data according to the number of instances. This is possible, but just
>>>>> has
>>>>> the overhead of reshuffling the data.
>>>>>
>>>>> No what I meant is ( that is also your question i think Mathias) that if
>>>> you grow a topic by a factor.
>>>> Even if your processor is statefull you can can just assign all the
>>>> multiples of the previous partition to
>>>> this consumer and the state to keep processing correctly will be present
>>>> w/o any shuffling.
>>>>
>>>> Say you have an assignment
>>>> Statefull consumer => partition
>>>> 0 => 0
>>>> 1 => 1
>>>> 2 => 2
>>>>
>>>> and you grow you topic by 4 you get,
>>>>
>>>> 0 => 0,3,6,9
>>>> 1 => 1,4,7,10
>>>> 2 => 2,5,8,11
>>>>
>>>> Say your hashcode is 8. 8%3 => 2  before so consumer for partition 2 has
>>>> it.
>>>> Now you you have 12 partitions so 8%12 => 8, so it goes into partition 8
>>>> which is assigned to the same consumer
>>>> who had 2 before and therefore knows the key.
>>>>
>>>> Userland reshuffeling is there as an options. And it does exactly what I
>>>> suggest. And I think its the perfect strategie. All I am suggestion is
>>>> broker side support to switch the producers to the newly partitioned
>>>> topic.
>>>> Then the old (to few partition topic) can go away.  Remember the list of
>>>> steps in the beginning of this thread. If one has broker support for all
>>>> where its required and streams support for those that aren’t necessarily.
>>>> Then one has solved the problem.
>>>> I repeat it because I think its important. I am really happy that you
>>>> brought that up! because its 100% what I want just with the differences
>>>> to
>>>> have an option to discard the to small topic later (after all consumers
>>>> adapted). And to have order correct there. I need broker support managing
>>>> the copy process + the produces and fence them against each other. I also
>>>> repeat. the copy process can run for weeks in the worst case. Copying the
>>>> data is not the longest task migrating consumers might very well be.
>>>> Once all consumers switched and copying is really up to date (think ISR
>>>> like up to date) only then we stop the producer, wait for the copy to
>>>> finish and use the new topic for producing.
>>>>
>>>> After this the topic is perfect in shape. and no one needs to worry about
>>>> complicated stuff. (old keys hanging around might arrive in some other
>>>> topic later.....). can only imagine how many tricky bugs gonna arrive
>>>> after
>>>> someone had grown and shrunken is topic 10 times.
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> 54. "The other thing I wanted to mention is that I believe the current
>>>>> suggestion (without copying data over) can be implemented in pure
>>>>> userland
>>>>> with a custom partitioner and a small feedbackloop from ProduceResponse
>>>>> =>
>>>>> Partitionier in coorporation with a change management system." I am not
>>>>> sure a customized partitioner itself solves the problem. We probably
>>>>> need
>>>>> some broker side support to enforce when the new partitions can be used.
>>>>> We
>>>>> also need some support on the consumer/kstream side to preserve the per
>>>>> key
>>>>> ordering and potentially migrate the processing state. This is not
>>>>> trivial
>>>>> and I am not sure if it's ideal to fully push to the application space.
>>>>>
>>>>> Broker support is defenitly the preferred way here. I have nothing
>>>> against
>>>> broker support.
>>>> I tried to say that for what I would preffer - copying the data over, at
>>>> least for log compacted topics -
>>>> I would require more broker support than the KIP currently offers.
>>>>
>>>>
>>>>
>>>> Jun
>>>>>
>>>>> On Tue, Mar 6, 2018 at 10:33 PM, Jan Filipiak <Jan.Filipiak@trivago.com
>>>>> wrote:
>>>>>
>>>>> Hi Dong,
>>>>>
>>>>>> are you actually reading my emails, or are you just using the thread I
>>>>>> started for general announcements regarding the KIP?
>>>>>>
>>>>>> I tried to argue really hard against linear hashing. Growing the topic
>>>>>> by
>>>>>> an integer factor does not require any state redistribution at all. I
>>>>>> fail
>>>>>> to see completely where linear hashing helps on log compacted topics.
>>>>>>
>>>>>> If you are not willing to explain to me what I might be overlooking:
>>>>>> that
>>>>>> is fine.
>>>>>> But I ask you to not reply to my emails then. Please understand my
>>>>>> frustration with this.
>>>>>>
>>>>>> Best Jan
>>>>>>
>>>>>>
>>>>>>
>>>>>> On 06.03.2018 19:38, Dong Lin wrote:
>>>>>>
>>>>>> Hi everyone,
>>>>>>
>>>>>>> Thanks for all the comments! It appears that everyone prefers linear
>>>>>>> hashing because it reduces the amount of state that needs to be moved
>>>>>>> between consumers (for stream processing). The KIP has been updated to
>>>>>>> use
>>>>>>> linear hashing.
>>>>>>>
>>>>>>> Regarding the migration endeavor: it seems that migrating producer
>>>>>>> library
>>>>>>> to use linear hashing should be pretty straightforward without
>>>>>>> much operational endeavor. If we don't upgrade client library to use
>>>>>>> this
>>>>>>> KIP, we can not support in-order delivery after partition is changed
>>>>>>> anyway. Suppose we upgrade client library to use this KIP, if
>>>>>>> partition
>>>>>>> number is not changed, the key -> partition mapping will be exactly
>>>>>>> the
>>>>>>> same as it is now because it is still determined using
>>>>>>> murmur_hash(key)
>>>>>>> %
>>>>>>> original_partition_num. In other words, this change is backward
>>>>>>> compatible.
>>>>>>>
>>>>>>> Regarding the load distribution: if we use linear hashing, the load
>>>>>>> may
>>>>>>> be
>>>>>>> unevenly distributed because those partitions which are not split may
>>>>>>> receive twice as much traffic as other partitions that are split. This
>>>>>>> issue can be mitigated by creating topic with partitions that are
>>>>>>> several
>>>>>>> times the number of consumers. And there will be no imbalance if the
>>>>>>> partition number is always doubled. So this imbalance seems
>>>>>>> acceptable.
>>>>>>>
>>>>>>> Regarding storing the partition strategy as per-topic config: It seems
>>>>>>> not
>>>>>>> necessary since we can still use murmur_hash as the default hash
>>>>>>> function
>>>>>>> and additionally apply the linear hashing algorithm if the partition
>>>>>>> number
>>>>>>> has increased. Not sure if there is any use-case for producer to use a
>>>>>>> different hash function. Jason, can you check if there is some
>>>>>>> use-case
>>>>>>> that I missed for using the per-topic partition strategy?
>>>>>>>
>>>>>>> Regarding how to reduce latency (due to state store/load) in stream
>>>>>>> processing consumer when partition number changes: I need to read the
>>>>>>> Kafka
>>>>>>> Stream code to understand how Kafka Stream currently migrate state
>>>>>>> between
>>>>>>> consumers when the application is added/removed for a given job. I
>>>>>>> will
>>>>>>> reply after I finish reading the documentation and code.
>>>>>>>
>>>>>>>
>>>>>>> Thanks,
>>>>>>> Dong
>>>>>>>
>>>>>>>
>>>>>>> On Mon, Mar 5, 2018 at 10:43 AM, Jason Gustafson <ja...@confluent.io>
>>>>>>> wrote:
>>>>>>>
>>>>>>> Great discussion. I think I'm wondering whether we can continue to
>>>>>>> leave
>>>>>>>
>>>>>>> Kafka agnostic to the partitioning strategy. The challenge is
>>>>>>>> communicating
>>>>>>>> the partitioning logic from producers to consumers so that the
>>>>>>>> dependencies
>>>>>>>> between each epoch can be determined. For the sake of discussion,
>>>>>>>> imagine
>>>>>>>> you did something like the following:
>>>>>>>>
>>>>>>>> 1. The name (and perhaps version) of a partitioning strategy is
>>>>>>>> stored
>>>>>>>> in
>>>>>>>> topic configuration when a topic is created.
>>>>>>>> 2. The producer looks up the partitioning strategy before writing to
>>>>>>>> a
>>>>>>>> topic and includes it in the produce request (for fencing). If it
>>>>>>>> doesn't
>>>>>>>> have an implementation for the configured strategy, it fails.
>>>>>>>> 3. The consumer also looks up the partitioning strategy and uses it
>>>>>>>> to
>>>>>>>> determine dependencies when reading a new epoch. It could either fail
>>>>>>>> or
>>>>>>>> make the most conservative dependency assumptions if it doesn't know
>>>>>>>> how
>>>>>>>> to
>>>>>>>> implement the partitioning strategy. For the consumer, the new
>>>>>>>> interface
>>>>>>>> might look something like this:
>>>>>>>>
>>>>>>>> // Return the partition dependencies following an epoch bump
>>>>>>>> Map<Integer, List<Integer>> dependencies(int
>>>>>>>> numPartitionsBeforeEpochBump,
>>>>>>>> int numPartitionsAfterEpochBump)
>>>>>>>>
>>>>>>>> The unordered case then is just a particular implementation which
>>>>>>>> never
>>>>>>>> has
>>>>>>>> any epoch dependencies. To implement this, we would need some way for
>>>>>>>> the
>>>>>>>> consumer to find out how many partitions there were in each epoch,
>>>>>>>> but
>>>>>>>> maybe that's not too unreasonable.
>>>>>>>>
>>>>>>>> Thanks,
>>>>>>>> Jason
>>>>>>>>
>>>>>>>>
>>>>>>>> On Mon, Mar 5, 2018 at 4:51 AM, Jan Filipiak <
>>>>>>>> Jan.Filipiak@trivago.com
>>>>>>>> wrote:
>>>>>>>>
>>>>>>>> Hi Dong
>>>>>>>>
>>>>>>>> thank you very much for your questions.
>>>>>>>>> regarding the time spend copying data across:
>>>>>>>>> It is correct that copying data from a topic with one partition
>>>>>>>>> mapping
>>>>>>>>>
>>>>>>>>> to
>>>>>>>>>
>>>>>>>> a topic with a different partition mapping takes way longer than we
>>>>>>>> can
>>>>>>>>
>>>>>>>>> stop producers. Tens of minutes is a very optimistic estimate here.
>>>>>>>>> Many
>>>>>>>>> people can not afford copy full steam and therefore will have some
>>>>>>>>> rate
>>>>>>>>> limiting in place, this can bump the timespan into the day's. The
>>>>>>>>> good
>>>>>>>>>
>>>>>>>>> part
>>>>>>>>>
>>>>>>>> is that the vast majority of the data can be copied while the
>>>>>>>> producers
>>>>>>>>
>>>>>>>>> are
>>>>>>>>>
>>>>>>>> still going. One can then, piggyback the consumers ontop of this
>>>>>>>>
>>>>>>>>> timeframe,
>>>>>>>>>
>>>>>>>> by the method mentioned (provide them an mapping from their old
>>>>>>>> offsets
>>>>>>>>
>>>>>>>>> to
>>>>>>>>>
>>>>>>>> new offsets in their repartitioned topics. In that way we separate
>>>>>>>>
>>>>>>>>> migration of consumers from migration of producers (decoupling these
>>>>>>>>> is
>>>>>>>>> what kafka is strongest at). The time to actually swap over the
>>>>>>>>> producers
>>>>>>>>> should be kept minimal by ensuring that when a swap attempt is
>>>>>>>>> started
>>>>>>>>>
>>>>>>>>> the
>>>>>>>>>
>>>>>>>> consumer copying over should be very close to the log end and is
>>>>>>>>
>>>>>>>>> expected
>>>>>>>>> to finish within the next fetch. The operation should have a
>>>>>>>>> time-out
>>>>>>>>> and
>>>>>>>>> should be "reattemtable".
>>>>>>>>>
>>>>>>>>> Importance of logcompaction:
>>>>>>>>> If a producer produces key A, to partiton 0, its forever gonna be
>>>>>>>>> there,
>>>>>>>>> unless it gets deleted. The record might sit in there for years. A
>>>>>>>>> new
>>>>>>>>> producer started with the new partitions will fail to delete the
>>>>>>>>> record
>>>>>>>>>
>>>>>>>>> in
>>>>>>>>>
>>>>>>>> the correct partition. Th record will be there forever and one can
>>>>>>>> not
>>>>>>>>
>>>>>>>>> reliable bootstrap new consumers. I cannot see how linear hashing
>>>>>>>>> can
>>>>>>>>>
>>>>>>>>> solve
>>>>>>>>>
>>>>>>>> this.
>>>>>>>>
>>>>>>>>> Regarding your skipping of userland copying:
>>>>>>>>> 100%, copying the data across in userland is, as far as i can see,
>>>>>>>>> only
>>>>>>>>> a
>>>>>>>>> usecase for log compacted topics. Even for logcompaction +
>>>>>>>>> retentions
>>>>>>>>> it
>>>>>>>>> should only be opt-in. Why did I bring it up? I think log compaction
>>>>>>>>> is
>>>>>>>>> a
>>>>>>>>> very important feature to really embrace kafka as a "data
>>>>>>>>> plattform".
>>>>>>>>> The
>>>>>>>>> point I also want to make is that copying data this way is
>>>>>>>>> completely
>>>>>>>>> inline with the kafka architecture. it only consists of reading and
>>>>>>>>>
>>>>>>>>> writing
>>>>>>>>>
>>>>>>>> to topics.
>>>>>>>>
>>>>>>>>> I hope it clarifies more why I think we should aim for more than the
>>>>>>>>> current KIP. I fear that once the KIP is done not much more effort
>>>>>>>>> will
>>>>>>>>>
>>>>>>>>> be
>>>>>>>>>
>>>>>>>> taken.
>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> On 04.03.2018 02:28, Dong Lin wrote:
>>>>>>>>>
>>>>>>>>> Hey Jan,
>>>>>>>>>
>>>>>>>>> In the current proposal, the consumer will be blocked on waiting for
>>>>>>>>>> other
>>>>>>>>>>
>>>>>>>>> consumers of the group to consume up to a given offset. In most
>>>>>>>>> cases,
>>>>>>>>> all
>>>>>>>>> consumers should be close to the LEO of the partitions when the
>>>>>>>>> partition
>>>>>>>>> expansion happens. Thus the time waiting should not be long e.g. on
>>>>>>>>> the
>>>>>>>>>
>>>>>>>>> order of seconds. On the other hand, it may take a long time to wait
>>>>>>>>>> for
>>>>>>>>>> the entire partition to be copied -- the amount of time is
>>>>>>>>>> proportional
>>>>>>>>>>
>>>>>>>>>> to
>>>>>>>>>>
>>>>>>>>> the amount of existing data in the partition, which can take tens of
>>>>>>>>>
>>>>>>>>> minutes. So the amount of time that we stop consumers may not be on
>>>>>>>>>> the
>>>>>>>>>> same order of magnitude.
>>>>>>>>>>
>>>>>>>>>> If we can implement this suggestion without copying data over in
>>>>>>>>>> purse
>>>>>>>>>> userland, it will be much more valuable. Do you have ideas on how
>>>>>>>>>> this
>>>>>>>>>>
>>>>>>>>>> can
>>>>>>>>>>
>>>>>>>>> be done?
>>>>>>>>>
>>>>>>>>> Not sure why the current KIP not help people who depend on log
>>>>>>>>>> compaction.
>>>>>>>>>>
>>>>>>>>> Could you elaborate more on this point?
>>>>>>>>>
>>>>>>>>> Thanks,
>>>>>>>>>> Dong
>>>>>>>>>>
>>>>>>>>>> On Wed, Feb 28, 2018 at 10:55 PM, Jan
>>>>>>>>>> Filipiak<Jan.Filipiak@trivago.
>>>>>>>>>> com
>>>>>>>>>> wrote:
>>>>>>>>>>
>>>>>>>>>> Hi Dong,
>>>>>>>>>>
>>>>>>>>>> I tried to focus on what the steps are one can currently perform to
>>>>>>>>>>
>>>>>>>>>>> expand
>>>>>>>>>>> or shrink a keyed topic while maintaining a top notch semantics.
>>>>>>>>>>> I can understand that there might be confusion about "stopping the
>>>>>>>>>>> consumer". It is exactly the same as proposed in the KIP. there
>>>>>>>>>>> needs
>>>>>>>>>>>
>>>>>>>>>>> to
>>>>>>>>>>>
>>>>>>>>>> be
>>>>>>>>> a time the producers agree on the new partitioning. The extra
>>>>>>>>>>> semantics I
>>>>>>>>>>>
>>>>>>>>>> want to put in there is that we have a possibility to wait until
>>>>>>>>> all
>>>>>>>>>
>>>>>>>>> the
>>>>>>>>>> existing data
>>>>>>>>> is copied over into the new partitioning scheme. When I say stopping
>>>>>>>>>>> I
>>>>>>>>>>> think more of having a memory barrier that ensures the ordering. I
>>>>>>>>>>> am
>>>>>>>>>>> still
>>>>>>>>>>> aming for latencies  on the scale of leader failovers.
>>>>>>>>>>>
>>>>>>>>>>> Consumers have to explicitly adapt the new partitioning scheme in
>>>>>>>>>>> the
>>>>>>>>>>> above scenario. The reason is that in these cases where you are
>>>>>>>>>>>
>>>>>>>>>>> dependent
>>>>>>>>>>>
>>>>>>>>>> on a particular partitioning scheme, you also have other topics
>>>>>>>>> that
>>>>>>>>>
>>>>>>>>> have
>>>>>>>>>> co-partition enforcements or the kind -frequently. Therefore all
>>>>>>>>> your
>>>>>>>>>
>>>>>>>>> other
>>>>>>>>>>> input topics might need to grow accordingly.
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> What I was suggesting was to streamline all these operations as
>>>>>>>>>>> best
>>>>>>>>>>> as
>>>>>>>>>>> possible to have "real" partition grow and shrinkage going on.
>>>>>>>>>>>
>>>>>>>>>>> Migrating
>>>>>>>>>>>
>>>>>>>>>> the producers to a new partitioning scheme can be much more
>>>>>>>>> streamlined
>>>>>>>>>
>>>>>>>>> with proper broker support for this. Migrating consumer is a step
>>>>>>>>>>> that
>>>>>>>>>>> might be made completly unnecessary if - for example streams -
>>>>>>>>>>> takes
>>>>>>>>>>>
>>>>>>>>>>> the
>>>>>>>>>>>
>>>>>>>>>> gcd as partitioning scheme instead of enforcing 1 to 1. Connect
>>>>>>>>> consumers
>>>>>>>>>> and other consumers should be fine anyways.
>>>>>>>>> I hope this makes more clear where I was aiming at. The rest needs
>>>>>>>>>> to
>>>>>>>>>>
>>>>>>>>>>> be
>>>>>>>>>>>
>>>>>>>>>> figured out. The only danger i see is that when we are introducing
>>>>>>>>> this
>>>>>>>>>
>>>>>>>>> feature as supposed in the KIP, it wont help any people depending on
>>>>>>>>>>> log
>>>>>>>>>>>
>>>>>>>>>> compaction.
>>>>>>>>> The other thing I wanted to mention is that I believe the current
>>>>>>>>>>> suggestion (without copying data over) can be implemented in pure
>>>>>>>>>>> userland
>>>>>>>>>>> with a custom partitioner and a small feedbackloop from
>>>>>>>>>>> ProduceResponse
>>>>>>>>>>> =>
>>>>>>>>>>> Partitionier in coorporation with a change management system.
>>>>>>>>>>>
>>>>>>>>>>> Best Jan
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> On 28.02.2018 07:13, Dong Lin wrote:
>>>>>>>>>>>
>>>>>>>>>>> Hey Jan,
>>>>>>>>>>>
>>>>>>>>>>> I am not sure if it is acceptable for producer to be stopped for a
>>>>>>>>>>>
>>>>>>>>>>>> while,
>>>>>>>>>>>> particularly for online application which requires low latency. I
>>>>>>>>>>>> am
>>>>>>>>>>>> also
>>>>>>>>>>>> not sure how consumers can switch to a new topic. Does user
>>>>>>>>>>>>
>>>>>>>>>>>> application
>>>>>>>>>>>>
>>>>>>>>>>> needs to explicitly specify a different topic for
>>>>>>>>>> producer/consumer
>>>>>>>>>>
>>>>>>>>> to
>>>>>>>>>
>>>>>>>>> subscribe to? It will be helpful for discussion if you can provide
>>>>>>>>>>> more
>>>>>>>>>>> detail on the interface change for this solution.
>>>>>>>>>> Thanks,
>>>>>>>>>>
>>>>>>>>>>> Dong
>>>>>>>>>>>> On Mon, Feb 26, 2018 at 12:48 AM, Jan
>>>>>>>>>>>> Filipiak<Jan.Filipiak@trivago.
>>>>>>>>>>>>
>>>>>>>>>>>> com
>>>>>>>>>>>>
>>>>>>>>>>> wrote:
>>>>>>>>>> Hi,
>>>>>>>>>>
>>>>>>>>>>> just want to throw my though in. In general the functionality is
>>>>>>>>>>>> very
>>>>>>>>>>>>
>>>>>>>>>>>> usefull, we should though not try to find the architecture to
>>>>>>>>>>>>> hard
>>>>>>>>>>>>> while
>>>>>>>>>>>>> implementing.
>>>>>>>>>>>>>
>>>>>>>>>>>>> The manual steps would be to
>>>>>>>>>>>>>
>>>>>>>>>>>>> create a new topic
>>>>>>>>>>>>> the mirrormake from the new old topic to the new topic
>>>>>>>>>>>>> wait for mirror making to catch up.
>>>>>>>>>>>>> then put the consumers onto the new topic
>>>>>>>>>>>>>           (having mirrormaker spit out a mapping from old
>>>>>>>>>>>>> offsets to
>>>>>>>>>>>>> new
>>>>>>>>>>>>> offsets:
>>>>>>>>>>>>>               if topic is increased by factor X there is gonna
>>>>>>>>>>>>> be a
>>>>>>>>>>>>> clean
>>>>>>>>>>>>> mapping from 1 offset in the old topic to X offsets in the new
>>>>>>>>>>>>> topic,
>>>>>>>>>>>>>               if there is no factor then there is no chance to
>>>>>>>>>>>>> generate a
>>>>>>>>>>>>> mapping that can be reasonable used for continuing)
>>>>>>>>>>>>>           make consumers stop at appropriate points and continue
>>>>>>>>>>>>> consumption
>>>>>>>>>>>>> with offsets from the mapping.
>>>>>>>>>>>>> have the producers stop for a minimal time.
>>>>>>>>>>>>> wait for mirrormaker to finish
>>>>>>>>>>>>> let producer produce with the new metadata.
>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>> Instead of implementing the approach suggest in the KIP which
>>>>>>>>>>>>> will
>>>>>>>>>>>>> leave
>>>>>>>>>>>>> log compacted topic completely crumbled and unusable.
>>>>>>>>>>>>> I would much rather try to build infrastructure to support the
>>>>>>>>>>>>> mentioned
>>>>>>>>>>>>> above operations more smoothly.
>>>>>>>>>>>>> Especially having producers stop and use another topic is
>>>>>>>>>>>>> difficult
>>>>>>>>>>>>>
>>>>>>>>>>>>> and
>>>>>>>>>>>>>
>>>>>>>>>>>> it would be nice if one can trigger "invalid metadata" exceptions
>>>>>>>>>> for
>>>>>>>>> them
>>>>>>>>>>> and
>>>>>>>>>>>>> if one could give topics aliases so that their produces with the
>>>>>>>>>>>>> old
>>>>>>>>>>>>> topic
>>>>>>>>>>>>> will arrive in the new topic.
>>>>>>>>>>>>>
>>>>>>>>>>>>> The downsides are obvious I guess ( having the same data twice
>>>>>>>>>>>>> for
>>>>>>>>>>>>>
>>>>>>>>>>>>> the
>>>>>>>>>>>>>
>>>>>>>>>>>> transition period, but kafka tends to scale well with datasize).
>>>>>>>>>>> So
>>>>>>>>>>>
>>>>>>>>>> its a
>>>>>>>>>>
>>>>>>>>>>> nicer fit into the architecture.
>>>>>>>>>>>>> I further want to argument that the functionality by the KIP can
>>>>>>>>>>>>> completely be implementing in "userland" with a custom
>>>>>>>>>>>>> partitioner
>>>>>>>>>>>>>
>>>>>>>>>>>>> that
>>>>>>>>>>>>>
>>>>>>>>>>>> handles the transition as needed. I would appreciate if someone
>>>>>>>>>> could
>>>>>>>>> point
>>>>>>>>>>> out what a custom partitioner couldn't handle in this case?
>>>>>>>>>>>>> With the above approach, shrinking a topic becomes the same
>>>>>>>>>>>>> steps.
>>>>>>>>>>>>> Without
>>>>>>>>>>>>> loosing keys in the discontinued partitions.
>>>>>>>>>>>>>
>>>>>>>>>>>>> Would love to hear what everyone thinks.
>>>>>>>>>>>>>
>>>>>>>>>>>>> Best Jan
>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>> On 11.02.2018 00:35, Dong Lin wrote:
>>>>>>>>>>>>>
>>>>>>>>>>>>> Hi all,
>>>>>>>>>>>>>
>>>>>>>>>>>>> I have created KIP-253: Support in-order message delivery with
>>>>>>>>>>>>>
>>>>>>>>>>>>> partition
>>>>>>>>>>>>>> expansion. See
>>>>>>>>>>>>>> https://cwiki.apache.org/confluence/display/KAFKA/KIP-253%
>>>>>>>>>>>>>> 3A+Support+in-order+message+delivery+with+partition+expansion
>>>>>>>>>>>>>> .
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> This KIP provides a way to allow messages of the same key from
>>>>>>>>>>>>>> the
>>>>>>>>>>>>>> same
>>>>>>>>>>>>>> producer to be consumed in the same order they are produced
>>>>>>>>>>>>>> even
>>>>>>>>>>>>>> if
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> we
>>>>>>>>>>>>>>
>>>>>>>>>>>>> expand partition of the topic.
>>>>>>>>>>> Thanks,
>>>>>>>>>>> Dong
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>



Re: [DISCUSS] KIP-253: Support in-order message delivery with partition expansion

Posted by Jun Rao <ju...@confluent.io>.
Hi, Jan,

Thanks for sharing your view.

I agree with you that recopying the data potentially makes the state
management easier since the consumer can just rebuild its state from
scratch (i.e., no need for state reshuffling).

On the flip slide, I saw a few disadvantages of the approach that you
suggested. (1) Building the state from the input topic from scratch is in
general less efficient than state reshuffling. Let's say one computes a
count per key from an input topic. The former requires reading all existing
records in the input topic whereas the latter only requires reading data
proportional to the number of unique keys. (2) The switching of the topic
needs modification to the application. If there are many applications on a
topic, coordinating such an effort may not be easy. Also, it's not clear
how to enforce exactly-once semantic during the switch. (3) If a topic
doesn't need any state management, recopying the data seems wasteful. In
that case, in place partition expansion seems more desirable.

I understand your concern about adding complexity in KStreams. But, perhaps
we could iterate on that a bit more to see if it can be simplified.

Jun


On Mon, Mar 12, 2018 at 11:21 PM, Jan Filipiak <Ja...@trivago.com>
wrote:

> Hi Jun,
>
> I will focus on point 61 as I think its _the_ fundamental part that I cant
> get across at the moment.
>
> Kafka is the platform to have state materialized multiple times from one
> input. I emphasize this: It is the building block in architectures that
> allow you to
> have your state maintained multiple times. You put a message in once, and
> you have it pop out as often as you like. I believe you understand this.
>
> Now! The path of thinking goes the following: I am using apache kafka and
> I _want_ my state multiple times. What am I going todo?
>
> A) Am I going to take my state that I build up, plunge some sort of RPC
> layer ontop of it, use that RPC layer to throw my records across instances?
> B) Am I just going to read the damn message twice?
>
> Approach A is fundamentally flawed and a violation of all that is good and
> holy in kafka deployments. I can not understand how this Idea can come in
> the first place.
> (I do understand: IQ in streams, they polluted the kafka streams codebase
> really bad already. It is not funny! I think they are equally flawed as A)
>
> I say, we do what Kafka is good at. We repartition the topic once. We
> switch the consumers.
> (Those that need more partitions are going to rebuild their state in
> multiple partitions by reading the new topic, those that don't just assign
> the new partitions properly)
> We switch producers. Done!
>
> The best thing! It is trivial, hipster stream processor will have an easy
> time with that aswell. Its so super simple. And simple IS good!
> It is what kafka was build todo. It is how we do it today. All I am saying
> is that a little broker help doing the producer swap is super useful.
>
> For everyone interested in why kafka is so powerful with approach B,
> please watch https://youtu.be/bEbeZPVo98c?t=1633
> I already looked up a good point in time, I think after 5 minutes the
> "state" topic is handled and you should be able to understand me
> and inch better.
>
> Please do not do A to the project, it deserves better!
>
> Best Jan
>
>
>
> On 13.03.2018 02:40, Jun Rao wrote:
>
>> Hi, Jan,
>>
>> Thanks for the reply. A few more comments below.
>>
>> 50. Ok, we can think a bit harder for supporting compacted topics.
>>
>> 51. This is a fundamental design question. In the more common case, the
>> reason why someone wants to increase the number of partitions is that the
>> consumer application is slow and one wants to run more consumer instances
>> to increase the degree of parallelism. So, fixing the number of running
>> consumer instances when expanding the partitions won't help this case. If
>> we do need to increase the number of consumer instances, we need to
>> somehow
>> reshuffle the state of the consumer across instances. What we have been
>> discussing in this KIP is whether we can do this more effectively through
>> the KStream library (e.g. through a 2-phase partition expansion). This
>> will
>> add some complexity, but it's probably better than everyone doing this in
>> the application space. The recopying approach that you mentioned doesn't
>> seem to address the consumer state management issue when the consumer
>> switches from an old to a new topic.
>>
>> 52. As for your example, it depends on whether the join key is the same
>> between (A,B) and (B,C). If the join key is the same, we can do a 2-phase
>> partition expansion of A, B, and C together. If the join keys are
>> different, one would need to repartition the data on a different key for
>> the second join, then the partition expansion can be done independently
>> between (A,B) and (B,C).
>>
>> 53. If you always fix the number of consumer instances, we you described
>> works. However, as I mentioned in #51, I am not sure how your proposal
>> deals with consumer states when the number of consumer instances grows.
>> Also, it just seems that it's better to avoid re-copying the existing
>> data.
>>
>> 60. "just want to throw in my question from the longer email in the other
>> Thread here. How will the bloom filter help a new consumer to decide to
>> apply the key or not?" Not sure that I fully understood your question. The
>> consumer just reads whatever key is in the log. The bloom filter just
>> helps
>> clean up the old keys.
>>
>> 61. "Why can we afford having a topic where its apparently not possible to
>> start a new application on? I think this is an overall flaw of the
>> discussed idea here. Not playing attention to the overall architecture."
>> Could you explain a bit more when one can't start a new application?
>>
>> Jun
>>
>>
>>
>> On Sat, Mar 10, 2018 at 1:40 AM, Jan Filipiak <Ja...@trivago.com>
>> wrote:
>>
>> Hi Jun, thanks for your mail.
>>>
>>> Thank you for your questions!
>>> I think they are really good and tackle the core of the problem I see.
>>>
>>> I will answer inline, mostly but still want to set the tone here.
>>>
>>> The core strength of kafka is what Martin once called the
>>> kappa-Architecture. How does this work?
>>> You have everything as a log as in kafka. When you need to change
>>> something.
>>> You create the new version of your application and leave it running in
>>> parallel.
>>> Once the new version is good you switch your users to use the new
>>> application.
>>>
>>> The online reshuffling effectively breaks this architecture and I think
>>> the switch in thinking here is more harmful
>>> than any details about the partitioning function to allow such a change.
>>> I
>>> feel with my suggestion we are the closest to
>>> the original and battle proven architecture and I can only warn to move
>>> away from it.
>>>
>>> I might have forgotten something, sometimes its hard for me to getting
>>> all
>>> the thoughts captured in a mail, but I hope the comments inline will
>>> further make my concern clear, and put some emphasis on why I prefer my
>>> solution ;)
>>>
>>> One thing we should all be aware of when discussing this, and I think
>>> Dong
>>> should have mentioned it (maybe he did).
>>> We are not discussing all of this out of thin air but there is an effort
>>> in the Samza project.
>>>
>>> https://cwiki.apache.org/confluence/display/SAMZA/SEP-5%3A+
>>> Enable+partition+expansion+of+input+streams
>>> https://issues.apache.org/jira/browse/SAMZA-1293
>>>
>>> To be clear. I think SEP-5 (state of last week, dont know if it adapted
>>> to
>>> this discussion) is on a way better path than KIP-253, and I can't really
>>> explain why.
>>>
>>> Best Jan,
>>>
>>> nice weekend everyone
>>>
>>>
>>> On 09.03.2018 03:36, Jun Rao wrote:
>>>
>>> Hi, Jan,
>>>>
>>>> Thanks for the feedback. Just some comments on the earlier points that
>>>> you
>>>> mentioned.
>>>>
>>>> 50. You brought up the question of whether existing data needs to be
>>>> copied
>>>> during partition expansion. My understand of your view is that avoid
>>>> copying existing data will be more efficient, but it doesn't work well
>>>> with
>>>> compacted topics since some keys in the original partitions will never
>>>> be
>>>> cleaned. It would be useful to understand your use case of compacted
>>>> topics
>>>> a bit more. In the common use case, the data volume in a compacted topic
>>>> may not be large. So, I am not sure if there is a strong need to expand
>>>> partitions in a compacted topic, at least initially.
>>>>
>>>> I do agree. State is usually smaller. Update rates might be also
>>> competitively high.
>>> Doing Log-compaction (even beeing very efficient and configurable) is
>>> also
>>> a more expensive operation than
>>> just discarding old segments. Further if you want to use more consumers
>>> processing the events
>>> you also have to grow the number of partitions. Especially for use-cases
>>> we do (KIP-213) a tiny state full
>>> table might be very expensive to process if it joins against a huge
>>> table.
>>>
>>> I can just say we have been in the spot of needing to grow log compacted
>>> topics. Mainly for processing power we can bring to the table.
>>>
>>> Further i am not at all concerned about the extra spaced used by "garbage
>>> keys". I am more concerned about the correctness of innocent consumers.
>>> The
>>> logic becomes complicated. Say for streams one would need to load the
>>> record into state but not forward it the topology ( to have it available
>>> for shuffeling). I rather have it simple and a topic clean regardless if
>>> it
>>> still has its old partition count. Especially with multiple partitions
>>> growth's I think it becomes insanely hard to to this shuffle correct.
>>> Maybe
>>> Streams and Samza can do it. Especially if you do "hipster stream
>>> processing" <https://www.confluent.io/blog/introducing-kafka-streams-
>>> stream-processing-made-simple/>. This makes kafka way to complicated.
>>> With my approach I think its way simpler because the topic has no
>>> "history"
>>> in terms of partitioning but is always clean.
>>>
>>>
>>> 51. "Growing the topic by an integer factor does not require any state
>>>> redistribution at all." Could you clarify this a bit more? Let's say you
>>>> have a consumer app that computes the windowed count per key. If you
>>>> double
>>>> the number of partitions from 1 to 2 and grow the consumer instances
>>>> from
>>>> 1
>>>> to 2, we would need to redistribute some of the counts to the new
>>>> consumer
>>>> instance. Regarding to linear hashing, it's true that it won't solve the
>>>> problem with compacted topics. The main benefit is that it redistributes
>>>> the keys in one partition to no more than two partitions, which could
>>>> help
>>>> redistribute the state.
>>>>
>>>> You don't need to spin up a new consumer in this case. every consumer
>>> would just read every partition with the (partition % num_task) task. it
>>> will still have the previous data right there and can go on.
>>>
>>> This sounds contradictory to what I said before, but please bear with me.
>>>
>>> 52. Good point on coordinating the expansion of 2 topics that need to be
>>>> joined together. This is where the 2-phase partition expansion could
>>>> potentially help. In the first phase, we could add new partitions to
>>>> the 2
>>>> topics one at a time but without publishing to the new patitions. Then,
>>>> we
>>>> can add new consumer instances to pick up the new partitions. In this
>>>> transition phase, no reshuffling is needed since no data is coming from
>>>> the
>>>> new partitions. Finally, we can enable the publishing to the new
>>>> partitions.
>>>>
>>>> I think its even worse than you think. I would like to introduce the
>>> Term
>>> transitive copartitioning. Imagine
>>> 2 streams application. One joins (A,B) the other (B,C) then there is a
>>> transitive copartition requirement for
>>> (A,C) to be copartitioned aswell. This can spread significantly and
>>> require many consumers to adapt at the same time.
>>>
>>> It is also not entirely clear to me how you not need reshuffling in this
>>> case. If A has a record that never gets updated after the expansion and
>>> the
>>> coresponding B record moves to a new partition. How shall they meet w/o
>>> shuffle?
>>>
>>> 53. "Migrating consumer is a step that might be made completly
>>>> unnecessary
>>>> if - for example streams - takes the gcd as partitioning scheme instead
>>>> of
>>>> enforcing 1 to 1." Not sure that I fully understand this. I think you
>>>> mean
>>>> that a consumer application can run more instances than the number of
>>>> partitions. In that case, the consumer can just repartitioning the input
>>>> data according to the number of instances. This is possible, but just
>>>> has
>>>> the overhead of reshuffling the data.
>>>>
>>>> No what I meant is ( that is also your question i think Mathias) that if
>>> you grow a topic by a factor.
>>> Even if your processor is statefull you can can just assign all the
>>> multiples of the previous partition to
>>> this consumer and the state to keep processing correctly will be present
>>> w/o any shuffling.
>>>
>>> Say you have an assignment
>>> Statefull consumer => partition
>>> 0 => 0
>>> 1 => 1
>>> 2 => 2
>>>
>>> and you grow you topic by 4 you get,
>>>
>>> 0 => 0,3,6,9
>>> 1 => 1,4,7,10
>>> 2 => 2,5,8,11
>>>
>>> Say your hashcode is 8. 8%3 => 2  before so consumer for partition 2 has
>>> it.
>>> Now you you have 12 partitions so 8%12 => 8, so it goes into partition 8
>>> which is assigned to the same consumer
>>> who had 2 before and therefore knows the key.
>>>
>>> Userland reshuffeling is there as an options. And it does exactly what I
>>> suggest. And I think its the perfect strategie. All I am suggestion is
>>> broker side support to switch the producers to the newly partitioned
>>> topic.
>>> Then the old (to few partition topic) can go away.  Remember the list of
>>> steps in the beginning of this thread. If one has broker support for all
>>> where its required and streams support for those that aren’t necessarily.
>>> Then one has solved the problem.
>>> I repeat it because I think its important. I am really happy that you
>>> brought that up! because its 100% what I want just with the differences
>>> to
>>> have an option to discard the to small topic later (after all consumers
>>> adapted). And to have order correct there. I need broker support managing
>>> the copy process + the produces and fence them against each other. I also
>>> repeat. the copy process can run for weeks in the worst case. Copying the
>>> data is not the longest task migrating consumers might very well be.
>>> Once all consumers switched and copying is really up to date (think ISR
>>> like up to date) only then we stop the producer, wait for the copy to
>>> finish and use the new topic for producing.
>>>
>>> After this the topic is perfect in shape. and no one needs to worry about
>>> complicated stuff. (old keys hanging around might arrive in some other
>>> topic later.....). can only imagine how many tricky bugs gonna arrive
>>> after
>>> someone had grown and shrunken is topic 10 times.
>>>
>>>
>>>
>>>
>>>
>>>
>>> 54. "The other thing I wanted to mention is that I believe the current
>>>> suggestion (without copying data over) can be implemented in pure
>>>> userland
>>>> with a custom partitioner and a small feedbackloop from ProduceResponse
>>>> =>
>>>> Partitionier in coorporation with a change management system." I am not
>>>> sure a customized partitioner itself solves the problem. We probably
>>>> need
>>>> some broker side support to enforce when the new partitions can be used.
>>>> We
>>>> also need some support on the consumer/kstream side to preserve the per
>>>> key
>>>> ordering and potentially migrate the processing state. This is not
>>>> trivial
>>>> and I am not sure if it's ideal to fully push to the application space.
>>>>
>>>> Broker support is defenitly the preferred way here. I have nothing
>>> against
>>> broker support.
>>> I tried to say that for what I would preffer - copying the data over, at
>>> least for log compacted topics -
>>> I would require more broker support than the KIP currently offers.
>>>
>>>
>>>
>>> Jun
>>>>
>>>>
>>>> On Tue, Mar 6, 2018 at 10:33 PM, Jan Filipiak <Jan.Filipiak@trivago.com
>>>> >
>>>> wrote:
>>>>
>>>> Hi Dong,
>>>>
>>>>> are you actually reading my emails, or are you just using the thread I
>>>>> started for general announcements regarding the KIP?
>>>>>
>>>>> I tried to argue really hard against linear hashing. Growing the topic
>>>>> by
>>>>> an integer factor does not require any state redistribution at all. I
>>>>> fail
>>>>> to see completely where linear hashing helps on log compacted topics.
>>>>>
>>>>> If you are not willing to explain to me what I might be overlooking:
>>>>> that
>>>>> is fine.
>>>>> But I ask you to not reply to my emails then. Please understand my
>>>>> frustration with this.
>>>>>
>>>>> Best Jan
>>>>>
>>>>>
>>>>>
>>>>> On 06.03.2018 19:38, Dong Lin wrote:
>>>>>
>>>>> Hi everyone,
>>>>>
>>>>>> Thanks for all the comments! It appears that everyone prefers linear
>>>>>> hashing because it reduces the amount of state that needs to be moved
>>>>>> between consumers (for stream processing). The KIP has been updated to
>>>>>> use
>>>>>> linear hashing.
>>>>>>
>>>>>> Regarding the migration endeavor: it seems that migrating producer
>>>>>> library
>>>>>> to use linear hashing should be pretty straightforward without
>>>>>> much operational endeavor. If we don't upgrade client library to use
>>>>>> this
>>>>>> KIP, we can not support in-order delivery after partition is changed
>>>>>> anyway. Suppose we upgrade client library to use this KIP, if
>>>>>> partition
>>>>>> number is not changed, the key -> partition mapping will be exactly
>>>>>> the
>>>>>> same as it is now because it is still determined using
>>>>>> murmur_hash(key)
>>>>>> %
>>>>>> original_partition_num. In other words, this change is backward
>>>>>> compatible.
>>>>>>
>>>>>> Regarding the load distribution: if we use linear hashing, the load
>>>>>> may
>>>>>> be
>>>>>> unevenly distributed because those partitions which are not split may
>>>>>> receive twice as much traffic as other partitions that are split. This
>>>>>> issue can be mitigated by creating topic with partitions that are
>>>>>> several
>>>>>> times the number of consumers. And there will be no imbalance if the
>>>>>> partition number is always doubled. So this imbalance seems
>>>>>> acceptable.
>>>>>>
>>>>>> Regarding storing the partition strategy as per-topic config: It seems
>>>>>> not
>>>>>> necessary since we can still use murmur_hash as the default hash
>>>>>> function
>>>>>> and additionally apply the linear hashing algorithm if the partition
>>>>>> number
>>>>>> has increased. Not sure if there is any use-case for producer to use a
>>>>>> different hash function. Jason, can you check if there is some
>>>>>> use-case
>>>>>> that I missed for using the per-topic partition strategy?
>>>>>>
>>>>>> Regarding how to reduce latency (due to state store/load) in stream
>>>>>> processing consumer when partition number changes: I need to read the
>>>>>> Kafka
>>>>>> Stream code to understand how Kafka Stream currently migrate state
>>>>>> between
>>>>>> consumers when the application is added/removed for a given job. I
>>>>>> will
>>>>>> reply after I finish reading the documentation and code.
>>>>>>
>>>>>>
>>>>>> Thanks,
>>>>>> Dong
>>>>>>
>>>>>>
>>>>>> On Mon, Mar 5, 2018 at 10:43 AM, Jason Gustafson <ja...@confluent.io>
>>>>>> wrote:
>>>>>>
>>>>>> Great discussion. I think I'm wondering whether we can continue to
>>>>>> leave
>>>>>>
>>>>>> Kafka agnostic to the partitioning strategy. The challenge is
>>>>>>> communicating
>>>>>>> the partitioning logic from producers to consumers so that the
>>>>>>> dependencies
>>>>>>> between each epoch can be determined. For the sake of discussion,
>>>>>>> imagine
>>>>>>> you did something like the following:
>>>>>>>
>>>>>>> 1. The name (and perhaps version) of a partitioning strategy is
>>>>>>> stored
>>>>>>> in
>>>>>>> topic configuration when a topic is created.
>>>>>>> 2. The producer looks up the partitioning strategy before writing to
>>>>>>> a
>>>>>>> topic and includes it in the produce request (for fencing). If it
>>>>>>> doesn't
>>>>>>> have an implementation for the configured strategy, it fails.
>>>>>>> 3. The consumer also looks up the partitioning strategy and uses it
>>>>>>> to
>>>>>>> determine dependencies when reading a new epoch. It could either fail
>>>>>>> or
>>>>>>> make the most conservative dependency assumptions if it doesn't know
>>>>>>> how
>>>>>>> to
>>>>>>> implement the partitioning strategy. For the consumer, the new
>>>>>>> interface
>>>>>>> might look something like this:
>>>>>>>
>>>>>>> // Return the partition dependencies following an epoch bump
>>>>>>> Map<Integer, List<Integer>> dependencies(int
>>>>>>> numPartitionsBeforeEpochBump,
>>>>>>> int numPartitionsAfterEpochBump)
>>>>>>>
>>>>>>> The unordered case then is just a particular implementation which
>>>>>>> never
>>>>>>> has
>>>>>>> any epoch dependencies. To implement this, we would need some way for
>>>>>>> the
>>>>>>> consumer to find out how many partitions there were in each epoch,
>>>>>>> but
>>>>>>> maybe that's not too unreasonable.
>>>>>>>
>>>>>>> Thanks,
>>>>>>> Jason
>>>>>>>
>>>>>>>
>>>>>>> On Mon, Mar 5, 2018 at 4:51 AM, Jan Filipiak <
>>>>>>> Jan.Filipiak@trivago.com
>>>>>>> wrote:
>>>>>>>
>>>>>>> Hi Dong
>>>>>>>
>>>>>>> thank you very much for your questions.
>>>>>>>>
>>>>>>>> regarding the time spend copying data across:
>>>>>>>> It is correct that copying data from a topic with one partition
>>>>>>>> mapping
>>>>>>>>
>>>>>>>> to
>>>>>>>>
>>>>>>> a topic with a different partition mapping takes way longer than we
>>>>>>> can
>>>>>>>
>>>>>>>> stop producers. Tens of minutes is a very optimistic estimate here.
>>>>>>>> Many
>>>>>>>> people can not afford copy full steam and therefore will have some
>>>>>>>> rate
>>>>>>>> limiting in place, this can bump the timespan into the day's. The
>>>>>>>> good
>>>>>>>>
>>>>>>>> part
>>>>>>>>
>>>>>>> is that the vast majority of the data can be copied while the
>>>>>>> producers
>>>>>>>
>>>>>>>> are
>>>>>>>>
>>>>>>> still going. One can then, piggyback the consumers ontop of this
>>>>>>>
>>>>>>>> timeframe,
>>>>>>>>
>>>>>>> by the method mentioned (provide them an mapping from their old
>>>>>>> offsets
>>>>>>>
>>>>>>>> to
>>>>>>>>
>>>>>>> new offsets in their repartitioned topics. In that way we separate
>>>>>>>
>>>>>>>> migration of consumers from migration of producers (decoupling these
>>>>>>>> is
>>>>>>>> what kafka is strongest at). The time to actually swap over the
>>>>>>>> producers
>>>>>>>> should be kept minimal by ensuring that when a swap attempt is
>>>>>>>> started
>>>>>>>>
>>>>>>>> the
>>>>>>>>
>>>>>>> consumer copying over should be very close to the log end and is
>>>>>>>
>>>>>>>> expected
>>>>>>>> to finish within the next fetch. The operation should have a
>>>>>>>> time-out
>>>>>>>> and
>>>>>>>> should be "reattemtable".
>>>>>>>>
>>>>>>>> Importance of logcompaction:
>>>>>>>> If a producer produces key A, to partiton 0, its forever gonna be
>>>>>>>> there,
>>>>>>>> unless it gets deleted. The record might sit in there for years. A
>>>>>>>> new
>>>>>>>> producer started with the new partitions will fail to delete the
>>>>>>>> record
>>>>>>>>
>>>>>>>> in
>>>>>>>>
>>>>>>> the correct partition. Th record will be there forever and one can
>>>>>>> not
>>>>>>>
>>>>>>>> reliable bootstrap new consumers. I cannot see how linear hashing
>>>>>>>> can
>>>>>>>>
>>>>>>>> solve
>>>>>>>>
>>>>>>> this.
>>>>>>>
>>>>>>>> Regarding your skipping of userland copying:
>>>>>>>> 100%, copying the data across in userland is, as far as i can see,
>>>>>>>> only
>>>>>>>> a
>>>>>>>> usecase for log compacted topics. Even for logcompaction +
>>>>>>>> retentions
>>>>>>>> it
>>>>>>>> should only be opt-in. Why did I bring it up? I think log compaction
>>>>>>>> is
>>>>>>>> a
>>>>>>>> very important feature to really embrace kafka as a "data
>>>>>>>> plattform".
>>>>>>>> The
>>>>>>>> point I also want to make is that copying data this way is
>>>>>>>> completely
>>>>>>>> inline with the kafka architecture. it only consists of reading and
>>>>>>>>
>>>>>>>> writing
>>>>>>>>
>>>>>>> to topics.
>>>>>>>
>>>>>>>> I hope it clarifies more why I think we should aim for more than the
>>>>>>>> current KIP. I fear that once the KIP is done not much more effort
>>>>>>>> will
>>>>>>>>
>>>>>>>> be
>>>>>>>>
>>>>>>> taken.
>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> On 04.03.2018 02:28, Dong Lin wrote:
>>>>>>>>
>>>>>>>> Hey Jan,
>>>>>>>>
>>>>>>>> In the current proposal, the consumer will be blocked on waiting for
>>>>>>>>>
>>>>>>>>> other
>>>>>>>>>
>>>>>>>> consumers of the group to consume up to a given offset. In most
>>>>>>>> cases,
>>>>>>>> all
>>>>>>>> consumers should be close to the LEO of the partitions when the
>>>>>>>> partition
>>>>>>>> expansion happens. Thus the time waiting should not be long e.g. on
>>>>>>>> the
>>>>>>>>
>>>>>>>> order of seconds. On the other hand, it may take a long time to wait
>>>>>>>>> for
>>>>>>>>> the entire partition to be copied -- the amount of time is
>>>>>>>>> proportional
>>>>>>>>>
>>>>>>>>> to
>>>>>>>>>
>>>>>>>> the amount of existing data in the partition, which can take tens of
>>>>>>>>
>>>>>>>> minutes. So the amount of time that we stop consumers may not be on
>>>>>>>>> the
>>>>>>>>> same order of magnitude.
>>>>>>>>>
>>>>>>>>> If we can implement this suggestion without copying data over in
>>>>>>>>> purse
>>>>>>>>> userland, it will be much more valuable. Do you have ideas on how
>>>>>>>>> this
>>>>>>>>>
>>>>>>>>> can
>>>>>>>>>
>>>>>>>> be done?
>>>>>>>>
>>>>>>>> Not sure why the current KIP not help people who depend on log
>>>>>>>>>
>>>>>>>>> compaction.
>>>>>>>>>
>>>>>>>> Could you elaborate more on this point?
>>>>>>>>
>>>>>>>> Thanks,
>>>>>>>>> Dong
>>>>>>>>>
>>>>>>>>> On Wed, Feb 28, 2018 at 10:55 PM, Jan
>>>>>>>>> Filipiak<Jan.Filipiak@trivago.
>>>>>>>>> com
>>>>>>>>> wrote:
>>>>>>>>>
>>>>>>>>> Hi Dong,
>>>>>>>>>
>>>>>>>>> I tried to focus on what the steps are one can currently perform to
>>>>>>>>>
>>>>>>>>>> expand
>>>>>>>>>> or shrink a keyed topic while maintaining a top notch semantics.
>>>>>>>>>> I can understand that there might be confusion about "stopping the
>>>>>>>>>> consumer". It is exactly the same as proposed in the KIP. there
>>>>>>>>>> needs
>>>>>>>>>>
>>>>>>>>>> to
>>>>>>>>>>
>>>>>>>>> be
>>>>>>>>
>>>>>>>> a time the producers agree on the new partitioning. The extra
>>>>>>>>>
>>>>>>>>>> semantics I
>>>>>>>>>>
>>>>>>>>> want to put in there is that we have a possibility to wait until
>>>>>>>> all
>>>>>>>>
>>>>>>>> the
>>>>>>>>>
>>>>>>>>> existing data
>>>>>>>>
>>>>>>>> is copied over into the new partitioning scheme. When I say stopping
>>>>>>>>>
>>>>>>>>>> I
>>>>>>>>>> think more of having a memory barrier that ensures the ordering. I
>>>>>>>>>> am
>>>>>>>>>> still
>>>>>>>>>> aming for latencies  on the scale of leader failovers.
>>>>>>>>>>
>>>>>>>>>> Consumers have to explicitly adapt the new partitioning scheme in
>>>>>>>>>> the
>>>>>>>>>> above scenario. The reason is that in these cases where you are
>>>>>>>>>>
>>>>>>>>>> dependent
>>>>>>>>>>
>>>>>>>>> on a particular partitioning scheme, you also have other topics
>>>>>>>> that
>>>>>>>>
>>>>>>>> have
>>>>>>>>>
>>>>>>>>> co-partition enforcements or the kind -frequently. Therefore all
>>>>>>>> your
>>>>>>>>
>>>>>>>> other
>>>>>>>>>
>>>>>>>>>> input topics might need to grow accordingly.
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> What I was suggesting was to streamline all these operations as
>>>>>>>>>> best
>>>>>>>>>> as
>>>>>>>>>> possible to have "real" partition grow and shrinkage going on.
>>>>>>>>>>
>>>>>>>>>> Migrating
>>>>>>>>>>
>>>>>>>>> the producers to a new partitioning scheme can be much more
>>>>>>>> streamlined
>>>>>>>>
>>>>>>>> with proper broker support for this. Migrating consumer is a step
>>>>>>>>>
>>>>>>>>>> that
>>>>>>>>>> might be made completly unnecessary if - for example streams -
>>>>>>>>>> takes
>>>>>>>>>>
>>>>>>>>>> the
>>>>>>>>>>
>>>>>>>>> gcd as partitioning scheme instead of enforcing 1 to 1. Connect
>>>>>>>>
>>>>>>>> consumers
>>>>>>>>>
>>>>>>>>> and other consumers should be fine anyways.
>>>>>>>>
>>>>>>>> I hope this makes more clear where I was aiming at. The rest needs
>>>>>>>>> to
>>>>>>>>>
>>>>>>>>>> be
>>>>>>>>>>
>>>>>>>>> figured out. The only danger i see is that when we are introducing
>>>>>>>> this
>>>>>>>>
>>>>>>>> feature as supposed in the KIP, it wont help any people depending on
>>>>>>>>>
>>>>>>>>>> log
>>>>>>>>>>
>>>>>>>>> compaction.
>>>>>>>>
>>>>>>>> The other thing I wanted to mention is that I believe the current
>>>>>>>>>
>>>>>>>>>> suggestion (without copying data over) can be implemented in pure
>>>>>>>>>> userland
>>>>>>>>>> with a custom partitioner and a small feedbackloop from
>>>>>>>>>> ProduceResponse
>>>>>>>>>> =>
>>>>>>>>>> Partitionier in coorporation with a change management system.
>>>>>>>>>>
>>>>>>>>>> Best Jan
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> On 28.02.2018 07:13, Dong Lin wrote:
>>>>>>>>>>
>>>>>>>>>> Hey Jan,
>>>>>>>>>>
>>>>>>>>>> I am not sure if it is acceptable for producer to be stopped for a
>>>>>>>>>>
>>>>>>>>>>> while,
>>>>>>>>>>> particularly for online application which requires low latency. I
>>>>>>>>>>> am
>>>>>>>>>>> also
>>>>>>>>>>> not sure how consumers can switch to a new topic. Does user
>>>>>>>>>>>
>>>>>>>>>>> application
>>>>>>>>>>>
>>>>>>>>>> needs to explicitly specify a different topic for
>>>>>>>>> producer/consumer
>>>>>>>>>
>>>>>>>> to
>>>>>>>>
>>>>>>>> subscribe to? It will be helpful for discussion if you can provide
>>>>>>>>>
>>>>>>>>>> more
>>>>>>>>>>>
>>>>>>>>>> detail on the interface change for this solution.
>>>>>>>>> Thanks,
>>>>>>>>>
>>>>>>>>>> Dong
>>>>>>>>>>>
>>>>>>>>>>> On Mon, Feb 26, 2018 at 12:48 AM, Jan
>>>>>>>>>>> Filipiak<Jan.Filipiak@trivago.
>>>>>>>>>>>
>>>>>>>>>>> com
>>>>>>>>>>>
>>>>>>>>>> wrote:
>>>>>>>>> Hi,
>>>>>>>>>
>>>>>>>>>> just want to throw my though in. In general the functionality is
>>>>>>>>>>> very
>>>>>>>>>>>
>>>>>>>>>>> usefull, we should though not try to find the architecture to
>>>>>>>>>>>> hard
>>>>>>>>>>>> while
>>>>>>>>>>>> implementing.
>>>>>>>>>>>>
>>>>>>>>>>>> The manual steps would be to
>>>>>>>>>>>>
>>>>>>>>>>>> create a new topic
>>>>>>>>>>>> the mirrormake from the new old topic to the new topic
>>>>>>>>>>>> wait for mirror making to catch up.
>>>>>>>>>>>> then put the consumers onto the new topic
>>>>>>>>>>>>          (having mirrormaker spit out a mapping from old
>>>>>>>>>>>> offsets to
>>>>>>>>>>>> new
>>>>>>>>>>>> offsets:
>>>>>>>>>>>>              if topic is increased by factor X there is gonna
>>>>>>>>>>>> be a
>>>>>>>>>>>> clean
>>>>>>>>>>>> mapping from 1 offset in the old topic to X offsets in the new
>>>>>>>>>>>> topic,
>>>>>>>>>>>>              if there is no factor then there is no chance to
>>>>>>>>>>>> generate a
>>>>>>>>>>>> mapping that can be reasonable used for continuing)
>>>>>>>>>>>>          make consumers stop at appropriate points and continue
>>>>>>>>>>>> consumption
>>>>>>>>>>>> with offsets from the mapping.
>>>>>>>>>>>> have the producers stop for a minimal time.
>>>>>>>>>>>> wait for mirrormaker to finish
>>>>>>>>>>>> let producer produce with the new metadata.
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>> Instead of implementing the approach suggest in the KIP which
>>>>>>>>>>>> will
>>>>>>>>>>>> leave
>>>>>>>>>>>> log compacted topic completely crumbled and unusable.
>>>>>>>>>>>> I would much rather try to build infrastructure to support the
>>>>>>>>>>>> mentioned
>>>>>>>>>>>> above operations more smoothly.
>>>>>>>>>>>> Especially having producers stop and use another topic is
>>>>>>>>>>>> difficult
>>>>>>>>>>>>
>>>>>>>>>>>> and
>>>>>>>>>>>>
>>>>>>>>>>> it would be nice if one can trigger "invalid metadata" exceptions
>>>>>>>>>>
>>>>>>>>> for
>>>>>>>>
>>>>>>>> them
>>>>>>>>>
>>>>>>>>>> and
>>>>>>>>>>>> if one could give topics aliases so that their produces with the
>>>>>>>>>>>> old
>>>>>>>>>>>> topic
>>>>>>>>>>>> will arrive in the new topic.
>>>>>>>>>>>>
>>>>>>>>>>>> The downsides are obvious I guess ( having the same data twice
>>>>>>>>>>>> for
>>>>>>>>>>>>
>>>>>>>>>>>> the
>>>>>>>>>>>>
>>>>>>>>>>> transition period, but kafka tends to scale well with datasize).
>>>>>>>>>> So
>>>>>>>>>>
>>>>>>>>> its a
>>>>>>>>>
>>>>>>>>>> nicer fit into the architecture.
>>>>>>>>>>>>
>>>>>>>>>>>> I further want to argument that the functionality by the KIP can
>>>>>>>>>>>> completely be implementing in "userland" with a custom
>>>>>>>>>>>> partitioner
>>>>>>>>>>>>
>>>>>>>>>>>> that
>>>>>>>>>>>>
>>>>>>>>>>> handles the transition as needed. I would appreciate if someone
>>>>>>>>>>
>>>>>>>>> could
>>>>>>>>
>>>>>>>> point
>>>>>>>>>
>>>>>>>>>> out what a custom partitioner couldn't handle in this case?
>>>>>>>>>>>>
>>>>>>>>>>>> With the above approach, shrinking a topic becomes the same
>>>>>>>>>>>> steps.
>>>>>>>>>>>> Without
>>>>>>>>>>>> loosing keys in the discontinued partitions.
>>>>>>>>>>>>
>>>>>>>>>>>> Would love to hear what everyone thinks.
>>>>>>>>>>>>
>>>>>>>>>>>> Best Jan
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>> On 11.02.2018 00:35, Dong Lin wrote:
>>>>>>>>>>>>
>>>>>>>>>>>> Hi all,
>>>>>>>>>>>>
>>>>>>>>>>>> I have created KIP-253: Support in-order message delivery with
>>>>>>>>>>>>
>>>>>>>>>>>> partition
>>>>>>>>>>>>> expansion. See
>>>>>>>>>>>>> https://cwiki.apache.org/confluence/display/KAFKA/KIP-253%
>>>>>>>>>>>>> 3A+Support+in-order+message+delivery+with+partition+expansion
>>>>>>>>>>>>> .
>>>>>>>>>>>>>
>>>>>>>>>>>>> This KIP provides a way to allow messages of the same key from
>>>>>>>>>>>>> the
>>>>>>>>>>>>> same
>>>>>>>>>>>>> producer to be consumed in the same order they are produced
>>>>>>>>>>>>> even
>>>>>>>>>>>>> if
>>>>>>>>>>>>>
>>>>>>>>>>>>> we
>>>>>>>>>>>>>
>>>>>>>>>>>> expand partition of the topic.
>>>>>>>>>>>
>>>>>>>>>> Thanks,
>>>>>>>>>
>>>>>>>>>> Dong
>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>>
>

Re: [DISCUSS] KIP-253: Support in-order message delivery with partition expansion

Posted by Jan Filipiak <Ja...@trivago.com>.
Hi Jun,

I will focus on point 61 as I think its _the_ fundamental part that I 
cant get across at the moment.

Kafka is the platform to have state materialized multiple times from one 
input. I emphasize this: It is the building block in architectures that 
allow you to
have your state maintained multiple times. You put a message in once, 
and you have it pop out as often as you like. I believe you understand this.

Now! The path of thinking goes the following: I am using apache kafka 
and I _want_ my state multiple times. What am I going todo?

A) Am I going to take my state that I build up, plunge some sort of RPC 
layer ontop of it, use that RPC layer to throw my records across instances?
B) Am I just going to read the damn message twice?

Approach A is fundamentally flawed and a violation of all that is good 
and holy in kafka deployments. I can not understand how this Idea can 
come in the first place.
(I do understand: IQ in streams, they polluted the kafka streams 
codebase really bad already. It is not funny! I think they are equally 
flawed as A)

I say, we do what Kafka is good at. We repartition the topic once. We 
switch the consumers.
(Those that need more partitions are going to rebuild their state in 
multiple partitions by reading the new topic, those that don't just 
assign the new partitions properly)
We switch producers. Done!

The best thing! It is trivial, hipster stream processor will have an 
easy time with that aswell. Its so super simple. And simple IS good!
It is what kafka was build todo. It is how we do it today. All I am 
saying is that a little broker help doing the producer swap is super useful.

For everyone interested in why kafka is so powerful with approach B, 
please watch https://youtu.be/bEbeZPVo98c?t=1633
I already looked up a good point in time, I think after 5 minutes the 
"state" topic is handled and you should be able to understand me
and inch better.

Please do not do A to the project, it deserves better!

Best Jan



On 13.03.2018 02:40, Jun Rao wrote:
> Hi, Jan,
>
> Thanks for the reply. A few more comments below.
>
> 50. Ok, we can think a bit harder for supporting compacted topics.
>
> 51. This is a fundamental design question. In the more common case, the
> reason why someone wants to increase the number of partitions is that the
> consumer application is slow and one wants to run more consumer instances
> to increase the degree of parallelism. So, fixing the number of running
> consumer instances when expanding the partitions won't help this case. If
> we do need to increase the number of consumer instances, we need to somehow
> reshuffle the state of the consumer across instances. What we have been
> discussing in this KIP is whether we can do this more effectively through
> the KStream library (e.g. through a 2-phase partition expansion). This will
> add some complexity, but it's probably better than everyone doing this in
> the application space. The recopying approach that you mentioned doesn't
> seem to address the consumer state management issue when the consumer
> switches from an old to a new topic.
>
> 52. As for your example, it depends on whether the join key is the same
> between (A,B) and (B,C). If the join key is the same, we can do a 2-phase
> partition expansion of A, B, and C together. If the join keys are
> different, one would need to repartition the data on a different key for
> the second join, then the partition expansion can be done independently
> between (A,B) and (B,C).
>
> 53. If you always fix the number of consumer instances, we you described
> works. However, as I mentioned in #51, I am not sure how your proposal
> deals with consumer states when the number of consumer instances grows.
> Also, it just seems that it's better to avoid re-copying the existing data.
>
> 60. "just want to throw in my question from the longer email in the other
> Thread here. How will the bloom filter help a new consumer to decide to
> apply the key or not?" Not sure that I fully understood your question. The
> consumer just reads whatever key is in the log. The bloom filter just helps
> clean up the old keys.
>
> 61. "Why can we afford having a topic where its apparently not possible to
> start a new application on? I think this is an overall flaw of the
> discussed idea here. Not playing attention to the overall architecture."
> Could you explain a bit more when one can't start a new application?
>
> Jun
>
>
>
> On Sat, Mar 10, 2018 at 1:40 AM, Jan Filipiak <Ja...@trivago.com>
> wrote:
>
>> Hi Jun, thanks for your mail.
>>
>> Thank you for your questions!
>> I think they are really good and tackle the core of the problem I see.
>>
>> I will answer inline, mostly but still want to set the tone here.
>>
>> The core strength of kafka is what Martin once called the
>> kappa-Architecture. How does this work?
>> You have everything as a log as in kafka. When you need to change
>> something.
>> You create the new version of your application and leave it running in
>> parallel.
>> Once the new version is good you switch your users to use the new
>> application.
>>
>> The online reshuffling effectively breaks this architecture and I think
>> the switch in thinking here is more harmful
>> than any details about the partitioning function to allow such a change. I
>> feel with my suggestion we are the closest to
>> the original and battle proven architecture and I can only warn to move
>> away from it.
>>
>> I might have forgotten something, sometimes its hard for me to getting all
>> the thoughts captured in a mail, but I hope the comments inline will
>> further make my concern clear, and put some emphasis on why I prefer my
>> solution ;)
>>
>> One thing we should all be aware of when discussing this, and I think Dong
>> should have mentioned it (maybe he did).
>> We are not discussing all of this out of thin air but there is an effort
>> in the Samza project.
>>
>> https://cwiki.apache.org/confluence/display/SAMZA/SEP-5%3A+
>> Enable+partition+expansion+of+input+streams
>> https://issues.apache.org/jira/browse/SAMZA-1293
>>
>> To be clear. I think SEP-5 (state of last week, dont know if it adapted to
>> this discussion) is on a way better path than KIP-253, and I can't really
>> explain why.
>>
>> Best Jan,
>>
>> nice weekend everyone
>>
>>
>> On 09.03.2018 03:36, Jun Rao wrote:
>>
>>> Hi, Jan,
>>>
>>> Thanks for the feedback. Just some comments on the earlier points that you
>>> mentioned.
>>>
>>> 50. You brought up the question of whether existing data needs to be
>>> copied
>>> during partition expansion. My understand of your view is that avoid
>>> copying existing data will be more efficient, but it doesn't work well
>>> with
>>> compacted topics since some keys in the original partitions will never be
>>> cleaned. It would be useful to understand your use case of compacted
>>> topics
>>> a bit more. In the common use case, the data volume in a compacted topic
>>> may not be large. So, I am not sure if there is a strong need to expand
>>> partitions in a compacted topic, at least initially.
>>>
>> I do agree. State is usually smaller. Update rates might be also
>> competitively high.
>> Doing Log-compaction (even beeing very efficient and configurable) is also
>> a more expensive operation than
>> just discarding old segments. Further if you want to use more consumers
>> processing the events
>> you also have to grow the number of partitions. Especially for use-cases
>> we do (KIP-213) a tiny state full
>> table might be very expensive to process if it joins against a huge table.
>>
>> I can just say we have been in the spot of needing to grow log compacted
>> topics. Mainly for processing power we can bring to the table.
>>
>> Further i am not at all concerned about the extra spaced used by "garbage
>> keys". I am more concerned about the correctness of innocent consumers. The
>> logic becomes complicated. Say for streams one would need to load the
>> record into state but not forward it the topology ( to have it available
>> for shuffeling). I rather have it simple and a topic clean regardless if it
>> still has its old partition count. Especially with multiple partitions
>> growth's I think it becomes insanely hard to to this shuffle correct. Maybe
>> Streams and Samza can do it. Especially if you do "hipster stream
>> processing" <https://www.confluent.io/blog/introducing-kafka-streams-
>> stream-processing-made-simple/>. This makes kafka way to complicated.
>> With my approach I think its way simpler because the topic has no "history"
>> in terms of partitioning but is always clean.
>>
>>
>>> 51. "Growing the topic by an integer factor does not require any state
>>> redistribution at all." Could you clarify this a bit more? Let's say you
>>> have a consumer app that computes the windowed count per key. If you
>>> double
>>> the number of partitions from 1 to 2 and grow the consumer instances from
>>> 1
>>> to 2, we would need to redistribute some of the counts to the new consumer
>>> instance. Regarding to linear hashing, it's true that it won't solve the
>>> problem with compacted topics. The main benefit is that it redistributes
>>> the keys in one partition to no more than two partitions, which could help
>>> redistribute the state.
>>>
>> You don't need to spin up a new consumer in this case. every consumer
>> would just read every partition with the (partition % num_task) task. it
>> will still have the previous data right there and can go on.
>>
>> This sounds contradictory to what I said before, but please bear with me.
>>
>>> 52. Good point on coordinating the expansion of 2 topics that need to be
>>> joined together. This is where the 2-phase partition expansion could
>>> potentially help. In the first phase, we could add new partitions to the 2
>>> topics one at a time but without publishing to the new patitions. Then, we
>>> can add new consumer instances to pick up the new partitions. In this
>>> transition phase, no reshuffling is needed since no data is coming from
>>> the
>>> new partitions. Finally, we can enable the publishing to the new
>>> partitions.
>>>
>> I think its even worse than you think. I would like to introduce the Term
>> transitive copartitioning. Imagine
>> 2 streams application. One joins (A,B) the other (B,C) then there is a
>> transitive copartition requirement for
>> (A,C) to be copartitioned aswell. This can spread significantly and
>> require many consumers to adapt at the same time.
>>
>> It is also not entirely clear to me how you not need reshuffling in this
>> case. If A has a record that never gets updated after the expansion and the
>> coresponding B record moves to a new partition. How shall they meet w/o
>> shuffle?
>>
>>> 53. "Migrating consumer is a step that might be made completly unnecessary
>>> if - for example streams - takes the gcd as partitioning scheme instead of
>>> enforcing 1 to 1." Not sure that I fully understand this. I think you mean
>>> that a consumer application can run more instances than the number of
>>> partitions. In that case, the consumer can just repartitioning the input
>>> data according to the number of instances. This is possible, but just has
>>> the overhead of reshuffling the data.
>>>
>> No what I meant is ( that is also your question i think Mathias) that if
>> you grow a topic by a factor.
>> Even if your processor is statefull you can can just assign all the
>> multiples of the previous partition to
>> this consumer and the state to keep processing correctly will be present
>> w/o any shuffling.
>>
>> Say you have an assignment
>> Statefull consumer => partition
>> 0 => 0
>> 1 => 1
>> 2 => 2
>>
>> and you grow you topic by 4 you get,
>>
>> 0 => 0,3,6,9
>> 1 => 1,4,7,10
>> 2 => 2,5,8,11
>>
>> Say your hashcode is 8. 8%3 => 2  before so consumer for partition 2 has
>> it.
>> Now you you have 12 partitions so 8%12 => 8, so it goes into partition 8
>> which is assigned to the same consumer
>> who had 2 before and therefore knows the key.
>>
>> Userland reshuffeling is there as an options. And it does exactly what I
>> suggest. And I think its the perfect strategie. All I am suggestion is
>> broker side support to switch the producers to the newly partitioned topic.
>> Then the old (to few partition topic) can go away.  Remember the list of
>> steps in the beginning of this thread. If one has broker support for all
>> where its required and streams support for those that aren’t necessarily.
>> Then one has solved the problem.
>> I repeat it because I think its important. I am really happy that you
>> brought that up! because its 100% what I want just with the differences to
>> have an option to discard the to small topic later (after all consumers
>> adapted). And to have order correct there. I need broker support managing
>> the copy process + the produces and fence them against each other. I also
>> repeat. the copy process can run for weeks in the worst case. Copying the
>> data is not the longest task migrating consumers might very well be.
>> Once all consumers switched and copying is really up to date (think ISR
>> like up to date) only then we stop the producer, wait for the copy to
>> finish and use the new topic for producing.
>>
>> After this the topic is perfect in shape. and no one needs to worry about
>> complicated stuff. (old keys hanging around might arrive in some other
>> topic later.....). can only imagine how many tricky bugs gonna arrive after
>> someone had grown and shrunken is topic 10 times.
>>
>>
>>
>>
>>
>>
>>> 54. "The other thing I wanted to mention is that I believe the current
>>> suggestion (without copying data over) can be implemented in pure userland
>>> with a custom partitioner and a small feedbackloop from ProduceResponse =>
>>> Partitionier in coorporation with a change management system." I am not
>>> sure a customized partitioner itself solves the problem. We probably need
>>> some broker side support to enforce when the new partitions can be used.
>>> We
>>> also need some support on the consumer/kstream side to preserve the per
>>> key
>>> ordering and potentially migrate the processing state. This is not trivial
>>> and I am not sure if it's ideal to fully push to the application space.
>>>
>> Broker support is defenitly the preferred way here. I have nothing against
>> broker support.
>> I tried to say that for what I would preffer - copying the data over, at
>> least for log compacted topics -
>> I would require more broker support than the KIP currently offers.
>>
>>
>>
>>> Jun
>>>
>>>
>>> On Tue, Mar 6, 2018 at 10:33 PM, Jan Filipiak <Ja...@trivago.com>
>>> wrote:
>>>
>>> Hi Dong,
>>>> are you actually reading my emails, or are you just using the thread I
>>>> started for general announcements regarding the KIP?
>>>>
>>>> I tried to argue really hard against linear hashing. Growing the topic by
>>>> an integer factor does not require any state redistribution at all. I
>>>> fail
>>>> to see completely where linear hashing helps on log compacted topics.
>>>>
>>>> If you are not willing to explain to me what I might be overlooking: that
>>>> is fine.
>>>> But I ask you to not reply to my emails then. Please understand my
>>>> frustration with this.
>>>>
>>>> Best Jan
>>>>
>>>>
>>>>
>>>> On 06.03.2018 19:38, Dong Lin wrote:
>>>>
>>>> Hi everyone,
>>>>> Thanks for all the comments! It appears that everyone prefers linear
>>>>> hashing because it reduces the amount of state that needs to be moved
>>>>> between consumers (for stream processing). The KIP has been updated to
>>>>> use
>>>>> linear hashing.
>>>>>
>>>>> Regarding the migration endeavor: it seems that migrating producer
>>>>> library
>>>>> to use linear hashing should be pretty straightforward without
>>>>> much operational endeavor. If we don't upgrade client library to use
>>>>> this
>>>>> KIP, we can not support in-order delivery after partition is changed
>>>>> anyway. Suppose we upgrade client library to use this KIP, if partition
>>>>> number is not changed, the key -> partition mapping will be exactly the
>>>>> same as it is now because it is still determined using murmur_hash(key)
>>>>> %
>>>>> original_partition_num. In other words, this change is backward
>>>>> compatible.
>>>>>
>>>>> Regarding the load distribution: if we use linear hashing, the load may
>>>>> be
>>>>> unevenly distributed because those partitions which are not split may
>>>>> receive twice as much traffic as other partitions that are split. This
>>>>> issue can be mitigated by creating topic with partitions that are
>>>>> several
>>>>> times the number of consumers. And there will be no imbalance if the
>>>>> partition number is always doubled. So this imbalance seems acceptable.
>>>>>
>>>>> Regarding storing the partition strategy as per-topic config: It seems
>>>>> not
>>>>> necessary since we can still use murmur_hash as the default hash
>>>>> function
>>>>> and additionally apply the linear hashing algorithm if the partition
>>>>> number
>>>>> has increased. Not sure if there is any use-case for producer to use a
>>>>> different hash function. Jason, can you check if there is some use-case
>>>>> that I missed for using the per-topic partition strategy?
>>>>>
>>>>> Regarding how to reduce latency (due to state store/load) in stream
>>>>> processing consumer when partition number changes: I need to read the
>>>>> Kafka
>>>>> Stream code to understand how Kafka Stream currently migrate state
>>>>> between
>>>>> consumers when the application is added/removed for a given job. I will
>>>>> reply after I finish reading the documentation and code.
>>>>>
>>>>>
>>>>> Thanks,
>>>>> Dong
>>>>>
>>>>>
>>>>> On Mon, Mar 5, 2018 at 10:43 AM, Jason Gustafson <ja...@confluent.io>
>>>>> wrote:
>>>>>
>>>>> Great discussion. I think I'm wondering whether we can continue to leave
>>>>>
>>>>>> Kafka agnostic to the partitioning strategy. The challenge is
>>>>>> communicating
>>>>>> the partitioning logic from producers to consumers so that the
>>>>>> dependencies
>>>>>> between each epoch can be determined. For the sake of discussion,
>>>>>> imagine
>>>>>> you did something like the following:
>>>>>>
>>>>>> 1. The name (and perhaps version) of a partitioning strategy is stored
>>>>>> in
>>>>>> topic configuration when a topic is created.
>>>>>> 2. The producer looks up the partitioning strategy before writing to a
>>>>>> topic and includes it in the produce request (for fencing). If it
>>>>>> doesn't
>>>>>> have an implementation for the configured strategy, it fails.
>>>>>> 3. The consumer also looks up the partitioning strategy and uses it to
>>>>>> determine dependencies when reading a new epoch. It could either fail
>>>>>> or
>>>>>> make the most conservative dependency assumptions if it doesn't know
>>>>>> how
>>>>>> to
>>>>>> implement the partitioning strategy. For the consumer, the new
>>>>>> interface
>>>>>> might look something like this:
>>>>>>
>>>>>> // Return the partition dependencies following an epoch bump
>>>>>> Map<Integer, List<Integer>> dependencies(int
>>>>>> numPartitionsBeforeEpochBump,
>>>>>> int numPartitionsAfterEpochBump)
>>>>>>
>>>>>> The unordered case then is just a particular implementation which never
>>>>>> has
>>>>>> any epoch dependencies. To implement this, we would need some way for
>>>>>> the
>>>>>> consumer to find out how many partitions there were in each epoch, but
>>>>>> maybe that's not too unreasonable.
>>>>>>
>>>>>> Thanks,
>>>>>> Jason
>>>>>>
>>>>>>
>>>>>> On Mon, Mar 5, 2018 at 4:51 AM, Jan Filipiak <Jan.Filipiak@trivago.com
>>>>>> wrote:
>>>>>>
>>>>>> Hi Dong
>>>>>>
>>>>>>> thank you very much for your questions.
>>>>>>>
>>>>>>> regarding the time spend copying data across:
>>>>>>> It is correct that copying data from a topic with one partition
>>>>>>> mapping
>>>>>>>
>>>>>>> to
>>>>>> a topic with a different partition mapping takes way longer than we can
>>>>>>> stop producers. Tens of minutes is a very optimistic estimate here.
>>>>>>> Many
>>>>>>> people can not afford copy full steam and therefore will have some
>>>>>>> rate
>>>>>>> limiting in place, this can bump the timespan into the day's. The good
>>>>>>>
>>>>>>> part
>>>>>> is that the vast majority of the data can be copied while the producers
>>>>>>> are
>>>>>> still going. One can then, piggyback the consumers ontop of this
>>>>>>> timeframe,
>>>>>> by the method mentioned (provide them an mapping from their old offsets
>>>>>>> to
>>>>>> new offsets in their repartitioned topics. In that way we separate
>>>>>>> migration of consumers from migration of producers (decoupling these
>>>>>>> is
>>>>>>> what kafka is strongest at). The time to actually swap over the
>>>>>>> producers
>>>>>>> should be kept minimal by ensuring that when a swap attempt is started
>>>>>>>
>>>>>>> the
>>>>>> consumer copying over should be very close to the log end and is
>>>>>>> expected
>>>>>>> to finish within the next fetch. The operation should have a time-out
>>>>>>> and
>>>>>>> should be "reattemtable".
>>>>>>>
>>>>>>> Importance of logcompaction:
>>>>>>> If a producer produces key A, to partiton 0, its forever gonna be
>>>>>>> there,
>>>>>>> unless it gets deleted. The record might sit in there for years. A new
>>>>>>> producer started with the new partitions will fail to delete the
>>>>>>> record
>>>>>>>
>>>>>>> in
>>>>>> the correct partition. Th record will be there forever and one can not
>>>>>>> reliable bootstrap new consumers. I cannot see how linear hashing can
>>>>>>>
>>>>>>> solve
>>>>>> this.
>>>>>>> Regarding your skipping of userland copying:
>>>>>>> 100%, copying the data across in userland is, as far as i can see,
>>>>>>> only
>>>>>>> a
>>>>>>> usecase for log compacted topics. Even for logcompaction + retentions
>>>>>>> it
>>>>>>> should only be opt-in. Why did I bring it up? I think log compaction
>>>>>>> is
>>>>>>> a
>>>>>>> very important feature to really embrace kafka as a "data plattform".
>>>>>>> The
>>>>>>> point I also want to make is that copying data this way is completely
>>>>>>> inline with the kafka architecture. it only consists of reading and
>>>>>>>
>>>>>>> writing
>>>>>> to topics.
>>>>>>> I hope it clarifies more why I think we should aim for more than the
>>>>>>> current KIP. I fear that once the KIP is done not much more effort
>>>>>>> will
>>>>>>>
>>>>>>> be
>>>>>> taken.
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> On 04.03.2018 02:28, Dong Lin wrote:
>>>>>>>
>>>>>>> Hey Jan,
>>>>>>>
>>>>>>>> In the current proposal, the consumer will be blocked on waiting for
>>>>>>>>
>>>>>>>> other
>>>>>>> consumers of the group to consume up to a given offset. In most cases,
>>>>>>> all
>>>>>>> consumers should be close to the LEO of the partitions when the
>>>>>>> partition
>>>>>>> expansion happens. Thus the time waiting should not be long e.g. on
>>>>>>> the
>>>>>>>
>>>>>>>> order of seconds. On the other hand, it may take a long time to wait
>>>>>>>> for
>>>>>>>> the entire partition to be copied -- the amount of time is
>>>>>>>> proportional
>>>>>>>>
>>>>>>>> to
>>>>>>> the amount of existing data in the partition, which can take tens of
>>>>>>>
>>>>>>>> minutes. So the amount of time that we stop consumers may not be on
>>>>>>>> the
>>>>>>>> same order of magnitude.
>>>>>>>>
>>>>>>>> If we can implement this suggestion without copying data over in
>>>>>>>> purse
>>>>>>>> userland, it will be much more valuable. Do you have ideas on how
>>>>>>>> this
>>>>>>>>
>>>>>>>> can
>>>>>>> be done?
>>>>>>>
>>>>>>>> Not sure why the current KIP not help people who depend on log
>>>>>>>>
>>>>>>>> compaction.
>>>>>>> Could you elaborate more on this point?
>>>>>>>
>>>>>>>> Thanks,
>>>>>>>> Dong
>>>>>>>>
>>>>>>>> On Wed, Feb 28, 2018 at 10:55 PM, Jan Filipiak<Jan.Filipiak@trivago.
>>>>>>>> com
>>>>>>>> wrote:
>>>>>>>>
>>>>>>>> Hi Dong,
>>>>>>>>
>>>>>>>> I tried to focus on what the steps are one can currently perform to
>>>>>>>>> expand
>>>>>>>>> or shrink a keyed topic while maintaining a top notch semantics.
>>>>>>>>> I can understand that there might be confusion about "stopping the
>>>>>>>>> consumer". It is exactly the same as proposed in the KIP. there
>>>>>>>>> needs
>>>>>>>>>
>>>>>>>>> to
>>>>>>> be
>>>>>>>
>>>>>>>> a time the producers agree on the new partitioning. The extra
>>>>>>>>> semantics I
>>>>>>> want to put in there is that we have a possibility to wait until all
>>>>>>>
>>>>>>>> the
>>>>>>>>
>>>>>>> existing data
>>>>>>>
>>>>>>>> is copied over into the new partitioning scheme. When I say stopping
>>>>>>>>> I
>>>>>>>>> think more of having a memory barrier that ensures the ordering. I
>>>>>>>>> am
>>>>>>>>> still
>>>>>>>>> aming for latencies  on the scale of leader failovers.
>>>>>>>>>
>>>>>>>>> Consumers have to explicitly adapt the new partitioning scheme in
>>>>>>>>> the
>>>>>>>>> above scenario. The reason is that in these cases where you are
>>>>>>>>>
>>>>>>>>> dependent
>>>>>>> on a particular partitioning scheme, you also have other topics that
>>>>>>>
>>>>>>>> have
>>>>>>>>
>>>>>>> co-partition enforcements or the kind -frequently. Therefore all your
>>>>>>>
>>>>>>>> other
>>>>>>>>> input topics might need to grow accordingly.
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> What I was suggesting was to streamline all these operations as best
>>>>>>>>> as
>>>>>>>>> possible to have "real" partition grow and shrinkage going on.
>>>>>>>>>
>>>>>>>>> Migrating
>>>>>>> the producers to a new partitioning scheme can be much more
>>>>>>> streamlined
>>>>>>>
>>>>>>>> with proper broker support for this. Migrating consumer is a step
>>>>>>>>> that
>>>>>>>>> might be made completly unnecessary if - for example streams - takes
>>>>>>>>>
>>>>>>>>> the
>>>>>>> gcd as partitioning scheme instead of enforcing 1 to 1. Connect
>>>>>>>
>>>>>>>> consumers
>>>>>>>>
>>>>>>> and other consumers should be fine anyways.
>>>>>>>
>>>>>>>> I hope this makes more clear where I was aiming at. The rest needs to
>>>>>>>>> be
>>>>>>> figured out. The only danger i see is that when we are introducing
>>>>>>> this
>>>>>>>
>>>>>>>> feature as supposed in the KIP, it wont help any people depending on
>>>>>>>>> log
>>>>>>> compaction.
>>>>>>>
>>>>>>>> The other thing I wanted to mention is that I believe the current
>>>>>>>>> suggestion (without copying data over) can be implemented in pure
>>>>>>>>> userland
>>>>>>>>> with a custom partitioner and a small feedbackloop from
>>>>>>>>> ProduceResponse
>>>>>>>>> =>
>>>>>>>>> Partitionier in coorporation with a change management system.
>>>>>>>>>
>>>>>>>>> Best Jan
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> On 28.02.2018 07:13, Dong Lin wrote:
>>>>>>>>>
>>>>>>>>> Hey Jan,
>>>>>>>>>
>>>>>>>>> I am not sure if it is acceptable for producer to be stopped for a
>>>>>>>>>> while,
>>>>>>>>>> particularly for online application which requires low latency. I
>>>>>>>>>> am
>>>>>>>>>> also
>>>>>>>>>> not sure how consumers can switch to a new topic. Does user
>>>>>>>>>>
>>>>>>>>>> application
>>>>>>>> needs to explicitly specify a different topic for producer/consumer
>>>>>>> to
>>>>>>>
>>>>>>>> subscribe to? It will be helpful for discussion if you can provide
>>>>>>>>>> more
>>>>>>>> detail on the interface change for this solution.
>>>>>>>> Thanks,
>>>>>>>>>> Dong
>>>>>>>>>>
>>>>>>>>>> On Mon, Feb 26, 2018 at 12:48 AM, Jan
>>>>>>>>>> Filipiak<Jan.Filipiak@trivago.
>>>>>>>>>>
>>>>>>>>>> com
>>>>>>>> wrote:
>>>>>>>> Hi,
>>>>>>>>>> just want to throw my though in. In general the functionality is
>>>>>>>>>> very
>>>>>>>>>>
>>>>>>>>>>> usefull, we should though not try to find the architecture to hard
>>>>>>>>>>> while
>>>>>>>>>>> implementing.
>>>>>>>>>>>
>>>>>>>>>>> The manual steps would be to
>>>>>>>>>>>
>>>>>>>>>>> create a new topic
>>>>>>>>>>> the mirrormake from the new old topic to the new topic
>>>>>>>>>>> wait for mirror making to catch up.
>>>>>>>>>>> then put the consumers onto the new topic
>>>>>>>>>>>          (having mirrormaker spit out a mapping from old offsets to
>>>>>>>>>>> new
>>>>>>>>>>> offsets:
>>>>>>>>>>>              if topic is increased by factor X there is gonna be a
>>>>>>>>>>> clean
>>>>>>>>>>> mapping from 1 offset in the old topic to X offsets in the new
>>>>>>>>>>> topic,
>>>>>>>>>>>              if there is no factor then there is no chance to
>>>>>>>>>>> generate a
>>>>>>>>>>> mapping that can be reasonable used for continuing)
>>>>>>>>>>>          make consumers stop at appropriate points and continue
>>>>>>>>>>> consumption
>>>>>>>>>>> with offsets from the mapping.
>>>>>>>>>>> have the producers stop for a minimal time.
>>>>>>>>>>> wait for mirrormaker to finish
>>>>>>>>>>> let producer produce with the new metadata.
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> Instead of implementing the approach suggest in the KIP which will
>>>>>>>>>>> leave
>>>>>>>>>>> log compacted topic completely crumbled and unusable.
>>>>>>>>>>> I would much rather try to build infrastructure to support the
>>>>>>>>>>> mentioned
>>>>>>>>>>> above operations more smoothly.
>>>>>>>>>>> Especially having producers stop and use another topic is
>>>>>>>>>>> difficult
>>>>>>>>>>>
>>>>>>>>>>> and
>>>>>>>>> it would be nice if one can trigger "invalid metadata" exceptions
>>>>>>> for
>>>>>>>
>>>>>>>> them
>>>>>>>>>>> and
>>>>>>>>>>> if one could give topics aliases so that their produces with the
>>>>>>>>>>> old
>>>>>>>>>>> topic
>>>>>>>>>>> will arrive in the new topic.
>>>>>>>>>>>
>>>>>>>>>>> The downsides are obvious I guess ( having the same data twice for
>>>>>>>>>>>
>>>>>>>>>>> the
>>>>>>>>> transition period, but kafka tends to scale well with datasize). So
>>>>>>>> its a
>>>>>>>>>>> nicer fit into the architecture.
>>>>>>>>>>>
>>>>>>>>>>> I further want to argument that the functionality by the KIP can
>>>>>>>>>>> completely be implementing in "userland" with a custom partitioner
>>>>>>>>>>>
>>>>>>>>>>> that
>>>>>>>>> handles the transition as needed. I would appreciate if someone
>>>>>>> could
>>>>>>>
>>>>>>>> point
>>>>>>>>>>> out what a custom partitioner couldn't handle in this case?
>>>>>>>>>>>
>>>>>>>>>>> With the above approach, shrinking a topic becomes the same steps.
>>>>>>>>>>> Without
>>>>>>>>>>> loosing keys in the discontinued partitions.
>>>>>>>>>>>
>>>>>>>>>>> Would love to hear what everyone thinks.
>>>>>>>>>>>
>>>>>>>>>>> Best Jan
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> On 11.02.2018 00:35, Dong Lin wrote:
>>>>>>>>>>>
>>>>>>>>>>> Hi all,
>>>>>>>>>>>
>>>>>>>>>>> I have created KIP-253: Support in-order message delivery with
>>>>>>>>>>>
>>>>>>>>>>>> partition
>>>>>>>>>>>> expansion. See
>>>>>>>>>>>> https://cwiki.apache.org/confluence/display/KAFKA/KIP-253%
>>>>>>>>>>>> 3A+Support+in-order+message+delivery+with+partition+expansion
>>>>>>>>>>>> .
>>>>>>>>>>>>
>>>>>>>>>>>> This KIP provides a way to allow messages of the same key from
>>>>>>>>>>>> the
>>>>>>>>>>>> same
>>>>>>>>>>>> producer to be consumed in the same order they are produced even
>>>>>>>>>>>> if
>>>>>>>>>>>>
>>>>>>>>>>>> we
>>>>>>>>>> expand partition of the topic.
>>>>>>>> Thanks,
>>>>>>>>>>>> Dong
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>


Re: [DISCUSS] KIP-253: Support in-order message delivery with partition expansion

Posted by Jun Rao <ju...@confluent.io>.
Hi, Jan,

Thanks for the reply. A few more comments below.

50. Ok, we can think a bit harder for supporting compacted topics.

51. This is a fundamental design question. In the more common case, the
reason why someone wants to increase the number of partitions is that the
consumer application is slow and one wants to run more consumer instances
to increase the degree of parallelism. So, fixing the number of running
consumer instances when expanding the partitions won't help this case. If
we do need to increase the number of consumer instances, we need to somehow
reshuffle the state of the consumer across instances. What we have been
discussing in this KIP is whether we can do this more effectively through
the KStream library (e.g. through a 2-phase partition expansion). This will
add some complexity, but it's probably better than everyone doing this in
the application space. The recopying approach that you mentioned doesn't
seem to address the consumer state management issue when the consumer
switches from an old to a new topic.

52. As for your example, it depends on whether the join key is the same
between (A,B) and (B,C). If the join key is the same, we can do a 2-phase
partition expansion of A, B, and C together. If the join keys are
different, one would need to repartition the data on a different key for
the second join, then the partition expansion can be done independently
between (A,B) and (B,C).

53. If you always fix the number of consumer instances, we you described
works. However, as I mentioned in #51, I am not sure how your proposal
deals with consumer states when the number of consumer instances grows.
Also, it just seems that it's better to avoid re-copying the existing data.

60. "just want to throw in my question from the longer email in the other
Thread here. How will the bloom filter help a new consumer to decide to
apply the key or not?" Not sure that I fully understood your question. The
consumer just reads whatever key is in the log. The bloom filter just helps
clean up the old keys.

61. "Why can we afford having a topic where its apparently not possible to
start a new application on? I think this is an overall flaw of the
discussed idea here. Not playing attention to the overall architecture."
Could you explain a bit more when one can't start a new application?

Jun



On Sat, Mar 10, 2018 at 1:40 AM, Jan Filipiak <Ja...@trivago.com>
wrote:

> Hi Jun, thanks for your mail.
>
> Thank you for your questions!
> I think they are really good and tackle the core of the problem I see.
>
> I will answer inline, mostly but still want to set the tone here.
>
> The core strength of kafka is what Martin once called the
> kappa-Architecture. How does this work?
> You have everything as a log as in kafka. When you need to change
> something.
> You create the new version of your application and leave it running in
> parallel.
> Once the new version is good you switch your users to use the new
> application.
>
> The online reshuffling effectively breaks this architecture and I think
> the switch in thinking here is more harmful
> than any details about the partitioning function to allow such a change. I
> feel with my suggestion we are the closest to
> the original and battle proven architecture and I can only warn to move
> away from it.
>
> I might have forgotten something, sometimes its hard for me to getting all
> the thoughts captured in a mail, but I hope the comments inline will
> further make my concern clear, and put some emphasis on why I prefer my
> solution ;)
>
> One thing we should all be aware of when discussing this, and I think Dong
> should have mentioned it (maybe he did).
> We are not discussing all of this out of thin air but there is an effort
> in the Samza project.
>
> https://cwiki.apache.org/confluence/display/SAMZA/SEP-5%3A+
> Enable+partition+expansion+of+input+streams
> https://issues.apache.org/jira/browse/SAMZA-1293
>
> To be clear. I think SEP-5 (state of last week, dont know if it adapted to
> this discussion) is on a way better path than KIP-253, and I can't really
> explain why.
>
> Best Jan,
>
> nice weekend everyone
>
>
> On 09.03.2018 03:36, Jun Rao wrote:
>
>> Hi, Jan,
>>
>> Thanks for the feedback. Just some comments on the earlier points that you
>> mentioned.
>>
>> 50. You brought up the question of whether existing data needs to be
>> copied
>> during partition expansion. My understand of your view is that avoid
>> copying existing data will be more efficient, but it doesn't work well
>> with
>> compacted topics since some keys in the original partitions will never be
>> cleaned. It would be useful to understand your use case of compacted
>> topics
>> a bit more. In the common use case, the data volume in a compacted topic
>> may not be large. So, I am not sure if there is a strong need to expand
>> partitions in a compacted topic, at least initially.
>>
> I do agree. State is usually smaller. Update rates might be also
> competitively high.
> Doing Log-compaction (even beeing very efficient and configurable) is also
> a more expensive operation than
> just discarding old segments. Further if you want to use more consumers
> processing the events
> you also have to grow the number of partitions. Especially for use-cases
> we do (KIP-213) a tiny state full
> table might be very expensive to process if it joins against a huge table.
>
> I can just say we have been in the spot of needing to grow log compacted
> topics. Mainly for processing power we can bring to the table.
>
> Further i am not at all concerned about the extra spaced used by "garbage
> keys". I am more concerned about the correctness of innocent consumers. The
> logic becomes complicated. Say for streams one would need to load the
> record into state but not forward it the topology ( to have it available
> for shuffeling). I rather have it simple and a topic clean regardless if it
> still has its old partition count. Especially with multiple partitions
> growth's I think it becomes insanely hard to to this shuffle correct. Maybe
> Streams and Samza can do it. Especially if you do "hipster stream
> processing" <https://www.confluent.io/blog/introducing-kafka-streams-
> stream-processing-made-simple/>. This makes kafka way to complicated.
> With my approach I think its way simpler because the topic has no "history"
> in terms of partitioning but is always clean.
>
>
>> 51. "Growing the topic by an integer factor does not require any state
>> redistribution at all." Could you clarify this a bit more? Let's say you
>> have a consumer app that computes the windowed count per key. If you
>> double
>> the number of partitions from 1 to 2 and grow the consumer instances from
>> 1
>> to 2, we would need to redistribute some of the counts to the new consumer
>> instance. Regarding to linear hashing, it's true that it won't solve the
>> problem with compacted topics. The main benefit is that it redistributes
>> the keys in one partition to no more than two partitions, which could help
>> redistribute the state.
>>
> You don't need to spin up a new consumer in this case. every consumer
> would just read every partition with the (partition % num_task) task. it
> will still have the previous data right there and can go on.
>
> This sounds contradictory to what I said before, but please bear with me.
>
>>
>> 52. Good point on coordinating the expansion of 2 topics that need to be
>> joined together. This is where the 2-phase partition expansion could
>> potentially help. In the first phase, we could add new partitions to the 2
>> topics one at a time but without publishing to the new patitions. Then, we
>> can add new consumer instances to pick up the new partitions. In this
>> transition phase, no reshuffling is needed since no data is coming from
>> the
>> new partitions. Finally, we can enable the publishing to the new
>> partitions.
>>
> I think its even worse than you think. I would like to introduce the Term
> transitive copartitioning. Imagine
> 2 streams application. One joins (A,B) the other (B,C) then there is a
> transitive copartition requirement for
> (A,C) to be copartitioned aswell. This can spread significantly and
> require many consumers to adapt at the same time.
>
> It is also not entirely clear to me how you not need reshuffling in this
> case. If A has a record that never gets updated after the expansion and the
> coresponding B record moves to a new partition. How shall they meet w/o
> shuffle?
>
>>
>> 53. "Migrating consumer is a step that might be made completly unnecessary
>> if - for example streams - takes the gcd as partitioning scheme instead of
>> enforcing 1 to 1." Not sure that I fully understand this. I think you mean
>> that a consumer application can run more instances than the number of
>> partitions. In that case, the consumer can just repartitioning the input
>> data according to the number of instances. This is possible, but just has
>> the overhead of reshuffling the data.
>>
> No what I meant is ( that is also your question i think Mathias) that if
> you grow a topic by a factor.
> Even if your processor is statefull you can can just assign all the
> multiples of the previous partition to
> this consumer and the state to keep processing correctly will be present
> w/o any shuffling.
>
> Say you have an assignment
> Statefull consumer => partition
> 0 => 0
> 1 => 1
> 2 => 2
>
> and you grow you topic by 4 you get,
>
> 0 => 0,3,6,9
> 1 => 1,4,7,10
> 2 => 2,5,8,11
>
> Say your hashcode is 8. 8%3 => 2  before so consumer for partition 2 has
> it.
> Now you you have 12 partitions so 8%12 => 8, so it goes into partition 8
> which is assigned to the same consumer
> who had 2 before and therefore knows the key.
>
> Userland reshuffeling is there as an options. And it does exactly what I
> suggest. And I think its the perfect strategie. All I am suggestion is
> broker side support to switch the producers to the newly partitioned topic.
> Then the old (to few partition topic) can go away.  Remember the list of
> steps in the beginning of this thread. If one has broker support for all
> where its required and streams support for those that aren’t necessarily.
> Then one has solved the problem.
> I repeat it because I think its important. I am really happy that you
> brought that up! because its 100% what I want just with the differences to
> have an option to discard the to small topic later (after all consumers
> adapted). And to have order correct there. I need broker support managing
> the copy process + the produces and fence them against each other. I also
> repeat. the copy process can run for weeks in the worst case. Copying the
> data is not the longest task migrating consumers might very well be.
> Once all consumers switched and copying is really up to date (think ISR
> like up to date) only then we stop the producer, wait for the copy to
> finish and use the new topic for producing.
>
> After this the topic is perfect in shape. and no one needs to worry about
> complicated stuff. (old keys hanging around might arrive in some other
> topic later.....). can only imagine how many tricky bugs gonna arrive after
> someone had grown and shrunken is topic 10 times.
>
>
>
>
>
>
>> 54. "The other thing I wanted to mention is that I believe the current
>> suggestion (without copying data over) can be implemented in pure userland
>> with a custom partitioner and a small feedbackloop from ProduceResponse =>
>> Partitionier in coorporation with a change management system." I am not
>> sure a customized partitioner itself solves the problem. We probably need
>> some broker side support to enforce when the new partitions can be used.
>> We
>> also need some support on the consumer/kstream side to preserve the per
>> key
>> ordering and potentially migrate the processing state. This is not trivial
>> and I am not sure if it's ideal to fully push to the application space.
>>
> Broker support is defenitly the preferred way here. I have nothing against
> broker support.
> I tried to say that for what I would preffer - copying the data over, at
> least for log compacted topics -
> I would require more broker support than the KIP currently offers.
>
>
>
>> Jun
>>
>>
>> On Tue, Mar 6, 2018 at 10:33 PM, Jan Filipiak <Ja...@trivago.com>
>> wrote:
>>
>> Hi Dong,
>>>
>>> are you actually reading my emails, or are you just using the thread I
>>> started for general announcements regarding the KIP?
>>>
>>> I tried to argue really hard against linear hashing. Growing the topic by
>>> an integer factor does not require any state redistribution at all. I
>>> fail
>>> to see completely where linear hashing helps on log compacted topics.
>>>
>>> If you are not willing to explain to me what I might be overlooking: that
>>> is fine.
>>> But I ask you to not reply to my emails then. Please understand my
>>> frustration with this.
>>>
>>> Best Jan
>>>
>>>
>>>
>>> On 06.03.2018 19:38, Dong Lin wrote:
>>>
>>> Hi everyone,
>>>>
>>>> Thanks for all the comments! It appears that everyone prefers linear
>>>> hashing because it reduces the amount of state that needs to be moved
>>>> between consumers (for stream processing). The KIP has been updated to
>>>> use
>>>> linear hashing.
>>>>
>>>> Regarding the migration endeavor: it seems that migrating producer
>>>> library
>>>> to use linear hashing should be pretty straightforward without
>>>> much operational endeavor. If we don't upgrade client library to use
>>>> this
>>>> KIP, we can not support in-order delivery after partition is changed
>>>> anyway. Suppose we upgrade client library to use this KIP, if partition
>>>> number is not changed, the key -> partition mapping will be exactly the
>>>> same as it is now because it is still determined using murmur_hash(key)
>>>> %
>>>> original_partition_num. In other words, this change is backward
>>>> compatible.
>>>>
>>>> Regarding the load distribution: if we use linear hashing, the load may
>>>> be
>>>> unevenly distributed because those partitions which are not split may
>>>> receive twice as much traffic as other partitions that are split. This
>>>> issue can be mitigated by creating topic with partitions that are
>>>> several
>>>> times the number of consumers. And there will be no imbalance if the
>>>> partition number is always doubled. So this imbalance seems acceptable.
>>>>
>>>> Regarding storing the partition strategy as per-topic config: It seems
>>>> not
>>>> necessary since we can still use murmur_hash as the default hash
>>>> function
>>>> and additionally apply the linear hashing algorithm if the partition
>>>> number
>>>> has increased. Not sure if there is any use-case for producer to use a
>>>> different hash function. Jason, can you check if there is some use-case
>>>> that I missed for using the per-topic partition strategy?
>>>>
>>>> Regarding how to reduce latency (due to state store/load) in stream
>>>> processing consumer when partition number changes: I need to read the
>>>> Kafka
>>>> Stream code to understand how Kafka Stream currently migrate state
>>>> between
>>>> consumers when the application is added/removed for a given job. I will
>>>> reply after I finish reading the documentation and code.
>>>>
>>>>
>>>> Thanks,
>>>> Dong
>>>>
>>>>
>>>> On Mon, Mar 5, 2018 at 10:43 AM, Jason Gustafson <ja...@confluent.io>
>>>> wrote:
>>>>
>>>> Great discussion. I think I'm wondering whether we can continue to leave
>>>>
>>>>> Kafka agnostic to the partitioning strategy. The challenge is
>>>>> communicating
>>>>> the partitioning logic from producers to consumers so that the
>>>>> dependencies
>>>>> between each epoch can be determined. For the sake of discussion,
>>>>> imagine
>>>>> you did something like the following:
>>>>>
>>>>> 1. The name (and perhaps version) of a partitioning strategy is stored
>>>>> in
>>>>> topic configuration when a topic is created.
>>>>> 2. The producer looks up the partitioning strategy before writing to a
>>>>> topic and includes it in the produce request (for fencing). If it
>>>>> doesn't
>>>>> have an implementation for the configured strategy, it fails.
>>>>> 3. The consumer also looks up the partitioning strategy and uses it to
>>>>> determine dependencies when reading a new epoch. It could either fail
>>>>> or
>>>>> make the most conservative dependency assumptions if it doesn't know
>>>>> how
>>>>> to
>>>>> implement the partitioning strategy. For the consumer, the new
>>>>> interface
>>>>> might look something like this:
>>>>>
>>>>> // Return the partition dependencies following an epoch bump
>>>>> Map<Integer, List<Integer>> dependencies(int
>>>>> numPartitionsBeforeEpochBump,
>>>>> int numPartitionsAfterEpochBump)
>>>>>
>>>>> The unordered case then is just a particular implementation which never
>>>>> has
>>>>> any epoch dependencies. To implement this, we would need some way for
>>>>> the
>>>>> consumer to find out how many partitions there were in each epoch, but
>>>>> maybe that's not too unreasonable.
>>>>>
>>>>> Thanks,
>>>>> Jason
>>>>>
>>>>>
>>>>> On Mon, Mar 5, 2018 at 4:51 AM, Jan Filipiak <Jan.Filipiak@trivago.com
>>>>> >
>>>>> wrote:
>>>>>
>>>>> Hi Dong
>>>>>
>>>>>> thank you very much for your questions.
>>>>>>
>>>>>> regarding the time spend copying data across:
>>>>>> It is correct that copying data from a topic with one partition
>>>>>> mapping
>>>>>>
>>>>>> to
>>>>>
>>>>> a topic with a different partition mapping takes way longer than we can
>>>>>> stop producers. Tens of minutes is a very optimistic estimate here.
>>>>>> Many
>>>>>> people can not afford copy full steam and therefore will have some
>>>>>> rate
>>>>>> limiting in place, this can bump the timespan into the day's. The good
>>>>>>
>>>>>> part
>>>>>
>>>>> is that the vast majority of the data can be copied while the producers
>>>>>>
>>>>>> are
>>>>>
>>>>> still going. One can then, piggyback the consumers ontop of this
>>>>>>
>>>>>> timeframe,
>>>>>
>>>>> by the method mentioned (provide them an mapping from their old offsets
>>>>>>
>>>>>> to
>>>>>
>>>>> new offsets in their repartitioned topics. In that way we separate
>>>>>> migration of consumers from migration of producers (decoupling these
>>>>>> is
>>>>>> what kafka is strongest at). The time to actually swap over the
>>>>>> producers
>>>>>> should be kept minimal by ensuring that when a swap attempt is started
>>>>>>
>>>>>> the
>>>>>
>>>>> consumer copying over should be very close to the log end and is
>>>>>> expected
>>>>>> to finish within the next fetch. The operation should have a time-out
>>>>>> and
>>>>>> should be "reattemtable".
>>>>>>
>>>>>> Importance of logcompaction:
>>>>>> If a producer produces key A, to partiton 0, its forever gonna be
>>>>>> there,
>>>>>> unless it gets deleted. The record might sit in there for years. A new
>>>>>> producer started with the new partitions will fail to delete the
>>>>>> record
>>>>>>
>>>>>> in
>>>>>
>>>>> the correct partition. Th record will be there forever and one can not
>>>>>> reliable bootstrap new consumers. I cannot see how linear hashing can
>>>>>>
>>>>>> solve
>>>>>
>>>>> this.
>>>>>>
>>>>>> Regarding your skipping of userland copying:
>>>>>> 100%, copying the data across in userland is, as far as i can see,
>>>>>> only
>>>>>> a
>>>>>> usecase for log compacted topics. Even for logcompaction + retentions
>>>>>> it
>>>>>> should only be opt-in. Why did I bring it up? I think log compaction
>>>>>> is
>>>>>> a
>>>>>> very important feature to really embrace kafka as a "data plattform".
>>>>>> The
>>>>>> point I also want to make is that copying data this way is completely
>>>>>> inline with the kafka architecture. it only consists of reading and
>>>>>>
>>>>>> writing
>>>>>
>>>>> to topics.
>>>>>>
>>>>>> I hope it clarifies more why I think we should aim for more than the
>>>>>> current KIP. I fear that once the KIP is done not much more effort
>>>>>> will
>>>>>>
>>>>>> be
>>>>>
>>>>> taken.
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> On 04.03.2018 02:28, Dong Lin wrote:
>>>>>>
>>>>>> Hey Jan,
>>>>>>
>>>>>>> In the current proposal, the consumer will be blocked on waiting for
>>>>>>>
>>>>>>> other
>>>>>> consumers of the group to consume up to a given offset. In most cases,
>>>>>> all
>>>>>> consumers should be close to the LEO of the partitions when the
>>>>>> partition
>>>>>> expansion happens. Thus the time waiting should not be long e.g. on
>>>>>> the
>>>>>>
>>>>>>> order of seconds. On the other hand, it may take a long time to wait
>>>>>>> for
>>>>>>> the entire partition to be copied -- the amount of time is
>>>>>>> proportional
>>>>>>>
>>>>>>> to
>>>>>> the amount of existing data in the partition, which can take tens of
>>>>>>
>>>>>>> minutes. So the amount of time that we stop consumers may not be on
>>>>>>> the
>>>>>>> same order of magnitude.
>>>>>>>
>>>>>>> If we can implement this suggestion without copying data over in
>>>>>>> purse
>>>>>>> userland, it will be much more valuable. Do you have ideas on how
>>>>>>> this
>>>>>>>
>>>>>>> can
>>>>>> be done?
>>>>>>
>>>>>>> Not sure why the current KIP not help people who depend on log
>>>>>>>
>>>>>>> compaction.
>>>>>> Could you elaborate more on this point?
>>>>>>
>>>>>>> Thanks,
>>>>>>> Dong
>>>>>>>
>>>>>>> On Wed, Feb 28, 2018 at 10:55 PM, Jan Filipiak<Jan.Filipiak@trivago.
>>>>>>> com
>>>>>>> wrote:
>>>>>>>
>>>>>>> Hi Dong,
>>>>>>>
>>>>>>> I tried to focus on what the steps are one can currently perform to
>>>>>>>> expand
>>>>>>>> or shrink a keyed topic while maintaining a top notch semantics.
>>>>>>>> I can understand that there might be confusion about "stopping the
>>>>>>>> consumer". It is exactly the same as proposed in the KIP. there
>>>>>>>> needs
>>>>>>>>
>>>>>>>> to
>>>>>>>
>>>>>> be
>>>>>>
>>>>>>> a time the producers agree on the new partitioning. The extra
>>>>>>>>
>>>>>>>> semantics I
>>>>>>>
>>>>>> want to put in there is that we have a possibility to wait until all
>>>>>>
>>>>>>> the
>>>>>>>
>>>>>> existing data
>>>>>>
>>>>>>> is copied over into the new partitioning scheme. When I say stopping
>>>>>>>> I
>>>>>>>> think more of having a memory barrier that ensures the ordering. I
>>>>>>>> am
>>>>>>>> still
>>>>>>>> aming for latencies  on the scale of leader failovers.
>>>>>>>>
>>>>>>>> Consumers have to explicitly adapt the new partitioning scheme in
>>>>>>>> the
>>>>>>>> above scenario. The reason is that in these cases where you are
>>>>>>>>
>>>>>>>> dependent
>>>>>>>
>>>>>> on a particular partitioning scheme, you also have other topics that
>>>>>>
>>>>>>> have
>>>>>>>
>>>>>> co-partition enforcements or the kind -frequently. Therefore all your
>>>>>>
>>>>>>> other
>>>>>>>> input topics might need to grow accordingly.
>>>>>>>>
>>>>>>>>
>>>>>>>> What I was suggesting was to streamline all these operations as best
>>>>>>>> as
>>>>>>>> possible to have "real" partition grow and shrinkage going on.
>>>>>>>>
>>>>>>>> Migrating
>>>>>>>
>>>>>> the producers to a new partitioning scheme can be much more
>>>>>> streamlined
>>>>>>
>>>>>>> with proper broker support for this. Migrating consumer is a step
>>>>>>>> that
>>>>>>>> might be made completly unnecessary if - for example streams - takes
>>>>>>>>
>>>>>>>> the
>>>>>>>
>>>>>> gcd as partitioning scheme instead of enforcing 1 to 1. Connect
>>>>>>
>>>>>>> consumers
>>>>>>>
>>>>>> and other consumers should be fine anyways.
>>>>>>
>>>>>>> I hope this makes more clear where I was aiming at. The rest needs to
>>>>>>>>
>>>>>>>> be
>>>>>>>
>>>>>> figured out. The only danger i see is that when we are introducing
>>>>>> this
>>>>>>
>>>>>>> feature as supposed in the KIP, it wont help any people depending on
>>>>>>>>
>>>>>>>> log
>>>>>>>
>>>>>> compaction.
>>>>>>
>>>>>>> The other thing I wanted to mention is that I believe the current
>>>>>>>> suggestion (without copying data over) can be implemented in pure
>>>>>>>> userland
>>>>>>>> with a custom partitioner and a small feedbackloop from
>>>>>>>> ProduceResponse
>>>>>>>> =>
>>>>>>>> Partitionier in coorporation with a change management system.
>>>>>>>>
>>>>>>>> Best Jan
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> On 28.02.2018 07:13, Dong Lin wrote:
>>>>>>>>
>>>>>>>> Hey Jan,
>>>>>>>>
>>>>>>>> I am not sure if it is acceptable for producer to be stopped for a
>>>>>>>>> while,
>>>>>>>>> particularly for online application which requires low latency. I
>>>>>>>>> am
>>>>>>>>> also
>>>>>>>>> not sure how consumers can switch to a new topic. Does user
>>>>>>>>>
>>>>>>>>> application
>>>>>>>>
>>>>>>> needs to explicitly specify a different topic for producer/consumer
>>>>>> to
>>>>>>
>>>>>>> subscribe to? It will be helpful for discussion if you can provide
>>>>>>>>>
>>>>>>>>> more
>>>>>>>>
>>>>>>> detail on the interface change for this solution.
>>>>>>
>>>>>>> Thanks,
>>>>>>>>> Dong
>>>>>>>>>
>>>>>>>>> On Mon, Feb 26, 2018 at 12:48 AM, Jan
>>>>>>>>> Filipiak<Jan.Filipiak@trivago.
>>>>>>>>>
>>>>>>>>> com
>>>>>>>>
>>>>>>> wrote:
>>>>>>
>>>>>>> Hi,
>>>>>>>>>
>>>>>>>>> just want to throw my though in. In general the functionality is
>>>>>>>>> very
>>>>>>>>>
>>>>>>>>>> usefull, we should though not try to find the architecture to hard
>>>>>>>>>> while
>>>>>>>>>> implementing.
>>>>>>>>>>
>>>>>>>>>> The manual steps would be to
>>>>>>>>>>
>>>>>>>>>> create a new topic
>>>>>>>>>> the mirrormake from the new old topic to the new topic
>>>>>>>>>> wait for mirror making to catch up.
>>>>>>>>>> then put the consumers onto the new topic
>>>>>>>>>>         (having mirrormaker spit out a mapping from old offsets to
>>>>>>>>>> new
>>>>>>>>>> offsets:
>>>>>>>>>>             if topic is increased by factor X there is gonna be a
>>>>>>>>>> clean
>>>>>>>>>> mapping from 1 offset in the old topic to X offsets in the new
>>>>>>>>>> topic,
>>>>>>>>>>             if there is no factor then there is no chance to
>>>>>>>>>> generate a
>>>>>>>>>> mapping that can be reasonable used for continuing)
>>>>>>>>>>         make consumers stop at appropriate points and continue
>>>>>>>>>> consumption
>>>>>>>>>> with offsets from the mapping.
>>>>>>>>>> have the producers stop for a minimal time.
>>>>>>>>>> wait for mirrormaker to finish
>>>>>>>>>> let producer produce with the new metadata.
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> Instead of implementing the approach suggest in the KIP which will
>>>>>>>>>> leave
>>>>>>>>>> log compacted topic completely crumbled and unusable.
>>>>>>>>>> I would much rather try to build infrastructure to support the
>>>>>>>>>> mentioned
>>>>>>>>>> above operations more smoothly.
>>>>>>>>>> Especially having producers stop and use another topic is
>>>>>>>>>> difficult
>>>>>>>>>>
>>>>>>>>>> and
>>>>>>>>>
>>>>>>>> it would be nice if one can trigger "invalid metadata" exceptions
>>>>>> for
>>>>>>
>>>>>>> them
>>>>>>>>>> and
>>>>>>>>>> if one could give topics aliases so that their produces with the
>>>>>>>>>> old
>>>>>>>>>> topic
>>>>>>>>>> will arrive in the new topic.
>>>>>>>>>>
>>>>>>>>>> The downsides are obvious I guess ( having the same data twice for
>>>>>>>>>>
>>>>>>>>>> the
>>>>>>>>>
>>>>>>>> transition period, but kafka tends to scale well with datasize). So
>>>>>>
>>>>>>> its a
>>>>>>>>>> nicer fit into the architecture.
>>>>>>>>>>
>>>>>>>>>> I further want to argument that the functionality by the KIP can
>>>>>>>>>> completely be implementing in "userland" with a custom partitioner
>>>>>>>>>>
>>>>>>>>>> that
>>>>>>>>>
>>>>>>>> handles the transition as needed. I would appreciate if someone
>>>>>> could
>>>>>>
>>>>>>> point
>>>>>>>>>> out what a custom partitioner couldn't handle in this case?
>>>>>>>>>>
>>>>>>>>>> With the above approach, shrinking a topic becomes the same steps.
>>>>>>>>>> Without
>>>>>>>>>> loosing keys in the discontinued partitions.
>>>>>>>>>>
>>>>>>>>>> Would love to hear what everyone thinks.
>>>>>>>>>>
>>>>>>>>>> Best Jan
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> On 11.02.2018 00:35, Dong Lin wrote:
>>>>>>>>>>
>>>>>>>>>> Hi all,
>>>>>>>>>>
>>>>>>>>>> I have created KIP-253: Support in-order message delivery with
>>>>>>>>>>
>>>>>>>>>>> partition
>>>>>>>>>>> expansion. See
>>>>>>>>>>> https://cwiki.apache.org/confluence/display/KAFKA/KIP-253%
>>>>>>>>>>> 3A+Support+in-order+message+delivery+with+partition+expansion
>>>>>>>>>>> .
>>>>>>>>>>>
>>>>>>>>>>> This KIP provides a way to allow messages of the same key from
>>>>>>>>>>> the
>>>>>>>>>>> same
>>>>>>>>>>> producer to be consumed in the same order they are produced even
>>>>>>>>>>> if
>>>>>>>>>>>
>>>>>>>>>>> we
>>>>>>>>>>
>>>>>>>>> expand partition of the topic.
>>>>>>
>>>>>>> Thanks,
>>>>>>>>>>> Dong
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>

Re: [DISCUSS] KIP-253: Support in-order message delivery with partition expansion

Posted by Jan Filipiak <Ja...@trivago.com>.
Hi Jun, thanks for your mail.

Thank you for your questions!
I think they are really good and tackle the core of the problem I see.

I will answer inline, mostly but still want to set the tone here.

The core strength of kafka is what Martin once called the 
kappa-Architecture. How does this work?
You have everything as a log as in kafka. When you need to change 
something.
You create the new version of your application and leave it running in 
parallel.
Once the new version is good you switch your users to use the new 
application.

The online reshuffling effectively breaks this architecture and I think 
the switch in thinking here is more harmful
than any details about the partitioning function to allow such a change. 
I feel with my suggestion we are the closest to
the original and battle proven architecture and I can only warn to move 
away from it.

I might have forgotten something, sometimes its hard for me to getting 
all the thoughts captured in a mail, but I hope the comments inline will 
further make my concern clear, and put some emphasis on why I prefer my 
solution ;)

One thing we should all be aware of when discussing this, and I think 
Dong should have mentioned it (maybe he did).
We are not discussing all of this out of thin air but there is an effort 
in the Samza project.

https://cwiki.apache.org/confluence/display/SAMZA/SEP-5%3A+Enable+partition+expansion+of+input+streams
https://issues.apache.org/jira/browse/SAMZA-1293

To be clear. I think SEP-5 (state of last week, dont know if it adapted 
to this discussion) is on a way better path than KIP-253, and I can't 
really explain why.

Best Jan,

nice weekend everyone


On 09.03.2018 03:36, Jun Rao wrote:
> Hi, Jan,
>
> Thanks for the feedback. Just some comments on the earlier points that you
> mentioned.
>
> 50. You brought up the question of whether existing data needs to be copied
> during partition expansion. My understand of your view is that avoid
> copying existing data will be more efficient, but it doesn't work well with
> compacted topics since some keys in the original partitions will never be
> cleaned. It would be useful to understand your use case of compacted topics
> a bit more. In the common use case, the data volume in a compacted topic
> may not be large. So, I am not sure if there is a strong need to expand
> partitions in a compacted topic, at least initially.
I do agree. State is usually smaller. Update rates might be also 
competitively high.
Doing Log-compaction (even beeing very efficient and configurable) is 
also a more expensive operation than
just discarding old segments. Further if you want to use more consumers 
processing the events
you also have to grow the number of partitions. Especially for use-cases 
we do (KIP-213) a tiny state full
table might be very expensive to process if it joins against a huge table.

I can just say we have been in the spot of needing to grow log compacted 
topics. Mainly for processing power we can bring to the table.

Further i am not at all concerned about the extra spaced used by 
"garbage keys". I am more concerned about the correctness of innocent 
consumers. The logic becomes complicated. Say for streams one would need 
to load the record into state but not forward it the topology ( to have 
it available for shuffeling). I rather have it simple and a topic clean 
regardless if it still has its old partition count. Especially with 
multiple partitions growth's I think it becomes insanely hard to to this 
shuffle correct. Maybe Streams and Samza can do it. Especially if you do 
"hipster stream processing" 
<https://www.confluent.io/blog/introducing-kafka-streams-stream-processing-made-simple/>. 
This makes kafka way to complicated. With my approach I think its way 
simpler because the topic has no "history" in terms of partitioning but 
is always clean.

>
> 51. "Growing the topic by an integer factor does not require any state
> redistribution at all." Could you clarify this a bit more? Let's say you
> have a consumer app that computes the windowed count per key. If you double
> the number of partitions from 1 to 2 and grow the consumer instances from 1
> to 2, we would need to redistribute some of the counts to the new consumer
> instance. Regarding to linear hashing, it's true that it won't solve the
> problem with compacted topics. The main benefit is that it redistributes
> the keys in one partition to no more than two partitions, which could help
> redistribute the state.
You don't need to spin up a new consumer in this case. every consumer 
would just read every partition with the (partition % num_task) task. it 
will still have the previous data right there and can go on.

This sounds contradictory to what I said before, but please bear with me.
>
> 52. Good point on coordinating the expansion of 2 topics that need to be
> joined together. This is where the 2-phase partition expansion could
> potentially help. In the first phase, we could add new partitions to the 2
> topics one at a time but without publishing to the new patitions. Then, we
> can add new consumer instances to pick up the new partitions. In this
> transition phase, no reshuffling is needed since no data is coming from the
> new partitions. Finally, we can enable the publishing to the new
> partitions.
I think its even worse than you think. I would like to introduce the 
Term transitive copartitioning. Imagine
2 streams application. One joins (A,B) the other (B,C) then there is a 
transitive copartition requirement for
(A,C) to be copartitioned aswell. This can spread significantly and 
require many consumers to adapt at the same time.

It is also not entirely clear to me how you not need reshuffling in this 
case. If A has a record that never gets updated after the expansion and 
the coresponding B record moves to a new partition. How shall they meet 
w/o shuffle?
>
> 53. "Migrating consumer is a step that might be made completly unnecessary
> if - for example streams - takes the gcd as partitioning scheme instead of
> enforcing 1 to 1." Not sure that I fully understand this. I think you mean
> that a consumer application can run more instances than the number of
> partitions. In that case, the consumer can just repartitioning the input
> data according to the number of instances. This is possible, but just has
> the overhead of reshuffling the data.
No what I meant is ( that is also your question i think Mathias) that if 
you grow a topic by a factor.
Even if your processor is statefull you can can just assign all the 
multiples of the previous partition to
this consumer and the state to keep processing correctly will be present 
w/o any shuffling.

Say you have an assignment
Statefull consumer => partition
0 => 0
1 => 1
2 => 2

and you grow you topic by 4 you get,

0 => 0,3,6,9
1 => 1,4,7,10
2 => 2,5,8,11

Say your hashcode is 8. 8%3 => 2  before so consumer for partition 2 has it.
Now you you have 12 partitions so 8%12 => 8, so it goes into partition 8 
which is assigned to the same consumer
who had 2 before and therefore knows the key.

Userland reshuffeling is there as an options. And it does exactly what I 
suggest. And I think its the perfect strategie. All I am suggestion is 
broker side support to switch the producers to the newly partitioned 
topic. Then the old (to few partition topic) can go away.  Remember the 
list of steps in the beginning of this thread. If one has broker support 
for all where its required and streams support for those that aren’t 
necessarily. Then one has solved the problem.
I repeat it because I think its important. I am really happy that you 
brought that up! because its 100% what I want just with the differences 
to have an option to discard the to small topic later (after all 
consumers adapted). And to have order correct there. I need broker 
support managing the copy process + the produces and fence them against 
each other. I also repeat. the copy process can run for weeks in the 
worst case. Copying the data is not the longest task migrating consumers 
might very well be.
Once all consumers switched and copying is really up to date (think ISR 
like up to date) only then we stop the producer, wait for the copy to 
finish and use the new topic for producing.

After this the topic is perfect in shape. and no one needs to worry 
about complicated stuff. (old keys hanging around might arrive in some 
other topic later.....). can only imagine how many tricky bugs gonna 
arrive after someone had grown and shrunken is topic 10 times.





>
> 54. "The other thing I wanted to mention is that I believe the current
> suggestion (without copying data over) can be implemented in pure userland
> with a custom partitioner and a small feedbackloop from ProduceResponse =>
> Partitionier in coorporation with a change management system." I am not
> sure a customized partitioner itself solves the problem. We probably need
> some broker side support to enforce when the new partitions can be used. We
> also need some support on the consumer/kstream side to preserve the per key
> ordering and potentially migrate the processing state. This is not trivial
> and I am not sure if it's ideal to fully push to the application space.
Broker support is defenitly the preferred way here. I have nothing 
against broker support.
I tried to say that for what I would preffer - copying the data over, at 
least for log compacted topics -
I would require more broker support than the KIP currently offers.

>
> Jun
>
>
> On Tue, Mar 6, 2018 at 10:33 PM, Jan Filipiak <Ja...@trivago.com>
> wrote:
>
>> Hi Dong,
>>
>> are you actually reading my emails, or are you just using the thread I
>> started for general announcements regarding the KIP?
>>
>> I tried to argue really hard against linear hashing. Growing the topic by
>> an integer factor does not require any state redistribution at all. I fail
>> to see completely where linear hashing helps on log compacted topics.
>>
>> If you are not willing to explain to me what I might be overlooking: that
>> is fine.
>> But I ask you to not reply to my emails then. Please understand my
>> frustration with this.
>>
>> Best Jan
>>
>>
>>
>> On 06.03.2018 19:38, Dong Lin wrote:
>>
>>> Hi everyone,
>>>
>>> Thanks for all the comments! It appears that everyone prefers linear
>>> hashing because it reduces the amount of state that needs to be moved
>>> between consumers (for stream processing). The KIP has been updated to use
>>> linear hashing.
>>>
>>> Regarding the migration endeavor: it seems that migrating producer library
>>> to use linear hashing should be pretty straightforward without
>>> much operational endeavor. If we don't upgrade client library to use this
>>> KIP, we can not support in-order delivery after partition is changed
>>> anyway. Suppose we upgrade client library to use this KIP, if partition
>>> number is not changed, the key -> partition mapping will be exactly the
>>> same as it is now because it is still determined using murmur_hash(key) %
>>> original_partition_num. In other words, this change is backward
>>> compatible.
>>>
>>> Regarding the load distribution: if we use linear hashing, the load may be
>>> unevenly distributed because those partitions which are not split may
>>> receive twice as much traffic as other partitions that are split. This
>>> issue can be mitigated by creating topic with partitions that are several
>>> times the number of consumers. And there will be no imbalance if the
>>> partition number is always doubled. So this imbalance seems acceptable.
>>>
>>> Regarding storing the partition strategy as per-topic config: It seems not
>>> necessary since we can still use murmur_hash as the default hash function
>>> and additionally apply the linear hashing algorithm if the partition
>>> number
>>> has increased. Not sure if there is any use-case for producer to use a
>>> different hash function. Jason, can you check if there is some use-case
>>> that I missed for using the per-topic partition strategy?
>>>
>>> Regarding how to reduce latency (due to state store/load) in stream
>>> processing consumer when partition number changes: I need to read the
>>> Kafka
>>> Stream code to understand how Kafka Stream currently migrate state between
>>> consumers when the application is added/removed for a given job. I will
>>> reply after I finish reading the documentation and code.
>>>
>>>
>>> Thanks,
>>> Dong
>>>
>>>
>>> On Mon, Mar 5, 2018 at 10:43 AM, Jason Gustafson <ja...@confluent.io>
>>> wrote:
>>>
>>> Great discussion. I think I'm wondering whether we can continue to leave
>>>> Kafka agnostic to the partitioning strategy. The challenge is
>>>> communicating
>>>> the partitioning logic from producers to consumers so that the
>>>> dependencies
>>>> between each epoch can be determined. For the sake of discussion, imagine
>>>> you did something like the following:
>>>>
>>>> 1. The name (and perhaps version) of a partitioning strategy is stored in
>>>> topic configuration when a topic is created.
>>>> 2. The producer looks up the partitioning strategy before writing to a
>>>> topic and includes it in the produce request (for fencing). If it doesn't
>>>> have an implementation for the configured strategy, it fails.
>>>> 3. The consumer also looks up the partitioning strategy and uses it to
>>>> determine dependencies when reading a new epoch. It could either fail or
>>>> make the most conservative dependency assumptions if it doesn't know how
>>>> to
>>>> implement the partitioning strategy. For the consumer, the new interface
>>>> might look something like this:
>>>>
>>>> // Return the partition dependencies following an epoch bump
>>>> Map<Integer, List<Integer>> dependencies(int
>>>> numPartitionsBeforeEpochBump,
>>>> int numPartitionsAfterEpochBump)
>>>>
>>>> The unordered case then is just a particular implementation which never
>>>> has
>>>> any epoch dependencies. To implement this, we would need some way for the
>>>> consumer to find out how many partitions there were in each epoch, but
>>>> maybe that's not too unreasonable.
>>>>
>>>> Thanks,
>>>> Jason
>>>>
>>>>
>>>> On Mon, Mar 5, 2018 at 4:51 AM, Jan Filipiak <Ja...@trivago.com>
>>>> wrote:
>>>>
>>>> Hi Dong
>>>>> thank you very much for your questions.
>>>>>
>>>>> regarding the time spend copying data across:
>>>>> It is correct that copying data from a topic with one partition mapping
>>>>>
>>>> to
>>>>
>>>>> a topic with a different partition mapping takes way longer than we can
>>>>> stop producers. Tens of minutes is a very optimistic estimate here. Many
>>>>> people can not afford copy full steam and therefore will have some rate
>>>>> limiting in place, this can bump the timespan into the day's. The good
>>>>>
>>>> part
>>>>
>>>>> is that the vast majority of the data can be copied while the producers
>>>>>
>>>> are
>>>>
>>>>> still going. One can then, piggyback the consumers ontop of this
>>>>>
>>>> timeframe,
>>>>
>>>>> by the method mentioned (provide them an mapping from their old offsets
>>>>>
>>>> to
>>>>
>>>>> new offsets in their repartitioned topics. In that way we separate
>>>>> migration of consumers from migration of producers (decoupling these is
>>>>> what kafka is strongest at). The time to actually swap over the
>>>>> producers
>>>>> should be kept minimal by ensuring that when a swap attempt is started
>>>>>
>>>> the
>>>>
>>>>> consumer copying over should be very close to the log end and is
>>>>> expected
>>>>> to finish within the next fetch. The operation should have a time-out
>>>>> and
>>>>> should be "reattemtable".
>>>>>
>>>>> Importance of logcompaction:
>>>>> If a producer produces key A, to partiton 0, its forever gonna be there,
>>>>> unless it gets deleted. The record might sit in there for years. A new
>>>>> producer started with the new partitions will fail to delete the record
>>>>>
>>>> in
>>>>
>>>>> the correct partition. Th record will be there forever and one can not
>>>>> reliable bootstrap new consumers. I cannot see how linear hashing can
>>>>>
>>>> solve
>>>>
>>>>> this.
>>>>>
>>>>> Regarding your skipping of userland copying:
>>>>> 100%, copying the data across in userland is, as far as i can see, only
>>>>> a
>>>>> usecase for log compacted topics. Even for logcompaction + retentions it
>>>>> should only be opt-in. Why did I bring it up? I think log compaction is
>>>>> a
>>>>> very important feature to really embrace kafka as a "data plattform".
>>>>> The
>>>>> point I also want to make is that copying data this way is completely
>>>>> inline with the kafka architecture. it only consists of reading and
>>>>>
>>>> writing
>>>>
>>>>> to topics.
>>>>>
>>>>> I hope it clarifies more why I think we should aim for more than the
>>>>> current KIP. I fear that once the KIP is done not much more effort will
>>>>>
>>>> be
>>>>
>>>>> taken.
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> On 04.03.2018 02:28, Dong Lin wrote:
>>>>>
>>>>> Hey Jan,
>>>>>> In the current proposal, the consumer will be blocked on waiting for
>>>>>>
>>>>> other
>>>>> consumers of the group to consume up to a given offset. In most cases,
>>>>> all
>>>>> consumers should be close to the LEO of the partitions when the
>>>>> partition
>>>>> expansion happens. Thus the time waiting should not be long e.g. on the
>>>>>> order of seconds. On the other hand, it may take a long time to wait
>>>>>> for
>>>>>> the entire partition to be copied -- the amount of time is proportional
>>>>>>
>>>>> to
>>>>> the amount of existing data in the partition, which can take tens of
>>>>>> minutes. So the amount of time that we stop consumers may not be on the
>>>>>> same order of magnitude.
>>>>>>
>>>>>> If we can implement this suggestion without copying data over in purse
>>>>>> userland, it will be much more valuable. Do you have ideas on how this
>>>>>>
>>>>> can
>>>>> be done?
>>>>>> Not sure why the current KIP not help people who depend on log
>>>>>>
>>>>> compaction.
>>>>> Could you elaborate more on this point?
>>>>>> Thanks,
>>>>>> Dong
>>>>>>
>>>>>> On Wed, Feb 28, 2018 at 10:55 PM, Jan Filipiak<Jan.Filipiak@trivago.
>>>>>> com
>>>>>> wrote:
>>>>>>
>>>>>> Hi Dong,
>>>>>>
>>>>>>> I tried to focus on what the steps are one can currently perform to
>>>>>>> expand
>>>>>>> or shrink a keyed topic while maintaining a top notch semantics.
>>>>>>> I can understand that there might be confusion about "stopping the
>>>>>>> consumer". It is exactly the same as proposed in the KIP. there needs
>>>>>>>
>>>>>> to
>>>>> be
>>>>>>> a time the producers agree on the new partitioning. The extra
>>>>>>>
>>>>>> semantics I
>>>>> want to put in there is that we have a possibility to wait until all
>>>>>> the
>>>>> existing data
>>>>>>> is copied over into the new partitioning scheme. When I say stopping I
>>>>>>> think more of having a memory barrier that ensures the ordering. I am
>>>>>>> still
>>>>>>> aming for latencies  on the scale of leader failovers.
>>>>>>>
>>>>>>> Consumers have to explicitly adapt the new partitioning scheme in the
>>>>>>> above scenario. The reason is that in these cases where you are
>>>>>>>
>>>>>> dependent
>>>>> on a particular partitioning scheme, you also have other topics that
>>>>>> have
>>>>> co-partition enforcements or the kind -frequently. Therefore all your
>>>>>>> other
>>>>>>> input topics might need to grow accordingly.
>>>>>>>
>>>>>>>
>>>>>>> What I was suggesting was to streamline all these operations as best
>>>>>>> as
>>>>>>> possible to have "real" partition grow and shrinkage going on.
>>>>>>>
>>>>>> Migrating
>>>>> the producers to a new partitioning scheme can be much more streamlined
>>>>>>> with proper broker support for this. Migrating consumer is a step that
>>>>>>> might be made completly unnecessary if - for example streams - takes
>>>>>>>
>>>>>> the
>>>>> gcd as partitioning scheme instead of enforcing 1 to 1. Connect
>>>>>> consumers
>>>>> and other consumers should be fine anyways.
>>>>>>> I hope this makes more clear where I was aiming at. The rest needs to
>>>>>>>
>>>>>> be
>>>>> figured out. The only danger i see is that when we are introducing this
>>>>>>> feature as supposed in the KIP, it wont help any people depending on
>>>>>>>
>>>>>> log
>>>>> compaction.
>>>>>>> The other thing I wanted to mention is that I believe the current
>>>>>>> suggestion (without copying data over) can be implemented in pure
>>>>>>> userland
>>>>>>> with a custom partitioner and a small feedbackloop from
>>>>>>> ProduceResponse
>>>>>>> =>
>>>>>>> Partitionier in coorporation with a change management system.
>>>>>>>
>>>>>>> Best Jan
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> On 28.02.2018 07:13, Dong Lin wrote:
>>>>>>>
>>>>>>> Hey Jan,
>>>>>>>
>>>>>>>> I am not sure if it is acceptable for producer to be stopped for a
>>>>>>>> while,
>>>>>>>> particularly for online application which requires low latency. I am
>>>>>>>> also
>>>>>>>> not sure how consumers can switch to a new topic. Does user
>>>>>>>>
>>>>>>> application
>>>>> needs to explicitly specify a different topic for producer/consumer to
>>>>>>>> subscribe to? It will be helpful for discussion if you can provide
>>>>>>>>
>>>>>>> more
>>>>> detail on the interface change for this solution.
>>>>>>>> Thanks,
>>>>>>>> Dong
>>>>>>>>
>>>>>>>> On Mon, Feb 26, 2018 at 12:48 AM, Jan Filipiak<Jan.Filipiak@trivago.
>>>>>>>>
>>>>>>> com
>>>>> wrote:
>>>>>>>> Hi,
>>>>>>>>
>>>>>>>> just want to throw my though in. In general the functionality is very
>>>>>>>>> usefull, we should though not try to find the architecture to hard
>>>>>>>>> while
>>>>>>>>> implementing.
>>>>>>>>>
>>>>>>>>> The manual steps would be to
>>>>>>>>>
>>>>>>>>> create a new topic
>>>>>>>>> the mirrormake from the new old topic to the new topic
>>>>>>>>> wait for mirror making to catch up.
>>>>>>>>> then put the consumers onto the new topic
>>>>>>>>>         (having mirrormaker spit out a mapping from old offsets to
>>>>>>>>> new
>>>>>>>>> offsets:
>>>>>>>>>             if topic is increased by factor X there is gonna be a
>>>>>>>>> clean
>>>>>>>>> mapping from 1 offset in the old topic to X offsets in the new
>>>>>>>>> topic,
>>>>>>>>>             if there is no factor then there is no chance to
>>>>>>>>> generate a
>>>>>>>>> mapping that can be reasonable used for continuing)
>>>>>>>>>         make consumers stop at appropriate points and continue
>>>>>>>>> consumption
>>>>>>>>> with offsets from the mapping.
>>>>>>>>> have the producers stop for a minimal time.
>>>>>>>>> wait for mirrormaker to finish
>>>>>>>>> let producer produce with the new metadata.
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> Instead of implementing the approach suggest in the KIP which will
>>>>>>>>> leave
>>>>>>>>> log compacted topic completely crumbled and unusable.
>>>>>>>>> I would much rather try to build infrastructure to support the
>>>>>>>>> mentioned
>>>>>>>>> above operations more smoothly.
>>>>>>>>> Especially having producers stop and use another topic is difficult
>>>>>>>>>
>>>>>>>> and
>>>>> it would be nice if one can trigger "invalid metadata" exceptions for
>>>>>>>>> them
>>>>>>>>> and
>>>>>>>>> if one could give topics aliases so that their produces with the old
>>>>>>>>> topic
>>>>>>>>> will arrive in the new topic.
>>>>>>>>>
>>>>>>>>> The downsides are obvious I guess ( having the same data twice for
>>>>>>>>>
>>>>>>>> the
>>>>> transition period, but kafka tends to scale well with datasize). So
>>>>>>>>> its a
>>>>>>>>> nicer fit into the architecture.
>>>>>>>>>
>>>>>>>>> I further want to argument that the functionality by the KIP can
>>>>>>>>> completely be implementing in "userland" with a custom partitioner
>>>>>>>>>
>>>>>>>> that
>>>>> handles the transition as needed. I would appreciate if someone could
>>>>>>>>> point
>>>>>>>>> out what a custom partitioner couldn't handle in this case?
>>>>>>>>>
>>>>>>>>> With the above approach, shrinking a topic becomes the same steps.
>>>>>>>>> Without
>>>>>>>>> loosing keys in the discontinued partitions.
>>>>>>>>>
>>>>>>>>> Would love to hear what everyone thinks.
>>>>>>>>>
>>>>>>>>> Best Jan
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> On 11.02.2018 00:35, Dong Lin wrote:
>>>>>>>>>
>>>>>>>>> Hi all,
>>>>>>>>>
>>>>>>>>> I have created KIP-253: Support in-order message delivery with
>>>>>>>>>> partition
>>>>>>>>>> expansion. See
>>>>>>>>>> https://cwiki.apache.org/confluence/display/KAFKA/KIP-253%
>>>>>>>>>> 3A+Support+in-order+message+delivery+with+partition+expansion
>>>>>>>>>> .
>>>>>>>>>>
>>>>>>>>>> This KIP provides a way to allow messages of the same key from the
>>>>>>>>>> same
>>>>>>>>>> producer to be consumed in the same order they are produced even if
>>>>>>>>>>
>>>>>>>>> we
>>>>> expand partition of the topic.
>>>>>>>>>> Thanks,
>>>>>>>>>> Dong
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>


Re: [DISCUSS] KIP-253: Support in-order message delivery with partition expansion

Posted by Jun Rao <ju...@confluent.io>.
Hi, Jan,

Thanks for the feedback. Just some comments on the earlier points that you
mentioned.

50. You brought up the question of whether existing data needs to be copied
during partition expansion. My understand of your view is that avoid
copying existing data will be more efficient, but it doesn't work well with
compacted topics since some keys in the original partitions will never be
cleaned. It would be useful to understand your use case of compacted topics
a bit more. In the common use case, the data volume in a compacted topic
may not be large. So, I am not sure if there is a strong need to expand
partitions in a compacted topic, at least initially.

51. "Growing the topic by an integer factor does not require any state
redistribution at all." Could you clarify this a bit more? Let's say you
have a consumer app that computes the windowed count per key. If you double
the number of partitions from 1 to 2 and grow the consumer instances from 1
to 2, we would need to redistribute some of the counts to the new consumer
instance. Regarding to linear hashing, it's true that it won't solve the
problem with compacted topics. The main benefit is that it redistributes
the keys in one partition to no more than two partitions, which could help
redistribute the state.

52. Good point on coordinating the expansion of 2 topics that need to be
joined together. This is where the 2-phase partition expansion could
potentially help. In the first phase, we could add new partitions to the 2
topics one at a time but without publishing to the new patitions. Then, we
can add new consumer instances to pick up the new partitions. In this
transition phase, no reshuffling is needed since no data is coming from the
new partitions. Finally, we can enable the publishing to the new
partitions.

53. "Migrating consumer is a step that might be made completly unnecessary
if - for example streams - takes the gcd as partitioning scheme instead of
enforcing 1 to 1." Not sure that I fully understand this. I think you mean
that a consumer application can run more instances than the number of
partitions. In that case, the consumer can just repartitioning the input
data according to the number of instances. This is possible, but just has
the overhead of reshuffling the data.

54. "The other thing I wanted to mention is that I believe the current
suggestion (without copying data over) can be implemented in pure userland
with a custom partitioner and a small feedbackloop from ProduceResponse =>
Partitionier in coorporation with a change management system." I am not
sure a customized partitioner itself solves the problem. We probably need
some broker side support to enforce when the new partitions can be used. We
also need some support on the consumer/kstream side to preserve the per key
ordering and potentially migrate the processing state. This is not trivial
and I am not sure if it's ideal to fully push to the application space.

Jun


On Tue, Mar 6, 2018 at 10:33 PM, Jan Filipiak <Ja...@trivago.com>
wrote:

> Hi Dong,
>
> are you actually reading my emails, or are you just using the thread I
> started for general announcements regarding the KIP?
>
> I tried to argue really hard against linear hashing. Growing the topic by
> an integer factor does not require any state redistribution at all. I fail
> to see completely where linear hashing helps on log compacted topics.
>
> If you are not willing to explain to me what I might be overlooking: that
> is fine.
> But I ask you to not reply to my emails then. Please understand my
> frustration with this.
>
> Best Jan
>
>
>
> On 06.03.2018 19:38, Dong Lin wrote:
>
>> Hi everyone,
>>
>> Thanks for all the comments! It appears that everyone prefers linear
>> hashing because it reduces the amount of state that needs to be moved
>> between consumers (for stream processing). The KIP has been updated to use
>> linear hashing.
>>
>> Regarding the migration endeavor: it seems that migrating producer library
>> to use linear hashing should be pretty straightforward without
>> much operational endeavor. If we don't upgrade client library to use this
>> KIP, we can not support in-order delivery after partition is changed
>> anyway. Suppose we upgrade client library to use this KIP, if partition
>> number is not changed, the key -> partition mapping will be exactly the
>> same as it is now because it is still determined using murmur_hash(key) %
>> original_partition_num. In other words, this change is backward
>> compatible.
>>
>> Regarding the load distribution: if we use linear hashing, the load may be
>> unevenly distributed because those partitions which are not split may
>> receive twice as much traffic as other partitions that are split. This
>> issue can be mitigated by creating topic with partitions that are several
>> times the number of consumers. And there will be no imbalance if the
>> partition number is always doubled. So this imbalance seems acceptable.
>>
>> Regarding storing the partition strategy as per-topic config: It seems not
>> necessary since we can still use murmur_hash as the default hash function
>> and additionally apply the linear hashing algorithm if the partition
>> number
>> has increased. Not sure if there is any use-case for producer to use a
>> different hash function. Jason, can you check if there is some use-case
>> that I missed for using the per-topic partition strategy?
>>
>> Regarding how to reduce latency (due to state store/load) in stream
>> processing consumer when partition number changes: I need to read the
>> Kafka
>> Stream code to understand how Kafka Stream currently migrate state between
>> consumers when the application is added/removed for a given job. I will
>> reply after I finish reading the documentation and code.
>>
>>
>> Thanks,
>> Dong
>>
>>
>> On Mon, Mar 5, 2018 at 10:43 AM, Jason Gustafson <ja...@confluent.io>
>> wrote:
>>
>> Great discussion. I think I'm wondering whether we can continue to leave
>>> Kafka agnostic to the partitioning strategy. The challenge is
>>> communicating
>>> the partitioning logic from producers to consumers so that the
>>> dependencies
>>> between each epoch can be determined. For the sake of discussion, imagine
>>> you did something like the following:
>>>
>>> 1. The name (and perhaps version) of a partitioning strategy is stored in
>>> topic configuration when a topic is created.
>>> 2. The producer looks up the partitioning strategy before writing to a
>>> topic and includes it in the produce request (for fencing). If it doesn't
>>> have an implementation for the configured strategy, it fails.
>>> 3. The consumer also looks up the partitioning strategy and uses it to
>>> determine dependencies when reading a new epoch. It could either fail or
>>> make the most conservative dependency assumptions if it doesn't know how
>>> to
>>> implement the partitioning strategy. For the consumer, the new interface
>>> might look something like this:
>>>
>>> // Return the partition dependencies following an epoch bump
>>> Map<Integer, List<Integer>> dependencies(int
>>> numPartitionsBeforeEpochBump,
>>> int numPartitionsAfterEpochBump)
>>>
>>> The unordered case then is just a particular implementation which never
>>> has
>>> any epoch dependencies. To implement this, we would need some way for the
>>> consumer to find out how many partitions there were in each epoch, but
>>> maybe that's not too unreasonable.
>>>
>>> Thanks,
>>> Jason
>>>
>>>
>>> On Mon, Mar 5, 2018 at 4:51 AM, Jan Filipiak <Ja...@trivago.com>
>>> wrote:
>>>
>>> Hi Dong
>>>>
>>>> thank you very much for your questions.
>>>>
>>>> regarding the time spend copying data across:
>>>> It is correct that copying data from a topic with one partition mapping
>>>>
>>> to
>>>
>>>> a topic with a different partition mapping takes way longer than we can
>>>> stop producers. Tens of minutes is a very optimistic estimate here. Many
>>>> people can not afford copy full steam and therefore will have some rate
>>>> limiting in place, this can bump the timespan into the day's. The good
>>>>
>>> part
>>>
>>>> is that the vast majority of the data can be copied while the producers
>>>>
>>> are
>>>
>>>> still going. One can then, piggyback the consumers ontop of this
>>>>
>>> timeframe,
>>>
>>>> by the method mentioned (provide them an mapping from their old offsets
>>>>
>>> to
>>>
>>>> new offsets in their repartitioned topics. In that way we separate
>>>> migration of consumers from migration of producers (decoupling these is
>>>> what kafka is strongest at). The time to actually swap over the
>>>> producers
>>>> should be kept minimal by ensuring that when a swap attempt is started
>>>>
>>> the
>>>
>>>> consumer copying over should be very close to the log end and is
>>>> expected
>>>> to finish within the next fetch. The operation should have a time-out
>>>> and
>>>> should be "reattemtable".
>>>>
>>>> Importance of logcompaction:
>>>> If a producer produces key A, to partiton 0, its forever gonna be there,
>>>> unless it gets deleted. The record might sit in there for years. A new
>>>> producer started with the new partitions will fail to delete the record
>>>>
>>> in
>>>
>>>> the correct partition. Th record will be there forever and one can not
>>>> reliable bootstrap new consumers. I cannot see how linear hashing can
>>>>
>>> solve
>>>
>>>> this.
>>>>
>>>> Regarding your skipping of userland copying:
>>>> 100%, copying the data across in userland is, as far as i can see, only
>>>> a
>>>> usecase for log compacted topics. Even for logcompaction + retentions it
>>>> should only be opt-in. Why did I bring it up? I think log compaction is
>>>> a
>>>> very important feature to really embrace kafka as a "data plattform".
>>>> The
>>>> point I also want to make is that copying data this way is completely
>>>> inline with the kafka architecture. it only consists of reading and
>>>>
>>> writing
>>>
>>>> to topics.
>>>>
>>>> I hope it clarifies more why I think we should aim for more than the
>>>> current KIP. I fear that once the KIP is done not much more effort will
>>>>
>>> be
>>>
>>>> taken.
>>>>
>>>>
>>>>
>>>>
>>>> On 04.03.2018 02:28, Dong Lin wrote:
>>>>
>>>> Hey Jan,
>>>>>
>>>>> In the current proposal, the consumer will be blocked on waiting for
>>>>>
>>>> other
>>>
>>>> consumers of the group to consume up to a given offset. In most cases,
>>>>>
>>>> all
>>>
>>>> consumers should be close to the LEO of the partitions when the
>>>>>
>>>> partition
>>>
>>>> expansion happens. Thus the time waiting should not be long e.g. on the
>>>>> order of seconds. On the other hand, it may take a long time to wait
>>>>> for
>>>>> the entire partition to be copied -- the amount of time is proportional
>>>>>
>>>> to
>>>
>>>> the amount of existing data in the partition, which can take tens of
>>>>> minutes. So the amount of time that we stop consumers may not be on the
>>>>> same order of magnitude.
>>>>>
>>>>> If we can implement this suggestion without copying data over in purse
>>>>> userland, it will be much more valuable. Do you have ideas on how this
>>>>>
>>>> can
>>>
>>>> be done?
>>>>>
>>>>> Not sure why the current KIP not help people who depend on log
>>>>>
>>>> compaction.
>>>
>>>> Could you elaborate more on this point?
>>>>>
>>>>> Thanks,
>>>>> Dong
>>>>>
>>>>> On Wed, Feb 28, 2018 at 10:55 PM, Jan Filipiak<Jan.Filipiak@trivago.
>>>>> com
>>>>> wrote:
>>>>>
>>>>> Hi Dong,
>>>>>
>>>>>> I tried to focus on what the steps are one can currently perform to
>>>>>> expand
>>>>>> or shrink a keyed topic while maintaining a top notch semantics.
>>>>>> I can understand that there might be confusion about "stopping the
>>>>>> consumer". It is exactly the same as proposed in the KIP. there needs
>>>>>>
>>>>> to
>>>
>>>> be
>>>>>> a time the producers agree on the new partitioning. The extra
>>>>>>
>>>>> semantics I
>>>
>>>> want to put in there is that we have a possibility to wait until all
>>>>>>
>>>>> the
>>>
>>>> existing data
>>>>>> is copied over into the new partitioning scheme. When I say stopping I
>>>>>> think more of having a memory barrier that ensures the ordering. I am
>>>>>> still
>>>>>> aming for latencies  on the scale of leader failovers.
>>>>>>
>>>>>> Consumers have to explicitly adapt the new partitioning scheme in the
>>>>>> above scenario. The reason is that in these cases where you are
>>>>>>
>>>>> dependent
>>>
>>>> on a particular partitioning scheme, you also have other topics that
>>>>>>
>>>>> have
>>>
>>>> co-partition enforcements or the kind -frequently. Therefore all your
>>>>>> other
>>>>>> input topics might need to grow accordingly.
>>>>>>
>>>>>>
>>>>>> What I was suggesting was to streamline all these operations as best
>>>>>> as
>>>>>> possible to have "real" partition grow and shrinkage going on.
>>>>>>
>>>>> Migrating
>>>
>>>> the producers to a new partitioning scheme can be much more streamlined
>>>>>> with proper broker support for this. Migrating consumer is a step that
>>>>>> might be made completly unnecessary if - for example streams - takes
>>>>>>
>>>>> the
>>>
>>>> gcd as partitioning scheme instead of enforcing 1 to 1. Connect
>>>>>>
>>>>> consumers
>>>
>>>> and other consumers should be fine anyways.
>>>>>>
>>>>>> I hope this makes more clear where I was aiming at. The rest needs to
>>>>>>
>>>>> be
>>>
>>>> figured out. The only danger i see is that when we are introducing this
>>>>>> feature as supposed in the KIP, it wont help any people depending on
>>>>>>
>>>>> log
>>>
>>>> compaction.
>>>>>>
>>>>>> The other thing I wanted to mention is that I believe the current
>>>>>> suggestion (without copying data over) can be implemented in pure
>>>>>> userland
>>>>>> with a custom partitioner and a small feedbackloop from
>>>>>> ProduceResponse
>>>>>> =>
>>>>>> Partitionier in coorporation with a change management system.
>>>>>>
>>>>>> Best Jan
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> On 28.02.2018 07:13, Dong Lin wrote:
>>>>>>
>>>>>> Hey Jan,
>>>>>>
>>>>>>> I am not sure if it is acceptable for producer to be stopped for a
>>>>>>> while,
>>>>>>> particularly for online application which requires low latency. I am
>>>>>>> also
>>>>>>> not sure how consumers can switch to a new topic. Does user
>>>>>>>
>>>>>> application
>>>
>>>> needs to explicitly specify a different topic for producer/consumer to
>>>>>>> subscribe to? It will be helpful for discussion if you can provide
>>>>>>>
>>>>>> more
>>>
>>>> detail on the interface change for this solution.
>>>>>>>
>>>>>>> Thanks,
>>>>>>> Dong
>>>>>>>
>>>>>>> On Mon, Feb 26, 2018 at 12:48 AM, Jan Filipiak<Jan.Filipiak@trivago.
>>>>>>>
>>>>>> com
>>>
>>>> wrote:
>>>>>>>
>>>>>>> Hi,
>>>>>>>
>>>>>>> just want to throw my though in. In general the functionality is very
>>>>>>>> usefull, we should though not try to find the architecture to hard
>>>>>>>> while
>>>>>>>> implementing.
>>>>>>>>
>>>>>>>> The manual steps would be to
>>>>>>>>
>>>>>>>> create a new topic
>>>>>>>> the mirrormake from the new old topic to the new topic
>>>>>>>> wait for mirror making to catch up.
>>>>>>>> then put the consumers onto the new topic
>>>>>>>>        (having mirrormaker spit out a mapping from old offsets to
>>>>>>>> new
>>>>>>>> offsets:
>>>>>>>>            if topic is increased by factor X there is gonna be a
>>>>>>>> clean
>>>>>>>> mapping from 1 offset in the old topic to X offsets in the new
>>>>>>>> topic,
>>>>>>>>            if there is no factor then there is no chance to
>>>>>>>> generate a
>>>>>>>> mapping that can be reasonable used for continuing)
>>>>>>>>        make consumers stop at appropriate points and continue
>>>>>>>> consumption
>>>>>>>> with offsets from the mapping.
>>>>>>>> have the producers stop for a minimal time.
>>>>>>>> wait for mirrormaker to finish
>>>>>>>> let producer produce with the new metadata.
>>>>>>>>
>>>>>>>>
>>>>>>>> Instead of implementing the approach suggest in the KIP which will
>>>>>>>> leave
>>>>>>>> log compacted topic completely crumbled and unusable.
>>>>>>>> I would much rather try to build infrastructure to support the
>>>>>>>> mentioned
>>>>>>>> above operations more smoothly.
>>>>>>>> Especially having producers stop and use another topic is difficult
>>>>>>>>
>>>>>>> and
>>>
>>>> it would be nice if one can trigger "invalid metadata" exceptions for
>>>>>>>> them
>>>>>>>> and
>>>>>>>> if one could give topics aliases so that their produces with the old
>>>>>>>> topic
>>>>>>>> will arrive in the new topic.
>>>>>>>>
>>>>>>>> The downsides are obvious I guess ( having the same data twice for
>>>>>>>>
>>>>>>> the
>>>
>>>> transition period, but kafka tends to scale well with datasize). So
>>>>>>>> its a
>>>>>>>> nicer fit into the architecture.
>>>>>>>>
>>>>>>>> I further want to argument that the functionality by the KIP can
>>>>>>>> completely be implementing in "userland" with a custom partitioner
>>>>>>>>
>>>>>>> that
>>>
>>>> handles the transition as needed. I would appreciate if someone could
>>>>>>>> point
>>>>>>>> out what a custom partitioner couldn't handle in this case?
>>>>>>>>
>>>>>>>> With the above approach, shrinking a topic becomes the same steps.
>>>>>>>> Without
>>>>>>>> loosing keys in the discontinued partitions.
>>>>>>>>
>>>>>>>> Would love to hear what everyone thinks.
>>>>>>>>
>>>>>>>> Best Jan
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> On 11.02.2018 00:35, Dong Lin wrote:
>>>>>>>>
>>>>>>>> Hi all,
>>>>>>>>
>>>>>>>> I have created KIP-253: Support in-order message delivery with
>>>>>>>>> partition
>>>>>>>>> expansion. See
>>>>>>>>> https://cwiki.apache.org/confluence/display/KAFKA/KIP-253%
>>>>>>>>> 3A+Support+in-order+message+delivery+with+partition+expansion
>>>>>>>>> .
>>>>>>>>>
>>>>>>>>> This KIP provides a way to allow messages of the same key from the
>>>>>>>>> same
>>>>>>>>> producer to be consumed in the same order they are produced even if
>>>>>>>>>
>>>>>>>> we
>>>
>>>> expand partition of the topic.
>>>>>>>>>
>>>>>>>>> Thanks,
>>>>>>>>> Dong
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>

Re: [DISCUSS] KIP-253: Support in-order message delivery with partition expansion

Posted by Dong Lin <li...@gmail.com>.
Hey Jan,

Sorry for the frustration. I haven't finished replying to all comments. For
example in my last email it is mentioned that "I will reply after I finish
reading the documentation and code". It takes time to think through
comments thoroughly. I have been busy with my daily work and haven't had
time to reply to all comments.

I have some quick rely to your comments. It is true that some space will be
wasted with the current approach in the KIP for log compacted topics. But
it does not actually affect correctness. If the goal is to save space for
log compacted topics after partition change, there can be a couple other
approaches as Jun mentioned. And these can be done separately outside this
KIP. Even if we use the data copying approach to address problem for log
compacted topics, it may still worth using the linear hashing to address
problem for non-log compacted topics to avoid copying large amount of data.
What do you think? Can you also take a look at Jun's comments?

Thanks,
Dong


On Tue, Mar 6, 2018 at 10:33 PM, Jan Filipiak <Ja...@trivago.com>
wrote:

> Hi Dong,
>
> are you actually reading my emails, or are you just using the thread I
> started for general announcements regarding the KIP?
>
> I tried to argue really hard against linear hashing. Growing the topic by
> an integer factor does not require any state redistribution at all. I fail
> to see completely where linear hashing helps on log compacted topics.
>
> If you are not willing to explain to me what I might be overlooking: that
> is fine.
> But I ask you to not reply to my emails then. Please understand my
> frustration with this.
>
> Best Jan
>
>
>
> On 06.03.2018 19:38, Dong Lin wrote:
>
>> Hi everyone,
>>
>> Thanks for all the comments! It appears that everyone prefers linear
>> hashing because it reduces the amount of state that needs to be moved
>> between consumers (for stream processing). The KIP has been updated to use
>> linear hashing.
>>
>> Regarding the migration endeavor: it seems that migrating producer library
>> to use linear hashing should be pretty straightforward without
>> much operational endeavor. If we don't upgrade client library to use this
>> KIP, we can not support in-order delivery after partition is changed
>> anyway. Suppose we upgrade client library to use this KIP, if partition
>> number is not changed, the key -> partition mapping will be exactly the
>> same as it is now because it is still determined using murmur_hash(key) %
>> original_partition_num. In other words, this change is backward
>> compatible.
>>
>> Regarding the load distribution: if we use linear hashing, the load may be
>> unevenly distributed because those partitions which are not split may
>> receive twice as much traffic as other partitions that are split. This
>> issue can be mitigated by creating topic with partitions that are several
>> times the number of consumers. And there will be no imbalance if the
>> partition number is always doubled. So this imbalance seems acceptable.
>>
>> Regarding storing the partition strategy as per-topic config: It seems not
>> necessary since we can still use murmur_hash as the default hash function
>> and additionally apply the linear hashing algorithm if the partition
>> number
>> has increased. Not sure if there is any use-case for producer to use a
>> different hash function. Jason, can you check if there is some use-case
>> that I missed for using the per-topic partition strategy?
>>
>> Regarding how to reduce latency (due to state store/load) in stream
>> processing consumer when partition number changes: I need to read the
>> Kafka
>> Stream code to understand how Kafka Stream currently migrate state between
>> consumers when the application is added/removed for a given job. I will
>> reply after I finish reading the documentation and code.
>>
>>
>> Thanks,
>> Dong
>>
>>
>> On Mon, Mar 5, 2018 at 10:43 AM, Jason Gustafson <ja...@confluent.io>
>> wrote:
>>
>> Great discussion. I think I'm wondering whether we can continue to leave
>>> Kafka agnostic to the partitioning strategy. The challenge is
>>> communicating
>>> the partitioning logic from producers to consumers so that the
>>> dependencies
>>> between each epoch can be determined. For the sake of discussion, imagine
>>> you did something like the following:
>>>
>>> 1. The name (and perhaps version) of a partitioning strategy is stored in
>>> topic configuration when a topic is created.
>>> 2. The producer looks up the partitioning strategy before writing to a
>>> topic and includes it in the produce request (for fencing). If it doesn't
>>> have an implementation for the configured strategy, it fails.
>>> 3. The consumer also looks up the partitioning strategy and uses it to
>>> determine dependencies when reading a new epoch. It could either fail or
>>> make the most conservative dependency assumptions if it doesn't know how
>>> to
>>> implement the partitioning strategy. For the consumer, the new interface
>>> might look something like this:
>>>
>>> // Return the partition dependencies following an epoch bump
>>> Map<Integer, List<Integer>> dependencies(int
>>> numPartitionsBeforeEpochBump,
>>> int numPartitionsAfterEpochBump)
>>>
>>> The unordered case then is just a particular implementation which never
>>> has
>>> any epoch dependencies. To implement this, we would need some way for the
>>> consumer to find out how many partitions there were in each epoch, but
>>> maybe that's not too unreasonable.
>>>
>>> Thanks,
>>> Jason
>>>
>>>
>>> On Mon, Mar 5, 2018 at 4:51 AM, Jan Filipiak <Ja...@trivago.com>
>>> wrote:
>>>
>>> Hi Dong
>>>>
>>>> thank you very much for your questions.
>>>>
>>>> regarding the time spend copying data across:
>>>> It is correct that copying data from a topic with one partition mapping
>>>>
>>> to
>>>
>>>> a topic with a different partition mapping takes way longer than we can
>>>> stop producers. Tens of minutes is a very optimistic estimate here. Many
>>>> people can not afford copy full steam and therefore will have some rate
>>>> limiting in place, this can bump the timespan into the day's. The good
>>>>
>>> part
>>>
>>>> is that the vast majority of the data can be copied while the producers
>>>>
>>> are
>>>
>>>> still going. One can then, piggyback the consumers ontop of this
>>>>
>>> timeframe,
>>>
>>>> by the method mentioned (provide them an mapping from their old offsets
>>>>
>>> to
>>>
>>>> new offsets in their repartitioned topics. In that way we separate
>>>> migration of consumers from migration of producers (decoupling these is
>>>> what kafka is strongest at). The time to actually swap over the
>>>> producers
>>>> should be kept minimal by ensuring that when a swap attempt is started
>>>>
>>> the
>>>
>>>> consumer copying over should be very close to the log end and is
>>>> expected
>>>> to finish within the next fetch. The operation should have a time-out
>>>> and
>>>> should be "reattemtable".
>>>>
>>>> Importance of logcompaction:
>>>> If a producer produces key A, to partiton 0, its forever gonna be there,
>>>> unless it gets deleted. The record might sit in there for years. A new
>>>> producer started with the new partitions will fail to delete the record
>>>>
>>> in
>>>
>>>> the correct partition. Th record will be there forever and one can not
>>>> reliable bootstrap new consumers. I cannot see how linear hashing can
>>>>
>>> solve
>>>
>>>> this.
>>>>
>>>> Regarding your skipping of userland copying:
>>>> 100%, copying the data across in userland is, as far as i can see, only
>>>> a
>>>> usecase for log compacted topics. Even for logcompaction + retentions it
>>>> should only be opt-in. Why did I bring it up? I think log compaction is
>>>> a
>>>> very important feature to really embrace kafka as a "data plattform".
>>>> The
>>>> point I also want to make is that copying data this way is completely
>>>> inline with the kafka architecture. it only consists of reading and
>>>>
>>> writing
>>>
>>>> to topics.
>>>>
>>>> I hope it clarifies more why I think we should aim for more than the
>>>> current KIP. I fear that once the KIP is done not much more effort will
>>>>
>>> be
>>>
>>>> taken.
>>>>
>>>>
>>>>
>>>>
>>>> On 04.03.2018 02:28, Dong Lin wrote:
>>>>
>>>> Hey Jan,
>>>>>
>>>>> In the current proposal, the consumer will be blocked on waiting for
>>>>>
>>>> other
>>>
>>>> consumers of the group to consume up to a given offset. In most cases,
>>>>>
>>>> all
>>>
>>>> consumers should be close to the LEO of the partitions when the
>>>>>
>>>> partition
>>>
>>>> expansion happens. Thus the time waiting should not be long e.g. on the
>>>>> order of seconds. On the other hand, it may take a long time to wait
>>>>> for
>>>>> the entire partition to be copied -- the amount of time is proportional
>>>>>
>>>> to
>>>
>>>> the amount of existing data in the partition, which can take tens of
>>>>> minutes. So the amount of time that we stop consumers may not be on the
>>>>> same order of magnitude.
>>>>>
>>>>> If we can implement this suggestion without copying data over in purse
>>>>> userland, it will be much more valuable. Do you have ideas on how this
>>>>>
>>>> can
>>>
>>>> be done?
>>>>>
>>>>> Not sure why the current KIP not help people who depend on log
>>>>>
>>>> compaction.
>>>
>>>> Could you elaborate more on this point?
>>>>>
>>>>> Thanks,
>>>>> Dong
>>>>>
>>>>> On Wed, Feb 28, 2018 at 10:55 PM, Jan Filipiak<Jan.Filipiak@trivago.
>>>>> com
>>>>> wrote:
>>>>>
>>>>> Hi Dong,
>>>>>
>>>>>> I tried to focus on what the steps are one can currently perform to
>>>>>> expand
>>>>>> or shrink a keyed topic while maintaining a top notch semantics.
>>>>>> I can understand that there might be confusion about "stopping the
>>>>>> consumer". It is exactly the same as proposed in the KIP. there needs
>>>>>>
>>>>> to
>>>
>>>> be
>>>>>> a time the producers agree on the new partitioning. The extra
>>>>>>
>>>>> semantics I
>>>
>>>> want to put in there is that we have a possibility to wait until all
>>>>>>
>>>>> the
>>>
>>>> existing data
>>>>>> is copied over into the new partitioning scheme. When I say stopping I
>>>>>> think more of having a memory barrier that ensures the ordering. I am
>>>>>> still
>>>>>> aming for latencies  on the scale of leader failovers.
>>>>>>
>>>>>> Consumers have to explicitly adapt the new partitioning scheme in the
>>>>>> above scenario. The reason is that in these cases where you are
>>>>>>
>>>>> dependent
>>>
>>>> on a particular partitioning scheme, you also have other topics that
>>>>>>
>>>>> have
>>>
>>>> co-partition enforcements or the kind -frequently. Therefore all your
>>>>>> other
>>>>>> input topics might need to grow accordingly.
>>>>>>
>>>>>>
>>>>>> What I was suggesting was to streamline all these operations as best
>>>>>> as
>>>>>> possible to have "real" partition grow and shrinkage going on.
>>>>>>
>>>>> Migrating
>>>
>>>> the producers to a new partitioning scheme can be much more streamlined
>>>>>> with proper broker support for this. Migrating consumer is a step that
>>>>>> might be made completly unnecessary if - for example streams - takes
>>>>>>
>>>>> the
>>>
>>>> gcd as partitioning scheme instead of enforcing 1 to 1. Connect
>>>>>>
>>>>> consumers
>>>
>>>> and other consumers should be fine anyways.
>>>>>>
>>>>>> I hope this makes more clear where I was aiming at. The rest needs to
>>>>>>
>>>>> be
>>>
>>>> figured out. The only danger i see is that when we are introducing this
>>>>>> feature as supposed in the KIP, it wont help any people depending on
>>>>>>
>>>>> log
>>>
>>>> compaction.
>>>>>>
>>>>>> The other thing I wanted to mention is that I believe the current
>>>>>> suggestion (without copying data over) can be implemented in pure
>>>>>> userland
>>>>>> with a custom partitioner and a small feedbackloop from
>>>>>> ProduceResponse
>>>>>> =>
>>>>>> Partitionier in coorporation with a change management system.
>>>>>>
>>>>>> Best Jan
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> On 28.02.2018 07:13, Dong Lin wrote:
>>>>>>
>>>>>> Hey Jan,
>>>>>>
>>>>>>> I am not sure if it is acceptable for producer to be stopped for a
>>>>>>> while,
>>>>>>> particularly for online application which requires low latency. I am
>>>>>>> also
>>>>>>> not sure how consumers can switch to a new topic. Does user
>>>>>>>
>>>>>> application
>>>
>>>> needs to explicitly specify a different topic for producer/consumer to
>>>>>>> subscribe to? It will be helpful for discussion if you can provide
>>>>>>>
>>>>>> more
>>>
>>>> detail on the interface change for this solution.
>>>>>>>
>>>>>>> Thanks,
>>>>>>> Dong
>>>>>>>
>>>>>>> On Mon, Feb 26, 2018 at 12:48 AM, Jan Filipiak<Jan.Filipiak@trivago.
>>>>>>>
>>>>>> com
>>>
>>>> wrote:
>>>>>>>
>>>>>>> Hi,
>>>>>>>
>>>>>>> just want to throw my though in. In general the functionality is very
>>>>>>>> usefull, we should though not try to find the architecture to hard
>>>>>>>> while
>>>>>>>> implementing.
>>>>>>>>
>>>>>>>> The manual steps would be to
>>>>>>>>
>>>>>>>> create a new topic
>>>>>>>> the mirrormake from the new old topic to the new topic
>>>>>>>> wait for mirror making to catch up.
>>>>>>>> then put the consumers onto the new topic
>>>>>>>>        (having mirrormaker spit out a mapping from old offsets to
>>>>>>>> new
>>>>>>>> offsets:
>>>>>>>>            if topic is increased by factor X there is gonna be a
>>>>>>>> clean
>>>>>>>> mapping from 1 offset in the old topic to X offsets in the new
>>>>>>>> topic,
>>>>>>>>            if there is no factor then there is no chance to
>>>>>>>> generate a
>>>>>>>> mapping that can be reasonable used for continuing)
>>>>>>>>        make consumers stop at appropriate points and continue
>>>>>>>> consumption
>>>>>>>> with offsets from the mapping.
>>>>>>>> have the producers stop for a minimal time.
>>>>>>>> wait for mirrormaker to finish
>>>>>>>> let producer produce with the new metadata.
>>>>>>>>
>>>>>>>>
>>>>>>>> Instead of implementing the approach suggest in the KIP which will
>>>>>>>> leave
>>>>>>>> log compacted topic completely crumbled and unusable.
>>>>>>>> I would much rather try to build infrastructure to support the
>>>>>>>> mentioned
>>>>>>>> above operations more smoothly.
>>>>>>>> Especially having producers stop and use another topic is difficult
>>>>>>>>
>>>>>>> and
>>>
>>>> it would be nice if one can trigger "invalid metadata" exceptions for
>>>>>>>> them
>>>>>>>> and
>>>>>>>> if one could give topics aliases so that their produces with the old
>>>>>>>> topic
>>>>>>>> will arrive in the new topic.
>>>>>>>>
>>>>>>>> The downsides are obvious I guess ( having the same data twice for
>>>>>>>>
>>>>>>> the
>>>
>>>> transition period, but kafka tends to scale well with datasize). So
>>>>>>>> its a
>>>>>>>> nicer fit into the architecture.
>>>>>>>>
>>>>>>>> I further want to argument that the functionality by the KIP can
>>>>>>>> completely be implementing in "userland" with a custom partitioner
>>>>>>>>
>>>>>>> that
>>>
>>>> handles the transition as needed. I would appreciate if someone could
>>>>>>>> point
>>>>>>>> out what a custom partitioner couldn't handle in this case?
>>>>>>>>
>>>>>>>> With the above approach, shrinking a topic becomes the same steps.
>>>>>>>> Without
>>>>>>>> loosing keys in the discontinued partitions.
>>>>>>>>
>>>>>>>> Would love to hear what everyone thinks.
>>>>>>>>
>>>>>>>> Best Jan
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> On 11.02.2018 00:35, Dong Lin wrote:
>>>>>>>>
>>>>>>>> Hi all,
>>>>>>>>
>>>>>>>> I have created KIP-253: Support in-order message delivery with
>>>>>>>>> partition
>>>>>>>>> expansion. See
>>>>>>>>> https://cwiki.apache.org/confluence/display/KAFKA/KIP-253%
>>>>>>>>> 3A+Support+in-order+message+delivery+with+partition+expansion
>>>>>>>>> .
>>>>>>>>>
>>>>>>>>> This KIP provides a way to allow messages of the same key from the
>>>>>>>>> same
>>>>>>>>> producer to be consumed in the same order they are produced even if
>>>>>>>>>
>>>>>>>> we
>>>
>>>> expand partition of the topic.
>>>>>>>>>
>>>>>>>>> Thanks,
>>>>>>>>> Dong
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>

Re: [DISCUSS] KIP-253: Support in-order message delivery with partition expansion

Posted by Jan Filipiak <Ja...@trivago.com>.
Hi Dong,

are you actually reading my emails, or are you just using the thread I 
started for general announcements regarding the KIP?

I tried to argue really hard against linear hashing. Growing the topic 
by an integer factor does not require any state redistribution at all. I 
fail to see completely where linear hashing helps on log compacted topics.

If you are not willing to explain to me what I might be overlooking: 
that is fine.
But I ask you to not reply to my emails then. Please understand my 
frustration with this.

Best Jan


On 06.03.2018 19:38, Dong Lin wrote:
> Hi everyone,
>
> Thanks for all the comments! It appears that everyone prefers linear
> hashing because it reduces the amount of state that needs to be moved
> between consumers (for stream processing). The KIP has been updated to use
> linear hashing.
>
> Regarding the migration endeavor: it seems that migrating producer library
> to use linear hashing should be pretty straightforward without
> much operational endeavor. If we don't upgrade client library to use this
> KIP, we can not support in-order delivery after partition is changed
> anyway. Suppose we upgrade client library to use this KIP, if partition
> number is not changed, the key -> partition mapping will be exactly the
> same as it is now because it is still determined using murmur_hash(key) %
> original_partition_num. In other words, this change is backward compatible.
>
> Regarding the load distribution: if we use linear hashing, the load may be
> unevenly distributed because those partitions which are not split may
> receive twice as much traffic as other partitions that are split. This
> issue can be mitigated by creating topic with partitions that are several
> times the number of consumers. And there will be no imbalance if the
> partition number is always doubled. So this imbalance seems acceptable.
>
> Regarding storing the partition strategy as per-topic config: It seems not
> necessary since we can still use murmur_hash as the default hash function
> and additionally apply the linear hashing algorithm if the partition number
> has increased. Not sure if there is any use-case for producer to use a
> different hash function. Jason, can you check if there is some use-case
> that I missed for using the per-topic partition strategy?
>
> Regarding how to reduce latency (due to state store/load) in stream
> processing consumer when partition number changes: I need to read the Kafka
> Stream code to understand how Kafka Stream currently migrate state between
> consumers when the application is added/removed for a given job. I will
> reply after I finish reading the documentation and code.
>
>
> Thanks,
> Dong
>
>
> On Mon, Mar 5, 2018 at 10:43 AM, Jason Gustafson <ja...@confluent.io> wrote:
>
>> Great discussion. I think I'm wondering whether we can continue to leave
>> Kafka agnostic to the partitioning strategy. The challenge is communicating
>> the partitioning logic from producers to consumers so that the dependencies
>> between each epoch can be determined. For the sake of discussion, imagine
>> you did something like the following:
>>
>> 1. The name (and perhaps version) of a partitioning strategy is stored in
>> topic configuration when a topic is created.
>> 2. The producer looks up the partitioning strategy before writing to a
>> topic and includes it in the produce request (for fencing). If it doesn't
>> have an implementation for the configured strategy, it fails.
>> 3. The consumer also looks up the partitioning strategy and uses it to
>> determine dependencies when reading a new epoch. It could either fail or
>> make the most conservative dependency assumptions if it doesn't know how to
>> implement the partitioning strategy. For the consumer, the new interface
>> might look something like this:
>>
>> // Return the partition dependencies following an epoch bump
>> Map<Integer, List<Integer>> dependencies(int numPartitionsBeforeEpochBump,
>> int numPartitionsAfterEpochBump)
>>
>> The unordered case then is just a particular implementation which never has
>> any epoch dependencies. To implement this, we would need some way for the
>> consumer to find out how many partitions there were in each epoch, but
>> maybe that's not too unreasonable.
>>
>> Thanks,
>> Jason
>>
>>
>> On Mon, Mar 5, 2018 at 4:51 AM, Jan Filipiak <Ja...@trivago.com>
>> wrote:
>>
>>> Hi Dong
>>>
>>> thank you very much for your questions.
>>>
>>> regarding the time spend copying data across:
>>> It is correct that copying data from a topic with one partition mapping
>> to
>>> a topic with a different partition mapping takes way longer than we can
>>> stop producers. Tens of minutes is a very optimistic estimate here. Many
>>> people can not afford copy full steam and therefore will have some rate
>>> limiting in place, this can bump the timespan into the day's. The good
>> part
>>> is that the vast majority of the data can be copied while the producers
>> are
>>> still going. One can then, piggyback the consumers ontop of this
>> timeframe,
>>> by the method mentioned (provide them an mapping from their old offsets
>> to
>>> new offsets in their repartitioned topics. In that way we separate
>>> migration of consumers from migration of producers (decoupling these is
>>> what kafka is strongest at). The time to actually swap over the producers
>>> should be kept minimal by ensuring that when a swap attempt is started
>> the
>>> consumer copying over should be very close to the log end and is expected
>>> to finish within the next fetch. The operation should have a time-out and
>>> should be "reattemtable".
>>>
>>> Importance of logcompaction:
>>> If a producer produces key A, to partiton 0, its forever gonna be there,
>>> unless it gets deleted. The record might sit in there for years. A new
>>> producer started with the new partitions will fail to delete the record
>> in
>>> the correct partition. Th record will be there forever and one can not
>>> reliable bootstrap new consumers. I cannot see how linear hashing can
>> solve
>>> this.
>>>
>>> Regarding your skipping of userland copying:
>>> 100%, copying the data across in userland is, as far as i can see, only a
>>> usecase for log compacted topics. Even for logcompaction + retentions it
>>> should only be opt-in. Why did I bring it up? I think log compaction is a
>>> very important feature to really embrace kafka as a "data plattform". The
>>> point I also want to make is that copying data this way is completely
>>> inline with the kafka architecture. it only consists of reading and
>> writing
>>> to topics.
>>>
>>> I hope it clarifies more why I think we should aim for more than the
>>> current KIP. I fear that once the KIP is done not much more effort will
>> be
>>> taken.
>>>
>>>
>>>
>>>
>>> On 04.03.2018 02:28, Dong Lin wrote:
>>>
>>>> Hey Jan,
>>>>
>>>> In the current proposal, the consumer will be blocked on waiting for
>> other
>>>> consumers of the group to consume up to a given offset. In most cases,
>> all
>>>> consumers should be close to the LEO of the partitions when the
>> partition
>>>> expansion happens. Thus the time waiting should not be long e.g. on the
>>>> order of seconds. On the other hand, it may take a long time to wait for
>>>> the entire partition to be copied -- the amount of time is proportional
>> to
>>>> the amount of existing data in the partition, which can take tens of
>>>> minutes. So the amount of time that we stop consumers may not be on the
>>>> same order of magnitude.
>>>>
>>>> If we can implement this suggestion without copying data over in purse
>>>> userland, it will be much more valuable. Do you have ideas on how this
>> can
>>>> be done?
>>>>
>>>> Not sure why the current KIP not help people who depend on log
>> compaction.
>>>> Could you elaborate more on this point?
>>>>
>>>> Thanks,
>>>> Dong
>>>>
>>>> On Wed, Feb 28, 2018 at 10:55 PM, Jan Filipiak<Jan.Filipiak@trivago.com
>>>> wrote:
>>>>
>>>> Hi Dong,
>>>>> I tried to focus on what the steps are one can currently perform to
>>>>> expand
>>>>> or shrink a keyed topic while maintaining a top notch semantics.
>>>>> I can understand that there might be confusion about "stopping the
>>>>> consumer". It is exactly the same as proposed in the KIP. there needs
>> to
>>>>> be
>>>>> a time the producers agree on the new partitioning. The extra
>> semantics I
>>>>> want to put in there is that we have a possibility to wait until all
>> the
>>>>> existing data
>>>>> is copied over into the new partitioning scheme. When I say stopping I
>>>>> think more of having a memory barrier that ensures the ordering. I am
>>>>> still
>>>>> aming for latencies  on the scale of leader failovers.
>>>>>
>>>>> Consumers have to explicitly adapt the new partitioning scheme in the
>>>>> above scenario. The reason is that in these cases where you are
>> dependent
>>>>> on a particular partitioning scheme, you also have other topics that
>> have
>>>>> co-partition enforcements or the kind -frequently. Therefore all your
>>>>> other
>>>>> input topics might need to grow accordingly.
>>>>>
>>>>>
>>>>> What I was suggesting was to streamline all these operations as best as
>>>>> possible to have "real" partition grow and shrinkage going on.
>> Migrating
>>>>> the producers to a new partitioning scheme can be much more streamlined
>>>>> with proper broker support for this. Migrating consumer is a step that
>>>>> might be made completly unnecessary if - for example streams - takes
>> the
>>>>> gcd as partitioning scheme instead of enforcing 1 to 1. Connect
>> consumers
>>>>> and other consumers should be fine anyways.
>>>>>
>>>>> I hope this makes more clear where I was aiming at. The rest needs to
>> be
>>>>> figured out. The only danger i see is that when we are introducing this
>>>>> feature as supposed in the KIP, it wont help any people depending on
>> log
>>>>> compaction.
>>>>>
>>>>> The other thing I wanted to mention is that I believe the current
>>>>> suggestion (without copying data over) can be implemented in pure
>>>>> userland
>>>>> with a custom partitioner and a small feedbackloop from ProduceResponse
>>>>> =>
>>>>> Partitionier in coorporation with a change management system.
>>>>>
>>>>> Best Jan
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> On 28.02.2018 07:13, Dong Lin wrote:
>>>>>
>>>>> Hey Jan,
>>>>>> I am not sure if it is acceptable for producer to be stopped for a
>>>>>> while,
>>>>>> particularly for online application which requires low latency. I am
>>>>>> also
>>>>>> not sure how consumers can switch to a new topic. Does user
>> application
>>>>>> needs to explicitly specify a different topic for producer/consumer to
>>>>>> subscribe to? It will be helpful for discussion if you can provide
>> more
>>>>>> detail on the interface change for this solution.
>>>>>>
>>>>>> Thanks,
>>>>>> Dong
>>>>>>
>>>>>> On Mon, Feb 26, 2018 at 12:48 AM, Jan Filipiak<Jan.Filipiak@trivago.
>> com
>>>>>> wrote:
>>>>>>
>>>>>> Hi,
>>>>>>
>>>>>>> just want to throw my though in. In general the functionality is very
>>>>>>> usefull, we should though not try to find the architecture to hard
>>>>>>> while
>>>>>>> implementing.
>>>>>>>
>>>>>>> The manual steps would be to
>>>>>>>
>>>>>>> create a new topic
>>>>>>> the mirrormake from the new old topic to the new topic
>>>>>>> wait for mirror making to catch up.
>>>>>>> then put the consumers onto the new topic
>>>>>>>        (having mirrormaker spit out a mapping from old offsets to new
>>>>>>> offsets:
>>>>>>>            if topic is increased by factor X there is gonna be a clean
>>>>>>> mapping from 1 offset in the old topic to X offsets in the new topic,
>>>>>>>            if there is no factor then there is no chance to generate a
>>>>>>> mapping that can be reasonable used for continuing)
>>>>>>>        make consumers stop at appropriate points and continue
>>>>>>> consumption
>>>>>>> with offsets from the mapping.
>>>>>>> have the producers stop for a minimal time.
>>>>>>> wait for mirrormaker to finish
>>>>>>> let producer produce with the new metadata.
>>>>>>>
>>>>>>>
>>>>>>> Instead of implementing the approach suggest in the KIP which will
>>>>>>> leave
>>>>>>> log compacted topic completely crumbled and unusable.
>>>>>>> I would much rather try to build infrastructure to support the
>>>>>>> mentioned
>>>>>>> above operations more smoothly.
>>>>>>> Especially having producers stop and use another topic is difficult
>> and
>>>>>>> it would be nice if one can trigger "invalid metadata" exceptions for
>>>>>>> them
>>>>>>> and
>>>>>>> if one could give topics aliases so that their produces with the old
>>>>>>> topic
>>>>>>> will arrive in the new topic.
>>>>>>>
>>>>>>> The downsides are obvious I guess ( having the same data twice for
>> the
>>>>>>> transition period, but kafka tends to scale well with datasize). So
>>>>>>> its a
>>>>>>> nicer fit into the architecture.
>>>>>>>
>>>>>>> I further want to argument that the functionality by the KIP can
>>>>>>> completely be implementing in "userland" with a custom partitioner
>> that
>>>>>>> handles the transition as needed. I would appreciate if someone could
>>>>>>> point
>>>>>>> out what a custom partitioner couldn't handle in this case?
>>>>>>>
>>>>>>> With the above approach, shrinking a topic becomes the same steps.
>>>>>>> Without
>>>>>>> loosing keys in the discontinued partitions.
>>>>>>>
>>>>>>> Would love to hear what everyone thinks.
>>>>>>>
>>>>>>> Best Jan
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> On 11.02.2018 00:35, Dong Lin wrote:
>>>>>>>
>>>>>>> Hi all,
>>>>>>>
>>>>>>>> I have created KIP-253: Support in-order message delivery with
>>>>>>>> partition
>>>>>>>> expansion. See
>>>>>>>> https://cwiki.apache.org/confluence/display/KAFKA/KIP-253%
>>>>>>>> 3A+Support+in-order+message+delivery+with+partition+expansion
>>>>>>>> .
>>>>>>>>
>>>>>>>> This KIP provides a way to allow messages of the same key from the
>>>>>>>> same
>>>>>>>> producer to be consumed in the same order they are produced even if
>> we
>>>>>>>> expand partition of the topic.
>>>>>>>>
>>>>>>>> Thanks,
>>>>>>>> Dong
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>


Re: [DISCUSS] KIP-253: Support in-order message delivery with partition expansion

Posted by Jan Filipiak <Ja...@trivago.com>.
Hey,

just want to throw in my question from the longer email in the other 
Thread here.
How will the bloom filter help a new consumer to decide to apply the key 
or not?

Why can we afford having a topic where its apparently not possible to 
start a new application on?
I think this is an overall flaw of the discussed idea here. Not playing 
attention to the overall architecture.

Best Jan


On 12.03.2018 00:09, Dong Lin wrote:
> Hey Jason,
>
> This is a good solution on the server side for log compacted topic.
> Thinking about this more, there maybe another probably simpler solution on
> the client side for log compacted topics. This solution is now specified in
> the section "Changes in how producer produced keyed messages to log
> compacted topics" of the KIP. The client-side solution seems simpler with
> less performance overhead than the server-side solution. What do you think?
>
> Thanks,
> Dong
>
>
> On Sat, Mar 10, 2018 at 10:55 AM, Jason Gustafson <ja...@confluent.io>
> wrote:
>
>> Hey Dong,
>>
>> I was thinking a bit about log compaction after a partition split. I think
>> the best you could hope for in terms of efficiency is that the network
>> overhead would be proportional to the number of remapped keys that need
>> cleaning. One thought I had which gets close to this is to propagate a
>> bloom filter covering the keys in the log prior to the split to all
>> partitions that might contain some of the remapped keys. As a simple
>> example, suppose we have a single partition which is split into two at
>> offset N. Say that broker 0 owns partition 0 and broker 1 owns partition 1.
>> Some subset of the keys prior to N will move to partition 1 and the rest
>> will remain on partition 0. The idea is something like this:
>>
>> 1. Every time we clean partition 0 on broker 0, we compute a bloom filter
>> for the keys in the log prior to offset N.
>> 2. The bloom filter is propagated to broker 1 and cached.
>> 3. The next time broker 1 cleans the log, it uses the bloom filter to
>> collect a set of possible matches.
>> 4. When the cleaning completes, the matching keys are propagated to broker
>> 0, where they are cached until the next cleaning.
>> 5. The next time broker 0 cleans the log, it can remove all keys that have
>> been cached from the region prior to the split.
>>
>> This incremental approach allows us to tradeoff cleaning latency to reduce
>> network traffic and memory overhead. A few points:
>>
>> - The accuracy of bloom filters decreases as you add more elements to them.
>> We would probably choose to propagate the bloom filter for a subset of the
>> keys once it had reached a certain capacity to avoid having too many false
>> positives.
>> - We can limit the number of bloom filter matches that we will collect and
>> return in a single round of cleaning. These keys have to be cached in the
>> broker for a little while (until the next cleaning), so this lets us keep
>> the memory usage bounded.
>>
>> There is probably some room for cleverness as well to avoid repeating work.
>> For example, the broker matching the bloom filter can also send the offset
>> of the last key that was matched against the filter. The next time we send
>> a bloom filter for a certain range of keys, we can send the starting offset
>> for matching. It's kind of like our "dirty offset" notion.
>>
>> Needs a bit of investigation to work out the details (e.g. handling
>> multiple splits), but seems like it could work. What do you think?
>>
>> -Jason
>>
>>
>>
>> On Fri, Mar 9, 2018 at 1:23 PM, Matthias J. Sax <ma...@confluent.io>
>> wrote:
>>
>>> Thanks for your comment Clemens. It make sense what you are saying.
>>> However, your described pattern is to split partitions and use linear
>>> hashing to avoid random key distribution. But this is what Jan thinks we
>>> should not do...
>>>
>>> Also, I just picked an example with 2 -> 3 partitions, but if you don't
>>> use linear hashing I think the same issue occurs if you double the
>>> number of partitions.
>>>
>>> I am in favor of using linear hashing. Still think, it is also useful to
>>> split single partitions, too, in case load is not balanced and some
>>> partitions are hot spots while others are "idle".
>>>
>>> -Matthias
>>>
>>>
>>> On 3/9/18 5:41 AM, Clemens Valiente wrote:
>>>> I think it's fair to assume that topics will always be increased by an
>>> integer factor - e.g. from 2 partitions to 4 partitions. Then the mapping
>>> is much easier.
>>>> Why anyone would increase partitions by lass than x2 is a mystery to
>> me.
>>> If your two partitions cannot handle the load, then with three partitions
>>> each one will still get 67% of that load which is still way too
>> dangerous.
>>>>
>>>> So in your case we go from
>>>>
>>>> part1: A B C D
>>>>
>>>> part2: E F G H
>>>>
>>>>
>>>> to
>>>>
>>>>
>>>> part1: A C
>>>>
>>>> part2: B D
>>>>
>>>> part3: E F
>>>>
>>>> part4: G H
>>>>
>>>>
>>>> ________________________________
>>>> From: Matthias J. Sax <ma...@confluent.io>
>>>> Sent: 09 March 2018 07:53
>>>> To: dev@kafka.apache.org
>>>> Subject: Re: [DISCUSS] KIP-253: Support in-order message delivery with
>>> partition expansion
>>>> @Jan: You suggest to copy the data from one topic to a new topic, and
>>>> provide an "offset mapping" from the old to the new topic for the
>>>> consumers. I don't quite understand how this would work.
>>>>
>>>> Let's say there are 2 partitions in the original topic and 3 partitions
>>>> in the new topic. If we assume that we don't use linear hashing as you
>>>> suggest, there is no guarantee how data will be distributed in the new
>>>> topic and also no guarantee about ordering of records in the new topic.
>>>>
>>>> Example (I hope I got it right -- please correct me if it's wrong)
>>>>
>>>> A B C D
>>>> E F G H
>>>>
>>>> could be copied to:
>>>>
>>>> A C H
>>>> B E F
>>>> D G
>>>>
>>>> If the consumer was at offset 1 and 2 in the first topic how would the
>>>> mapping be computed? We need to enures that B C D as well as G H are
>>>> read after the switch. Thus, offset would need to be 1 0 0. I am not
>>>> sure how this would be computed?
>>>>
>>>> Furthermore, I want to point out that the new offsets would imply that
>> E
>>>> is consumed a second time by the consumer. E and F were consumed
>>>> originally, but E is copied after B that was not yet consumed.
>>>>
>>>> Or is there a way that we can ensure that this "flip" does never happen
>>>> while we copy the data?
>>>>
>>>>
>>>> -Matthias
>>>>
>>>>
>>>>
>>>> On 3/8/18 10:32 PM, Matthias J. Sax wrote:
>>>>> As I just mentioned joins:
>>>>>
>>>>> For Kafka Streams it might also be required to change the partition
>>>>> count for multiple topics in a coordinated way that allows to maintain
>>>>> the co-partitioning property that Kafka Streams uses to computed
>> joins.
>>>>> Any thoughts how this could be handled?
>>>>>
>>>>>
>>>>> -Matthias
>>>>>
>>>>> On 3/8/18 10:08 PM, Matthias J. Sax wrote:
>>>>>> Jun,
>>>>>>
>>>>>> There is one more case: non-windowed aggregations. For windowed
>>>>>> aggregation, the changelog topic will be compact+delete. However, for
>>>>>> non-windowed aggregation the policy is compact only.
>>>>>>
>>>>>> Even if we assume that windowed aggregations are dominant and
>>>>>> non-windowed aggregation are used rarely, it seems to be bad to not
>>>>>> support the feature is a non-windowed aggregation is used. Also,
>>>>>> non-windowed aggregation volume depends on input-stream volume that
>>>>>> might be high.
>>>>>>
>>>>>> Furthermore, we support stream-table join and this requires that the
>>>>>> stream and the table are co-partitioned. Thus, even if the table
>> would
>>>>>> have lower volume but the stream must be scaled out, we also need to
>>>>>> scale out the table to preserve co-partitioning.
>>>>>>
>>>>>>
>>>>>> -Matthias
>>>>>>
>>>>>> On 3/8/18 6:44 PM, Jun Rao wrote:
>>>>>>> Hi, Matthis,
>>>>>>>
>>>>>>> My understanding is that in KStream, the only case when a changelog
>>> topic
>>>>>>> needs to be compacted is when the corresponding input is a KTable.
>> In
>>> all
>>>>>>> other cases, the changelog topics are of compacted + deletion. So,
>> if
>>> most
>>>>>>> KTables are not high volume, there may not be a need to expand its
>>>>>>> partitions and therefore the partitions of the corresponding
>> changelog
>>>>>>> topic.
>>>>>>>
>>>>>>> Thanks,
>>>>>>>
>>>>>>> Jun
>>>>>>>
>>>>>>> On Wed, Mar 7, 2018 at 2:34 PM, Matthias J. Sax <
>>> matthias@confluent.io>
>>>>>>> wrote:
>>>>>>>
>>>>>>>> Jun,
>>>>>>>>
>>>>>>>> thanks for your comment. This should actually work for Streams,
>>> because
>>>>>>>> we don't rely on producer "hashing" but specify the partition
>> number
>>>>>>>> explicitly on send().
>>>>>>>>
>>>>>>>> About not allowing to change the number of partition for changelog
>>>>>>>> topics: for Streams, this seems to imply that we need to create a
>>> second
>>>>>>>> changelog topic for each store with the new partition count.
>>> However, it
>>>>>>>> would be unclear when/if we can delete the old topic. Thus, it
>> moves
>>> the
>>>>>>>> "problem" into the application layer. It's hard to judge for me atm
>>> what
>>>>>>>> the impact would be, but it's something we should pay attention to.
>>>>>>>>
>>>>>>>>
>>>>>>>> -Matthias
>>>>>>>>
>>>>>>>> On 3/6/18 3:45 PM, Jun Rao wrote:
>>>>>>>>> Hi, Mattias,
>>>>>>>>>
>>>>>>>>> Regarding your comment "If it would be time-delay based, it might
>> be
>>>>>>>>> problematic
>>>>>>>>> for Kafka Streams: if we get the information that the new input
>>>>>>>> partitions
>>>>>>>>> are available for producing, we need to enable the new changelog
>>>>>>>> partitions
>>>>>>>>> for producing, too. If those would not be available yet, because
>> the
>>>>>>>>> time-delay did not trigger yet, it would be problematic to avoid
>>>>>>>>> crashing.", could you just enable the changelog topic to write to
>>> its new
>>>>>>>>> partitions immediately?  The input topic can be configured with a
>>> delay
>>>>>>>> in
>>>>>>>>> writing to the new partitions. Initially, there won't be new data
>>>>>>>> produced
>>>>>>>>> into the newly added partitions in the input topic. However, we
>>> could
>>>>>>>>> prebuild the state for the new input partition and write the state
>>>>>>>> changes
>>>>>>>>> to the corresponding new partitions in the changelog topic.
>>>>>>>>>
>>>>>>>>> Hi, Jan,
>>>>>>>>>
>>>>>>>>> For a compacted topic, garbage collecting the old keys in the
>>> existing
>>>>>>>>> partitions after partition expansion can be tricky as your pointed
>>> out. A
>>>>>>>>> few options here. (a) Let brokers exchange keys across brokers
>>> during
>>>>>>>>> compaction. This will add complexity on the broker side. (b) Build
>>> an
>>>>>>>>> external tool that scans the compacted topic and drop the prefix
>> of
>>> a
>>>>>>>>> partition if all records in the prefix are removable. The admin
>> can
>>> then
>>>>>>>>> run this tool when the unneeded space needs to be reclaimed. (c)
>>> Don't
>>>>>>>>> support partition change in a compacted topic. This might be ok
>>> since
>>>>>>>> most
>>>>>>>>> compacted topics are not high volume.
>>>>>>>>>
>>>>>>>>> Thanks,
>>>>>>>>>
>>>>>>>>> Jun
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> On Tue, Mar 6, 2018 at 10:38 AM, Dong Lin <li...@gmail.com>
>>> wrote:
>>>>>>>>>> Hi everyone,
>>>>>>>>>>
>>>>>>>>>> Thanks for all the comments! It appears that everyone prefers
>>> linear
>>>>>>>>>> hashing because it reduces the amount of state that needs to be
>>> moved
>>>>>>>>>> between consumers (for stream processing). The KIP has been
>>> updated to
>>>>>>>> use
>>>>>>>>>> linear hashing.
>>>>>>>>>>
>>>>>>>>>> Regarding the migration endeavor: it seems that migrating
>> producer
>>>>>>>> library
>>>>>>>>>> to use linear hashing should be pretty straightforward without
>>>>>>>>>> much operational endeavor. If we don't upgrade client library to
>>> use
>>>>>>>> this
>>>>>>>>>> KIP, we can not support in-order delivery after partition is
>>> changed
>>>>>>>>>> anyway. Suppose we upgrade client library to use this KIP, if
>>> partition
>>>>>>>>>> number is not changed, the key -> partition mapping will be
>>> exactly the
>>>>>>>>>> same as it is now because it is still determined using
>>> murmur_hash(key)
>>>>>>>> %
>>>>>>>>>> original_partition_num. In other words, this change is backward
>>>>>>>> compatible.
>>>>>>>>>> Regarding the load distribution: if we use linear hashing, the
>>> load may
>>>>>>>> be
>>>>>>>>>> unevenly distributed because those partitions which are not split
>>> may
>>>>>>>>>> receive twice as much traffic as other partitions that are split.
>>> This
>>>>>>>>>> issue can be mitigated by creating topic with partitions that are
>>>>>>>> several
>>>>>>>>>> times the number of consumers. And there will be no imbalance if
>>> the
>>>>>>>>>> partition number is always doubled. So this imbalance seems
>>> acceptable.
>>>>>>>>>> Regarding storing the partition strategy as per-topic config: It
>>> seems
>>>>>>>> not
>>>>>>>>>> necessary since we can still use murmur_hash as the default hash
>>>>>>>> function
>>>>>>>>>> and additionally apply the linear hashing algorithm if the
>>> partition
>>>>>>>> number
>>>>>>>>>> has increased. Not sure if there is any use-case for producer to
>>> use a
>>>>>>>>>> different hash function. Jason, can you check if there is some
>>> use-case
>>>>>>>>>> that I missed for using the per-topic partition strategy?
>>>>>>>>>>
>>>>>>>>>> Regarding how to reduce latency (due to state store/load) in
>> stream
>>>>>>>>>> processing consumer when partition number changes: I need to read
>>> the
>>>>>>>> Kafka
>>>>>>>>>> Stream code to understand how Kafka Stream currently migrate
>> state
>>>>>>>> between
>>>>>>>>>> consumers when the application is added/removed for a given job.
>> I
>>> will
>>>>>>>>>> reply after I finish reading the documentation and code.
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> Thanks,
>>>>>>>>>> Dong
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> On Mon, Mar 5, 2018 at 10:43 AM, Jason Gustafson <
>>> jason@confluent.io>
>>>>>>>>>> wrote:
>>>>>>>>>>
>>>>>>>>>>> Great discussion. I think I'm wondering whether we can continue
>> to
>>>>>>>> leave
>>>>>>>>>>> Kafka agnostic to the partitioning strategy. The challenge is
>>>>>>>>>> communicating
>>>>>>>>>>> the partitioning logic from producers to consumers so that the
>>>>>>>>>> dependencies
>>>>>>>>>>> between each epoch can be determined. For the sake of
>> discussion,
>>>>>>>> imagine
>>>>>>>>>>> you did something like the following:
>>>>>>>>>>>
>>>>>>>>>>> 1. The name (and perhaps version) of a partitioning strategy is
>>> stored
>>>>>>>> in
>>>>>>>>>>> topic configuration when a topic is created.
>>>>>>>>>>> 2. The producer looks up the partitioning strategy before
>> writing
>>> to a
>>>>>>>>>>> topic and includes it in the produce request (for fencing). If
>> it
>>>>>>>> doesn't
>>>>>>>>>>> have an implementation for the configured strategy, it fails.
>>>>>>>>>>> 3. The consumer also looks up the partitioning strategy and uses
>>> it to
>>>>>>>>>>> determine dependencies when reading a new epoch. It could either
>>> fail
>>>>>>>> or
>>>>>>>>>>> make the most conservative dependency assumptions if it doesn't
>>> know
>>>>>>>> how
>>>>>>>>>> to
>>>>>>>>>>> implement the partitioning strategy. For the consumer, the new
>>>>>>>> interface
>>>>>>>>>>> might look something like this:
>>>>>>>>>>>
>>>>>>>>>>> // Return the partition dependencies following an epoch bump
>>>>>>>>>>> Map<Integer, List<Integer>> dependencies(int
>>>>>>>>>> numPartitionsBeforeEpochBump,
>>>>>>>>>>> int numPartitionsAfterEpochBump)
>>>>>>>>>>>
>>>>>>>>>>> The unordered case then is just a particular implementation
>> which
>>> never
>>>>>>>>>> has
>>>>>>>>>>> any epoch dependencies. To implement this, we would need some
>> way
>>> for
>>>>>>>> the
>>>>>>>>>>> consumer to find out how many partitions there were in each
>>> epoch, but
>>>>>>>>>>> maybe that's not too unreasonable.
>>>>>>>>>>>
>>>>>>>>>>> Thanks,
>>>>>>>>>>> Jason
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> On Mon, Mar 5, 2018 at 4:51 AM, Jan Filipiak <
>>> Jan.Filipiak@trivago.com
>>>>>>>>>>> wrote:
>>>>>>>>>>>
>>>>>>>>>>>> Hi Dong
>>>>>>>>>>>>
>>>>>>>>>>>> thank you very much for your questions.
>>>>>>>>>>>>
>>>>>>>>>>>> regarding the time spend copying data across:
>>>>>>>>>>>> It is correct that copying data from a topic with one partition
>>>>>>>> mapping
>>>>>>>>>>> to
>>>>>>>>>>>> a topic with a different partition mapping takes way longer
>> than
>>> we
>>>>>>>> can
>>>>>>>>>>>> stop producers. Tens of minutes is a very optimistic estimate
>>> here.
>>>>>>>>>> Many
>>>>>>>>>>>> people can not afford copy full steam and therefore will have
>>> some
>>>>>>>> rate
>>>>>>>>>>>> limiting in place, this can bump the timespan into the day's.
>>> The good
>>>>>>>>>>> part
>>>>>>>>>>>> is that the vast majority of the data can be copied while the
>>>>>>>> producers
>>>>>>>>>>> are
>>>>>>>>>>>> still going. One can then, piggyback the consumers ontop of
>> this
>>>>>>>>>>> timeframe,
>>>>>>>>>>>> by the method mentioned (provide them an mapping from their old
>>>>>>>> offsets
>>>>>>>>>>> to
>>>>>>>>>>>> new offsets in their repartitioned topics. In that way we
>>> separate
>>>>>>>>>>>> migration of consumers from migration of producers (decoupling
>>> these
>>>>>>>> is
>>>>>>>>>>>> what kafka is strongest at). The time to actually swap over the
>>>>>>>>>> producers
>>>>>>>>>>>> should be kept minimal by ensuring that when a swap attempt is
>>> started
>>>>>>>>>>> the
>>>>>>>>>>>> consumer copying over should be very close to the log end and
>> is
>>>>>>>>>> expected
>>>>>>>>>>>> to finish within the next fetch. The operation should have a
>>> time-out
>>>>>>>>>> and
>>>>>>>>>>>> should be "reattemtable".
>>>>>>>>>>>>
>>>>>>>>>>>> Importance of logcompaction:
>>>>>>>>>>>> If a producer produces key A, to partiton 0, its forever gonna
>> be
>>>>>>>>>> there,
>>>>>>>>>>>> unless it gets deleted. The record might sit in there for
>> years.
>>> A new
>>>>>>>>>>>> producer started with the new partitions will fail to delete
>> the
>>>>>>>> record
>>>>>>>>>>> in
>>>>>>>>>>>> the correct partition. Th record will be there forever and one
>>> can not
>>>>>>>>>>>> reliable bootstrap new consumers. I cannot see how linear
>>> hashing can
>>>>>>>>>>> solve
>>>>>>>>>>>> this.
>>>>>>>>>>>>
>>>>>>>>>>>> Regarding your skipping of userland copying:
>>>>>>>>>>>> 100%, copying the data across in userland is, as far as i can
>>> see,
>>>>>>>>>> only a
>>>>>>>>>>>> usecase for log compacted topics. Even for logcompaction +
>>> retentions
>>>>>>>>>> it
>>>>>>>>>>>> should only be opt-in. Why did I bring it up? I think log
>>> compaction
>>>>>>>>>> is a
>>>>>>>>>>>> very important feature to really embrace kafka as a "data
>>> plattform".
>>>>>>>>>> The
>>>>>>>>>>>> point I also want to make is that copying data this way is
>>> completely
>>>>>>>>>>>> inline with the kafka architecture. it only consists of reading
>>> and
>>>>>>>>>>> writing
>>>>>>>>>>>> to topics.
>>>>>>>>>>>>
>>>>>>>>>>>> I hope it clarifies more why I think we should aim for more
>> than
>>> the
>>>>>>>>>>>> current KIP. I fear that once the KIP is done not much more
>>> effort
>>>>>>>> will
>>>>>>>>>>> be
>>>>>>>>>>>> taken.
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>> On 04.03.2018 02:28, Dong Lin wrote:
>>>>>>>>>>>>
>>>>>>>>>>>>> Hey Jan,
>>>>>>>>>>>>>
>>>>>>>>>>>>> In the current proposal, the consumer will be blocked on
>>> waiting for
>>>>>>>>>>> other
>>>>>>>>>>>>> consumers of the group to consume up to a given offset. In
>> most
>>>>>>>> cases,
>>>>>>>>>>> all
>>>>>>>>>>>>> consumers should be close to the LEO of the partitions when
>> the
>>>>>>>>>>> partition
>>>>>>>>>>>>> expansion happens. Thus the time waiting should not be long
>>> e.g. on
>>>>>>>>>> the
>>>>>>>>>>>>> order of seconds. On the other hand, it may take a long time
>> to
>>> wait
>>>>>>>>>> for
>>>>>>>>>>>>> the entire partition to be copied -- the amount of time is
>>>>>>>>>> proportional
>>>>>>>>>>> to
>>>>>>>>>>>>> the amount of existing data in the partition, which can take
>>> tens of
>>>>>>>>>>>>> minutes. So the amount of time that we stop consumers may not
>>> be on
>>>>>>>>>> the
>>>>>>>>>>>>> same order of magnitude.
>>>>>>>>>>>>>
>>>>>>>>>>>>> If we can implement this suggestion without copying data over
>> in
>>>>>>>> purse
>>>>>>>>>>>>> userland, it will be much more valuable. Do you have ideas on
>>> how
>>>>>>>> this
>>>>>>>>>>> can
>>>>>>>>>>>>> be done?
>>>>>>>>>>>>>
>>>>>>>>>>>>> Not sure why the current KIP not help people who depend on log
>>>>>>>>>>> compaction.
>>>>>>>>>>>>> Could you elaborate more on this point?
>>>>>>>>>>>>>
>>>>>>>>>>>>> Thanks,
>>>>>>>>>>>>> Dong
>>>>>>>>>>>>>
>>>>>>>>>>>>> On Wed, Feb 28, 2018 at 10:55 PM, Jan
>>> Filipiak<Jan.Filipiak@trivago.
>>>>>>>>>> com
>>>>>>>>>>>>> wrote:
>>>>>>>>>>>>>
>>>>>>>>>>>>> Hi Dong,
>>>>>>>>>>>>>> I tried to focus on what the steps are one can currently
>>> perform to
>>>>>>>>>>>>>> expand
>>>>>>>>>>>>>> or shrink a keyed topic while maintaining a top notch
>>> semantics.
>>>>>>>>>>>>>> I can understand that there might be confusion about
>> "stopping
>>> the
>>>>>>>>>>>>>> consumer". It is exactly the same as proposed in the KIP.
>> there
>>>>>>>> needs
>>>>>>>>>>> to
>>>>>>>>>>>>>> be
>>>>>>>>>>>>>> a time the producers agree on the new partitioning. The extra
>>>>>>>>>>> semantics I
>>>>>>>>>>>>>> want to put in there is that we have a possibility to wait
>>> until all
>>>>>>>>>>> the
>>>>>>>>>>>>>> existing data
>>>>>>>>>>>>>> is copied over into the new partitioning scheme. When I say
>>> stopping
>>>>>>>>>> I
>>>>>>>>>>>>>> think more of having a memory barrier that ensures the
>>> ordering. I
>>>>>>>> am
>>>>>>>>>>>>>> still
>>>>>>>>>>>>>> aming for latencies  on the scale of leader failovers.
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> Consumers have to explicitly adapt the new partitioning
>> scheme
>>> in
>>>>>>>> the
>>>>>>>>>>>>>> above scenario. The reason is that in these cases where you
>> are
>>>>>>>>>>> dependent
>>>>>>>>>>>>>> on a particular partitioning scheme, you also have other
>>> topics that
>>>>>>>>>>> have
>>>>>>>>>>>>>> co-partition enforcements or the kind -frequently. Therefore
>>> all
>>>>>>>> your
>>>>>>>>>>>>>> other
>>>>>>>>>>>>>> input topics might need to grow accordingly.
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> What I was suggesting was to streamline all these operations
>>> as best
>>>>>>>>>> as
>>>>>>>>>>>>>> possible to have "real" partition grow and shrinkage going
>> on.
>>>>>>>>>>> Migrating
>>>>>>>>>>>>>> the producers to a new partitioning scheme can be much more
>>>>>>>>>> streamlined
>>>>>>>>>>>>>> with proper broker support for this. Migrating consumer is a
>>> step
>>>>>>>>>> that
>>>>>>>>>>>>>> might be made completly unnecessary if - for example streams
>> -
>>> takes
>>>>>>>>>>> the
>>>>>>>>>>>>>> gcd as partitioning scheme instead of enforcing 1 to 1.
>> Connect
>>>>>>>>>>> consumers
>>>>>>>>>>>>>> and other consumers should be fine anyways.
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> I hope this makes more clear where I was aiming at. The rest
>>> needs
>>>>>>>> to
>>>>>>>>>>> be
>>>>>>>>>>>>>> figured out. The only danger i see is that when we are
>>> introducing
>>>>>>>>>> this
>>>>>>>>>>>>>> feature as supposed in the KIP, it wont help any people
>>> depending on
>>>>>>>>>>> log
>>>>>>>>>>>>>> compaction.
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> The other thing I wanted to mention is that I believe the
>>> current
>>>>>>>>>>>>>> suggestion (without copying data over) can be implemented in
>>> pure
>>>>>>>>>>>>>> userland
>>>>>>>>>>>>>> with a custom partitioner and a small feedbackloop from
>>>>>>>>>> ProduceResponse
>>>>>>>>>>>>>> =>
>>>>>>>>>>>>>> Partitionier in coorporation with a change management system.
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> Best Jan
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> On 28.02.2018 07:13, Dong Lin wrote:
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> Hey Jan,
>>>>>>>>>>>>>>> I am not sure if it is acceptable for producer to be stopped
>>> for a
>>>>>>>>>>>>>>> while,
>>>>>>>>>>>>>>> particularly for online application which requires low
>>> latency. I
>>>>>>>> am
>>>>>>>>>>>>>>> also
>>>>>>>>>>>>>>> not sure how consumers can switch to a new topic. Does user
>>>>>>>>>>> application
>>>>>>>>>>>>>>> needs to explicitly specify a different topic for
>>> producer/consumer
>>>>>>>>>> to
>>>>>>>>>>>>>>> subscribe to? It will be helpful for discussion if you can
>>> provide
>>>>>>>>>>> more
>>>>>>>>>>>>>>> detail on the interface change for this solution.
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> Thanks,
>>>>>>>>>>>>>>> Dong
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> On Mon, Feb 26, 2018 at 12:48 AM, Jan
>>>>>>>> Filipiak<Jan.Filipiak@trivago.
>>>>>>>>>>> com
>>>>>>>>>>>>>>> wrote:
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> Hi,
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> just want to throw my though in. In general the
>>> functionality is
>>>>>>>>>> very
>>>>>>>>>>>>>>>> usefull, we should though not try to find the architecture
>>> to hard
>>>>>>>>>>>>>>>> while
>>>>>>>>>>>>>>>> implementing.
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> The manual steps would be to
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> create a new topic
>>>>>>>>>>>>>>>> the mirrormake from the new old topic to the new topic
>>>>>>>>>>>>>>>> wait for mirror making to catch up.
>>>>>>>>>>>>>>>> then put the consumers onto the new topic
>>>>>>>>>>>>>>>>        (having mirrormaker spit out a mapping from old
>>> offsets to
>>>>>>>>>> new
>>>>>>>>>>>>>>>> offsets:
>>>>>>>>>>>>>>>>            if topic is increased by factor X there is gonna
>>> be a
>>>>>>>>>> clean
>>>>>>>>>>>>>>>> mapping from 1 offset in the old topic to X offsets in the
>>> new
>>>>>>>>>> topic,
>>>>>>>>>>>>>>>>            if there is no factor then there is no chance to
>>>>>>>>>> generate a
>>>>>>>>>>>>>>>> mapping that can be reasonable used for continuing)
>>>>>>>>>>>>>>>>        make consumers stop at appropriate points and
>> continue
>>>>>>>>>>>>>>>> consumption
>>>>>>>>>>>>>>>> with offsets from the mapping.
>>>>>>>>>>>>>>>> have the producers stop for a minimal time.
>>>>>>>>>>>>>>>> wait for mirrormaker to finish
>>>>>>>>>>>>>>>> let producer produce with the new metadata.
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> Instead of implementing the approach suggest in the KIP
>>> which will
>>>>>>>>>>>>>>>> leave
>>>>>>>>>>>>>>>> log compacted topic completely crumbled and unusable.
>>>>>>>>>>>>>>>> I would much rather try to build infrastructure to support
>>> the
>>>>>>>>>>>>>>>> mentioned
>>>>>>>>>>>>>>>> above operations more smoothly.
>>>>>>>>>>>>>>>> Especially having producers stop and use another topic is
>>>>>>>> difficult
>>>>>>>>>>> and
>>>>>>>>>>>>>>>> it would be nice if one can trigger "invalid metadata"
>>> exceptions
>>>>>>>>>> for
>>>>>>>>>>>>>>>> them
>>>>>>>>>>>>>>>> and
>>>>>>>>>>>>>>>> if one could give topics aliases so that their produces
>> with
>>> the
>>>>>>>>>> old
>>>>>>>>>>>>>>>> topic
>>>>>>>>>>>>>>>> will arrive in the new topic.
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> The downsides are obvious I guess ( having the same data
>>> twice for
>>>>>>>>>>> the
>>>>>>>>>>>>>>>> transition period, but kafka tends to scale well with
>>> datasize).
>>>>>>>> So
>>>>>>>>>>>>>>>> its a
>>>>>>>>>>>>>>>> nicer fit into the architecture.
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> I further want to argument that the functionality by the
>> KIP
>>> can
>>>>>>>>>>>>>>>> completely be implementing in "userland" with a custom
>>> partitioner
>>>>>>>>>>> that
>>>>>>>>>>>>>>>> handles the transition as needed. I would appreciate if
>>> someone
>>>>>>>>>> could
>>>>>>>>>>>>>>>> point
>>>>>>>>>>>>>>>> out what a custom partitioner couldn't handle in this case?
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> With the above approach, shrinking a topic becomes the same
>>> steps.
>>>>>>>>>>>>>>>> Without
>>>>>>>>>>>>>>>> loosing keys in the discontinued partitions.
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> Would love to hear what everyone thinks.
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> Best Jan
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> On 11.02.2018 00:35, Dong Lin wrote:
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> Hi all,
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> I have created KIP-253: Support in-order message delivery
>>> with
>>>>>>>>>>>>>>>>> partition
>>>>>>>>>>>>>>>>> expansion. See
>>>>>>>>>>>>>>>>> https://cwiki.apache.org/confluence/display/KAFKA/KIP-
>> 253%
>>>>>>>>>>>>>>>>> 3A+Support+in-order+message+delivery+with+partition+
>>> expansion
>>>>>>>>>>>>>>>>> .
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> This KIP provides a way to allow messages of the same key
>>> from
>>>>>>>> the
>>>>>>>>>>>>>>>>> same
>>>>>>>>>>>>>>>>> producer to be consumed in the same order they are
>> produced
>>> even
>>>>>>>>>> if
>>>>>>>>>>> we
>>>>>>>>>>>>>>>>> expand partition of the topic.
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> Thanks,
>>>>>>>>>>>>>>>>> Dong
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>
>>>>>>>>
>>>>
>>>


Re: [DISCUSS] KIP-253: Support in-order message delivery with partition expansion

Posted by Dong Lin <li...@gmail.com>.
Hey Jason,

This is a good solution on the server side for log compacted topic.
Thinking about this more, there maybe another probably simpler solution on
the client side for log compacted topics. This solution is now specified in
the section "Changes in how producer produced keyed messages to log
compacted topics" of the KIP. The client-side solution seems simpler with
less performance overhead than the server-side solution. What do you think?

Thanks,
Dong


On Sat, Mar 10, 2018 at 10:55 AM, Jason Gustafson <ja...@confluent.io>
wrote:

> Hey Dong,
>
> I was thinking a bit about log compaction after a partition split. I think
> the best you could hope for in terms of efficiency is that the network
> overhead would be proportional to the number of remapped keys that need
> cleaning. One thought I had which gets close to this is to propagate a
> bloom filter covering the keys in the log prior to the split to all
> partitions that might contain some of the remapped keys. As a simple
> example, suppose we have a single partition which is split into two at
> offset N. Say that broker 0 owns partition 0 and broker 1 owns partition 1.
> Some subset of the keys prior to N will move to partition 1 and the rest
> will remain on partition 0. The idea is something like this:
>
> 1. Every time we clean partition 0 on broker 0, we compute a bloom filter
> for the keys in the log prior to offset N.
> 2. The bloom filter is propagated to broker 1 and cached.
> 3. The next time broker 1 cleans the log, it uses the bloom filter to
> collect a set of possible matches.
> 4. When the cleaning completes, the matching keys are propagated to broker
> 0, where they are cached until the next cleaning.
> 5. The next time broker 0 cleans the log, it can remove all keys that have
> been cached from the region prior to the split.
>
> This incremental approach allows us to tradeoff cleaning latency to reduce
> network traffic and memory overhead. A few points:
>
> - The accuracy of bloom filters decreases as you add more elements to them.
> We would probably choose to propagate the bloom filter for a subset of the
> keys once it had reached a certain capacity to avoid having too many false
> positives.
> - We can limit the number of bloom filter matches that we will collect and
> return in a single round of cleaning. These keys have to be cached in the
> broker for a little while (until the next cleaning), so this lets us keep
> the memory usage bounded.
>
> There is probably some room for cleverness as well to avoid repeating work.
> For example, the broker matching the bloom filter can also send the offset
> of the last key that was matched against the filter. The next time we send
> a bloom filter for a certain range of keys, we can send the starting offset
> for matching. It's kind of like our "dirty offset" notion.
>
> Needs a bit of investigation to work out the details (e.g. handling
> multiple splits), but seems like it could work. What do you think?
>
> -Jason
>
>
>
> On Fri, Mar 9, 2018 at 1:23 PM, Matthias J. Sax <ma...@confluent.io>
> wrote:
>
> > Thanks for your comment Clemens. It make sense what you are saying.
> > However, your described pattern is to split partitions and use linear
> > hashing to avoid random key distribution. But this is what Jan thinks we
> > should not do...
> >
> > Also, I just picked an example with 2 -> 3 partitions, but if you don't
> > use linear hashing I think the same issue occurs if you double the
> > number of partitions.
> >
> > I am in favor of using linear hashing. Still think, it is also useful to
> > split single partitions, too, in case load is not balanced and some
> > partitions are hot spots while others are "idle".
> >
> > -Matthias
> >
> >
> > On 3/9/18 5:41 AM, Clemens Valiente wrote:
> > > I think it's fair to assume that topics will always be increased by an
> > integer factor - e.g. from 2 partitions to 4 partitions. Then the mapping
> > is much easier.
> > >
> > > Why anyone would increase partitions by lass than x2 is a mystery to
> me.
> > If your two partitions cannot handle the load, then with three partitions
> > each one will still get 67% of that load which is still way too
> dangerous.
> > >
> > >
> > > So in your case we go from
> > >
> > > part1: A B C D
> > >
> > > part2: E F G H
> > >
> > >
> > > to
> > >
> > >
> > > part1: A C
> > >
> > > part2: B D
> > >
> > > part3: E F
> > >
> > > part4: G H
> > >
> > >
> > > ________________________________
> > > From: Matthias J. Sax <ma...@confluent.io>
> > > Sent: 09 March 2018 07:53
> > > To: dev@kafka.apache.org
> > > Subject: Re: [DISCUSS] KIP-253: Support in-order message delivery with
> > partition expansion
> > >
> > > @Jan: You suggest to copy the data from one topic to a new topic, and
> > > provide an "offset mapping" from the old to the new topic for the
> > > consumers. I don't quite understand how this would work.
> > >
> > > Let's say there are 2 partitions in the original topic and 3 partitions
> > > in the new topic. If we assume that we don't use linear hashing as you
> > > suggest, there is no guarantee how data will be distributed in the new
> > > topic and also no guarantee about ordering of records in the new topic.
> > >
> > > Example (I hope I got it right -- please correct me if it's wrong)
> > >
> > > A B C D
> > > E F G H
> > >
> > > could be copied to:
> > >
> > > A C H
> > > B E F
> > > D G
> > >
> > > If the consumer was at offset 1 and 2 in the first topic how would the
> > > mapping be computed? We need to enures that B C D as well as G H are
> > > read after the switch. Thus, offset would need to be 1 0 0. I am not
> > > sure how this would be computed?
> > >
> > > Furthermore, I want to point out that the new offsets would imply that
> E
> > > is consumed a second time by the consumer. E and F were consumed
> > > originally, but E is copied after B that was not yet consumed.
> > >
> > > Or is there a way that we can ensure that this "flip" does never happen
> > > while we copy the data?
> > >
> > >
> > > -Matthias
> > >
> > >
> > >
> > > On 3/8/18 10:32 PM, Matthias J. Sax wrote:
> > >> As I just mentioned joins:
> > >>
> > >> For Kafka Streams it might also be required to change the partition
> > >> count for multiple topics in a coordinated way that allows to maintain
> > >> the co-partitioning property that Kafka Streams uses to computed
> joins.
> > >>
> > >> Any thoughts how this could be handled?
> > >>
> > >>
> > >> -Matthias
> > >>
> > >> On 3/8/18 10:08 PM, Matthias J. Sax wrote:
> > >>> Jun,
> > >>>
> > >>> There is one more case: non-windowed aggregations. For windowed
> > >>> aggregation, the changelog topic will be compact+delete. However, for
> > >>> non-windowed aggregation the policy is compact only.
> > >>>
> > >>> Even if we assume that windowed aggregations are dominant and
> > >>> non-windowed aggregation are used rarely, it seems to be bad to not
> > >>> support the feature is a non-windowed aggregation is used. Also,
> > >>> non-windowed aggregation volume depends on input-stream volume that
> > >>> might be high.
> > >>>
> > >>> Furthermore, we support stream-table join and this requires that the
> > >>> stream and the table are co-partitioned. Thus, even if the table
> would
> > >>> have lower volume but the stream must be scaled out, we also need to
> > >>> scale out the table to preserve co-partitioning.
> > >>>
> > >>>
> > >>> -Matthias
> > >>>
> > >>> On 3/8/18 6:44 PM, Jun Rao wrote:
> > >>>> Hi, Matthis,
> > >>>>
> > >>>> My understanding is that in KStream, the only case when a changelog
> > topic
> > >>>> needs to be compacted is when the corresponding input is a KTable.
> In
> > all
> > >>>> other cases, the changelog topics are of compacted + deletion. So,
> if
> > most
> > >>>> KTables are not high volume, there may not be a need to expand its
> > >>>> partitions and therefore the partitions of the corresponding
> changelog
> > >>>> topic.
> > >>>>
> > >>>> Thanks,
> > >>>>
> > >>>> Jun
> > >>>>
> > >>>> On Wed, Mar 7, 2018 at 2:34 PM, Matthias J. Sax <
> > matthias@confluent.io>
> > >>>> wrote:
> > >>>>
> > >>>>> Jun,
> > >>>>>
> > >>>>> thanks for your comment. This should actually work for Streams,
> > because
> > >>>>> we don't rely on producer "hashing" but specify the partition
> number
> > >>>>> explicitly on send().
> > >>>>>
> > >>>>> About not allowing to change the number of partition for changelog
> > >>>>> topics: for Streams, this seems to imply that we need to create a
> > second
> > >>>>> changelog topic for each store with the new partition count.
> > However, it
> > >>>>> would be unclear when/if we can delete the old topic. Thus, it
> moves
> > the
> > >>>>> "problem" into the application layer. It's hard to judge for me atm
> > what
> > >>>>> the impact would be, but it's something we should pay attention to.
> > >>>>>
> > >>>>>
> > >>>>> -Matthias
> > >>>>>
> > >>>>> On 3/6/18 3:45 PM, Jun Rao wrote:
> > >>>>>> Hi, Mattias,
> > >>>>>>
> > >>>>>> Regarding your comment "If it would be time-delay based, it might
> be
> > >>>>>> problematic
> > >>>>>> for Kafka Streams: if we get the information that the new input
> > >>>>> partitions
> > >>>>>> are available for producing, we need to enable the new changelog
> > >>>>> partitions
> > >>>>>> for producing, too. If those would not be available yet, because
> the
> > >>>>>> time-delay did not trigger yet, it would be problematic to avoid
> > >>>>>> crashing.", could you just enable the changelog topic to write to
> > its new
> > >>>>>> partitions immediately?  The input topic can be configured with a
> > delay
> > >>>>> in
> > >>>>>> writing to the new partitions. Initially, there won't be new data
> > >>>>> produced
> > >>>>>> into the newly added partitions in the input topic. However, we
> > could
> > >>>>>> prebuild the state for the new input partition and write the state
> > >>>>> changes
> > >>>>>> to the corresponding new partitions in the changelog topic.
> > >>>>>>
> > >>>>>> Hi, Jan,
> > >>>>>>
> > >>>>>> For a compacted topic, garbage collecting the old keys in the
> > existing
> > >>>>>> partitions after partition expansion can be tricky as your pointed
> > out. A
> > >>>>>> few options here. (a) Let brokers exchange keys across brokers
> > during
> > >>>>>> compaction. This will add complexity on the broker side. (b) Build
> > an
> > >>>>>> external tool that scans the compacted topic and drop the prefix
> of
> > a
> > >>>>>> partition if all records in the prefix are removable. The admin
> can
> > then
> > >>>>>> run this tool when the unneeded space needs to be reclaimed. (c)
> > Don't
> > >>>>>> support partition change in a compacted topic. This might be ok
> > since
> > >>>>> most
> > >>>>>> compacted topics are not high volume.
> > >>>>>>
> > >>>>>> Thanks,
> > >>>>>>
> > >>>>>> Jun
> > >>>>>>
> > >>>>>>
> > >>>>>> On Tue, Mar 6, 2018 at 10:38 AM, Dong Lin <li...@gmail.com>
> > wrote:
> > >>>>>>
> > >>>>>>> Hi everyone,
> > >>>>>>>
> > >>>>>>> Thanks for all the comments! It appears that everyone prefers
> > linear
> > >>>>>>> hashing because it reduces the amount of state that needs to be
> > moved
> > >>>>>>> between consumers (for stream processing). The KIP has been
> > updated to
> > >>>>> use
> > >>>>>>> linear hashing.
> > >>>>>>>
> > >>>>>>> Regarding the migration endeavor: it seems that migrating
> producer
> > >>>>> library
> > >>>>>>> to use linear hashing should be pretty straightforward without
> > >>>>>>> much operational endeavor. If we don't upgrade client library to
> > use
> > >>>>> this
> > >>>>>>> KIP, we can not support in-order delivery after partition is
> > changed
> > >>>>>>> anyway. Suppose we upgrade client library to use this KIP, if
> > partition
> > >>>>>>> number is not changed, the key -> partition mapping will be
> > exactly the
> > >>>>>>> same as it is now because it is still determined using
> > murmur_hash(key)
> > >>>>> %
> > >>>>>>> original_partition_num. In other words, this change is backward
> > >>>>> compatible.
> > >>>>>>>
> > >>>>>>> Regarding the load distribution: if we use linear hashing, the
> > load may
> > >>>>> be
> > >>>>>>> unevenly distributed because those partitions which are not split
> > may
> > >>>>>>> receive twice as much traffic as other partitions that are split.
> > This
> > >>>>>>> issue can be mitigated by creating topic with partitions that are
> > >>>>> several
> > >>>>>>> times the number of consumers. And there will be no imbalance if
> > the
> > >>>>>>> partition number is always doubled. So this imbalance seems
> > acceptable.
> > >>>>>>>
> > >>>>>>> Regarding storing the partition strategy as per-topic config: It
> > seems
> > >>>>> not
> > >>>>>>> necessary since we can still use murmur_hash as the default hash
> > >>>>> function
> > >>>>>>> and additionally apply the linear hashing algorithm if the
> > partition
> > >>>>> number
> > >>>>>>> has increased. Not sure if there is any use-case for producer to
> > use a
> > >>>>>>> different hash function. Jason, can you check if there is some
> > use-case
> > >>>>>>> that I missed for using the per-topic partition strategy?
> > >>>>>>>
> > >>>>>>> Regarding how to reduce latency (due to state store/load) in
> stream
> > >>>>>>> processing consumer when partition number changes: I need to read
> > the
> > >>>>> Kafka
> > >>>>>>> Stream code to understand how Kafka Stream currently migrate
> state
> > >>>>> between
> > >>>>>>> consumers when the application is added/removed for a given job.
> I
> > will
> > >>>>>>> reply after I finish reading the documentation and code.
> > >>>>>>>
> > >>>>>>>
> > >>>>>>> Thanks,
> > >>>>>>> Dong
> > >>>>>>>
> > >>>>>>>
> > >>>>>>> On Mon, Mar 5, 2018 at 10:43 AM, Jason Gustafson <
> > jason@confluent.io>
> > >>>>>>> wrote:
> > >>>>>>>
> > >>>>>>>> Great discussion. I think I'm wondering whether we can continue
> to
> > >>>>> leave
> > >>>>>>>> Kafka agnostic to the partitioning strategy. The challenge is
> > >>>>>>> communicating
> > >>>>>>>> the partitioning logic from producers to consumers so that the
> > >>>>>>> dependencies
> > >>>>>>>> between each epoch can be determined. For the sake of
> discussion,
> > >>>>> imagine
> > >>>>>>>> you did something like the following:
> > >>>>>>>>
> > >>>>>>>> 1. The name (and perhaps version) of a partitioning strategy is
> > stored
> > >>>>> in
> > >>>>>>>> topic configuration when a topic is created.
> > >>>>>>>> 2. The producer looks up the partitioning strategy before
> writing
> > to a
> > >>>>>>>> topic and includes it in the produce request (for fencing). If
> it
> > >>>>> doesn't
> > >>>>>>>> have an implementation for the configured strategy, it fails.
> > >>>>>>>> 3. The consumer also looks up the partitioning strategy and uses
> > it to
> > >>>>>>>> determine dependencies when reading a new epoch. It could either
> > fail
> > >>>>> or
> > >>>>>>>> make the most conservative dependency assumptions if it doesn't
> > know
> > >>>>> how
> > >>>>>>> to
> > >>>>>>>> implement the partitioning strategy. For the consumer, the new
> > >>>>> interface
> > >>>>>>>> might look something like this:
> > >>>>>>>>
> > >>>>>>>> // Return the partition dependencies following an epoch bump
> > >>>>>>>> Map<Integer, List<Integer>> dependencies(int
> > >>>>>>> numPartitionsBeforeEpochBump,
> > >>>>>>>> int numPartitionsAfterEpochBump)
> > >>>>>>>>
> > >>>>>>>> The unordered case then is just a particular implementation
> which
> > never
> > >>>>>>> has
> > >>>>>>>> any epoch dependencies. To implement this, we would need some
> way
> > for
> > >>>>> the
> > >>>>>>>> consumer to find out how many partitions there were in each
> > epoch, but
> > >>>>>>>> maybe that's not too unreasonable.
> > >>>>>>>>
> > >>>>>>>> Thanks,
> > >>>>>>>> Jason
> > >>>>>>>>
> > >>>>>>>>
> > >>>>>>>> On Mon, Mar 5, 2018 at 4:51 AM, Jan Filipiak <
> > Jan.Filipiak@trivago.com
> > >>>>>>
> > >>>>>>>> wrote:
> > >>>>>>>>
> > >>>>>>>>> Hi Dong
> > >>>>>>>>>
> > >>>>>>>>> thank you very much for your questions.
> > >>>>>>>>>
> > >>>>>>>>> regarding the time spend copying data across:
> > >>>>>>>>> It is correct that copying data from a topic with one partition
> > >>>>> mapping
> > >>>>>>>> to
> > >>>>>>>>> a topic with a different partition mapping takes way longer
> than
> > we
> > >>>>> can
> > >>>>>>>>> stop producers. Tens of minutes is a very optimistic estimate
> > here.
> > >>>>>>> Many
> > >>>>>>>>> people can not afford copy full steam and therefore will have
> > some
> > >>>>> rate
> > >>>>>>>>> limiting in place, this can bump the timespan into the day's.
> > The good
> > >>>>>>>> part
> > >>>>>>>>> is that the vast majority of the data can be copied while the
> > >>>>> producers
> > >>>>>>>> are
> > >>>>>>>>> still going. One can then, piggyback the consumers ontop of
> this
> > >>>>>>>> timeframe,
> > >>>>>>>>> by the method mentioned (provide them an mapping from their old
> > >>>>> offsets
> > >>>>>>>> to
> > >>>>>>>>> new offsets in their repartitioned topics. In that way we
> > separate
> > >>>>>>>>> migration of consumers from migration of producers (decoupling
> > these
> > >>>>> is
> > >>>>>>>>> what kafka is strongest at). The time to actually swap over the
> > >>>>>>> producers
> > >>>>>>>>> should be kept minimal by ensuring that when a swap attempt is
> > started
> > >>>>>>>> the
> > >>>>>>>>> consumer copying over should be very close to the log end and
> is
> > >>>>>>> expected
> > >>>>>>>>> to finish within the next fetch. The operation should have a
> > time-out
> > >>>>>>> and
> > >>>>>>>>> should be "reattemtable".
> > >>>>>>>>>
> > >>>>>>>>> Importance of logcompaction:
> > >>>>>>>>> If a producer produces key A, to partiton 0, its forever gonna
> be
> > >>>>>>> there,
> > >>>>>>>>> unless it gets deleted. The record might sit in there for
> years.
> > A new
> > >>>>>>>>> producer started with the new partitions will fail to delete
> the
> > >>>>> record
> > >>>>>>>> in
> > >>>>>>>>> the correct partition. Th record will be there forever and one
> > can not
> > >>>>>>>>> reliable bootstrap new consumers. I cannot see how linear
> > hashing can
> > >>>>>>>> solve
> > >>>>>>>>> this.
> > >>>>>>>>>
> > >>>>>>>>> Regarding your skipping of userland copying:
> > >>>>>>>>> 100%, copying the data across in userland is, as far as i can
> > see,
> > >>>>>>> only a
> > >>>>>>>>> usecase for log compacted topics. Even for logcompaction +
> > retentions
> > >>>>>>> it
> > >>>>>>>>> should only be opt-in. Why did I bring it up? I think log
> > compaction
> > >>>>>>> is a
> > >>>>>>>>> very important feature to really embrace kafka as a "data
> > plattform".
> > >>>>>>> The
> > >>>>>>>>> point I also want to make is that copying data this way is
> > completely
> > >>>>>>>>> inline with the kafka architecture. it only consists of reading
> > and
> > >>>>>>>> writing
> > >>>>>>>>> to topics.
> > >>>>>>>>>
> > >>>>>>>>> I hope it clarifies more why I think we should aim for more
> than
> > the
> > >>>>>>>>> current KIP. I fear that once the KIP is done not much more
> > effort
> > >>>>> will
> > >>>>>>>> be
> > >>>>>>>>> taken.
> > >>>>>>>>>
> > >>>>>>>>>
> > >>>>>>>>>
> > >>>>>>>>>
> > >>>>>>>>> On 04.03.2018 02:28, Dong Lin wrote:
> > >>>>>>>>>
> > >>>>>>>>>> Hey Jan,
> > >>>>>>>>>>
> > >>>>>>>>>> In the current proposal, the consumer will be blocked on
> > waiting for
> > >>>>>>>> other
> > >>>>>>>>>> consumers of the group to consume up to a given offset. In
> most
> > >>>>> cases,
> > >>>>>>>> all
> > >>>>>>>>>> consumers should be close to the LEO of the partitions when
> the
> > >>>>>>>> partition
> > >>>>>>>>>> expansion happens. Thus the time waiting should not be long
> > e.g. on
> > >>>>>>> the
> > >>>>>>>>>> order of seconds. On the other hand, it may take a long time
> to
> > wait
> > >>>>>>> for
> > >>>>>>>>>> the entire partition to be copied -- the amount of time is
> > >>>>>>> proportional
> > >>>>>>>> to
> > >>>>>>>>>> the amount of existing data in the partition, which can take
> > tens of
> > >>>>>>>>>> minutes. So the amount of time that we stop consumers may not
> > be on
> > >>>>>>> the
> > >>>>>>>>>> same order of magnitude.
> > >>>>>>>>>>
> > >>>>>>>>>> If we can implement this suggestion without copying data over
> in
> > >>>>> purse
> > >>>>>>>>>> userland, it will be much more valuable. Do you have ideas on
> > how
> > >>>>> this
> > >>>>>>>> can
> > >>>>>>>>>> be done?
> > >>>>>>>>>>
> > >>>>>>>>>> Not sure why the current KIP not help people who depend on log
> > >>>>>>>> compaction.
> > >>>>>>>>>> Could you elaborate more on this point?
> > >>>>>>>>>>
> > >>>>>>>>>> Thanks,
> > >>>>>>>>>> Dong
> > >>>>>>>>>>
> > >>>>>>>>>> On Wed, Feb 28, 2018 at 10:55 PM, Jan
> > Filipiak<Jan.Filipiak@trivago.
> > >>>>>>> com
> > >>>>>>>>>
> > >>>>>>>>>> wrote:
> > >>>>>>>>>>
> > >>>>>>>>>> Hi Dong,
> > >>>>>>>>>>>
> > >>>>>>>>>>> I tried to focus on what the steps are one can currently
> > perform to
> > >>>>>>>>>>> expand
> > >>>>>>>>>>> or shrink a keyed topic while maintaining a top notch
> > semantics.
> > >>>>>>>>>>> I can understand that there might be confusion about
> "stopping
> > the
> > >>>>>>>>>>> consumer". It is exactly the same as proposed in the KIP.
> there
> > >>>>> needs
> > >>>>>>>> to
> > >>>>>>>>>>> be
> > >>>>>>>>>>> a time the producers agree on the new partitioning. The extra
> > >>>>>>>> semantics I
> > >>>>>>>>>>> want to put in there is that we have a possibility to wait
> > until all
> > >>>>>>>> the
> > >>>>>>>>>>> existing data
> > >>>>>>>>>>> is copied over into the new partitioning scheme. When I say
> > stopping
> > >>>>>>> I
> > >>>>>>>>>>> think more of having a memory barrier that ensures the
> > ordering. I
> > >>>>> am
> > >>>>>>>>>>> still
> > >>>>>>>>>>> aming for latencies  on the scale of leader failovers.
> > >>>>>>>>>>>
> > >>>>>>>>>>> Consumers have to explicitly adapt the new partitioning
> scheme
> > in
> > >>>>> the
> > >>>>>>>>>>> above scenario. The reason is that in these cases where you
> are
> > >>>>>>>> dependent
> > >>>>>>>>>>> on a particular partitioning scheme, you also have other
> > topics that
> > >>>>>>>> have
> > >>>>>>>>>>> co-partition enforcements or the kind -frequently. Therefore
> > all
> > >>>>> your
> > >>>>>>>>>>> other
> > >>>>>>>>>>> input topics might need to grow accordingly.
> > >>>>>>>>>>>
> > >>>>>>>>>>>
> > >>>>>>>>>>> What I was suggesting was to streamline all these operations
> > as best
> > >>>>>>> as
> > >>>>>>>>>>> possible to have "real" partition grow and shrinkage going
> on.
> > >>>>>>>> Migrating
> > >>>>>>>>>>> the producers to a new partitioning scheme can be much more
> > >>>>>>> streamlined
> > >>>>>>>>>>> with proper broker support for this. Migrating consumer is a
> > step
> > >>>>>>> that
> > >>>>>>>>>>> might be made completly unnecessary if - for example streams
> -
> > takes
> > >>>>>>>> the
> > >>>>>>>>>>> gcd as partitioning scheme instead of enforcing 1 to 1.
> Connect
> > >>>>>>>> consumers
> > >>>>>>>>>>> and other consumers should be fine anyways.
> > >>>>>>>>>>>
> > >>>>>>>>>>> I hope this makes more clear where I was aiming at. The rest
> > needs
> > >>>>> to
> > >>>>>>>> be
> > >>>>>>>>>>> figured out. The only danger i see is that when we are
> > introducing
> > >>>>>>> this
> > >>>>>>>>>>> feature as supposed in the KIP, it wont help any people
> > depending on
> > >>>>>>>> log
> > >>>>>>>>>>> compaction.
> > >>>>>>>>>>>
> > >>>>>>>>>>> The other thing I wanted to mention is that I believe the
> > current
> > >>>>>>>>>>> suggestion (without copying data over) can be implemented in
> > pure
> > >>>>>>>>>>> userland
> > >>>>>>>>>>> with a custom partitioner and a small feedbackloop from
> > >>>>>>> ProduceResponse
> > >>>>>>>>>>> =>
> > >>>>>>>>>>> Partitionier in coorporation with a change management system.
> > >>>>>>>>>>>
> > >>>>>>>>>>> Best Jan
> > >>>>>>>>>>>
> > >>>>>>>>>>>
> > >>>>>>>>>>>
> > >>>>>>>>>>>
> > >>>>>>>>>>>
> > >>>>>>>>>>>
> > >>>>>>>>>>>
> > >>>>>>>>>>>
> > >>>>>>>>>>> On 28.02.2018 07:13, Dong Lin wrote:
> > >>>>>>>>>>>
> > >>>>>>>>>>> Hey Jan,
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> I am not sure if it is acceptable for producer to be stopped
> > for a
> > >>>>>>>>>>>> while,
> > >>>>>>>>>>>> particularly for online application which requires low
> > latency. I
> > >>>>> am
> > >>>>>>>>>>>> also
> > >>>>>>>>>>>> not sure how consumers can switch to a new topic. Does user
> > >>>>>>>> application
> > >>>>>>>>>>>> needs to explicitly specify a different topic for
> > producer/consumer
> > >>>>>>> to
> > >>>>>>>>>>>> subscribe to? It will be helpful for discussion if you can
> > provide
> > >>>>>>>> more
> > >>>>>>>>>>>> detail on the interface change for this solution.
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> Thanks,
> > >>>>>>>>>>>> Dong
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> On Mon, Feb 26, 2018 at 12:48 AM, Jan
> > >>>>> Filipiak<Jan.Filipiak@trivago.
> > >>>>>>>> com
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>> wrote:
> > >>>>>>>>>>>>
> > >>>>>>>>>>>> Hi,
> > >>>>>>>>>>>>
> > >>>>>>>>>>>>> just want to throw my though in. In general the
> > functionality is
> > >>>>>>> very
> > >>>>>>>>>>>>> usefull, we should though not try to find the architecture
> > to hard
> > >>>>>>>>>>>>> while
> > >>>>>>>>>>>>> implementing.
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>>> The manual steps would be to
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>>> create a new topic
> > >>>>>>>>>>>>> the mirrormake from the new old topic to the new topic
> > >>>>>>>>>>>>> wait for mirror making to catch up.
> > >>>>>>>>>>>>> then put the consumers onto the new topic
> > >>>>>>>>>>>>>       (having mirrormaker spit out a mapping from old
> > offsets to
> > >>>>>>> new
> > >>>>>>>>>>>>> offsets:
> > >>>>>>>>>>>>>           if topic is increased by factor X there is gonna
> > be a
> > >>>>>>> clean
> > >>>>>>>>>>>>> mapping from 1 offset in the old topic to X offsets in the
> > new
> > >>>>>>> topic,
> > >>>>>>>>>>>>>           if there is no factor then there is no chance to
> > >>>>>>> generate a
> > >>>>>>>>>>>>> mapping that can be reasonable used for continuing)
> > >>>>>>>>>>>>>       make consumers stop at appropriate points and
> continue
> > >>>>>>>>>>>>> consumption
> > >>>>>>>>>>>>> with offsets from the mapping.
> > >>>>>>>>>>>>> have the producers stop for a minimal time.
> > >>>>>>>>>>>>> wait for mirrormaker to finish
> > >>>>>>>>>>>>> let producer produce with the new metadata.
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>>> Instead of implementing the approach suggest in the KIP
> > which will
> > >>>>>>>>>>>>> leave
> > >>>>>>>>>>>>> log compacted topic completely crumbled and unusable.
> > >>>>>>>>>>>>> I would much rather try to build infrastructure to support
> > the
> > >>>>>>>>>>>>> mentioned
> > >>>>>>>>>>>>> above operations more smoothly.
> > >>>>>>>>>>>>> Especially having producers stop and use another topic is
> > >>>>> difficult
> > >>>>>>>> and
> > >>>>>>>>>>>>> it would be nice if one can trigger "invalid metadata"
> > exceptions
> > >>>>>>> for
> > >>>>>>>>>>>>> them
> > >>>>>>>>>>>>> and
> > >>>>>>>>>>>>> if one could give topics aliases so that their produces
> with
> > the
> > >>>>>>> old
> > >>>>>>>>>>>>> topic
> > >>>>>>>>>>>>> will arrive in the new topic.
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>>> The downsides are obvious I guess ( having the same data
> > twice for
> > >>>>>>>> the
> > >>>>>>>>>>>>> transition period, but kafka tends to scale well with
> > datasize).
> > >>>>> So
> > >>>>>>>>>>>>> its a
> > >>>>>>>>>>>>> nicer fit into the architecture.
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>>> I further want to argument that the functionality by the
> KIP
> > can
> > >>>>>>>>>>>>> completely be implementing in "userland" with a custom
> > partitioner
> > >>>>>>>> that
> > >>>>>>>>>>>>> handles the transition as needed. I would appreciate if
> > someone
> > >>>>>>> could
> > >>>>>>>>>>>>> point
> > >>>>>>>>>>>>> out what a custom partitioner couldn't handle in this case?
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>>> With the above approach, shrinking a topic becomes the same
> > steps.
> > >>>>>>>>>>>>> Without
> > >>>>>>>>>>>>> loosing keys in the discontinued partitions.
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>>> Would love to hear what everyone thinks.
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>>> Best Jan
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>>> On 11.02.2018 00:35, Dong Lin wrote:
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>>> Hi all,
> > >>>>>>>>>>>>>
> > >>>>>>>>>>>>>> I have created KIP-253: Support in-order message delivery
> > with
> > >>>>>>>>>>>>>> partition
> > >>>>>>>>>>>>>> expansion. See
> > >>>>>>>>>>>>>> https://cwiki.apache.org/confluence/display/KAFKA/KIP-
> 253%
> > >>>>>>>>>>>>>> 3A+Support+in-order+message+delivery+with+partition+
> > expansion
> > >>>>>>>>>>>>>> .
> > >>>>>>>>>>>>>>
> > >>>>>>>>>>>>>> This KIP provides a way to allow messages of the same key
> > from
> > >>>>> the
> > >>>>>>>>>>>>>> same
> > >>>>>>>>>>>>>> producer to be consumed in the same order they are
> produced
> > even
> > >>>>>>> if
> > >>>>>>>> we
> > >>>>>>>>>>>>>> expand partition of the topic.
> > >>>>>>>>>>>>>>
> > >>>>>>>>>>>>>> Thanks,
> > >>>>>>>>>>>>>> Dong
> > >>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>
> > >>>>>>>>>>>>>>
> > >>>>>>>>>
> > >>>>>>>>
> > >>>>>>>
> > >>>>>>
> > >>>>>
> > >>>>>
> > >>>>
> > >>>
> > >>
> > >
> > >
> >
> >
>

Re: [DISCUSS] KIP-253: Support in-order message delivery with partition expansion

Posted by Jason Gustafson <ja...@confluent.io>.
Hey Dong,

I was thinking a bit about log compaction after a partition split. I think
the best you could hope for in terms of efficiency is that the network
overhead would be proportional to the number of remapped keys that need
cleaning. One thought I had which gets close to this is to propagate a
bloom filter covering the keys in the log prior to the split to all
partitions that might contain some of the remapped keys. As a simple
example, suppose we have a single partition which is split into two at
offset N. Say that broker 0 owns partition 0 and broker 1 owns partition 1.
Some subset of the keys prior to N will move to partition 1 and the rest
will remain on partition 0. The idea is something like this:

1. Every time we clean partition 0 on broker 0, we compute a bloom filter
for the keys in the log prior to offset N.
2. The bloom filter is propagated to broker 1 and cached.
3. The next time broker 1 cleans the log, it uses the bloom filter to
collect a set of possible matches.
4. When the cleaning completes, the matching keys are propagated to broker
0, where they are cached until the next cleaning.
5. The next time broker 0 cleans the log, it can remove all keys that have
been cached from the region prior to the split.

This incremental approach allows us to tradeoff cleaning latency to reduce
network traffic and memory overhead. A few points:

- The accuracy of bloom filters decreases as you add more elements to them.
We would probably choose to propagate the bloom filter for a subset of the
keys once it had reached a certain capacity to avoid having too many false
positives.
- We can limit the number of bloom filter matches that we will collect and
return in a single round of cleaning. These keys have to be cached in the
broker for a little while (until the next cleaning), so this lets us keep
the memory usage bounded.

There is probably some room for cleverness as well to avoid repeating work.
For example, the broker matching the bloom filter can also send the offset
of the last key that was matched against the filter. The next time we send
a bloom filter for a certain range of keys, we can send the starting offset
for matching. It's kind of like our "dirty offset" notion.

Needs a bit of investigation to work out the details (e.g. handling
multiple splits), but seems like it could work. What do you think?

-Jason



On Fri, Mar 9, 2018 at 1:23 PM, Matthias J. Sax <ma...@confluent.io>
wrote:

> Thanks for your comment Clemens. It make sense what you are saying.
> However, your described pattern is to split partitions and use linear
> hashing to avoid random key distribution. But this is what Jan thinks we
> should not do...
>
> Also, I just picked an example with 2 -> 3 partitions, but if you don't
> use linear hashing I think the same issue occurs if you double the
> number of partitions.
>
> I am in favor of using linear hashing. Still think, it is also useful to
> split single partitions, too, in case load is not balanced and some
> partitions are hot spots while others are "idle".
>
> -Matthias
>
>
> On 3/9/18 5:41 AM, Clemens Valiente wrote:
> > I think it's fair to assume that topics will always be increased by an
> integer factor - e.g. from 2 partitions to 4 partitions. Then the mapping
> is much easier.
> >
> > Why anyone would increase partitions by lass than x2 is a mystery to me.
> If your two partitions cannot handle the load, then with three partitions
> each one will still get 67% of that load which is still way too dangerous.
> >
> >
> > So in your case we go from
> >
> > part1: A B C D
> >
> > part2: E F G H
> >
> >
> > to
> >
> >
> > part1: A C
> >
> > part2: B D
> >
> > part3: E F
> >
> > part4: G H
> >
> >
> > ________________________________
> > From: Matthias J. Sax <ma...@confluent.io>
> > Sent: 09 March 2018 07:53
> > To: dev@kafka.apache.org
> > Subject: Re: [DISCUSS] KIP-253: Support in-order message delivery with
> partition expansion
> >
> > @Jan: You suggest to copy the data from one topic to a new topic, and
> > provide an "offset mapping" from the old to the new topic for the
> > consumers. I don't quite understand how this would work.
> >
> > Let's say there are 2 partitions in the original topic and 3 partitions
> > in the new topic. If we assume that we don't use linear hashing as you
> > suggest, there is no guarantee how data will be distributed in the new
> > topic and also no guarantee about ordering of records in the new topic.
> >
> > Example (I hope I got it right -- please correct me if it's wrong)
> >
> > A B C D
> > E F G H
> >
> > could be copied to:
> >
> > A C H
> > B E F
> > D G
> >
> > If the consumer was at offset 1 and 2 in the first topic how would the
> > mapping be computed? We need to enures that B C D as well as G H are
> > read after the switch. Thus, offset would need to be 1 0 0. I am not
> > sure how this would be computed?
> >
> > Furthermore, I want to point out that the new offsets would imply that E
> > is consumed a second time by the consumer. E and F were consumed
> > originally, but E is copied after B that was not yet consumed.
> >
> > Or is there a way that we can ensure that this "flip" does never happen
> > while we copy the data?
> >
> >
> > -Matthias
> >
> >
> >
> > On 3/8/18 10:32 PM, Matthias J. Sax wrote:
> >> As I just mentioned joins:
> >>
> >> For Kafka Streams it might also be required to change the partition
> >> count for multiple topics in a coordinated way that allows to maintain
> >> the co-partitioning property that Kafka Streams uses to computed joins.
> >>
> >> Any thoughts how this could be handled?
> >>
> >>
> >> -Matthias
> >>
> >> On 3/8/18 10:08 PM, Matthias J. Sax wrote:
> >>> Jun,
> >>>
> >>> There is one more case: non-windowed aggregations. For windowed
> >>> aggregation, the changelog topic will be compact+delete. However, for
> >>> non-windowed aggregation the policy is compact only.
> >>>
> >>> Even if we assume that windowed aggregations are dominant and
> >>> non-windowed aggregation are used rarely, it seems to be bad to not
> >>> support the feature is a non-windowed aggregation is used. Also,
> >>> non-windowed aggregation volume depends on input-stream volume that
> >>> might be high.
> >>>
> >>> Furthermore, we support stream-table join and this requires that the
> >>> stream and the table are co-partitioned. Thus, even if the table would
> >>> have lower volume but the stream must be scaled out, we also need to
> >>> scale out the table to preserve co-partitioning.
> >>>
> >>>
> >>> -Matthias
> >>>
> >>> On 3/8/18 6:44 PM, Jun Rao wrote:
> >>>> Hi, Matthis,
> >>>>
> >>>> My understanding is that in KStream, the only case when a changelog
> topic
> >>>> needs to be compacted is when the corresponding input is a KTable. In
> all
> >>>> other cases, the changelog topics are of compacted + deletion. So, if
> most
> >>>> KTables are not high volume, there may not be a need to expand its
> >>>> partitions and therefore the partitions of the corresponding changelog
> >>>> topic.
> >>>>
> >>>> Thanks,
> >>>>
> >>>> Jun
> >>>>
> >>>> On Wed, Mar 7, 2018 at 2:34 PM, Matthias J. Sax <
> matthias@confluent.io>
> >>>> wrote:
> >>>>
> >>>>> Jun,
> >>>>>
> >>>>> thanks for your comment. This should actually work for Streams,
> because
> >>>>> we don't rely on producer "hashing" but specify the partition number
> >>>>> explicitly on send().
> >>>>>
> >>>>> About not allowing to change the number of partition for changelog
> >>>>> topics: for Streams, this seems to imply that we need to create a
> second
> >>>>> changelog topic for each store with the new partition count.
> However, it
> >>>>> would be unclear when/if we can delete the old topic. Thus, it moves
> the
> >>>>> "problem" into the application layer. It's hard to judge for me atm
> what
> >>>>> the impact would be, but it's something we should pay attention to.
> >>>>>
> >>>>>
> >>>>> -Matthias
> >>>>>
> >>>>> On 3/6/18 3:45 PM, Jun Rao wrote:
> >>>>>> Hi, Mattias,
> >>>>>>
> >>>>>> Regarding your comment "If it would be time-delay based, it might be
> >>>>>> problematic
> >>>>>> for Kafka Streams: if we get the information that the new input
> >>>>> partitions
> >>>>>> are available for producing, we need to enable the new changelog
> >>>>> partitions
> >>>>>> for producing, too. If those would not be available yet, because the
> >>>>>> time-delay did not trigger yet, it would be problematic to avoid
> >>>>>> crashing.", could you just enable the changelog topic to write to
> its new
> >>>>>> partitions immediately?  The input topic can be configured with a
> delay
> >>>>> in
> >>>>>> writing to the new partitions. Initially, there won't be new data
> >>>>> produced
> >>>>>> into the newly added partitions in the input topic. However, we
> could
> >>>>>> prebuild the state for the new input partition and write the state
> >>>>> changes
> >>>>>> to the corresponding new partitions in the changelog topic.
> >>>>>>
> >>>>>> Hi, Jan,
> >>>>>>
> >>>>>> For a compacted topic, garbage collecting the old keys in the
> existing
> >>>>>> partitions after partition expansion can be tricky as your pointed
> out. A
> >>>>>> few options here. (a) Let brokers exchange keys across brokers
> during
> >>>>>> compaction. This will add complexity on the broker side. (b) Build
> an
> >>>>>> external tool that scans the compacted topic and drop the prefix of
> a
> >>>>>> partition if all records in the prefix are removable. The admin can
> then
> >>>>>> run this tool when the unneeded space needs to be reclaimed. (c)
> Don't
> >>>>>> support partition change in a compacted topic. This might be ok
> since
> >>>>> most
> >>>>>> compacted topics are not high volume.
> >>>>>>
> >>>>>> Thanks,
> >>>>>>
> >>>>>> Jun
> >>>>>>
> >>>>>>
> >>>>>> On Tue, Mar 6, 2018 at 10:38 AM, Dong Lin <li...@gmail.com>
> wrote:
> >>>>>>
> >>>>>>> Hi everyone,
> >>>>>>>
> >>>>>>> Thanks for all the comments! It appears that everyone prefers
> linear
> >>>>>>> hashing because it reduces the amount of state that needs to be
> moved
> >>>>>>> between consumers (for stream processing). The KIP has been
> updated to
> >>>>> use
> >>>>>>> linear hashing.
> >>>>>>>
> >>>>>>> Regarding the migration endeavor: it seems that migrating producer
> >>>>> library
> >>>>>>> to use linear hashing should be pretty straightforward without
> >>>>>>> much operational endeavor. If we don't upgrade client library to
> use
> >>>>> this
> >>>>>>> KIP, we can not support in-order delivery after partition is
> changed
> >>>>>>> anyway. Suppose we upgrade client library to use this KIP, if
> partition
> >>>>>>> number is not changed, the key -> partition mapping will be
> exactly the
> >>>>>>> same as it is now because it is still determined using
> murmur_hash(key)
> >>>>> %
> >>>>>>> original_partition_num. In other words, this change is backward
> >>>>> compatible.
> >>>>>>>
> >>>>>>> Regarding the load distribution: if we use linear hashing, the
> load may
> >>>>> be
> >>>>>>> unevenly distributed because those partitions which are not split
> may
> >>>>>>> receive twice as much traffic as other partitions that are split.
> This
> >>>>>>> issue can be mitigated by creating topic with partitions that are
> >>>>> several
> >>>>>>> times the number of consumers. And there will be no imbalance if
> the
> >>>>>>> partition number is always doubled. So this imbalance seems
> acceptable.
> >>>>>>>
> >>>>>>> Regarding storing the partition strategy as per-topic config: It
> seems
> >>>>> not
> >>>>>>> necessary since we can still use murmur_hash as the default hash
> >>>>> function
> >>>>>>> and additionally apply the linear hashing algorithm if the
> partition
> >>>>> number
> >>>>>>> has increased. Not sure if there is any use-case for producer to
> use a
> >>>>>>> different hash function. Jason, can you check if there is some
> use-case
> >>>>>>> that I missed for using the per-topic partition strategy?
> >>>>>>>
> >>>>>>> Regarding how to reduce latency (due to state store/load) in stream
> >>>>>>> processing consumer when partition number changes: I need to read
> the
> >>>>> Kafka
> >>>>>>> Stream code to understand how Kafka Stream currently migrate state
> >>>>> between
> >>>>>>> consumers when the application is added/removed for a given job. I
> will
> >>>>>>> reply after I finish reading the documentation and code.
> >>>>>>>
> >>>>>>>
> >>>>>>> Thanks,
> >>>>>>> Dong
> >>>>>>>
> >>>>>>>
> >>>>>>> On Mon, Mar 5, 2018 at 10:43 AM, Jason Gustafson <
> jason@confluent.io>
> >>>>>>> wrote:
> >>>>>>>
> >>>>>>>> Great discussion. I think I'm wondering whether we can continue to
> >>>>> leave
> >>>>>>>> Kafka agnostic to the partitioning strategy. The challenge is
> >>>>>>> communicating
> >>>>>>>> the partitioning logic from producers to consumers so that the
> >>>>>>> dependencies
> >>>>>>>> between each epoch can be determined. For the sake of discussion,
> >>>>> imagine
> >>>>>>>> you did something like the following:
> >>>>>>>>
> >>>>>>>> 1. The name (and perhaps version) of a partitioning strategy is
> stored
> >>>>> in
> >>>>>>>> topic configuration when a topic is created.
> >>>>>>>> 2. The producer looks up the partitioning strategy before writing
> to a
> >>>>>>>> topic and includes it in the produce request (for fencing). If it
> >>>>> doesn't
> >>>>>>>> have an implementation for the configured strategy, it fails.
> >>>>>>>> 3. The consumer also looks up the partitioning strategy and uses
> it to
> >>>>>>>> determine dependencies when reading a new epoch. It could either
> fail
> >>>>> or
> >>>>>>>> make the most conservative dependency assumptions if it doesn't
> know
> >>>>> how
> >>>>>>> to
> >>>>>>>> implement the partitioning strategy. For the consumer, the new
> >>>>> interface
> >>>>>>>> might look something like this:
> >>>>>>>>
> >>>>>>>> // Return the partition dependencies following an epoch bump
> >>>>>>>> Map<Integer, List<Integer>> dependencies(int
> >>>>>>> numPartitionsBeforeEpochBump,
> >>>>>>>> int numPartitionsAfterEpochBump)
> >>>>>>>>
> >>>>>>>> The unordered case then is just a particular implementation which
> never
> >>>>>>> has
> >>>>>>>> any epoch dependencies. To implement this, we would need some way
> for
> >>>>> the
> >>>>>>>> consumer to find out how many partitions there were in each
> epoch, but
> >>>>>>>> maybe that's not too unreasonable.
> >>>>>>>>
> >>>>>>>> Thanks,
> >>>>>>>> Jason
> >>>>>>>>
> >>>>>>>>
> >>>>>>>> On Mon, Mar 5, 2018 at 4:51 AM, Jan Filipiak <
> Jan.Filipiak@trivago.com
> >>>>>>
> >>>>>>>> wrote:
> >>>>>>>>
> >>>>>>>>> Hi Dong
> >>>>>>>>>
> >>>>>>>>> thank you very much for your questions.
> >>>>>>>>>
> >>>>>>>>> regarding the time spend copying data across:
> >>>>>>>>> It is correct that copying data from a topic with one partition
> >>>>> mapping
> >>>>>>>> to
> >>>>>>>>> a topic with a different partition mapping takes way longer than
> we
> >>>>> can
> >>>>>>>>> stop producers. Tens of minutes is a very optimistic estimate
> here.
> >>>>>>> Many
> >>>>>>>>> people can not afford copy full steam and therefore will have
> some
> >>>>> rate
> >>>>>>>>> limiting in place, this can bump the timespan into the day's.
> The good
> >>>>>>>> part
> >>>>>>>>> is that the vast majority of the data can be copied while the
> >>>>> producers
> >>>>>>>> are
> >>>>>>>>> still going. One can then, piggyback the consumers ontop of this
> >>>>>>>> timeframe,
> >>>>>>>>> by the method mentioned (provide them an mapping from their old
> >>>>> offsets
> >>>>>>>> to
> >>>>>>>>> new offsets in their repartitioned topics. In that way we
> separate
> >>>>>>>>> migration of consumers from migration of producers (decoupling
> these
> >>>>> is
> >>>>>>>>> what kafka is strongest at). The time to actually swap over the
> >>>>>>> producers
> >>>>>>>>> should be kept minimal by ensuring that when a swap attempt is
> started
> >>>>>>>> the
> >>>>>>>>> consumer copying over should be very close to the log end and is
> >>>>>>> expected
> >>>>>>>>> to finish within the next fetch. The operation should have a
> time-out
> >>>>>>> and
> >>>>>>>>> should be "reattemtable".
> >>>>>>>>>
> >>>>>>>>> Importance of logcompaction:
> >>>>>>>>> If a producer produces key A, to partiton 0, its forever gonna be
> >>>>>>> there,
> >>>>>>>>> unless it gets deleted. The record might sit in there for years.
> A new
> >>>>>>>>> producer started with the new partitions will fail to delete the
> >>>>> record
> >>>>>>>> in
> >>>>>>>>> the correct partition. Th record will be there forever and one
> can not
> >>>>>>>>> reliable bootstrap new consumers. I cannot see how linear
> hashing can
> >>>>>>>> solve
> >>>>>>>>> this.
> >>>>>>>>>
> >>>>>>>>> Regarding your skipping of userland copying:
> >>>>>>>>> 100%, copying the data across in userland is, as far as i can
> see,
> >>>>>>> only a
> >>>>>>>>> usecase for log compacted topics. Even for logcompaction +
> retentions
> >>>>>>> it
> >>>>>>>>> should only be opt-in. Why did I bring it up? I think log
> compaction
> >>>>>>> is a
> >>>>>>>>> very important feature to really embrace kafka as a "data
> plattform".
> >>>>>>> The
> >>>>>>>>> point I also want to make is that copying data this way is
> completely
> >>>>>>>>> inline with the kafka architecture. it only consists of reading
> and
> >>>>>>>> writing
> >>>>>>>>> to topics.
> >>>>>>>>>
> >>>>>>>>> I hope it clarifies more why I think we should aim for more than
> the
> >>>>>>>>> current KIP. I fear that once the KIP is done not much more
> effort
> >>>>> will
> >>>>>>>> be
> >>>>>>>>> taken.
> >>>>>>>>>
> >>>>>>>>>
> >>>>>>>>>
> >>>>>>>>>
> >>>>>>>>> On 04.03.2018 02:28, Dong Lin wrote:
> >>>>>>>>>
> >>>>>>>>>> Hey Jan,
> >>>>>>>>>>
> >>>>>>>>>> In the current proposal, the consumer will be blocked on
> waiting for
> >>>>>>>> other
> >>>>>>>>>> consumers of the group to consume up to a given offset. In most
> >>>>> cases,
> >>>>>>>> all
> >>>>>>>>>> consumers should be close to the LEO of the partitions when the
> >>>>>>>> partition
> >>>>>>>>>> expansion happens. Thus the time waiting should not be long
> e.g. on
> >>>>>>> the
> >>>>>>>>>> order of seconds. On the other hand, it may take a long time to
> wait
> >>>>>>> for
> >>>>>>>>>> the entire partition to be copied -- the amount of time is
> >>>>>>> proportional
> >>>>>>>> to
> >>>>>>>>>> the amount of existing data in the partition, which can take
> tens of
> >>>>>>>>>> minutes. So the amount of time that we stop consumers may not
> be on
> >>>>>>> the
> >>>>>>>>>> same order of magnitude.
> >>>>>>>>>>
> >>>>>>>>>> If we can implement this suggestion without copying data over in
> >>>>> purse
> >>>>>>>>>> userland, it will be much more valuable. Do you have ideas on
> how
> >>>>> this
> >>>>>>>> can
> >>>>>>>>>> be done?
> >>>>>>>>>>
> >>>>>>>>>> Not sure why the current KIP not help people who depend on log
> >>>>>>>> compaction.
> >>>>>>>>>> Could you elaborate more on this point?
> >>>>>>>>>>
> >>>>>>>>>> Thanks,
> >>>>>>>>>> Dong
> >>>>>>>>>>
> >>>>>>>>>> On Wed, Feb 28, 2018 at 10:55 PM, Jan
> Filipiak<Jan.Filipiak@trivago.
> >>>>>>> com
> >>>>>>>>>
> >>>>>>>>>> wrote:
> >>>>>>>>>>
> >>>>>>>>>> Hi Dong,
> >>>>>>>>>>>
> >>>>>>>>>>> I tried to focus on what the steps are one can currently
> perform to
> >>>>>>>>>>> expand
> >>>>>>>>>>> or shrink a keyed topic while maintaining a top notch
> semantics.
> >>>>>>>>>>> I can understand that there might be confusion about "stopping
> the
> >>>>>>>>>>> consumer". It is exactly the same as proposed in the KIP. there
> >>>>> needs
> >>>>>>>> to
> >>>>>>>>>>> be
> >>>>>>>>>>> a time the producers agree on the new partitioning. The extra
> >>>>>>>> semantics I
> >>>>>>>>>>> want to put in there is that we have a possibility to wait
> until all
> >>>>>>>> the
> >>>>>>>>>>> existing data
> >>>>>>>>>>> is copied over into the new partitioning scheme. When I say
> stopping
> >>>>>>> I
> >>>>>>>>>>> think more of having a memory barrier that ensures the
> ordering. I
> >>>>> am
> >>>>>>>>>>> still
> >>>>>>>>>>> aming for latencies  on the scale of leader failovers.
> >>>>>>>>>>>
> >>>>>>>>>>> Consumers have to explicitly adapt the new partitioning scheme
> in
> >>>>> the
> >>>>>>>>>>> above scenario. The reason is that in these cases where you are
> >>>>>>>> dependent
> >>>>>>>>>>> on a particular partitioning scheme, you also have other
> topics that
> >>>>>>>> have
> >>>>>>>>>>> co-partition enforcements or the kind -frequently. Therefore
> all
> >>>>> your
> >>>>>>>>>>> other
> >>>>>>>>>>> input topics might need to grow accordingly.
> >>>>>>>>>>>
> >>>>>>>>>>>
> >>>>>>>>>>> What I was suggesting was to streamline all these operations
> as best
> >>>>>>> as
> >>>>>>>>>>> possible to have "real" partition grow and shrinkage going on.
> >>>>>>>> Migrating
> >>>>>>>>>>> the producers to a new partitioning scheme can be much more
> >>>>>>> streamlined
> >>>>>>>>>>> with proper broker support for this. Migrating consumer is a
> step
> >>>>>>> that
> >>>>>>>>>>> might be made completly unnecessary if - for example streams -
> takes
> >>>>>>>> the
> >>>>>>>>>>> gcd as partitioning scheme instead of enforcing 1 to 1. Connect
> >>>>>>>> consumers
> >>>>>>>>>>> and other consumers should be fine anyways.
> >>>>>>>>>>>
> >>>>>>>>>>> I hope this makes more clear where I was aiming at. The rest
> needs
> >>>>> to
> >>>>>>>> be
> >>>>>>>>>>> figured out. The only danger i see is that when we are
> introducing
> >>>>>>> this
> >>>>>>>>>>> feature as supposed in the KIP, it wont help any people
> depending on
> >>>>>>>> log
> >>>>>>>>>>> compaction.
> >>>>>>>>>>>
> >>>>>>>>>>> The other thing I wanted to mention is that I believe the
> current
> >>>>>>>>>>> suggestion (without copying data over) can be implemented in
> pure
> >>>>>>>>>>> userland
> >>>>>>>>>>> with a custom partitioner and a small feedbackloop from
> >>>>>>> ProduceResponse
> >>>>>>>>>>> =>
> >>>>>>>>>>> Partitionier in coorporation with a change management system.
> >>>>>>>>>>>
> >>>>>>>>>>> Best Jan
> >>>>>>>>>>>
> >>>>>>>>>>>
> >>>>>>>>>>>
> >>>>>>>>>>>
> >>>>>>>>>>>
> >>>>>>>>>>>
> >>>>>>>>>>>
> >>>>>>>>>>>
> >>>>>>>>>>> On 28.02.2018 07:13, Dong Lin wrote:
> >>>>>>>>>>>
> >>>>>>>>>>> Hey Jan,
> >>>>>>>>>>>>
> >>>>>>>>>>>> I am not sure if it is acceptable for producer to be stopped
> for a
> >>>>>>>>>>>> while,
> >>>>>>>>>>>> particularly for online application which requires low
> latency. I
> >>>>> am
> >>>>>>>>>>>> also
> >>>>>>>>>>>> not sure how consumers can switch to a new topic. Does user
> >>>>>>>> application
> >>>>>>>>>>>> needs to explicitly specify a different topic for
> producer/consumer
> >>>>>>> to
> >>>>>>>>>>>> subscribe to? It will be helpful for discussion if you can
> provide
> >>>>>>>> more
> >>>>>>>>>>>> detail on the interface change for this solution.
> >>>>>>>>>>>>
> >>>>>>>>>>>> Thanks,
> >>>>>>>>>>>> Dong
> >>>>>>>>>>>>
> >>>>>>>>>>>> On Mon, Feb 26, 2018 at 12:48 AM, Jan
> >>>>> Filipiak<Jan.Filipiak@trivago.
> >>>>>>>> com
> >>>>>>>>>>>>>
> >>>>>>>>>>>> wrote:
> >>>>>>>>>>>>
> >>>>>>>>>>>> Hi,
> >>>>>>>>>>>>
> >>>>>>>>>>>>> just want to throw my though in. In general the
> functionality is
> >>>>>>> very
> >>>>>>>>>>>>> usefull, we should though not try to find the architecture
> to hard
> >>>>>>>>>>>>> while
> >>>>>>>>>>>>> implementing.
> >>>>>>>>>>>>>
> >>>>>>>>>>>>> The manual steps would be to
> >>>>>>>>>>>>>
> >>>>>>>>>>>>> create a new topic
> >>>>>>>>>>>>> the mirrormake from the new old topic to the new topic
> >>>>>>>>>>>>> wait for mirror making to catch up.
> >>>>>>>>>>>>> then put the consumers onto the new topic
> >>>>>>>>>>>>>       (having mirrormaker spit out a mapping from old
> offsets to
> >>>>>>> new
> >>>>>>>>>>>>> offsets:
> >>>>>>>>>>>>>           if topic is increased by factor X there is gonna
> be a
> >>>>>>> clean
> >>>>>>>>>>>>> mapping from 1 offset in the old topic to X offsets in the
> new
> >>>>>>> topic,
> >>>>>>>>>>>>>           if there is no factor then there is no chance to
> >>>>>>> generate a
> >>>>>>>>>>>>> mapping that can be reasonable used for continuing)
> >>>>>>>>>>>>>       make consumers stop at appropriate points and continue
> >>>>>>>>>>>>> consumption
> >>>>>>>>>>>>> with offsets from the mapping.
> >>>>>>>>>>>>> have the producers stop for a minimal time.
> >>>>>>>>>>>>> wait for mirrormaker to finish
> >>>>>>>>>>>>> let producer produce with the new metadata.
> >>>>>>>>>>>>>
> >>>>>>>>>>>>>
> >>>>>>>>>>>>> Instead of implementing the approach suggest in the KIP
> which will
> >>>>>>>>>>>>> leave
> >>>>>>>>>>>>> log compacted topic completely crumbled and unusable.
> >>>>>>>>>>>>> I would much rather try to build infrastructure to support
> the
> >>>>>>>>>>>>> mentioned
> >>>>>>>>>>>>> above operations more smoothly.
> >>>>>>>>>>>>> Especially having producers stop and use another topic is
> >>>>> difficult
> >>>>>>>> and
> >>>>>>>>>>>>> it would be nice if one can trigger "invalid metadata"
> exceptions
> >>>>>>> for
> >>>>>>>>>>>>> them
> >>>>>>>>>>>>> and
> >>>>>>>>>>>>> if one could give topics aliases so that their produces with
> the
> >>>>>>> old
> >>>>>>>>>>>>> topic
> >>>>>>>>>>>>> will arrive in the new topic.
> >>>>>>>>>>>>>
> >>>>>>>>>>>>> The downsides are obvious I guess ( having the same data
> twice for
> >>>>>>>> the
> >>>>>>>>>>>>> transition period, but kafka tends to scale well with
> datasize).
> >>>>> So
> >>>>>>>>>>>>> its a
> >>>>>>>>>>>>> nicer fit into the architecture.
> >>>>>>>>>>>>>
> >>>>>>>>>>>>> I further want to argument that the functionality by the KIP
> can
> >>>>>>>>>>>>> completely be implementing in "userland" with a custom
> partitioner
> >>>>>>>> that
> >>>>>>>>>>>>> handles the transition as needed. I would appreciate if
> someone
> >>>>>>> could
> >>>>>>>>>>>>> point
> >>>>>>>>>>>>> out what a custom partitioner couldn't handle in this case?
> >>>>>>>>>>>>>
> >>>>>>>>>>>>> With the above approach, shrinking a topic becomes the same
> steps.
> >>>>>>>>>>>>> Without
> >>>>>>>>>>>>> loosing keys in the discontinued partitions.
> >>>>>>>>>>>>>
> >>>>>>>>>>>>> Would love to hear what everyone thinks.
> >>>>>>>>>>>>>
> >>>>>>>>>>>>> Best Jan
> >>>>>>>>>>>>>
> >>>>>>>>>>>>>
> >>>>>>>>>>>>>
> >>>>>>>>>>>>>
> >>>>>>>>>>>>>
> >>>>>>>>>>>>>
> >>>>>>>>>>>>>
> >>>>>>>>>>>>>
> >>>>>>>>>>>>>
> >>>>>>>>>>>>>
> >>>>>>>>>>>>>
> >>>>>>>>>>>>>
> >>>>>>>>>>>>>
> >>>>>>>>>>>>>
> >>>>>>>>>>>>>
> >>>>>>>>>>>>>
> >>>>>>>>>>>>>
> >>>>>>>>>>>>>
> >>>>>>>>>>>>> On 11.02.2018 00:35, Dong Lin wrote:
> >>>>>>>>>>>>>
> >>>>>>>>>>>>> Hi all,
> >>>>>>>>>>>>>
> >>>>>>>>>>>>>> I have created KIP-253: Support in-order message delivery
> with
> >>>>>>>>>>>>>> partition
> >>>>>>>>>>>>>> expansion. See
> >>>>>>>>>>>>>> https://cwiki.apache.org/confluence/display/KAFKA/KIP-253%
> >>>>>>>>>>>>>> 3A+Support+in-order+message+delivery+with+partition+
> expansion
> >>>>>>>>>>>>>> .
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>> This KIP provides a way to allow messages of the same key
> from
> >>>>> the
> >>>>>>>>>>>>>> same
> >>>>>>>>>>>>>> producer to be consumed in the same order they are produced
> even
> >>>>>>> if
> >>>>>>>> we
> >>>>>>>>>>>>>> expand partition of the topic.
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>> Thanks,
> >>>>>>>>>>>>>> Dong
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>>
> >>>>>>>>>
> >>>>>>>>
> >>>>>>>
> >>>>>>
> >>>>>
> >>>>>
> >>>>
> >>>
> >>
> >
> >
>
>

Re: [DISCUSS] KIP-253: Support in-order message delivery with partition expansion

Posted by "Matthias J. Sax" <ma...@confluent.io>.
Thanks for your comment Clemens. It make sense what you are saying.
However, your described pattern is to split partitions and use linear
hashing to avoid random key distribution. But this is what Jan thinks we
should not do...

Also, I just picked an example with 2 -> 3 partitions, but if you don't
use linear hashing I think the same issue occurs if you double the
number of partitions.

I am in favor of using linear hashing. Still think, it is also useful to
split single partitions, too, in case load is not balanced and some
partitions are hot spots while others are "idle".

-Matthias


On 3/9/18 5:41 AM, Clemens Valiente wrote:
> I think it's fair to assume that topics will always be increased by an integer factor - e.g. from 2 partitions to 4 partitions. Then the mapping is much easier.
> 
> Why anyone would increase partitions by lass than x2 is a mystery to me. If your two partitions cannot handle the load, then with three partitions each one will still get 67% of that load which is still way too dangerous.
> 
> 
> So in your case we go from
> 
> part1: A B C D
> 
> part2: E F G H
> 
> 
> to
> 
> 
> part1: A C
> 
> part2: B D
> 
> part3: E F
> 
> part4: G H
> 
> 
> ________________________________
> From: Matthias J. Sax <ma...@confluent.io>
> Sent: 09 March 2018 07:53
> To: dev@kafka.apache.org
> Subject: Re: [DISCUSS] KIP-253: Support in-order message delivery with partition expansion
> 
> @Jan: You suggest to copy the data from one topic to a new topic, and
> provide an "offset mapping" from the old to the new topic for the
> consumers. I don't quite understand how this would work.
> 
> Let's say there are 2 partitions in the original topic and 3 partitions
> in the new topic. If we assume that we don't use linear hashing as you
> suggest, there is no guarantee how data will be distributed in the new
> topic and also no guarantee about ordering of records in the new topic.
> 
> Example (I hope I got it right -- please correct me if it's wrong)
> 
> A B C D
> E F G H
> 
> could be copied to:
> 
> A C H
> B E F
> D G
> 
> If the consumer was at offset 1 and 2 in the first topic how would the
> mapping be computed? We need to enures that B C D as well as G H are
> read after the switch. Thus, offset would need to be 1 0 0. I am not
> sure how this would be computed?
> 
> Furthermore, I want to point out that the new offsets would imply that E
> is consumed a second time by the consumer. E and F were consumed
> originally, but E is copied after B that was not yet consumed.
> 
> Or is there a way that we can ensure that this "flip" does never happen
> while we copy the data?
> 
> 
> -Matthias
> 
> 
> 
> On 3/8/18 10:32 PM, Matthias J. Sax wrote:
>> As I just mentioned joins:
>>
>> For Kafka Streams it might also be required to change the partition
>> count for multiple topics in a coordinated way that allows to maintain
>> the co-partitioning property that Kafka Streams uses to computed joins.
>>
>> Any thoughts how this could be handled?
>>
>>
>> -Matthias
>>
>> On 3/8/18 10:08 PM, Matthias J. Sax wrote:
>>> Jun,
>>>
>>> There is one more case: non-windowed aggregations. For windowed
>>> aggregation, the changelog topic will be compact+delete. However, for
>>> non-windowed aggregation the policy is compact only.
>>>
>>> Even if we assume that windowed aggregations are dominant and
>>> non-windowed aggregation are used rarely, it seems to be bad to not
>>> support the feature is a non-windowed aggregation is used. Also,
>>> non-windowed aggregation volume depends on input-stream volume that
>>> might be high.
>>>
>>> Furthermore, we support stream-table join and this requires that the
>>> stream and the table are co-partitioned. Thus, even if the table would
>>> have lower volume but the stream must be scaled out, we also need to
>>> scale out the table to preserve co-partitioning.
>>>
>>>
>>> -Matthias
>>>
>>> On 3/8/18 6:44 PM, Jun Rao wrote:
>>>> Hi, Matthis,
>>>>
>>>> My understanding is that in KStream, the only case when a changelog topic
>>>> needs to be compacted is when the corresponding input is a KTable. In all
>>>> other cases, the changelog topics are of compacted + deletion. So, if most
>>>> KTables are not high volume, there may not be a need to expand its
>>>> partitions and therefore the partitions of the corresponding changelog
>>>> topic.
>>>>
>>>> Thanks,
>>>>
>>>> Jun
>>>>
>>>> On Wed, Mar 7, 2018 at 2:34 PM, Matthias J. Sax <ma...@confluent.io>
>>>> wrote:
>>>>
>>>>> Jun,
>>>>>
>>>>> thanks for your comment. This should actually work for Streams, because
>>>>> we don't rely on producer "hashing" but specify the partition number
>>>>> explicitly on send().
>>>>>
>>>>> About not allowing to change the number of partition for changelog
>>>>> topics: for Streams, this seems to imply that we need to create a second
>>>>> changelog topic for each store with the new partition count. However, it
>>>>> would be unclear when/if we can delete the old topic. Thus, it moves the
>>>>> "problem" into the application layer. It's hard to judge for me atm what
>>>>> the impact would be, but it's something we should pay attention to.
>>>>>
>>>>>
>>>>> -Matthias
>>>>>
>>>>> On 3/6/18 3:45 PM, Jun Rao wrote:
>>>>>> Hi, Mattias,
>>>>>>
>>>>>> Regarding your comment "If it would be time-delay based, it might be
>>>>>> problematic
>>>>>> for Kafka Streams: if we get the information that the new input
>>>>> partitions
>>>>>> are available for producing, we need to enable the new changelog
>>>>> partitions
>>>>>> for producing, too. If those would not be available yet, because the
>>>>>> time-delay did not trigger yet, it would be problematic to avoid
>>>>>> crashing.", could you just enable the changelog topic to write to its new
>>>>>> partitions immediately?  The input topic can be configured with a delay
>>>>> in
>>>>>> writing to the new partitions. Initially, there won't be new data
>>>>> produced
>>>>>> into the newly added partitions in the input topic. However, we could
>>>>>> prebuild the state for the new input partition and write the state
>>>>> changes
>>>>>> to the corresponding new partitions in the changelog topic.
>>>>>>
>>>>>> Hi, Jan,
>>>>>>
>>>>>> For a compacted topic, garbage collecting the old keys in the existing
>>>>>> partitions after partition expansion can be tricky as your pointed out. A
>>>>>> few options here. (a) Let brokers exchange keys across brokers during
>>>>>> compaction. This will add complexity on the broker side. (b) Build an
>>>>>> external tool that scans the compacted topic and drop the prefix of a
>>>>>> partition if all records in the prefix are removable. The admin can then
>>>>>> run this tool when the unneeded space needs to be reclaimed. (c) Don't
>>>>>> support partition change in a compacted topic. This might be ok since
>>>>> most
>>>>>> compacted topics are not high volume.
>>>>>>
>>>>>> Thanks,
>>>>>>
>>>>>> Jun
>>>>>>
>>>>>>
>>>>>> On Tue, Mar 6, 2018 at 10:38 AM, Dong Lin <li...@gmail.com> wrote:
>>>>>>
>>>>>>> Hi everyone,
>>>>>>>
>>>>>>> Thanks for all the comments! It appears that everyone prefers linear
>>>>>>> hashing because it reduces the amount of state that needs to be moved
>>>>>>> between consumers (for stream processing). The KIP has been updated to
>>>>> use
>>>>>>> linear hashing.
>>>>>>>
>>>>>>> Regarding the migration endeavor: it seems that migrating producer
>>>>> library
>>>>>>> to use linear hashing should be pretty straightforward without
>>>>>>> much operational endeavor. If we don't upgrade client library to use
>>>>> this
>>>>>>> KIP, we can not support in-order delivery after partition is changed
>>>>>>> anyway. Suppose we upgrade client library to use this KIP, if partition
>>>>>>> number is not changed, the key -> partition mapping will be exactly the
>>>>>>> same as it is now because it is still determined using murmur_hash(key)
>>>>> %
>>>>>>> original_partition_num. In other words, this change is backward
>>>>> compatible.
>>>>>>>
>>>>>>> Regarding the load distribution: if we use linear hashing, the load may
>>>>> be
>>>>>>> unevenly distributed because those partitions which are not split may
>>>>>>> receive twice as much traffic as other partitions that are split. This
>>>>>>> issue can be mitigated by creating topic with partitions that are
>>>>> several
>>>>>>> times the number of consumers. And there will be no imbalance if the
>>>>>>> partition number is always doubled. So this imbalance seems acceptable.
>>>>>>>
>>>>>>> Regarding storing the partition strategy as per-topic config: It seems
>>>>> not
>>>>>>> necessary since we can still use murmur_hash as the default hash
>>>>> function
>>>>>>> and additionally apply the linear hashing algorithm if the partition
>>>>> number
>>>>>>> has increased. Not sure if there is any use-case for producer to use a
>>>>>>> different hash function. Jason, can you check if there is some use-case
>>>>>>> that I missed for using the per-topic partition strategy?
>>>>>>>
>>>>>>> Regarding how to reduce latency (due to state store/load) in stream
>>>>>>> processing consumer when partition number changes: I need to read the
>>>>> Kafka
>>>>>>> Stream code to understand how Kafka Stream currently migrate state
>>>>> between
>>>>>>> consumers when the application is added/removed for a given job. I will
>>>>>>> reply after I finish reading the documentation and code.
>>>>>>>
>>>>>>>
>>>>>>> Thanks,
>>>>>>> Dong
>>>>>>>
>>>>>>>
>>>>>>> On Mon, Mar 5, 2018 at 10:43 AM, Jason Gustafson <ja...@confluent.io>
>>>>>>> wrote:
>>>>>>>
>>>>>>>> Great discussion. I think I'm wondering whether we can continue to
>>>>> leave
>>>>>>>> Kafka agnostic to the partitioning strategy. The challenge is
>>>>>>> communicating
>>>>>>>> the partitioning logic from producers to consumers so that the
>>>>>>> dependencies
>>>>>>>> between each epoch can be determined. For the sake of discussion,
>>>>> imagine
>>>>>>>> you did something like the following:
>>>>>>>>
>>>>>>>> 1. The name (and perhaps version) of a partitioning strategy is stored
>>>>> in
>>>>>>>> topic configuration when a topic is created.
>>>>>>>> 2. The producer looks up the partitioning strategy before writing to a
>>>>>>>> topic and includes it in the produce request (for fencing). If it
>>>>> doesn't
>>>>>>>> have an implementation for the configured strategy, it fails.
>>>>>>>> 3. The consumer also looks up the partitioning strategy and uses it to
>>>>>>>> determine dependencies when reading a new epoch. It could either fail
>>>>> or
>>>>>>>> make the most conservative dependency assumptions if it doesn't know
>>>>> how
>>>>>>> to
>>>>>>>> implement the partitioning strategy. For the consumer, the new
>>>>> interface
>>>>>>>> might look something like this:
>>>>>>>>
>>>>>>>> // Return the partition dependencies following an epoch bump
>>>>>>>> Map<Integer, List<Integer>> dependencies(int
>>>>>>> numPartitionsBeforeEpochBump,
>>>>>>>> int numPartitionsAfterEpochBump)
>>>>>>>>
>>>>>>>> The unordered case then is just a particular implementation which never
>>>>>>> has
>>>>>>>> any epoch dependencies. To implement this, we would need some way for
>>>>> the
>>>>>>>> consumer to find out how many partitions there were in each epoch, but
>>>>>>>> maybe that's not too unreasonable.
>>>>>>>>
>>>>>>>> Thanks,
>>>>>>>> Jason
>>>>>>>>
>>>>>>>>
>>>>>>>> On Mon, Mar 5, 2018 at 4:51 AM, Jan Filipiak <Jan.Filipiak@trivago.com
>>>>>>
>>>>>>>> wrote:
>>>>>>>>
>>>>>>>>> Hi Dong
>>>>>>>>>
>>>>>>>>> thank you very much for your questions.
>>>>>>>>>
>>>>>>>>> regarding the time spend copying data across:
>>>>>>>>> It is correct that copying data from a topic with one partition
>>>>> mapping
>>>>>>>> to
>>>>>>>>> a topic with a different partition mapping takes way longer than we
>>>>> can
>>>>>>>>> stop producers. Tens of minutes is a very optimistic estimate here.
>>>>>>> Many
>>>>>>>>> people can not afford copy full steam and therefore will have some
>>>>> rate
>>>>>>>>> limiting in place, this can bump the timespan into the day's. The good
>>>>>>>> part
>>>>>>>>> is that the vast majority of the data can be copied while the
>>>>> producers
>>>>>>>> are
>>>>>>>>> still going. One can then, piggyback the consumers ontop of this
>>>>>>>> timeframe,
>>>>>>>>> by the method mentioned (provide them an mapping from their old
>>>>> offsets
>>>>>>>> to
>>>>>>>>> new offsets in their repartitioned topics. In that way we separate
>>>>>>>>> migration of consumers from migration of producers (decoupling these
>>>>> is
>>>>>>>>> what kafka is strongest at). The time to actually swap over the
>>>>>>> producers
>>>>>>>>> should be kept minimal by ensuring that when a swap attempt is started
>>>>>>>> the
>>>>>>>>> consumer copying over should be very close to the log end and is
>>>>>>> expected
>>>>>>>>> to finish within the next fetch. The operation should have a time-out
>>>>>>> and
>>>>>>>>> should be "reattemtable".
>>>>>>>>>
>>>>>>>>> Importance of logcompaction:
>>>>>>>>> If a producer produces key A, to partiton 0, its forever gonna be
>>>>>>> there,
>>>>>>>>> unless it gets deleted. The record might sit in there for years. A new
>>>>>>>>> producer started with the new partitions will fail to delete the
>>>>> record
>>>>>>>> in
>>>>>>>>> the correct partition. Th record will be there forever and one can not
>>>>>>>>> reliable bootstrap new consumers. I cannot see how linear hashing can
>>>>>>>> solve
>>>>>>>>> this.
>>>>>>>>>
>>>>>>>>> Regarding your skipping of userland copying:
>>>>>>>>> 100%, copying the data across in userland is, as far as i can see,
>>>>>>> only a
>>>>>>>>> usecase for log compacted topics. Even for logcompaction + retentions
>>>>>>> it
>>>>>>>>> should only be opt-in. Why did I bring it up? I think log compaction
>>>>>>> is a
>>>>>>>>> very important feature to really embrace kafka as a "data plattform".
>>>>>>> The
>>>>>>>>> point I also want to make is that copying data this way is completely
>>>>>>>>> inline with the kafka architecture. it only consists of reading and
>>>>>>>> writing
>>>>>>>>> to topics.
>>>>>>>>>
>>>>>>>>> I hope it clarifies more why I think we should aim for more than the
>>>>>>>>> current KIP. I fear that once the KIP is done not much more effort
>>>>> will
>>>>>>>> be
>>>>>>>>> taken.
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> On 04.03.2018 02:28, Dong Lin wrote:
>>>>>>>>>
>>>>>>>>>> Hey Jan,
>>>>>>>>>>
>>>>>>>>>> In the current proposal, the consumer will be blocked on waiting for
>>>>>>>> other
>>>>>>>>>> consumers of the group to consume up to a given offset. In most
>>>>> cases,
>>>>>>>> all
>>>>>>>>>> consumers should be close to the LEO of the partitions when the
>>>>>>>> partition
>>>>>>>>>> expansion happens. Thus the time waiting should not be long e.g. on
>>>>>>> the
>>>>>>>>>> order of seconds. On the other hand, it may take a long time to wait
>>>>>>> for
>>>>>>>>>> the entire partition to be copied -- the amount of time is
>>>>>>> proportional
>>>>>>>> to
>>>>>>>>>> the amount of existing data in the partition, which can take tens of
>>>>>>>>>> minutes. So the amount of time that we stop consumers may not be on
>>>>>>> the
>>>>>>>>>> same order of magnitude.
>>>>>>>>>>
>>>>>>>>>> If we can implement this suggestion without copying data over in
>>>>> purse
>>>>>>>>>> userland, it will be much more valuable. Do you have ideas on how
>>>>> this
>>>>>>>> can
>>>>>>>>>> be done?
>>>>>>>>>>
>>>>>>>>>> Not sure why the current KIP not help people who depend on log
>>>>>>>> compaction.
>>>>>>>>>> Could you elaborate more on this point?
>>>>>>>>>>
>>>>>>>>>> Thanks,
>>>>>>>>>> Dong
>>>>>>>>>>
>>>>>>>>>> On Wed, Feb 28, 2018 at 10:55 PM, Jan Filipiak<Jan.Filipiak@trivago.
>>>>>>> com
>>>>>>>>>
>>>>>>>>>> wrote:
>>>>>>>>>>
>>>>>>>>>> Hi Dong,
>>>>>>>>>>>
>>>>>>>>>>> I tried to focus on what the steps are one can currently perform to
>>>>>>>>>>> expand
>>>>>>>>>>> or shrink a keyed topic while maintaining a top notch semantics.
>>>>>>>>>>> I can understand that there might be confusion about "stopping the
>>>>>>>>>>> consumer". It is exactly the same as proposed in the KIP. there
>>>>> needs
>>>>>>>> to
>>>>>>>>>>> be
>>>>>>>>>>> a time the producers agree on the new partitioning. The extra
>>>>>>>> semantics I
>>>>>>>>>>> want to put in there is that we have a possibility to wait until all
>>>>>>>> the
>>>>>>>>>>> existing data
>>>>>>>>>>> is copied over into the new partitioning scheme. When I say stopping
>>>>>>> I
>>>>>>>>>>> think more of having a memory barrier that ensures the ordering. I
>>>>> am
>>>>>>>>>>> still
>>>>>>>>>>> aming for latencies  on the scale of leader failovers.
>>>>>>>>>>>
>>>>>>>>>>> Consumers have to explicitly adapt the new partitioning scheme in
>>>>> the
>>>>>>>>>>> above scenario. The reason is that in these cases where you are
>>>>>>>> dependent
>>>>>>>>>>> on a particular partitioning scheme, you also have other topics that
>>>>>>>> have
>>>>>>>>>>> co-partition enforcements or the kind -frequently. Therefore all
>>>>> your
>>>>>>>>>>> other
>>>>>>>>>>> input topics might need to grow accordingly.
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> What I was suggesting was to streamline all these operations as best
>>>>>>> as
>>>>>>>>>>> possible to have "real" partition grow and shrinkage going on.
>>>>>>>> Migrating
>>>>>>>>>>> the producers to a new partitioning scheme can be much more
>>>>>>> streamlined
>>>>>>>>>>> with proper broker support for this. Migrating consumer is a step
>>>>>>> that
>>>>>>>>>>> might be made completly unnecessary if - for example streams - takes
>>>>>>>> the
>>>>>>>>>>> gcd as partitioning scheme instead of enforcing 1 to 1. Connect
>>>>>>>> consumers
>>>>>>>>>>> and other consumers should be fine anyways.
>>>>>>>>>>>
>>>>>>>>>>> I hope this makes more clear where I was aiming at. The rest needs
>>>>> to
>>>>>>>> be
>>>>>>>>>>> figured out. The only danger i see is that when we are introducing
>>>>>>> this
>>>>>>>>>>> feature as supposed in the KIP, it wont help any people depending on
>>>>>>>> log
>>>>>>>>>>> compaction.
>>>>>>>>>>>
>>>>>>>>>>> The other thing I wanted to mention is that I believe the current
>>>>>>>>>>> suggestion (without copying data over) can be implemented in pure
>>>>>>>>>>> userland
>>>>>>>>>>> with a custom partitioner and a small feedbackloop from
>>>>>>> ProduceResponse
>>>>>>>>>>> =>
>>>>>>>>>>> Partitionier in coorporation with a change management system.
>>>>>>>>>>>
>>>>>>>>>>> Best Jan
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> On 28.02.2018 07:13, Dong Lin wrote:
>>>>>>>>>>>
>>>>>>>>>>> Hey Jan,
>>>>>>>>>>>>
>>>>>>>>>>>> I am not sure if it is acceptable for producer to be stopped for a
>>>>>>>>>>>> while,
>>>>>>>>>>>> particularly for online application which requires low latency. I
>>>>> am
>>>>>>>>>>>> also
>>>>>>>>>>>> not sure how consumers can switch to a new topic. Does user
>>>>>>>> application
>>>>>>>>>>>> needs to explicitly specify a different topic for producer/consumer
>>>>>>> to
>>>>>>>>>>>> subscribe to? It will be helpful for discussion if you can provide
>>>>>>>> more
>>>>>>>>>>>> detail on the interface change for this solution.
>>>>>>>>>>>>
>>>>>>>>>>>> Thanks,
>>>>>>>>>>>> Dong
>>>>>>>>>>>>
>>>>>>>>>>>> On Mon, Feb 26, 2018 at 12:48 AM, Jan
>>>>> Filipiak<Jan.Filipiak@trivago.
>>>>>>>> com
>>>>>>>>>>>>>
>>>>>>>>>>>> wrote:
>>>>>>>>>>>>
>>>>>>>>>>>> Hi,
>>>>>>>>>>>>
>>>>>>>>>>>>> just want to throw my though in. In general the functionality is
>>>>>>> very
>>>>>>>>>>>>> usefull, we should though not try to find the architecture to hard
>>>>>>>>>>>>> while
>>>>>>>>>>>>> implementing.
>>>>>>>>>>>>>
>>>>>>>>>>>>> The manual steps would be to
>>>>>>>>>>>>>
>>>>>>>>>>>>> create a new topic
>>>>>>>>>>>>> the mirrormake from the new old topic to the new topic
>>>>>>>>>>>>> wait for mirror making to catch up.
>>>>>>>>>>>>> then put the consumers onto the new topic
>>>>>>>>>>>>>       (having mirrormaker spit out a mapping from old offsets to
>>>>>>> new
>>>>>>>>>>>>> offsets:
>>>>>>>>>>>>>           if topic is increased by factor X there is gonna be a
>>>>>>> clean
>>>>>>>>>>>>> mapping from 1 offset in the old topic to X offsets in the new
>>>>>>> topic,
>>>>>>>>>>>>>           if there is no factor then there is no chance to
>>>>>>> generate a
>>>>>>>>>>>>> mapping that can be reasonable used for continuing)
>>>>>>>>>>>>>       make consumers stop at appropriate points and continue
>>>>>>>>>>>>> consumption
>>>>>>>>>>>>> with offsets from the mapping.
>>>>>>>>>>>>> have the producers stop for a minimal time.
>>>>>>>>>>>>> wait for mirrormaker to finish
>>>>>>>>>>>>> let producer produce with the new metadata.
>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>> Instead of implementing the approach suggest in the KIP which will
>>>>>>>>>>>>> leave
>>>>>>>>>>>>> log compacted topic completely crumbled and unusable.
>>>>>>>>>>>>> I would much rather try to build infrastructure to support the
>>>>>>>>>>>>> mentioned
>>>>>>>>>>>>> above operations more smoothly.
>>>>>>>>>>>>> Especially having producers stop and use another topic is
>>>>> difficult
>>>>>>>> and
>>>>>>>>>>>>> it would be nice if one can trigger "invalid metadata" exceptions
>>>>>>> for
>>>>>>>>>>>>> them
>>>>>>>>>>>>> and
>>>>>>>>>>>>> if one could give topics aliases so that their produces with the
>>>>>>> old
>>>>>>>>>>>>> topic
>>>>>>>>>>>>> will arrive in the new topic.
>>>>>>>>>>>>>
>>>>>>>>>>>>> The downsides are obvious I guess ( having the same data twice for
>>>>>>>> the
>>>>>>>>>>>>> transition period, but kafka tends to scale well with datasize).
>>>>> So
>>>>>>>>>>>>> its a
>>>>>>>>>>>>> nicer fit into the architecture.
>>>>>>>>>>>>>
>>>>>>>>>>>>> I further want to argument that the functionality by the KIP can
>>>>>>>>>>>>> completely be implementing in "userland" with a custom partitioner
>>>>>>>> that
>>>>>>>>>>>>> handles the transition as needed. I would appreciate if someone
>>>>>>> could
>>>>>>>>>>>>> point
>>>>>>>>>>>>> out what a custom partitioner couldn't handle in this case?
>>>>>>>>>>>>>
>>>>>>>>>>>>> With the above approach, shrinking a topic becomes the same steps.
>>>>>>>>>>>>> Without
>>>>>>>>>>>>> loosing keys in the discontinued partitions.
>>>>>>>>>>>>>
>>>>>>>>>>>>> Would love to hear what everyone thinks.
>>>>>>>>>>>>>
>>>>>>>>>>>>> Best Jan
>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>> On 11.02.2018 00:35, Dong Lin wrote:
>>>>>>>>>>>>>
>>>>>>>>>>>>> Hi all,
>>>>>>>>>>>>>
>>>>>>>>>>>>>> I have created KIP-253: Support in-order message delivery with
>>>>>>>>>>>>>> partition
>>>>>>>>>>>>>> expansion. See
>>>>>>>>>>>>>> https://cwiki.apache.org/confluence/display/KAFKA/KIP-253%
>>>>>>>>>>>>>> 3A+Support+in-order+message+delivery+with+partition+expansion
>>>>>>>>>>>>>> .
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> This KIP provides a way to allow messages of the same key from
>>>>> the
>>>>>>>>>>>>>> same
>>>>>>>>>>>>>> producer to be consumed in the same order they are produced even
>>>>>>> if
>>>>>>>> we
>>>>>>>>>>>>>> expand partition of the topic.
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> Thanks,
>>>>>>>>>>>>>> Dong
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>
>>>>>>>>>
>>>>>>>>
>>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>
>>>
>>
> 
> 


Re: [DISCUSS] KIP-253: Support in-order message delivery with partition expansion

Posted by Clemens Valiente <Cl...@trivago.com>.
I think it's fair to assume that topics will always be increased by an integer factor - e.g. from 2 partitions to 4 partitions. Then the mapping is much easier.

Why anyone would increase partitions by lass than x2 is a mystery to me. If your two partitions cannot handle the load, then with three partitions each one will still get 67% of that load which is still way too dangerous.


So in your case we go from

part1: A B C D

part2: E F G H


to


part1: A C

part2: B D

part3: E F

part4: G H


________________________________
From: Matthias J. Sax <ma...@confluent.io>
Sent: 09 March 2018 07:53
To: dev@kafka.apache.org
Subject: Re: [DISCUSS] KIP-253: Support in-order message delivery with partition expansion

@Jan: You suggest to copy the data from one topic to a new topic, and
provide an "offset mapping" from the old to the new topic for the
consumers. I don't quite understand how this would work.

Let's say there are 2 partitions in the original topic and 3 partitions
in the new topic. If we assume that we don't use linear hashing as you
suggest, there is no guarantee how data will be distributed in the new
topic and also no guarantee about ordering of records in the new topic.

Example (I hope I got it right -- please correct me if it's wrong)

A B C D
E F G H

could be copied to:

A C H
B E F
D G

If the consumer was at offset 1 and 2 in the first topic how would the
mapping be computed? We need to enures that B C D as well as G H are
read after the switch. Thus, offset would need to be 1 0 0. I am not
sure how this would be computed?

Furthermore, I want to point out that the new offsets would imply that E
is consumed a second time by the consumer. E and F were consumed
originally, but E is copied after B that was not yet consumed.

Or is there a way that we can ensure that this "flip" does never happen
while we copy the data?


-Matthias



On 3/8/18 10:32 PM, Matthias J. Sax wrote:
> As I just mentioned joins:
>
> For Kafka Streams it might also be required to change the partition
> count for multiple topics in a coordinated way that allows to maintain
> the co-partitioning property that Kafka Streams uses to computed joins.
>
> Any thoughts how this could be handled?
>
>
> -Matthias
>
> On 3/8/18 10:08 PM, Matthias J. Sax wrote:
>> Jun,
>>
>> There is one more case: non-windowed aggregations. For windowed
>> aggregation, the changelog topic will be compact+delete. However, for
>> non-windowed aggregation the policy is compact only.
>>
>> Even if we assume that windowed aggregations are dominant and
>> non-windowed aggregation are used rarely, it seems to be bad to not
>> support the feature is a non-windowed aggregation is used. Also,
>> non-windowed aggregation volume depends on input-stream volume that
>> might be high.
>>
>> Furthermore, we support stream-table join and this requires that the
>> stream and the table are co-partitioned. Thus, even if the table would
>> have lower volume but the stream must be scaled out, we also need to
>> scale out the table to preserve co-partitioning.
>>
>>
>> -Matthias
>>
>> On 3/8/18 6:44 PM, Jun Rao wrote:
>>> Hi, Matthis,
>>>
>>> My understanding is that in KStream, the only case when a changelog topic
>>> needs to be compacted is when the corresponding input is a KTable. In all
>>> other cases, the changelog topics are of compacted + deletion. So, if most
>>> KTables are not high volume, there may not be a need to expand its
>>> partitions and therefore the partitions of the corresponding changelog
>>> topic.
>>>
>>> Thanks,
>>>
>>> Jun
>>>
>>> On Wed, Mar 7, 2018 at 2:34 PM, Matthias J. Sax <ma...@confluent.io>
>>> wrote:
>>>
>>>> Jun,
>>>>
>>>> thanks for your comment. This should actually work for Streams, because
>>>> we don't rely on producer "hashing" but specify the partition number
>>>> explicitly on send().
>>>>
>>>> About not allowing to change the number of partition for changelog
>>>> topics: for Streams, this seems to imply that we need to create a second
>>>> changelog topic for each store with the new partition count. However, it
>>>> would be unclear when/if we can delete the old topic. Thus, it moves the
>>>> "problem" into the application layer. It's hard to judge for me atm what
>>>> the impact would be, but it's something we should pay attention to.
>>>>
>>>>
>>>> -Matthias
>>>>
>>>> On 3/6/18 3:45 PM, Jun Rao wrote:
>>>>> Hi, Mattias,
>>>>>
>>>>> Regarding your comment "If it would be time-delay based, it might be
>>>>> problematic
>>>>> for Kafka Streams: if we get the information that the new input
>>>> partitions
>>>>> are available for producing, we need to enable the new changelog
>>>> partitions
>>>>> for producing, too. If those would not be available yet, because the
>>>>> time-delay did not trigger yet, it would be problematic to avoid
>>>>> crashing.", could you just enable the changelog topic to write to its new
>>>>> partitions immediately?  The input topic can be configured with a delay
>>>> in
>>>>> writing to the new partitions. Initially, there won't be new data
>>>> produced
>>>>> into the newly added partitions in the input topic. However, we could
>>>>> prebuild the state for the new input partition and write the state
>>>> changes
>>>>> to the corresponding new partitions in the changelog topic.
>>>>>
>>>>> Hi, Jan,
>>>>>
>>>>> For a compacted topic, garbage collecting the old keys in the existing
>>>>> partitions after partition expansion can be tricky as your pointed out. A
>>>>> few options here. (a) Let brokers exchange keys across brokers during
>>>>> compaction. This will add complexity on the broker side. (b) Build an
>>>>> external tool that scans the compacted topic and drop the prefix of a
>>>>> partition if all records in the prefix are removable. The admin can then
>>>>> run this tool when the unneeded space needs to be reclaimed. (c) Don't
>>>>> support partition change in a compacted topic. This might be ok since
>>>> most
>>>>> compacted topics are not high volume.
>>>>>
>>>>> Thanks,
>>>>>
>>>>> Jun
>>>>>
>>>>>
>>>>> On Tue, Mar 6, 2018 at 10:38 AM, Dong Lin <li...@gmail.com> wrote:
>>>>>
>>>>>> Hi everyone,
>>>>>>
>>>>>> Thanks for all the comments! It appears that everyone prefers linear
>>>>>> hashing because it reduces the amount of state that needs to be moved
>>>>>> between consumers (for stream processing). The KIP has been updated to
>>>> use
>>>>>> linear hashing.
>>>>>>
>>>>>> Regarding the migration endeavor: it seems that migrating producer
>>>> library
>>>>>> to use linear hashing should be pretty straightforward without
>>>>>> much operational endeavor. If we don't upgrade client library to use
>>>> this
>>>>>> KIP, we can not support in-order delivery after partition is changed
>>>>>> anyway. Suppose we upgrade client library to use this KIP, if partition
>>>>>> number is not changed, the key -> partition mapping will be exactly the
>>>>>> same as it is now because it is still determined using murmur_hash(key)
>>>> %
>>>>>> original_partition_num. In other words, this change is backward
>>>> compatible.
>>>>>>
>>>>>> Regarding the load distribution: if we use linear hashing, the load may
>>>> be
>>>>>> unevenly distributed because those partitions which are not split may
>>>>>> receive twice as much traffic as other partitions that are split. This
>>>>>> issue can be mitigated by creating topic with partitions that are
>>>> several
>>>>>> times the number of consumers. And there will be no imbalance if the
>>>>>> partition number is always doubled. So this imbalance seems acceptable.
>>>>>>
>>>>>> Regarding storing the partition strategy as per-topic config: It seems
>>>> not
>>>>>> necessary since we can still use murmur_hash as the default hash
>>>> function
>>>>>> and additionally apply the linear hashing algorithm if the partition
>>>> number
>>>>>> has increased. Not sure if there is any use-case for producer to use a
>>>>>> different hash function. Jason, can you check if there is some use-case
>>>>>> that I missed for using the per-topic partition strategy?
>>>>>>
>>>>>> Regarding how to reduce latency (due to state store/load) in stream
>>>>>> processing consumer when partition number changes: I need to read the
>>>> Kafka
>>>>>> Stream code to understand how Kafka Stream currently migrate state
>>>> between
>>>>>> consumers when the application is added/removed for a given job. I will
>>>>>> reply after I finish reading the documentation and code.
>>>>>>
>>>>>>
>>>>>> Thanks,
>>>>>> Dong
>>>>>>
>>>>>>
>>>>>> On Mon, Mar 5, 2018 at 10:43 AM, Jason Gustafson <ja...@confluent.io>
>>>>>> wrote:
>>>>>>
>>>>>>> Great discussion. I think I'm wondering whether we can continue to
>>>> leave
>>>>>>> Kafka agnostic to the partitioning strategy. The challenge is
>>>>>> communicating
>>>>>>> the partitioning logic from producers to consumers so that the
>>>>>> dependencies
>>>>>>> between each epoch can be determined. For the sake of discussion,
>>>> imagine
>>>>>>> you did something like the following:
>>>>>>>
>>>>>>> 1. The name (and perhaps version) of a partitioning strategy is stored
>>>> in
>>>>>>> topic configuration when a topic is created.
>>>>>>> 2. The producer looks up the partitioning strategy before writing to a
>>>>>>> topic and includes it in the produce request (for fencing). If it
>>>> doesn't
>>>>>>> have an implementation for the configured strategy, it fails.
>>>>>>> 3. The consumer also looks up the partitioning strategy and uses it to
>>>>>>> determine dependencies when reading a new epoch. It could either fail
>>>> or
>>>>>>> make the most conservative dependency assumptions if it doesn't know
>>>> how
>>>>>> to
>>>>>>> implement the partitioning strategy. For the consumer, the new
>>>> interface
>>>>>>> might look something like this:
>>>>>>>
>>>>>>> // Return the partition dependencies following an epoch bump
>>>>>>> Map<Integer, List<Integer>> dependencies(int
>>>>>> numPartitionsBeforeEpochBump,
>>>>>>> int numPartitionsAfterEpochBump)
>>>>>>>
>>>>>>> The unordered case then is just a particular implementation which never
>>>>>> has
>>>>>>> any epoch dependencies. To implement this, we would need some way for
>>>> the
>>>>>>> consumer to find out how many partitions there were in each epoch, but
>>>>>>> maybe that's not too unreasonable.
>>>>>>>
>>>>>>> Thanks,
>>>>>>> Jason
>>>>>>>
>>>>>>>
>>>>>>> On Mon, Mar 5, 2018 at 4:51 AM, Jan Filipiak <Jan.Filipiak@trivago.com
>>>>>
>>>>>>> wrote:
>>>>>>>
>>>>>>>> Hi Dong
>>>>>>>>
>>>>>>>> thank you very much for your questions.
>>>>>>>>
>>>>>>>> regarding the time spend copying data across:
>>>>>>>> It is correct that copying data from a topic with one partition
>>>> mapping
>>>>>>> to
>>>>>>>> a topic with a different partition mapping takes way longer than we
>>>> can
>>>>>>>> stop producers. Tens of minutes is a very optimistic estimate here.
>>>>>> Many
>>>>>>>> people can not afford copy full steam and therefore will have some
>>>> rate
>>>>>>>> limiting in place, this can bump the timespan into the day's. The good
>>>>>>> part
>>>>>>>> is that the vast majority of the data can be copied while the
>>>> producers
>>>>>>> are
>>>>>>>> still going. One can then, piggyback the consumers ontop of this
>>>>>>> timeframe,
>>>>>>>> by the method mentioned (provide them an mapping from their old
>>>> offsets
>>>>>>> to
>>>>>>>> new offsets in their repartitioned topics. In that way we separate
>>>>>>>> migration of consumers from migration of producers (decoupling these
>>>> is
>>>>>>>> what kafka is strongest at). The time to actually swap over the
>>>>>> producers
>>>>>>>> should be kept minimal by ensuring that when a swap attempt is started
>>>>>>> the
>>>>>>>> consumer copying over should be very close to the log end and is
>>>>>> expected
>>>>>>>> to finish within the next fetch. The operation should have a time-out
>>>>>> and
>>>>>>>> should be "reattemtable".
>>>>>>>>
>>>>>>>> Importance of logcompaction:
>>>>>>>> If a producer produces key A, to partiton 0, its forever gonna be
>>>>>> there,
>>>>>>>> unless it gets deleted. The record might sit in there for years. A new
>>>>>>>> producer started with the new partitions will fail to delete the
>>>> record
>>>>>>> in
>>>>>>>> the correct partition. Th record will be there forever and one can not
>>>>>>>> reliable bootstrap new consumers. I cannot see how linear hashing can
>>>>>>> solve
>>>>>>>> this.
>>>>>>>>
>>>>>>>> Regarding your skipping of userland copying:
>>>>>>>> 100%, copying the data across in userland is, as far as i can see,
>>>>>> only a
>>>>>>>> usecase for log compacted topics. Even for logcompaction + retentions
>>>>>> it
>>>>>>>> should only be opt-in. Why did I bring it up? I think log compaction
>>>>>> is a
>>>>>>>> very important feature to really embrace kafka as a "data plattform".
>>>>>> The
>>>>>>>> point I also want to make is that copying data this way is completely
>>>>>>>> inline with the kafka architecture. it only consists of reading and
>>>>>>> writing
>>>>>>>> to topics.
>>>>>>>>
>>>>>>>> I hope it clarifies more why I think we should aim for more than the
>>>>>>>> current KIP. I fear that once the KIP is done not much more effort
>>>> will
>>>>>>> be
>>>>>>>> taken.
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> On 04.03.2018 02:28, Dong Lin wrote:
>>>>>>>>
>>>>>>>>> Hey Jan,
>>>>>>>>>
>>>>>>>>> In the current proposal, the consumer will be blocked on waiting for
>>>>>>> other
>>>>>>>>> consumers of the group to consume up to a given offset. In most
>>>> cases,
>>>>>>> all
>>>>>>>>> consumers should be close to the LEO of the partitions when the
>>>>>>> partition
>>>>>>>>> expansion happens. Thus the time waiting should not be long e.g. on
>>>>>> the
>>>>>>>>> order of seconds. On the other hand, it may take a long time to wait
>>>>>> for
>>>>>>>>> the entire partition to be copied -- the amount of time is
>>>>>> proportional
>>>>>>> to
>>>>>>>>> the amount of existing data in the partition, which can take tens of
>>>>>>>>> minutes. So the amount of time that we stop consumers may not be on
>>>>>> the
>>>>>>>>> same order of magnitude.
>>>>>>>>>
>>>>>>>>> If we can implement this suggestion without copying data over in
>>>> purse
>>>>>>>>> userland, it will be much more valuable. Do you have ideas on how
>>>> this
>>>>>>> can
>>>>>>>>> be done?
>>>>>>>>>
>>>>>>>>> Not sure why the current KIP not help people who depend on log
>>>>>>> compaction.
>>>>>>>>> Could you elaborate more on this point?
>>>>>>>>>
>>>>>>>>> Thanks,
>>>>>>>>> Dong
>>>>>>>>>
>>>>>>>>> On Wed, Feb 28, 2018 at 10:55 PM, Jan Filipiak<Jan.Filipiak@trivago.
>>>>>> com
>>>>>>>>
>>>>>>>>> wrote:
>>>>>>>>>
>>>>>>>>> Hi Dong,
>>>>>>>>>>
>>>>>>>>>> I tried to focus on what the steps are one can currently perform to
>>>>>>>>>> expand
>>>>>>>>>> or shrink a keyed topic while maintaining a top notch semantics.
>>>>>>>>>> I can understand that there might be confusion about "stopping the
>>>>>>>>>> consumer". It is exactly the same as proposed in the KIP. there
>>>> needs
>>>>>>> to
>>>>>>>>>> be
>>>>>>>>>> a time the producers agree on the new partitioning. The extra
>>>>>>> semantics I
>>>>>>>>>> want to put in there is that we have a possibility to wait until all
>>>>>>> the
>>>>>>>>>> existing data
>>>>>>>>>> is copied over into the new partitioning scheme. When I say stopping
>>>>>> I
>>>>>>>>>> think more of having a memory barrier that ensures the ordering. I
>>>> am
>>>>>>>>>> still
>>>>>>>>>> aming for latencies  on the scale of leader failovers.
>>>>>>>>>>
>>>>>>>>>> Consumers have to explicitly adapt the new partitioning scheme in
>>>> the
>>>>>>>>>> above scenario. The reason is that in these cases where you are
>>>>>>> dependent
>>>>>>>>>> on a particular partitioning scheme, you also have other topics that
>>>>>>> have
>>>>>>>>>> co-partition enforcements or the kind -frequently. Therefore all
>>>> your
>>>>>>>>>> other
>>>>>>>>>> input topics might need to grow accordingly.
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> What I was suggesting was to streamline all these operations as best
>>>>>> as
>>>>>>>>>> possible to have "real" partition grow and shrinkage going on.
>>>>>>> Migrating
>>>>>>>>>> the producers to a new partitioning scheme can be much more
>>>>>> streamlined
>>>>>>>>>> with proper broker support for this. Migrating consumer is a step
>>>>>> that
>>>>>>>>>> might be made completly unnecessary if - for example streams - takes
>>>>>>> the
>>>>>>>>>> gcd as partitioning scheme instead of enforcing 1 to 1. Connect
>>>>>>> consumers
>>>>>>>>>> and other consumers should be fine anyways.
>>>>>>>>>>
>>>>>>>>>> I hope this makes more clear where I was aiming at. The rest needs
>>>> to
>>>>>>> be
>>>>>>>>>> figured out. The only danger i see is that when we are introducing
>>>>>> this
>>>>>>>>>> feature as supposed in the KIP, it wont help any people depending on
>>>>>>> log
>>>>>>>>>> compaction.
>>>>>>>>>>
>>>>>>>>>> The other thing I wanted to mention is that I believe the current
>>>>>>>>>> suggestion (without copying data over) can be implemented in pure
>>>>>>>>>> userland
>>>>>>>>>> with a custom partitioner and a small feedbackloop from
>>>>>> ProduceResponse
>>>>>>>>>> =>
>>>>>>>>>> Partitionier in coorporation with a change management system.
>>>>>>>>>>
>>>>>>>>>> Best Jan
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> On 28.02.2018 07:13, Dong Lin wrote:
>>>>>>>>>>
>>>>>>>>>> Hey Jan,
>>>>>>>>>>>
>>>>>>>>>>> I am not sure if it is acceptable for producer to be stopped for a
>>>>>>>>>>> while,
>>>>>>>>>>> particularly for online application which requires low latency. I
>>>> am
>>>>>>>>>>> also
>>>>>>>>>>> not sure how consumers can switch to a new topic. Does user
>>>>>>> application
>>>>>>>>>>> needs to explicitly specify a different topic for producer/consumer
>>>>>> to
>>>>>>>>>>> subscribe to? It will be helpful for discussion if you can provide
>>>>>>> more
>>>>>>>>>>> detail on the interface change for this solution.
>>>>>>>>>>>
>>>>>>>>>>> Thanks,
>>>>>>>>>>> Dong
>>>>>>>>>>>
>>>>>>>>>>> On Mon, Feb 26, 2018 at 12:48 AM, Jan
>>>> Filipiak<Jan.Filipiak@trivago.
>>>>>>> com
>>>>>>>>>>>>
>>>>>>>>>>> wrote:
>>>>>>>>>>>
>>>>>>>>>>> Hi,
>>>>>>>>>>>
>>>>>>>>>>>> just want to throw my though in. In general the functionality is
>>>>>> very
>>>>>>>>>>>> usefull, we should though not try to find the architecture to hard
>>>>>>>>>>>> while
>>>>>>>>>>>> implementing.
>>>>>>>>>>>>
>>>>>>>>>>>> The manual steps would be to
>>>>>>>>>>>>
>>>>>>>>>>>> create a new topic
>>>>>>>>>>>> the mirrormake from the new old topic to the new topic
>>>>>>>>>>>> wait for mirror making to catch up.
>>>>>>>>>>>> then put the consumers onto the new topic
>>>>>>>>>>>>       (having mirrormaker spit out a mapping from old offsets to
>>>>>> new
>>>>>>>>>>>> offsets:
>>>>>>>>>>>>           if topic is increased by factor X there is gonna be a
>>>>>> clean
>>>>>>>>>>>> mapping from 1 offset in the old topic to X offsets in the new
>>>>>> topic,
>>>>>>>>>>>>           if there is no factor then there is no chance to
>>>>>> generate a
>>>>>>>>>>>> mapping that can be reasonable used for continuing)
>>>>>>>>>>>>       make consumers stop at appropriate points and continue
>>>>>>>>>>>> consumption
>>>>>>>>>>>> with offsets from the mapping.
>>>>>>>>>>>> have the producers stop for a minimal time.
>>>>>>>>>>>> wait for mirrormaker to finish
>>>>>>>>>>>> let producer produce with the new metadata.
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>> Instead of implementing the approach suggest in the KIP which will
>>>>>>>>>>>> leave
>>>>>>>>>>>> log compacted topic completely crumbled and unusable.
>>>>>>>>>>>> I would much rather try to build infrastructure to support the
>>>>>>>>>>>> mentioned
>>>>>>>>>>>> above operations more smoothly.
>>>>>>>>>>>> Especially having producers stop and use another topic is
>>>> difficult
>>>>>>> and
>>>>>>>>>>>> it would be nice if one can trigger "invalid metadata" exceptions
>>>>>> for
>>>>>>>>>>>> them
>>>>>>>>>>>> and
>>>>>>>>>>>> if one could give topics aliases so that their produces with the
>>>>>> old
>>>>>>>>>>>> topic
>>>>>>>>>>>> will arrive in the new topic.
>>>>>>>>>>>>
>>>>>>>>>>>> The downsides are obvious I guess ( having the same data twice for
>>>>>>> the
>>>>>>>>>>>> transition period, but kafka tends to scale well with datasize).
>>>> So
>>>>>>>>>>>> its a
>>>>>>>>>>>> nicer fit into the architecture.
>>>>>>>>>>>>
>>>>>>>>>>>> I further want to argument that the functionality by the KIP can
>>>>>>>>>>>> completely be implementing in "userland" with a custom partitioner
>>>>>>> that
>>>>>>>>>>>> handles the transition as needed. I would appreciate if someone
>>>>>> could
>>>>>>>>>>>> point
>>>>>>>>>>>> out what a custom partitioner couldn't handle in this case?
>>>>>>>>>>>>
>>>>>>>>>>>> With the above approach, shrinking a topic becomes the same steps.
>>>>>>>>>>>> Without
>>>>>>>>>>>> loosing keys in the discontinued partitions.
>>>>>>>>>>>>
>>>>>>>>>>>> Would love to hear what everyone thinks.
>>>>>>>>>>>>
>>>>>>>>>>>> Best Jan
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>> On 11.02.2018 00:35, Dong Lin wrote:
>>>>>>>>>>>>
>>>>>>>>>>>> Hi all,
>>>>>>>>>>>>
>>>>>>>>>>>>> I have created KIP-253: Support in-order message delivery with
>>>>>>>>>>>>> partition
>>>>>>>>>>>>> expansion. See
>>>>>>>>>>>>> https://cwiki.apache.org/confluence/display/KAFKA/KIP-253%
>>>>>>>>>>>>> 3A+Support+in-order+message+delivery+with+partition+expansion
>>>>>>>>>>>>> .
>>>>>>>>>>>>>
>>>>>>>>>>>>> This KIP provides a way to allow messages of the same key from
>>>> the
>>>>>>>>>>>>> same
>>>>>>>>>>>>> producer to be consumed in the same order they are produced even
>>>>>> if
>>>>>>> we
>>>>>>>>>>>>> expand partition of the topic.
>>>>>>>>>>>>>
>>>>>>>>>>>>> Thanks,
>>>>>>>>>>>>> Dong
>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>
>>>>>>>
>>>>>>
>>>>>
>>>>
>>>>
>>>
>>
>


Re: [DISCUSS] KIP-253: Support in-order message delivery with partition expansion

Posted by "Matthias J. Sax" <ma...@confluent.io>.
@Jan: You suggest to copy the data from one topic to a new topic, and
provide an "offset mapping" from the old to the new topic for the
consumers. I don't quite understand how this would work.

Let's say there are 2 partitions in the original topic and 3 partitions
in the new topic. If we assume that we don't use linear hashing as you
suggest, there is no guarantee how data will be distributed in the new
topic and also no guarantee about ordering of records in the new topic.

Example (I hope I got it right -- please correct me if it's wrong)

A B C D
E F G H

could be copied to:

A C H
B E F
D G

If the consumer was at offset 1 and 2 in the first topic how would the
mapping be computed? We need to enures that B C D as well as G H are
read after the switch. Thus, offset would need to be 1 0 0. I am not
sure how this would be computed?

Furthermore, I want to point out that the new offsets would imply that E
is consumed a second time by the consumer. E and F were consumed
originally, but E is copied after B that was not yet consumed.

Or is there a way that we can ensure that this "flip" does never happen
while we copy the data?


-Matthias



On 3/8/18 10:32 PM, Matthias J. Sax wrote:
> As I just mentioned joins:
> 
> For Kafka Streams it might also be required to change the partition
> count for multiple topics in a coordinated way that allows to maintain
> the co-partitioning property that Kafka Streams uses to computed joins.
> 
> Any thoughts how this could be handled?
> 
> 
> -Matthias
> 
> On 3/8/18 10:08 PM, Matthias J. Sax wrote:
>> Jun,
>>
>> There is one more case: non-windowed aggregations. For windowed
>> aggregation, the changelog topic will be compact+delete. However, for
>> non-windowed aggregation the policy is compact only.
>>
>> Even if we assume that windowed aggregations are dominant and
>> non-windowed aggregation are used rarely, it seems to be bad to not
>> support the feature is a non-windowed aggregation is used. Also,
>> non-windowed aggregation volume depends on input-stream volume that
>> might be high.
>>
>> Furthermore, we support stream-table join and this requires that the
>> stream and the table are co-partitioned. Thus, even if the table would
>> have lower volume but the stream must be scaled out, we also need to
>> scale out the table to preserve co-partitioning.
>>
>>
>> -Matthias
>>
>> On 3/8/18 6:44 PM, Jun Rao wrote:
>>> Hi, Matthis,
>>>
>>> My understanding is that in KStream, the only case when a changelog topic
>>> needs to be compacted is when the corresponding input is a KTable. In all
>>> other cases, the changelog topics are of compacted + deletion. So, if most
>>> KTables are not high volume, there may not be a need to expand its
>>> partitions and therefore the partitions of the corresponding changelog
>>> topic.
>>>
>>> Thanks,
>>>
>>> Jun
>>>
>>> On Wed, Mar 7, 2018 at 2:34 PM, Matthias J. Sax <ma...@confluent.io>
>>> wrote:
>>>
>>>> Jun,
>>>>
>>>> thanks for your comment. This should actually work for Streams, because
>>>> we don't rely on producer "hashing" but specify the partition number
>>>> explicitly on send().
>>>>
>>>> About not allowing to change the number of partition for changelog
>>>> topics: for Streams, this seems to imply that we need to create a second
>>>> changelog topic for each store with the new partition count. However, it
>>>> would be unclear when/if we can delete the old topic. Thus, it moves the
>>>> "problem" into the application layer. It's hard to judge for me atm what
>>>> the impact would be, but it's something we should pay attention to.
>>>>
>>>>
>>>> -Matthias
>>>>
>>>> On 3/6/18 3:45 PM, Jun Rao wrote:
>>>>> Hi, Mattias,
>>>>>
>>>>> Regarding your comment "If it would be time-delay based, it might be
>>>>> problematic
>>>>> for Kafka Streams: if we get the information that the new input
>>>> partitions
>>>>> are available for producing, we need to enable the new changelog
>>>> partitions
>>>>> for producing, too. If those would not be available yet, because the
>>>>> time-delay did not trigger yet, it would be problematic to avoid
>>>>> crashing.", could you just enable the changelog topic to write to its new
>>>>> partitions immediately?  The input topic can be configured with a delay
>>>> in
>>>>> writing to the new partitions. Initially, there won't be new data
>>>> produced
>>>>> into the newly added partitions in the input topic. However, we could
>>>>> prebuild the state for the new input partition and write the state
>>>> changes
>>>>> to the corresponding new partitions in the changelog topic.
>>>>>
>>>>> Hi, Jan,
>>>>>
>>>>> For a compacted topic, garbage collecting the old keys in the existing
>>>>> partitions after partition expansion can be tricky as your pointed out. A
>>>>> few options here. (a) Let brokers exchange keys across brokers during
>>>>> compaction. This will add complexity on the broker side. (b) Build an
>>>>> external tool that scans the compacted topic and drop the prefix of a
>>>>> partition if all records in the prefix are removable. The admin can then
>>>>> run this tool when the unneeded space needs to be reclaimed. (c) Don't
>>>>> support partition change in a compacted topic. This might be ok since
>>>> most
>>>>> compacted topics are not high volume.
>>>>>
>>>>> Thanks,
>>>>>
>>>>> Jun
>>>>>
>>>>>
>>>>> On Tue, Mar 6, 2018 at 10:38 AM, Dong Lin <li...@gmail.com> wrote:
>>>>>
>>>>>> Hi everyone,
>>>>>>
>>>>>> Thanks for all the comments! It appears that everyone prefers linear
>>>>>> hashing because it reduces the amount of state that needs to be moved
>>>>>> between consumers (for stream processing). The KIP has been updated to
>>>> use
>>>>>> linear hashing.
>>>>>>
>>>>>> Regarding the migration endeavor: it seems that migrating producer
>>>> library
>>>>>> to use linear hashing should be pretty straightforward without
>>>>>> much operational endeavor. If we don't upgrade client library to use
>>>> this
>>>>>> KIP, we can not support in-order delivery after partition is changed
>>>>>> anyway. Suppose we upgrade client library to use this KIP, if partition
>>>>>> number is not changed, the key -> partition mapping will be exactly the
>>>>>> same as it is now because it is still determined using murmur_hash(key)
>>>> %
>>>>>> original_partition_num. In other words, this change is backward
>>>> compatible.
>>>>>>
>>>>>> Regarding the load distribution: if we use linear hashing, the load may
>>>> be
>>>>>> unevenly distributed because those partitions which are not split may
>>>>>> receive twice as much traffic as other partitions that are split. This
>>>>>> issue can be mitigated by creating topic with partitions that are
>>>> several
>>>>>> times the number of consumers. And there will be no imbalance if the
>>>>>> partition number is always doubled. So this imbalance seems acceptable.
>>>>>>
>>>>>> Regarding storing the partition strategy as per-topic config: It seems
>>>> not
>>>>>> necessary since we can still use murmur_hash as the default hash
>>>> function
>>>>>> and additionally apply the linear hashing algorithm if the partition
>>>> number
>>>>>> has increased. Not sure if there is any use-case for producer to use a
>>>>>> different hash function. Jason, can you check if there is some use-case
>>>>>> that I missed for using the per-topic partition strategy?
>>>>>>
>>>>>> Regarding how to reduce latency (due to state store/load) in stream
>>>>>> processing consumer when partition number changes: I need to read the
>>>> Kafka
>>>>>> Stream code to understand how Kafka Stream currently migrate state
>>>> between
>>>>>> consumers when the application is added/removed for a given job. I will
>>>>>> reply after I finish reading the documentation and code.
>>>>>>
>>>>>>
>>>>>> Thanks,
>>>>>> Dong
>>>>>>
>>>>>>
>>>>>> On Mon, Mar 5, 2018 at 10:43 AM, Jason Gustafson <ja...@confluent.io>
>>>>>> wrote:
>>>>>>
>>>>>>> Great discussion. I think I'm wondering whether we can continue to
>>>> leave
>>>>>>> Kafka agnostic to the partitioning strategy. The challenge is
>>>>>> communicating
>>>>>>> the partitioning logic from producers to consumers so that the
>>>>>> dependencies
>>>>>>> between each epoch can be determined. For the sake of discussion,
>>>> imagine
>>>>>>> you did something like the following:
>>>>>>>
>>>>>>> 1. The name (and perhaps version) of a partitioning strategy is stored
>>>> in
>>>>>>> topic configuration when a topic is created.
>>>>>>> 2. The producer looks up the partitioning strategy before writing to a
>>>>>>> topic and includes it in the produce request (for fencing). If it
>>>> doesn't
>>>>>>> have an implementation for the configured strategy, it fails.
>>>>>>> 3. The consumer also looks up the partitioning strategy and uses it to
>>>>>>> determine dependencies when reading a new epoch. It could either fail
>>>> or
>>>>>>> make the most conservative dependency assumptions if it doesn't know
>>>> how
>>>>>> to
>>>>>>> implement the partitioning strategy. For the consumer, the new
>>>> interface
>>>>>>> might look something like this:
>>>>>>>
>>>>>>> // Return the partition dependencies following an epoch bump
>>>>>>> Map<Integer, List<Integer>> dependencies(int
>>>>>> numPartitionsBeforeEpochBump,
>>>>>>> int numPartitionsAfterEpochBump)
>>>>>>>
>>>>>>> The unordered case then is just a particular implementation which never
>>>>>> has
>>>>>>> any epoch dependencies. To implement this, we would need some way for
>>>> the
>>>>>>> consumer to find out how many partitions there were in each epoch, but
>>>>>>> maybe that's not too unreasonable.
>>>>>>>
>>>>>>> Thanks,
>>>>>>> Jason
>>>>>>>
>>>>>>>
>>>>>>> On Mon, Mar 5, 2018 at 4:51 AM, Jan Filipiak <Jan.Filipiak@trivago.com
>>>>>
>>>>>>> wrote:
>>>>>>>
>>>>>>>> Hi Dong
>>>>>>>>
>>>>>>>> thank you very much for your questions.
>>>>>>>>
>>>>>>>> regarding the time spend copying data across:
>>>>>>>> It is correct that copying data from a topic with one partition
>>>> mapping
>>>>>>> to
>>>>>>>> a topic with a different partition mapping takes way longer than we
>>>> can
>>>>>>>> stop producers. Tens of minutes is a very optimistic estimate here.
>>>>>> Many
>>>>>>>> people can not afford copy full steam and therefore will have some
>>>> rate
>>>>>>>> limiting in place, this can bump the timespan into the day's. The good
>>>>>>> part
>>>>>>>> is that the vast majority of the data can be copied while the
>>>> producers
>>>>>>> are
>>>>>>>> still going. One can then, piggyback the consumers ontop of this
>>>>>>> timeframe,
>>>>>>>> by the method mentioned (provide them an mapping from their old
>>>> offsets
>>>>>>> to
>>>>>>>> new offsets in their repartitioned topics. In that way we separate
>>>>>>>> migration of consumers from migration of producers (decoupling these
>>>> is
>>>>>>>> what kafka is strongest at). The time to actually swap over the
>>>>>> producers
>>>>>>>> should be kept minimal by ensuring that when a swap attempt is started
>>>>>>> the
>>>>>>>> consumer copying over should be very close to the log end and is
>>>>>> expected
>>>>>>>> to finish within the next fetch. The operation should have a time-out
>>>>>> and
>>>>>>>> should be "reattemtable".
>>>>>>>>
>>>>>>>> Importance of logcompaction:
>>>>>>>> If a producer produces key A, to partiton 0, its forever gonna be
>>>>>> there,
>>>>>>>> unless it gets deleted. The record might sit in there for years. A new
>>>>>>>> producer started with the new partitions will fail to delete the
>>>> record
>>>>>>> in
>>>>>>>> the correct partition. Th record will be there forever and one can not
>>>>>>>> reliable bootstrap new consumers. I cannot see how linear hashing can
>>>>>>> solve
>>>>>>>> this.
>>>>>>>>
>>>>>>>> Regarding your skipping of userland copying:
>>>>>>>> 100%, copying the data across in userland is, as far as i can see,
>>>>>> only a
>>>>>>>> usecase for log compacted topics. Even for logcompaction + retentions
>>>>>> it
>>>>>>>> should only be opt-in. Why did I bring it up? I think log compaction
>>>>>> is a
>>>>>>>> very important feature to really embrace kafka as a "data plattform".
>>>>>> The
>>>>>>>> point I also want to make is that copying data this way is completely
>>>>>>>> inline with the kafka architecture. it only consists of reading and
>>>>>>> writing
>>>>>>>> to topics.
>>>>>>>>
>>>>>>>> I hope it clarifies more why I think we should aim for more than the
>>>>>>>> current KIP. I fear that once the KIP is done not much more effort
>>>> will
>>>>>>> be
>>>>>>>> taken.
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> On 04.03.2018 02:28, Dong Lin wrote:
>>>>>>>>
>>>>>>>>> Hey Jan,
>>>>>>>>>
>>>>>>>>> In the current proposal, the consumer will be blocked on waiting for
>>>>>>> other
>>>>>>>>> consumers of the group to consume up to a given offset. In most
>>>> cases,
>>>>>>> all
>>>>>>>>> consumers should be close to the LEO of the partitions when the
>>>>>>> partition
>>>>>>>>> expansion happens. Thus the time waiting should not be long e.g. on
>>>>>> the
>>>>>>>>> order of seconds. On the other hand, it may take a long time to wait
>>>>>> for
>>>>>>>>> the entire partition to be copied -- the amount of time is
>>>>>> proportional
>>>>>>> to
>>>>>>>>> the amount of existing data in the partition, which can take tens of
>>>>>>>>> minutes. So the amount of time that we stop consumers may not be on
>>>>>> the
>>>>>>>>> same order of magnitude.
>>>>>>>>>
>>>>>>>>> If we can implement this suggestion without copying data over in
>>>> purse
>>>>>>>>> userland, it will be much more valuable. Do you have ideas on how
>>>> this
>>>>>>> can
>>>>>>>>> be done?
>>>>>>>>>
>>>>>>>>> Not sure why the current KIP not help people who depend on log
>>>>>>> compaction.
>>>>>>>>> Could you elaborate more on this point?
>>>>>>>>>
>>>>>>>>> Thanks,
>>>>>>>>> Dong
>>>>>>>>>
>>>>>>>>> On Wed, Feb 28, 2018 at 10:55 PM, Jan Filipiak<Jan.Filipiak@trivago.
>>>>>> com
>>>>>>>>
>>>>>>>>> wrote:
>>>>>>>>>
>>>>>>>>> Hi Dong,
>>>>>>>>>>
>>>>>>>>>> I tried to focus on what the steps are one can currently perform to
>>>>>>>>>> expand
>>>>>>>>>> or shrink a keyed topic while maintaining a top notch semantics.
>>>>>>>>>> I can understand that there might be confusion about "stopping the
>>>>>>>>>> consumer". It is exactly the same as proposed in the KIP. there
>>>> needs
>>>>>>> to
>>>>>>>>>> be
>>>>>>>>>> a time the producers agree on the new partitioning. The extra
>>>>>>> semantics I
>>>>>>>>>> want to put in there is that we have a possibility to wait until all
>>>>>>> the
>>>>>>>>>> existing data
>>>>>>>>>> is copied over into the new partitioning scheme. When I say stopping
>>>>>> I
>>>>>>>>>> think more of having a memory barrier that ensures the ordering. I
>>>> am
>>>>>>>>>> still
>>>>>>>>>> aming for latencies  on the scale of leader failovers.
>>>>>>>>>>
>>>>>>>>>> Consumers have to explicitly adapt the new partitioning scheme in
>>>> the
>>>>>>>>>> above scenario. The reason is that in these cases where you are
>>>>>>> dependent
>>>>>>>>>> on a particular partitioning scheme, you also have other topics that
>>>>>>> have
>>>>>>>>>> co-partition enforcements or the kind -frequently. Therefore all
>>>> your
>>>>>>>>>> other
>>>>>>>>>> input topics might need to grow accordingly.
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> What I was suggesting was to streamline all these operations as best
>>>>>> as
>>>>>>>>>> possible to have "real" partition grow and shrinkage going on.
>>>>>>> Migrating
>>>>>>>>>> the producers to a new partitioning scheme can be much more
>>>>>> streamlined
>>>>>>>>>> with proper broker support for this. Migrating consumer is a step
>>>>>> that
>>>>>>>>>> might be made completly unnecessary if - for example streams - takes
>>>>>>> the
>>>>>>>>>> gcd as partitioning scheme instead of enforcing 1 to 1. Connect
>>>>>>> consumers
>>>>>>>>>> and other consumers should be fine anyways.
>>>>>>>>>>
>>>>>>>>>> I hope this makes more clear where I was aiming at. The rest needs
>>>> to
>>>>>>> be
>>>>>>>>>> figured out. The only danger i see is that when we are introducing
>>>>>> this
>>>>>>>>>> feature as supposed in the KIP, it wont help any people depending on
>>>>>>> log
>>>>>>>>>> compaction.
>>>>>>>>>>
>>>>>>>>>> The other thing I wanted to mention is that I believe the current
>>>>>>>>>> suggestion (without copying data over) can be implemented in pure
>>>>>>>>>> userland
>>>>>>>>>> with a custom partitioner and a small feedbackloop from
>>>>>> ProduceResponse
>>>>>>>>>> =>
>>>>>>>>>> Partitionier in coorporation with a change management system.
>>>>>>>>>>
>>>>>>>>>> Best Jan
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> On 28.02.2018 07:13, Dong Lin wrote:
>>>>>>>>>>
>>>>>>>>>> Hey Jan,
>>>>>>>>>>>
>>>>>>>>>>> I am not sure if it is acceptable for producer to be stopped for a
>>>>>>>>>>> while,
>>>>>>>>>>> particularly for online application which requires low latency. I
>>>> am
>>>>>>>>>>> also
>>>>>>>>>>> not sure how consumers can switch to a new topic. Does user
>>>>>>> application
>>>>>>>>>>> needs to explicitly specify a different topic for producer/consumer
>>>>>> to
>>>>>>>>>>> subscribe to? It will be helpful for discussion if you can provide
>>>>>>> more
>>>>>>>>>>> detail on the interface change for this solution.
>>>>>>>>>>>
>>>>>>>>>>> Thanks,
>>>>>>>>>>> Dong
>>>>>>>>>>>
>>>>>>>>>>> On Mon, Feb 26, 2018 at 12:48 AM, Jan
>>>> Filipiak<Jan.Filipiak@trivago.
>>>>>>> com
>>>>>>>>>>>>
>>>>>>>>>>> wrote:
>>>>>>>>>>>
>>>>>>>>>>> Hi,
>>>>>>>>>>>
>>>>>>>>>>>> just want to throw my though in. In general the functionality is
>>>>>> very
>>>>>>>>>>>> usefull, we should though not try to find the architecture to hard
>>>>>>>>>>>> while
>>>>>>>>>>>> implementing.
>>>>>>>>>>>>
>>>>>>>>>>>> The manual steps would be to
>>>>>>>>>>>>
>>>>>>>>>>>> create a new topic
>>>>>>>>>>>> the mirrormake from the new old topic to the new topic
>>>>>>>>>>>> wait for mirror making to catch up.
>>>>>>>>>>>> then put the consumers onto the new topic
>>>>>>>>>>>>       (having mirrormaker spit out a mapping from old offsets to
>>>>>> new
>>>>>>>>>>>> offsets:
>>>>>>>>>>>>           if topic is increased by factor X there is gonna be a
>>>>>> clean
>>>>>>>>>>>> mapping from 1 offset in the old topic to X offsets in the new
>>>>>> topic,
>>>>>>>>>>>>           if there is no factor then there is no chance to
>>>>>> generate a
>>>>>>>>>>>> mapping that can be reasonable used for continuing)
>>>>>>>>>>>>       make consumers stop at appropriate points and continue
>>>>>>>>>>>> consumption
>>>>>>>>>>>> with offsets from the mapping.
>>>>>>>>>>>> have the producers stop for a minimal time.
>>>>>>>>>>>> wait for mirrormaker to finish
>>>>>>>>>>>> let producer produce with the new metadata.
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>> Instead of implementing the approach suggest in the KIP which will
>>>>>>>>>>>> leave
>>>>>>>>>>>> log compacted topic completely crumbled and unusable.
>>>>>>>>>>>> I would much rather try to build infrastructure to support the
>>>>>>>>>>>> mentioned
>>>>>>>>>>>> above operations more smoothly.
>>>>>>>>>>>> Especially having producers stop and use another topic is
>>>> difficult
>>>>>>> and
>>>>>>>>>>>> it would be nice if one can trigger "invalid metadata" exceptions
>>>>>> for
>>>>>>>>>>>> them
>>>>>>>>>>>> and
>>>>>>>>>>>> if one could give topics aliases so that their produces with the
>>>>>> old
>>>>>>>>>>>> topic
>>>>>>>>>>>> will arrive in the new topic.
>>>>>>>>>>>>
>>>>>>>>>>>> The downsides are obvious I guess ( having the same data twice for
>>>>>>> the
>>>>>>>>>>>> transition period, but kafka tends to scale well with datasize).
>>>> So
>>>>>>>>>>>> its a
>>>>>>>>>>>> nicer fit into the architecture.
>>>>>>>>>>>>
>>>>>>>>>>>> I further want to argument that the functionality by the KIP can
>>>>>>>>>>>> completely be implementing in "userland" with a custom partitioner
>>>>>>> that
>>>>>>>>>>>> handles the transition as needed. I would appreciate if someone
>>>>>> could
>>>>>>>>>>>> point
>>>>>>>>>>>> out what a custom partitioner couldn't handle in this case?
>>>>>>>>>>>>
>>>>>>>>>>>> With the above approach, shrinking a topic becomes the same steps.
>>>>>>>>>>>> Without
>>>>>>>>>>>> loosing keys in the discontinued partitions.
>>>>>>>>>>>>
>>>>>>>>>>>> Would love to hear what everyone thinks.
>>>>>>>>>>>>
>>>>>>>>>>>> Best Jan
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>> On 11.02.2018 00:35, Dong Lin wrote:
>>>>>>>>>>>>
>>>>>>>>>>>> Hi all,
>>>>>>>>>>>>
>>>>>>>>>>>>> I have created KIP-253: Support in-order message delivery with
>>>>>>>>>>>>> partition
>>>>>>>>>>>>> expansion. See
>>>>>>>>>>>>> https://cwiki.apache.org/confluence/display/KAFKA/KIP-253%
>>>>>>>>>>>>> 3A+Support+in-order+message+delivery+with+partition+expansion
>>>>>>>>>>>>> .
>>>>>>>>>>>>>
>>>>>>>>>>>>> This KIP provides a way to allow messages of the same key from
>>>> the
>>>>>>>>>>>>> same
>>>>>>>>>>>>> producer to be consumed in the same order they are produced even
>>>>>> if
>>>>>>> we
>>>>>>>>>>>>> expand partition of the topic.
>>>>>>>>>>>>>
>>>>>>>>>>>>> Thanks,
>>>>>>>>>>>>> Dong
>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>
>>>>>>>
>>>>>>
>>>>>
>>>>
>>>>
>>>
>>
> 


Re: [DISCUSS] KIP-253: Support in-order message delivery with partition expansion

Posted by "Matthias J. Sax" <ma...@confluent.io>.
As I just mentioned joins:

For Kafka Streams it might also be required to change the partition
count for multiple topics in a coordinated way that allows to maintain
the co-partitioning property that Kafka Streams uses to computed joins.

Any thoughts how this could be handled?


-Matthias

On 3/8/18 10:08 PM, Matthias J. Sax wrote:
> Jun,
> 
> There is one more case: non-windowed aggregations. For windowed
> aggregation, the changelog topic will be compact+delete. However, for
> non-windowed aggregation the policy is compact only.
> 
> Even if we assume that windowed aggregations are dominant and
> non-windowed aggregation are used rarely, it seems to be bad to not
> support the feature is a non-windowed aggregation is used. Also,
> non-windowed aggregation volume depends on input-stream volume that
> might be high.
> 
> Furthermore, we support stream-table join and this requires that the
> stream and the table are co-partitioned. Thus, even if the table would
> have lower volume but the stream must be scaled out, we also need to
> scale out the table to preserve co-partitioning.
> 
> 
> -Matthias
> 
> On 3/8/18 6:44 PM, Jun Rao wrote:
>> Hi, Matthis,
>>
>> My understanding is that in KStream, the only case when a changelog topic
>> needs to be compacted is when the corresponding input is a KTable. In all
>> other cases, the changelog topics are of compacted + deletion. So, if most
>> KTables are not high volume, there may not be a need to expand its
>> partitions and therefore the partitions of the corresponding changelog
>> topic.
>>
>> Thanks,
>>
>> Jun
>>
>> On Wed, Mar 7, 2018 at 2:34 PM, Matthias J. Sax <ma...@confluent.io>
>> wrote:
>>
>>> Jun,
>>>
>>> thanks for your comment. This should actually work for Streams, because
>>> we don't rely on producer "hashing" but specify the partition number
>>> explicitly on send().
>>>
>>> About not allowing to change the number of partition for changelog
>>> topics: for Streams, this seems to imply that we need to create a second
>>> changelog topic for each store with the new partition count. However, it
>>> would be unclear when/if we can delete the old topic. Thus, it moves the
>>> "problem" into the application layer. It's hard to judge for me atm what
>>> the impact would be, but it's something we should pay attention to.
>>>
>>>
>>> -Matthias
>>>
>>> On 3/6/18 3:45 PM, Jun Rao wrote:
>>>> Hi, Mattias,
>>>>
>>>> Regarding your comment "If it would be time-delay based, it might be
>>>> problematic
>>>> for Kafka Streams: if we get the information that the new input
>>> partitions
>>>> are available for producing, we need to enable the new changelog
>>> partitions
>>>> for producing, too. If those would not be available yet, because the
>>>> time-delay did not trigger yet, it would be problematic to avoid
>>>> crashing.", could you just enable the changelog topic to write to its new
>>>> partitions immediately?  The input topic can be configured with a delay
>>> in
>>>> writing to the new partitions. Initially, there won't be new data
>>> produced
>>>> into the newly added partitions in the input topic. However, we could
>>>> prebuild the state for the new input partition and write the state
>>> changes
>>>> to the corresponding new partitions in the changelog topic.
>>>>
>>>> Hi, Jan,
>>>>
>>>> For a compacted topic, garbage collecting the old keys in the existing
>>>> partitions after partition expansion can be tricky as your pointed out. A
>>>> few options here. (a) Let brokers exchange keys across brokers during
>>>> compaction. This will add complexity on the broker side. (b) Build an
>>>> external tool that scans the compacted topic and drop the prefix of a
>>>> partition if all records in the prefix are removable. The admin can then
>>>> run this tool when the unneeded space needs to be reclaimed. (c) Don't
>>>> support partition change in a compacted topic. This might be ok since
>>> most
>>>> compacted topics are not high volume.
>>>>
>>>> Thanks,
>>>>
>>>> Jun
>>>>
>>>>
>>>> On Tue, Mar 6, 2018 at 10:38 AM, Dong Lin <li...@gmail.com> wrote:
>>>>
>>>>> Hi everyone,
>>>>>
>>>>> Thanks for all the comments! It appears that everyone prefers linear
>>>>> hashing because it reduces the amount of state that needs to be moved
>>>>> between consumers (for stream processing). The KIP has been updated to
>>> use
>>>>> linear hashing.
>>>>>
>>>>> Regarding the migration endeavor: it seems that migrating producer
>>> library
>>>>> to use linear hashing should be pretty straightforward without
>>>>> much operational endeavor. If we don't upgrade client library to use
>>> this
>>>>> KIP, we can not support in-order delivery after partition is changed
>>>>> anyway. Suppose we upgrade client library to use this KIP, if partition
>>>>> number is not changed, the key -> partition mapping will be exactly the
>>>>> same as it is now because it is still determined using murmur_hash(key)
>>> %
>>>>> original_partition_num. In other words, this change is backward
>>> compatible.
>>>>>
>>>>> Regarding the load distribution: if we use linear hashing, the load may
>>> be
>>>>> unevenly distributed because those partitions which are not split may
>>>>> receive twice as much traffic as other partitions that are split. This
>>>>> issue can be mitigated by creating topic with partitions that are
>>> several
>>>>> times the number of consumers. And there will be no imbalance if the
>>>>> partition number is always doubled. So this imbalance seems acceptable.
>>>>>
>>>>> Regarding storing the partition strategy as per-topic config: It seems
>>> not
>>>>> necessary since we can still use murmur_hash as the default hash
>>> function
>>>>> and additionally apply the linear hashing algorithm if the partition
>>> number
>>>>> has increased. Not sure if there is any use-case for producer to use a
>>>>> different hash function. Jason, can you check if there is some use-case
>>>>> that I missed for using the per-topic partition strategy?
>>>>>
>>>>> Regarding how to reduce latency (due to state store/load) in stream
>>>>> processing consumer when partition number changes: I need to read the
>>> Kafka
>>>>> Stream code to understand how Kafka Stream currently migrate state
>>> between
>>>>> consumers when the application is added/removed for a given job. I will
>>>>> reply after I finish reading the documentation and code.
>>>>>
>>>>>
>>>>> Thanks,
>>>>> Dong
>>>>>
>>>>>
>>>>> On Mon, Mar 5, 2018 at 10:43 AM, Jason Gustafson <ja...@confluent.io>
>>>>> wrote:
>>>>>
>>>>>> Great discussion. I think I'm wondering whether we can continue to
>>> leave
>>>>>> Kafka agnostic to the partitioning strategy. The challenge is
>>>>> communicating
>>>>>> the partitioning logic from producers to consumers so that the
>>>>> dependencies
>>>>>> between each epoch can be determined. For the sake of discussion,
>>> imagine
>>>>>> you did something like the following:
>>>>>>
>>>>>> 1. The name (and perhaps version) of a partitioning strategy is stored
>>> in
>>>>>> topic configuration when a topic is created.
>>>>>> 2. The producer looks up the partitioning strategy before writing to a
>>>>>> topic and includes it in the produce request (for fencing). If it
>>> doesn't
>>>>>> have an implementation for the configured strategy, it fails.
>>>>>> 3. The consumer also looks up the partitioning strategy and uses it to
>>>>>> determine dependencies when reading a new epoch. It could either fail
>>> or
>>>>>> make the most conservative dependency assumptions if it doesn't know
>>> how
>>>>> to
>>>>>> implement the partitioning strategy. For the consumer, the new
>>> interface
>>>>>> might look something like this:
>>>>>>
>>>>>> // Return the partition dependencies following an epoch bump
>>>>>> Map<Integer, List<Integer>> dependencies(int
>>>>> numPartitionsBeforeEpochBump,
>>>>>> int numPartitionsAfterEpochBump)
>>>>>>
>>>>>> The unordered case then is just a particular implementation which never
>>>>> has
>>>>>> any epoch dependencies. To implement this, we would need some way for
>>> the
>>>>>> consumer to find out how many partitions there were in each epoch, but
>>>>>> maybe that's not too unreasonable.
>>>>>>
>>>>>> Thanks,
>>>>>> Jason
>>>>>>
>>>>>>
>>>>>> On Mon, Mar 5, 2018 at 4:51 AM, Jan Filipiak <Jan.Filipiak@trivago.com
>>>>
>>>>>> wrote:
>>>>>>
>>>>>>> Hi Dong
>>>>>>>
>>>>>>> thank you very much for your questions.
>>>>>>>
>>>>>>> regarding the time spend copying data across:
>>>>>>> It is correct that copying data from a topic with one partition
>>> mapping
>>>>>> to
>>>>>>> a topic with a different partition mapping takes way longer than we
>>> can
>>>>>>> stop producers. Tens of minutes is a very optimistic estimate here.
>>>>> Many
>>>>>>> people can not afford copy full steam and therefore will have some
>>> rate
>>>>>>> limiting in place, this can bump the timespan into the day's. The good
>>>>>> part
>>>>>>> is that the vast majority of the data can be copied while the
>>> producers
>>>>>> are
>>>>>>> still going. One can then, piggyback the consumers ontop of this
>>>>>> timeframe,
>>>>>>> by the method mentioned (provide them an mapping from their old
>>> offsets
>>>>>> to
>>>>>>> new offsets in their repartitioned topics. In that way we separate
>>>>>>> migration of consumers from migration of producers (decoupling these
>>> is
>>>>>>> what kafka is strongest at). The time to actually swap over the
>>>>> producers
>>>>>>> should be kept minimal by ensuring that when a swap attempt is started
>>>>>> the
>>>>>>> consumer copying over should be very close to the log end and is
>>>>> expected
>>>>>>> to finish within the next fetch. The operation should have a time-out
>>>>> and
>>>>>>> should be "reattemtable".
>>>>>>>
>>>>>>> Importance of logcompaction:
>>>>>>> If a producer produces key A, to partiton 0, its forever gonna be
>>>>> there,
>>>>>>> unless it gets deleted. The record might sit in there for years. A new
>>>>>>> producer started with the new partitions will fail to delete the
>>> record
>>>>>> in
>>>>>>> the correct partition. Th record will be there forever and one can not
>>>>>>> reliable bootstrap new consumers. I cannot see how linear hashing can
>>>>>> solve
>>>>>>> this.
>>>>>>>
>>>>>>> Regarding your skipping of userland copying:
>>>>>>> 100%, copying the data across in userland is, as far as i can see,
>>>>> only a
>>>>>>> usecase for log compacted topics. Even for logcompaction + retentions
>>>>> it
>>>>>>> should only be opt-in. Why did I bring it up? I think log compaction
>>>>> is a
>>>>>>> very important feature to really embrace kafka as a "data plattform".
>>>>> The
>>>>>>> point I also want to make is that copying data this way is completely
>>>>>>> inline with the kafka architecture. it only consists of reading and
>>>>>> writing
>>>>>>> to topics.
>>>>>>>
>>>>>>> I hope it clarifies more why I think we should aim for more than the
>>>>>>> current KIP. I fear that once the KIP is done not much more effort
>>> will
>>>>>> be
>>>>>>> taken.
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> On 04.03.2018 02:28, Dong Lin wrote:
>>>>>>>
>>>>>>>> Hey Jan,
>>>>>>>>
>>>>>>>> In the current proposal, the consumer will be blocked on waiting for
>>>>>> other
>>>>>>>> consumers of the group to consume up to a given offset. In most
>>> cases,
>>>>>> all
>>>>>>>> consumers should be close to the LEO of the partitions when the
>>>>>> partition
>>>>>>>> expansion happens. Thus the time waiting should not be long e.g. on
>>>>> the
>>>>>>>> order of seconds. On the other hand, it may take a long time to wait
>>>>> for
>>>>>>>> the entire partition to be copied -- the amount of time is
>>>>> proportional
>>>>>> to
>>>>>>>> the amount of existing data in the partition, which can take tens of
>>>>>>>> minutes. So the amount of time that we stop consumers may not be on
>>>>> the
>>>>>>>> same order of magnitude.
>>>>>>>>
>>>>>>>> If we can implement this suggestion without copying data over in
>>> purse
>>>>>>>> userland, it will be much more valuable. Do you have ideas on how
>>> this
>>>>>> can
>>>>>>>> be done?
>>>>>>>>
>>>>>>>> Not sure why the current KIP not help people who depend on log
>>>>>> compaction.
>>>>>>>> Could you elaborate more on this point?
>>>>>>>>
>>>>>>>> Thanks,
>>>>>>>> Dong
>>>>>>>>
>>>>>>>> On Wed, Feb 28, 2018 at 10:55 PM, Jan Filipiak<Jan.Filipiak@trivago.
>>>>> com
>>>>>>>
>>>>>>>> wrote:
>>>>>>>>
>>>>>>>> Hi Dong,
>>>>>>>>>
>>>>>>>>> I tried to focus on what the steps are one can currently perform to
>>>>>>>>> expand
>>>>>>>>> or shrink a keyed topic while maintaining a top notch semantics.
>>>>>>>>> I can understand that there might be confusion about "stopping the
>>>>>>>>> consumer". It is exactly the same as proposed in the KIP. there
>>> needs
>>>>>> to
>>>>>>>>> be
>>>>>>>>> a time the producers agree on the new partitioning. The extra
>>>>>> semantics I
>>>>>>>>> want to put in there is that we have a possibility to wait until all
>>>>>> the
>>>>>>>>> existing data
>>>>>>>>> is copied over into the new partitioning scheme. When I say stopping
>>>>> I
>>>>>>>>> think more of having a memory barrier that ensures the ordering. I
>>> am
>>>>>>>>> still
>>>>>>>>> aming for latencies  on the scale of leader failovers.
>>>>>>>>>
>>>>>>>>> Consumers have to explicitly adapt the new partitioning scheme in
>>> the
>>>>>>>>> above scenario. The reason is that in these cases where you are
>>>>>> dependent
>>>>>>>>> on a particular partitioning scheme, you also have other topics that
>>>>>> have
>>>>>>>>> co-partition enforcements or the kind -frequently. Therefore all
>>> your
>>>>>>>>> other
>>>>>>>>> input topics might need to grow accordingly.
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> What I was suggesting was to streamline all these operations as best
>>>>> as
>>>>>>>>> possible to have "real" partition grow and shrinkage going on.
>>>>>> Migrating
>>>>>>>>> the producers to a new partitioning scheme can be much more
>>>>> streamlined
>>>>>>>>> with proper broker support for this. Migrating consumer is a step
>>>>> that
>>>>>>>>> might be made completly unnecessary if - for example streams - takes
>>>>>> the
>>>>>>>>> gcd as partitioning scheme instead of enforcing 1 to 1. Connect
>>>>>> consumers
>>>>>>>>> and other consumers should be fine anyways.
>>>>>>>>>
>>>>>>>>> I hope this makes more clear where I was aiming at. The rest needs
>>> to
>>>>>> be
>>>>>>>>> figured out. The only danger i see is that when we are introducing
>>>>> this
>>>>>>>>> feature as supposed in the KIP, it wont help any people depending on
>>>>>> log
>>>>>>>>> compaction.
>>>>>>>>>
>>>>>>>>> The other thing I wanted to mention is that I believe the current
>>>>>>>>> suggestion (without copying data over) can be implemented in pure
>>>>>>>>> userland
>>>>>>>>> with a custom partitioner and a small feedbackloop from
>>>>> ProduceResponse
>>>>>>>>> =>
>>>>>>>>> Partitionier in coorporation with a change management system.
>>>>>>>>>
>>>>>>>>> Best Jan
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> On 28.02.2018 07:13, Dong Lin wrote:
>>>>>>>>>
>>>>>>>>> Hey Jan,
>>>>>>>>>>
>>>>>>>>>> I am not sure if it is acceptable for producer to be stopped for a
>>>>>>>>>> while,
>>>>>>>>>> particularly for online application which requires low latency. I
>>> am
>>>>>>>>>> also
>>>>>>>>>> not sure how consumers can switch to a new topic. Does user
>>>>>> application
>>>>>>>>>> needs to explicitly specify a different topic for producer/consumer
>>>>> to
>>>>>>>>>> subscribe to? It will be helpful for discussion if you can provide
>>>>>> more
>>>>>>>>>> detail on the interface change for this solution.
>>>>>>>>>>
>>>>>>>>>> Thanks,
>>>>>>>>>> Dong
>>>>>>>>>>
>>>>>>>>>> On Mon, Feb 26, 2018 at 12:48 AM, Jan
>>> Filipiak<Jan.Filipiak@trivago.
>>>>>> com
>>>>>>>>>>>
>>>>>>>>>> wrote:
>>>>>>>>>>
>>>>>>>>>> Hi,
>>>>>>>>>>
>>>>>>>>>>> just want to throw my though in. In general the functionality is
>>>>> very
>>>>>>>>>>> usefull, we should though not try to find the architecture to hard
>>>>>>>>>>> while
>>>>>>>>>>> implementing.
>>>>>>>>>>>
>>>>>>>>>>> The manual steps would be to
>>>>>>>>>>>
>>>>>>>>>>> create a new topic
>>>>>>>>>>> the mirrormake from the new old topic to the new topic
>>>>>>>>>>> wait for mirror making to catch up.
>>>>>>>>>>> then put the consumers onto the new topic
>>>>>>>>>>>       (having mirrormaker spit out a mapping from old offsets to
>>>>> new
>>>>>>>>>>> offsets:
>>>>>>>>>>>           if topic is increased by factor X there is gonna be a
>>>>> clean
>>>>>>>>>>> mapping from 1 offset in the old topic to X offsets in the new
>>>>> topic,
>>>>>>>>>>>           if there is no factor then there is no chance to
>>>>> generate a
>>>>>>>>>>> mapping that can be reasonable used for continuing)
>>>>>>>>>>>       make consumers stop at appropriate points and continue
>>>>>>>>>>> consumption
>>>>>>>>>>> with offsets from the mapping.
>>>>>>>>>>> have the producers stop for a minimal time.
>>>>>>>>>>> wait for mirrormaker to finish
>>>>>>>>>>> let producer produce with the new metadata.
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> Instead of implementing the approach suggest in the KIP which will
>>>>>>>>>>> leave
>>>>>>>>>>> log compacted topic completely crumbled and unusable.
>>>>>>>>>>> I would much rather try to build infrastructure to support the
>>>>>>>>>>> mentioned
>>>>>>>>>>> above operations more smoothly.
>>>>>>>>>>> Especially having producers stop and use another topic is
>>> difficult
>>>>>> and
>>>>>>>>>>> it would be nice if one can trigger "invalid metadata" exceptions
>>>>> for
>>>>>>>>>>> them
>>>>>>>>>>> and
>>>>>>>>>>> if one could give topics aliases so that their produces with the
>>>>> old
>>>>>>>>>>> topic
>>>>>>>>>>> will arrive in the new topic.
>>>>>>>>>>>
>>>>>>>>>>> The downsides are obvious I guess ( having the same data twice for
>>>>>> the
>>>>>>>>>>> transition period, but kafka tends to scale well with datasize).
>>> So
>>>>>>>>>>> its a
>>>>>>>>>>> nicer fit into the architecture.
>>>>>>>>>>>
>>>>>>>>>>> I further want to argument that the functionality by the KIP can
>>>>>>>>>>> completely be implementing in "userland" with a custom partitioner
>>>>>> that
>>>>>>>>>>> handles the transition as needed. I would appreciate if someone
>>>>> could
>>>>>>>>>>> point
>>>>>>>>>>> out what a custom partitioner couldn't handle in this case?
>>>>>>>>>>>
>>>>>>>>>>> With the above approach, shrinking a topic becomes the same steps.
>>>>>>>>>>> Without
>>>>>>>>>>> loosing keys in the discontinued partitions.
>>>>>>>>>>>
>>>>>>>>>>> Would love to hear what everyone thinks.
>>>>>>>>>>>
>>>>>>>>>>> Best Jan
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> On 11.02.2018 00:35, Dong Lin wrote:
>>>>>>>>>>>
>>>>>>>>>>> Hi all,
>>>>>>>>>>>
>>>>>>>>>>>> I have created KIP-253: Support in-order message delivery with
>>>>>>>>>>>> partition
>>>>>>>>>>>> expansion. See
>>>>>>>>>>>> https://cwiki.apache.org/confluence/display/KAFKA/KIP-253%
>>>>>>>>>>>> 3A+Support+in-order+message+delivery+with+partition+expansion
>>>>>>>>>>>> .
>>>>>>>>>>>>
>>>>>>>>>>>> This KIP provides a way to allow messages of the same key from
>>> the
>>>>>>>>>>>> same
>>>>>>>>>>>> producer to be consumed in the same order they are produced even
>>>>> if
>>>>>> we
>>>>>>>>>>>> expand partition of the topic.
>>>>>>>>>>>>
>>>>>>>>>>>> Thanks,
>>>>>>>>>>>> Dong
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>
>>>>>>
>>>>>
>>>>
>>>
>>>
>>
> 


Re: [DISCUSS] KIP-253: Support in-order message delivery with partition expansion

Posted by "Matthias J. Sax" <ma...@confluent.io>.
Jun,

There is one more case: non-windowed aggregations. For windowed
aggregation, the changelog topic will be compact+delete. However, for
non-windowed aggregation the policy is compact only.

Even if we assume that windowed aggregations are dominant and
non-windowed aggregation are used rarely, it seems to be bad to not
support the feature is a non-windowed aggregation is used. Also,
non-windowed aggregation volume depends on input-stream volume that
might be high.

Furthermore, we support stream-table join and this requires that the
stream and the table are co-partitioned. Thus, even if the table would
have lower volume but the stream must be scaled out, we also need to
scale out the table to preserve co-partitioning.


-Matthias

On 3/8/18 6:44 PM, Jun Rao wrote:
> Hi, Matthis,
> 
> My understanding is that in KStream, the only case when a changelog topic
> needs to be compacted is when the corresponding input is a KTable. In all
> other cases, the changelog topics are of compacted + deletion. So, if most
> KTables are not high volume, there may not be a need to expand its
> partitions and therefore the partitions of the corresponding changelog
> topic.
> 
> Thanks,
> 
> Jun
> 
> On Wed, Mar 7, 2018 at 2:34 PM, Matthias J. Sax <ma...@confluent.io>
> wrote:
> 
>> Jun,
>>
>> thanks for your comment. This should actually work for Streams, because
>> we don't rely on producer "hashing" but specify the partition number
>> explicitly on send().
>>
>> About not allowing to change the number of partition for changelog
>> topics: for Streams, this seems to imply that we need to create a second
>> changelog topic for each store with the new partition count. However, it
>> would be unclear when/if we can delete the old topic. Thus, it moves the
>> "problem" into the application layer. It's hard to judge for me atm what
>> the impact would be, but it's something we should pay attention to.
>>
>>
>> -Matthias
>>
>> On 3/6/18 3:45 PM, Jun Rao wrote:
>>> Hi, Mattias,
>>>
>>> Regarding your comment "If it would be time-delay based, it might be
>>> problematic
>>> for Kafka Streams: if we get the information that the new input
>> partitions
>>> are available for producing, we need to enable the new changelog
>> partitions
>>> for producing, too. If those would not be available yet, because the
>>> time-delay did not trigger yet, it would be problematic to avoid
>>> crashing.", could you just enable the changelog topic to write to its new
>>> partitions immediately?  The input topic can be configured with a delay
>> in
>>> writing to the new partitions. Initially, there won't be new data
>> produced
>>> into the newly added partitions in the input topic. However, we could
>>> prebuild the state for the new input partition and write the state
>> changes
>>> to the corresponding new partitions in the changelog topic.
>>>
>>> Hi, Jan,
>>>
>>> For a compacted topic, garbage collecting the old keys in the existing
>>> partitions after partition expansion can be tricky as your pointed out. A
>>> few options here. (a) Let brokers exchange keys across brokers during
>>> compaction. This will add complexity on the broker side. (b) Build an
>>> external tool that scans the compacted topic and drop the prefix of a
>>> partition if all records in the prefix are removable. The admin can then
>>> run this tool when the unneeded space needs to be reclaimed. (c) Don't
>>> support partition change in a compacted topic. This might be ok since
>> most
>>> compacted topics are not high volume.
>>>
>>> Thanks,
>>>
>>> Jun
>>>
>>>
>>> On Tue, Mar 6, 2018 at 10:38 AM, Dong Lin <li...@gmail.com> wrote:
>>>
>>>> Hi everyone,
>>>>
>>>> Thanks for all the comments! It appears that everyone prefers linear
>>>> hashing because it reduces the amount of state that needs to be moved
>>>> between consumers (for stream processing). The KIP has been updated to
>> use
>>>> linear hashing.
>>>>
>>>> Regarding the migration endeavor: it seems that migrating producer
>> library
>>>> to use linear hashing should be pretty straightforward without
>>>> much operational endeavor. If we don't upgrade client library to use
>> this
>>>> KIP, we can not support in-order delivery after partition is changed
>>>> anyway. Suppose we upgrade client library to use this KIP, if partition
>>>> number is not changed, the key -> partition mapping will be exactly the
>>>> same as it is now because it is still determined using murmur_hash(key)
>> %
>>>> original_partition_num. In other words, this change is backward
>> compatible.
>>>>
>>>> Regarding the load distribution: if we use linear hashing, the load may
>> be
>>>> unevenly distributed because those partitions which are not split may
>>>> receive twice as much traffic as other partitions that are split. This
>>>> issue can be mitigated by creating topic with partitions that are
>> several
>>>> times the number of consumers. And there will be no imbalance if the
>>>> partition number is always doubled. So this imbalance seems acceptable.
>>>>
>>>> Regarding storing the partition strategy as per-topic config: It seems
>> not
>>>> necessary since we can still use murmur_hash as the default hash
>> function
>>>> and additionally apply the linear hashing algorithm if the partition
>> number
>>>> has increased. Not sure if there is any use-case for producer to use a
>>>> different hash function. Jason, can you check if there is some use-case
>>>> that I missed for using the per-topic partition strategy?
>>>>
>>>> Regarding how to reduce latency (due to state store/load) in stream
>>>> processing consumer when partition number changes: I need to read the
>> Kafka
>>>> Stream code to understand how Kafka Stream currently migrate state
>> between
>>>> consumers when the application is added/removed for a given job. I will
>>>> reply after I finish reading the documentation and code.
>>>>
>>>>
>>>> Thanks,
>>>> Dong
>>>>
>>>>
>>>> On Mon, Mar 5, 2018 at 10:43 AM, Jason Gustafson <ja...@confluent.io>
>>>> wrote:
>>>>
>>>>> Great discussion. I think I'm wondering whether we can continue to
>> leave
>>>>> Kafka agnostic to the partitioning strategy. The challenge is
>>>> communicating
>>>>> the partitioning logic from producers to consumers so that the
>>>> dependencies
>>>>> between each epoch can be determined. For the sake of discussion,
>> imagine
>>>>> you did something like the following:
>>>>>
>>>>> 1. The name (and perhaps version) of a partitioning strategy is stored
>> in
>>>>> topic configuration when a topic is created.
>>>>> 2. The producer looks up the partitioning strategy before writing to a
>>>>> topic and includes it in the produce request (for fencing). If it
>> doesn't
>>>>> have an implementation for the configured strategy, it fails.
>>>>> 3. The consumer also looks up the partitioning strategy and uses it to
>>>>> determine dependencies when reading a new epoch. It could either fail
>> or
>>>>> make the most conservative dependency assumptions if it doesn't know
>> how
>>>> to
>>>>> implement the partitioning strategy. For the consumer, the new
>> interface
>>>>> might look something like this:
>>>>>
>>>>> // Return the partition dependencies following an epoch bump
>>>>> Map<Integer, List<Integer>> dependencies(int
>>>> numPartitionsBeforeEpochBump,
>>>>> int numPartitionsAfterEpochBump)
>>>>>
>>>>> The unordered case then is just a particular implementation which never
>>>> has
>>>>> any epoch dependencies. To implement this, we would need some way for
>> the
>>>>> consumer to find out how many partitions there were in each epoch, but
>>>>> maybe that's not too unreasonable.
>>>>>
>>>>> Thanks,
>>>>> Jason
>>>>>
>>>>>
>>>>> On Mon, Mar 5, 2018 at 4:51 AM, Jan Filipiak <Jan.Filipiak@trivago.com
>>>
>>>>> wrote:
>>>>>
>>>>>> Hi Dong
>>>>>>
>>>>>> thank you very much for your questions.
>>>>>>
>>>>>> regarding the time spend copying data across:
>>>>>> It is correct that copying data from a topic with one partition
>> mapping
>>>>> to
>>>>>> a topic with a different partition mapping takes way longer than we
>> can
>>>>>> stop producers. Tens of minutes is a very optimistic estimate here.
>>>> Many
>>>>>> people can not afford copy full steam and therefore will have some
>> rate
>>>>>> limiting in place, this can bump the timespan into the day's. The good
>>>>> part
>>>>>> is that the vast majority of the data can be copied while the
>> producers
>>>>> are
>>>>>> still going. One can then, piggyback the consumers ontop of this
>>>>> timeframe,
>>>>>> by the method mentioned (provide them an mapping from their old
>> offsets
>>>>> to
>>>>>> new offsets in their repartitioned topics. In that way we separate
>>>>>> migration of consumers from migration of producers (decoupling these
>> is
>>>>>> what kafka is strongest at). The time to actually swap over the
>>>> producers
>>>>>> should be kept minimal by ensuring that when a swap attempt is started
>>>>> the
>>>>>> consumer copying over should be very close to the log end and is
>>>> expected
>>>>>> to finish within the next fetch. The operation should have a time-out
>>>> and
>>>>>> should be "reattemtable".
>>>>>>
>>>>>> Importance of logcompaction:
>>>>>> If a producer produces key A, to partiton 0, its forever gonna be
>>>> there,
>>>>>> unless it gets deleted. The record might sit in there for years. A new
>>>>>> producer started with the new partitions will fail to delete the
>> record
>>>>> in
>>>>>> the correct partition. Th record will be there forever and one can not
>>>>>> reliable bootstrap new consumers. I cannot see how linear hashing can
>>>>> solve
>>>>>> this.
>>>>>>
>>>>>> Regarding your skipping of userland copying:
>>>>>> 100%, copying the data across in userland is, as far as i can see,
>>>> only a
>>>>>> usecase for log compacted topics. Even for logcompaction + retentions
>>>> it
>>>>>> should only be opt-in. Why did I bring it up? I think log compaction
>>>> is a
>>>>>> very important feature to really embrace kafka as a "data plattform".
>>>> The
>>>>>> point I also want to make is that copying data this way is completely
>>>>>> inline with the kafka architecture. it only consists of reading and
>>>>> writing
>>>>>> to topics.
>>>>>>
>>>>>> I hope it clarifies more why I think we should aim for more than the
>>>>>> current KIP. I fear that once the KIP is done not much more effort
>> will
>>>>> be
>>>>>> taken.
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> On 04.03.2018 02:28, Dong Lin wrote:
>>>>>>
>>>>>>> Hey Jan,
>>>>>>>
>>>>>>> In the current proposal, the consumer will be blocked on waiting for
>>>>> other
>>>>>>> consumers of the group to consume up to a given offset. In most
>> cases,
>>>>> all
>>>>>>> consumers should be close to the LEO of the partitions when the
>>>>> partition
>>>>>>> expansion happens. Thus the time waiting should not be long e.g. on
>>>> the
>>>>>>> order of seconds. On the other hand, it may take a long time to wait
>>>> for
>>>>>>> the entire partition to be copied -- the amount of time is
>>>> proportional
>>>>> to
>>>>>>> the amount of existing data in the partition, which can take tens of
>>>>>>> minutes. So the amount of time that we stop consumers may not be on
>>>> the
>>>>>>> same order of magnitude.
>>>>>>>
>>>>>>> If we can implement this suggestion without copying data over in
>> purse
>>>>>>> userland, it will be much more valuable. Do you have ideas on how
>> this
>>>>> can
>>>>>>> be done?
>>>>>>>
>>>>>>> Not sure why the current KIP not help people who depend on log
>>>>> compaction.
>>>>>>> Could you elaborate more on this point?
>>>>>>>
>>>>>>> Thanks,
>>>>>>> Dong
>>>>>>>
>>>>>>> On Wed, Feb 28, 2018 at 10:55 PM, Jan Filipiak<Jan.Filipiak@trivago.
>>>> com
>>>>>>
>>>>>>> wrote:
>>>>>>>
>>>>>>> Hi Dong,
>>>>>>>>
>>>>>>>> I tried to focus on what the steps are one can currently perform to
>>>>>>>> expand
>>>>>>>> or shrink a keyed topic while maintaining a top notch semantics.
>>>>>>>> I can understand that there might be confusion about "stopping the
>>>>>>>> consumer". It is exactly the same as proposed in the KIP. there
>> needs
>>>>> to
>>>>>>>> be
>>>>>>>> a time the producers agree on the new partitioning. The extra
>>>>> semantics I
>>>>>>>> want to put in there is that we have a possibility to wait until all
>>>>> the
>>>>>>>> existing data
>>>>>>>> is copied over into the new partitioning scheme. When I say stopping
>>>> I
>>>>>>>> think more of having a memory barrier that ensures the ordering. I
>> am
>>>>>>>> still
>>>>>>>> aming for latencies  on the scale of leader failovers.
>>>>>>>>
>>>>>>>> Consumers have to explicitly adapt the new partitioning scheme in
>> the
>>>>>>>> above scenario. The reason is that in these cases where you are
>>>>> dependent
>>>>>>>> on a particular partitioning scheme, you also have other topics that
>>>>> have
>>>>>>>> co-partition enforcements or the kind -frequently. Therefore all
>> your
>>>>>>>> other
>>>>>>>> input topics might need to grow accordingly.
>>>>>>>>
>>>>>>>>
>>>>>>>> What I was suggesting was to streamline all these operations as best
>>>> as
>>>>>>>> possible to have "real" partition grow and shrinkage going on.
>>>>> Migrating
>>>>>>>> the producers to a new partitioning scheme can be much more
>>>> streamlined
>>>>>>>> with proper broker support for this. Migrating consumer is a step
>>>> that
>>>>>>>> might be made completly unnecessary if - for example streams - takes
>>>>> the
>>>>>>>> gcd as partitioning scheme instead of enforcing 1 to 1. Connect
>>>>> consumers
>>>>>>>> and other consumers should be fine anyways.
>>>>>>>>
>>>>>>>> I hope this makes more clear where I was aiming at. The rest needs
>> to
>>>>> be
>>>>>>>> figured out. The only danger i see is that when we are introducing
>>>> this
>>>>>>>> feature as supposed in the KIP, it wont help any people depending on
>>>>> log
>>>>>>>> compaction.
>>>>>>>>
>>>>>>>> The other thing I wanted to mention is that I believe the current
>>>>>>>> suggestion (without copying data over) can be implemented in pure
>>>>>>>> userland
>>>>>>>> with a custom partitioner and a small feedbackloop from
>>>> ProduceResponse
>>>>>>>> =>
>>>>>>>> Partitionier in coorporation with a change management system.
>>>>>>>>
>>>>>>>> Best Jan
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> On 28.02.2018 07:13, Dong Lin wrote:
>>>>>>>>
>>>>>>>> Hey Jan,
>>>>>>>>>
>>>>>>>>> I am not sure if it is acceptable for producer to be stopped for a
>>>>>>>>> while,
>>>>>>>>> particularly for online application which requires low latency. I
>> am
>>>>>>>>> also
>>>>>>>>> not sure how consumers can switch to a new topic. Does user
>>>>> application
>>>>>>>>> needs to explicitly specify a different topic for producer/consumer
>>>> to
>>>>>>>>> subscribe to? It will be helpful for discussion if you can provide
>>>>> more
>>>>>>>>> detail on the interface change for this solution.
>>>>>>>>>
>>>>>>>>> Thanks,
>>>>>>>>> Dong
>>>>>>>>>
>>>>>>>>> On Mon, Feb 26, 2018 at 12:48 AM, Jan
>> Filipiak<Jan.Filipiak@trivago.
>>>>> com
>>>>>>>>>>
>>>>>>>>> wrote:
>>>>>>>>>
>>>>>>>>> Hi,
>>>>>>>>>
>>>>>>>>>> just want to throw my though in. In general the functionality is
>>>> very
>>>>>>>>>> usefull, we should though not try to find the architecture to hard
>>>>>>>>>> while
>>>>>>>>>> implementing.
>>>>>>>>>>
>>>>>>>>>> The manual steps would be to
>>>>>>>>>>
>>>>>>>>>> create a new topic
>>>>>>>>>> the mirrormake from the new old topic to the new topic
>>>>>>>>>> wait for mirror making to catch up.
>>>>>>>>>> then put the consumers onto the new topic
>>>>>>>>>>       (having mirrormaker spit out a mapping from old offsets to
>>>> new
>>>>>>>>>> offsets:
>>>>>>>>>>           if topic is increased by factor X there is gonna be a
>>>> clean
>>>>>>>>>> mapping from 1 offset in the old topic to X offsets in the new
>>>> topic,
>>>>>>>>>>           if there is no factor then there is no chance to
>>>> generate a
>>>>>>>>>> mapping that can be reasonable used for continuing)
>>>>>>>>>>       make consumers stop at appropriate points and continue
>>>>>>>>>> consumption
>>>>>>>>>> with offsets from the mapping.
>>>>>>>>>> have the producers stop for a minimal time.
>>>>>>>>>> wait for mirrormaker to finish
>>>>>>>>>> let producer produce with the new metadata.
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> Instead of implementing the approach suggest in the KIP which will
>>>>>>>>>> leave
>>>>>>>>>> log compacted topic completely crumbled and unusable.
>>>>>>>>>> I would much rather try to build infrastructure to support the
>>>>>>>>>> mentioned
>>>>>>>>>> above operations more smoothly.
>>>>>>>>>> Especially having producers stop and use another topic is
>> difficult
>>>>> and
>>>>>>>>>> it would be nice if one can trigger "invalid metadata" exceptions
>>>> for
>>>>>>>>>> them
>>>>>>>>>> and
>>>>>>>>>> if one could give topics aliases so that their produces with the
>>>> old
>>>>>>>>>> topic
>>>>>>>>>> will arrive in the new topic.
>>>>>>>>>>
>>>>>>>>>> The downsides are obvious I guess ( having the same data twice for
>>>>> the
>>>>>>>>>> transition period, but kafka tends to scale well with datasize).
>> So
>>>>>>>>>> its a
>>>>>>>>>> nicer fit into the architecture.
>>>>>>>>>>
>>>>>>>>>> I further want to argument that the functionality by the KIP can
>>>>>>>>>> completely be implementing in "userland" with a custom partitioner
>>>>> that
>>>>>>>>>> handles the transition as needed. I would appreciate if someone
>>>> could
>>>>>>>>>> point
>>>>>>>>>> out what a custom partitioner couldn't handle in this case?
>>>>>>>>>>
>>>>>>>>>> With the above approach, shrinking a topic becomes the same steps.
>>>>>>>>>> Without
>>>>>>>>>> loosing keys in the discontinued partitions.
>>>>>>>>>>
>>>>>>>>>> Would love to hear what everyone thinks.
>>>>>>>>>>
>>>>>>>>>> Best Jan
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> On 11.02.2018 00:35, Dong Lin wrote:
>>>>>>>>>>
>>>>>>>>>> Hi all,
>>>>>>>>>>
>>>>>>>>>>> I have created KIP-253: Support in-order message delivery with
>>>>>>>>>>> partition
>>>>>>>>>>> expansion. See
>>>>>>>>>>> https://cwiki.apache.org/confluence/display/KAFKA/KIP-253%
>>>>>>>>>>> 3A+Support+in-order+message+delivery+with+partition+expansion
>>>>>>>>>>> .
>>>>>>>>>>>
>>>>>>>>>>> This KIP provides a way to allow messages of the same key from
>> the
>>>>>>>>>>> same
>>>>>>>>>>> producer to be consumed in the same order they are produced even
>>>> if
>>>>> we
>>>>>>>>>>> expand partition of the topic.
>>>>>>>>>>>
>>>>>>>>>>> Thanks,
>>>>>>>>>>> Dong
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>
>>>>>
>>>>
>>>
>>
>>
> 


Re: [DISCUSS] KIP-253: Support in-order message delivery with partition expansion

Posted by Jun Rao <ju...@confluent.io>.
Hi, Matthis,

My understanding is that in KStream, the only case when a changelog topic
needs to be compacted is when the corresponding input is a KTable. In all
other cases, the changelog topics are of compacted + deletion. So, if most
KTables are not high volume, there may not be a need to expand its
partitions and therefore the partitions of the corresponding changelog
topic.

Thanks,

Jun

On Wed, Mar 7, 2018 at 2:34 PM, Matthias J. Sax <ma...@confluent.io>
wrote:

> Jun,
>
> thanks for your comment. This should actually work for Streams, because
> we don't rely on producer "hashing" but specify the partition number
> explicitly on send().
>
> About not allowing to change the number of partition for changelog
> topics: for Streams, this seems to imply that we need to create a second
> changelog topic for each store with the new partition count. However, it
> would be unclear when/if we can delete the old topic. Thus, it moves the
> "problem" into the application layer. It's hard to judge for me atm what
> the impact would be, but it's something we should pay attention to.
>
>
> -Matthias
>
> On 3/6/18 3:45 PM, Jun Rao wrote:
> > Hi, Mattias,
> >
> > Regarding your comment "If it would be time-delay based, it might be
> > problematic
> > for Kafka Streams: if we get the information that the new input
> partitions
> > are available for producing, we need to enable the new changelog
> partitions
> > for producing, too. If those would not be available yet, because the
> > time-delay did not trigger yet, it would be problematic to avoid
> > crashing.", could you just enable the changelog topic to write to its new
> > partitions immediately?  The input topic can be configured with a delay
> in
> > writing to the new partitions. Initially, there won't be new data
> produced
> > into the newly added partitions in the input topic. However, we could
> > prebuild the state for the new input partition and write the state
> changes
> > to the corresponding new partitions in the changelog topic.
> >
> > Hi, Jan,
> >
> > For a compacted topic, garbage collecting the old keys in the existing
> > partitions after partition expansion can be tricky as your pointed out. A
> > few options here. (a) Let brokers exchange keys across brokers during
> > compaction. This will add complexity on the broker side. (b) Build an
> > external tool that scans the compacted topic and drop the prefix of a
> > partition if all records in the prefix are removable. The admin can then
> > run this tool when the unneeded space needs to be reclaimed. (c) Don't
> > support partition change in a compacted topic. This might be ok since
> most
> > compacted topics are not high volume.
> >
> > Thanks,
> >
> > Jun
> >
> >
> > On Tue, Mar 6, 2018 at 10:38 AM, Dong Lin <li...@gmail.com> wrote:
> >
> >> Hi everyone,
> >>
> >> Thanks for all the comments! It appears that everyone prefers linear
> >> hashing because it reduces the amount of state that needs to be moved
> >> between consumers (for stream processing). The KIP has been updated to
> use
> >> linear hashing.
> >>
> >> Regarding the migration endeavor: it seems that migrating producer
> library
> >> to use linear hashing should be pretty straightforward without
> >> much operational endeavor. If we don't upgrade client library to use
> this
> >> KIP, we can not support in-order delivery after partition is changed
> >> anyway. Suppose we upgrade client library to use this KIP, if partition
> >> number is not changed, the key -> partition mapping will be exactly the
> >> same as it is now because it is still determined using murmur_hash(key)
> %
> >> original_partition_num. In other words, this change is backward
> compatible.
> >>
> >> Regarding the load distribution: if we use linear hashing, the load may
> be
> >> unevenly distributed because those partitions which are not split may
> >> receive twice as much traffic as other partitions that are split. This
> >> issue can be mitigated by creating topic with partitions that are
> several
> >> times the number of consumers. And there will be no imbalance if the
> >> partition number is always doubled. So this imbalance seems acceptable.
> >>
> >> Regarding storing the partition strategy as per-topic config: It seems
> not
> >> necessary since we can still use murmur_hash as the default hash
> function
> >> and additionally apply the linear hashing algorithm if the partition
> number
> >> has increased. Not sure if there is any use-case for producer to use a
> >> different hash function. Jason, can you check if there is some use-case
> >> that I missed for using the per-topic partition strategy?
> >>
> >> Regarding how to reduce latency (due to state store/load) in stream
> >> processing consumer when partition number changes: I need to read the
> Kafka
> >> Stream code to understand how Kafka Stream currently migrate state
> between
> >> consumers when the application is added/removed for a given job. I will
> >> reply after I finish reading the documentation and code.
> >>
> >>
> >> Thanks,
> >> Dong
> >>
> >>
> >> On Mon, Mar 5, 2018 at 10:43 AM, Jason Gustafson <ja...@confluent.io>
> >> wrote:
> >>
> >>> Great discussion. I think I'm wondering whether we can continue to
> leave
> >>> Kafka agnostic to the partitioning strategy. The challenge is
> >> communicating
> >>> the partitioning logic from producers to consumers so that the
> >> dependencies
> >>> between each epoch can be determined. For the sake of discussion,
> imagine
> >>> you did something like the following:
> >>>
> >>> 1. The name (and perhaps version) of a partitioning strategy is stored
> in
> >>> topic configuration when a topic is created.
> >>> 2. The producer looks up the partitioning strategy before writing to a
> >>> topic and includes it in the produce request (for fencing). If it
> doesn't
> >>> have an implementation for the configured strategy, it fails.
> >>> 3. The consumer also looks up the partitioning strategy and uses it to
> >>> determine dependencies when reading a new epoch. It could either fail
> or
> >>> make the most conservative dependency assumptions if it doesn't know
> how
> >> to
> >>> implement the partitioning strategy. For the consumer, the new
> interface
> >>> might look something like this:
> >>>
> >>> // Return the partition dependencies following an epoch bump
> >>> Map<Integer, List<Integer>> dependencies(int
> >> numPartitionsBeforeEpochBump,
> >>> int numPartitionsAfterEpochBump)
> >>>
> >>> The unordered case then is just a particular implementation which never
> >> has
> >>> any epoch dependencies. To implement this, we would need some way for
> the
> >>> consumer to find out how many partitions there were in each epoch, but
> >>> maybe that's not too unreasonable.
> >>>
> >>> Thanks,
> >>> Jason
> >>>
> >>>
> >>> On Mon, Mar 5, 2018 at 4:51 AM, Jan Filipiak <Jan.Filipiak@trivago.com
> >
> >>> wrote:
> >>>
> >>>> Hi Dong
> >>>>
> >>>> thank you very much for your questions.
> >>>>
> >>>> regarding the time spend copying data across:
> >>>> It is correct that copying data from a topic with one partition
> mapping
> >>> to
> >>>> a topic with a different partition mapping takes way longer than we
> can
> >>>> stop producers. Tens of minutes is a very optimistic estimate here.
> >> Many
> >>>> people can not afford copy full steam and therefore will have some
> rate
> >>>> limiting in place, this can bump the timespan into the day's. The good
> >>> part
> >>>> is that the vast majority of the data can be copied while the
> producers
> >>> are
> >>>> still going. One can then, piggyback the consumers ontop of this
> >>> timeframe,
> >>>> by the method mentioned (provide them an mapping from their old
> offsets
> >>> to
> >>>> new offsets in their repartitioned topics. In that way we separate
> >>>> migration of consumers from migration of producers (decoupling these
> is
> >>>> what kafka is strongest at). The time to actually swap over the
> >> producers
> >>>> should be kept minimal by ensuring that when a swap attempt is started
> >>> the
> >>>> consumer copying over should be very close to the log end and is
> >> expected
> >>>> to finish within the next fetch. The operation should have a time-out
> >> and
> >>>> should be "reattemtable".
> >>>>
> >>>> Importance of logcompaction:
> >>>> If a producer produces key A, to partiton 0, its forever gonna be
> >> there,
> >>>> unless it gets deleted. The record might sit in there for years. A new
> >>>> producer started with the new partitions will fail to delete the
> record
> >>> in
> >>>> the correct partition. Th record will be there forever and one can not
> >>>> reliable bootstrap new consumers. I cannot see how linear hashing can
> >>> solve
> >>>> this.
> >>>>
> >>>> Regarding your skipping of userland copying:
> >>>> 100%, copying the data across in userland is, as far as i can see,
> >> only a
> >>>> usecase for log compacted topics. Even for logcompaction + retentions
> >> it
> >>>> should only be opt-in. Why did I bring it up? I think log compaction
> >> is a
> >>>> very important feature to really embrace kafka as a "data plattform".
> >> The
> >>>> point I also want to make is that copying data this way is completely
> >>>> inline with the kafka architecture. it only consists of reading and
> >>> writing
> >>>> to topics.
> >>>>
> >>>> I hope it clarifies more why I think we should aim for more than the
> >>>> current KIP. I fear that once the KIP is done not much more effort
> will
> >>> be
> >>>> taken.
> >>>>
> >>>>
> >>>>
> >>>>
> >>>> On 04.03.2018 02:28, Dong Lin wrote:
> >>>>
> >>>>> Hey Jan,
> >>>>>
> >>>>> In the current proposal, the consumer will be blocked on waiting for
> >>> other
> >>>>> consumers of the group to consume up to a given offset. In most
> cases,
> >>> all
> >>>>> consumers should be close to the LEO of the partitions when the
> >>> partition
> >>>>> expansion happens. Thus the time waiting should not be long e.g. on
> >> the
> >>>>> order of seconds. On the other hand, it may take a long time to wait
> >> for
> >>>>> the entire partition to be copied -- the amount of time is
> >> proportional
> >>> to
> >>>>> the amount of existing data in the partition, which can take tens of
> >>>>> minutes. So the amount of time that we stop consumers may not be on
> >> the
> >>>>> same order of magnitude.
> >>>>>
> >>>>> If we can implement this suggestion without copying data over in
> purse
> >>>>> userland, it will be much more valuable. Do you have ideas on how
> this
> >>> can
> >>>>> be done?
> >>>>>
> >>>>> Not sure why the current KIP not help people who depend on log
> >>> compaction.
> >>>>> Could you elaborate more on this point?
> >>>>>
> >>>>> Thanks,
> >>>>> Dong
> >>>>>
> >>>>> On Wed, Feb 28, 2018 at 10:55 PM, Jan Filipiak<Jan.Filipiak@trivago.
> >> com
> >>>>
> >>>>> wrote:
> >>>>>
> >>>>> Hi Dong,
> >>>>>>
> >>>>>> I tried to focus on what the steps are one can currently perform to
> >>>>>> expand
> >>>>>> or shrink a keyed topic while maintaining a top notch semantics.
> >>>>>> I can understand that there might be confusion about "stopping the
> >>>>>> consumer". It is exactly the same as proposed in the KIP. there
> needs
> >>> to
> >>>>>> be
> >>>>>> a time the producers agree on the new partitioning. The extra
> >>> semantics I
> >>>>>> want to put in there is that we have a possibility to wait until all
> >>> the
> >>>>>> existing data
> >>>>>> is copied over into the new partitioning scheme. When I say stopping
> >> I
> >>>>>> think more of having a memory barrier that ensures the ordering. I
> am
> >>>>>> still
> >>>>>> aming for latencies  on the scale of leader failovers.
> >>>>>>
> >>>>>> Consumers have to explicitly adapt the new partitioning scheme in
> the
> >>>>>> above scenario. The reason is that in these cases where you are
> >>> dependent
> >>>>>> on a particular partitioning scheme, you also have other topics that
> >>> have
> >>>>>> co-partition enforcements or the kind -frequently. Therefore all
> your
> >>>>>> other
> >>>>>> input topics might need to grow accordingly.
> >>>>>>
> >>>>>>
> >>>>>> What I was suggesting was to streamline all these operations as best
> >> as
> >>>>>> possible to have "real" partition grow and shrinkage going on.
> >>> Migrating
> >>>>>> the producers to a new partitioning scheme can be much more
> >> streamlined
> >>>>>> with proper broker support for this. Migrating consumer is a step
> >> that
> >>>>>> might be made completly unnecessary if - for example streams - takes
> >>> the
> >>>>>> gcd as partitioning scheme instead of enforcing 1 to 1. Connect
> >>> consumers
> >>>>>> and other consumers should be fine anyways.
> >>>>>>
> >>>>>> I hope this makes more clear where I was aiming at. The rest needs
> to
> >>> be
> >>>>>> figured out. The only danger i see is that when we are introducing
> >> this
> >>>>>> feature as supposed in the KIP, it wont help any people depending on
> >>> log
> >>>>>> compaction.
> >>>>>>
> >>>>>> The other thing I wanted to mention is that I believe the current
> >>>>>> suggestion (without copying data over) can be implemented in pure
> >>>>>> userland
> >>>>>> with a custom partitioner and a small feedbackloop from
> >> ProduceResponse
> >>>>>> =>
> >>>>>> Partitionier in coorporation with a change management system.
> >>>>>>
> >>>>>> Best Jan
> >>>>>>
> >>>>>>
> >>>>>>
> >>>>>>
> >>>>>>
> >>>>>>
> >>>>>>
> >>>>>>
> >>>>>> On 28.02.2018 07:13, Dong Lin wrote:
> >>>>>>
> >>>>>> Hey Jan,
> >>>>>>>
> >>>>>>> I am not sure if it is acceptable for producer to be stopped for a
> >>>>>>> while,
> >>>>>>> particularly for online application which requires low latency. I
> am
> >>>>>>> also
> >>>>>>> not sure how consumers can switch to a new topic. Does user
> >>> application
> >>>>>>> needs to explicitly specify a different topic for producer/consumer
> >> to
> >>>>>>> subscribe to? It will be helpful for discussion if you can provide
> >>> more
> >>>>>>> detail on the interface change for this solution.
> >>>>>>>
> >>>>>>> Thanks,
> >>>>>>> Dong
> >>>>>>>
> >>>>>>> On Mon, Feb 26, 2018 at 12:48 AM, Jan
> Filipiak<Jan.Filipiak@trivago.
> >>> com
> >>>>>>>>
> >>>>>>> wrote:
> >>>>>>>
> >>>>>>> Hi,
> >>>>>>>
> >>>>>>>> just want to throw my though in. In general the functionality is
> >> very
> >>>>>>>> usefull, we should though not try to find the architecture to hard
> >>>>>>>> while
> >>>>>>>> implementing.
> >>>>>>>>
> >>>>>>>> The manual steps would be to
> >>>>>>>>
> >>>>>>>> create a new topic
> >>>>>>>> the mirrormake from the new old topic to the new topic
> >>>>>>>> wait for mirror making to catch up.
> >>>>>>>> then put the consumers onto the new topic
> >>>>>>>>       (having mirrormaker spit out a mapping from old offsets to
> >> new
> >>>>>>>> offsets:
> >>>>>>>>           if topic is increased by factor X there is gonna be a
> >> clean
> >>>>>>>> mapping from 1 offset in the old topic to X offsets in the new
> >> topic,
> >>>>>>>>           if there is no factor then there is no chance to
> >> generate a
> >>>>>>>> mapping that can be reasonable used for continuing)
> >>>>>>>>       make consumers stop at appropriate points and continue
> >>>>>>>> consumption
> >>>>>>>> with offsets from the mapping.
> >>>>>>>> have the producers stop for a minimal time.
> >>>>>>>> wait for mirrormaker to finish
> >>>>>>>> let producer produce with the new metadata.
> >>>>>>>>
> >>>>>>>>
> >>>>>>>> Instead of implementing the approach suggest in the KIP which will
> >>>>>>>> leave
> >>>>>>>> log compacted topic completely crumbled and unusable.
> >>>>>>>> I would much rather try to build infrastructure to support the
> >>>>>>>> mentioned
> >>>>>>>> above operations more smoothly.
> >>>>>>>> Especially having producers stop and use another topic is
> difficult
> >>> and
> >>>>>>>> it would be nice if one can trigger "invalid metadata" exceptions
> >> for
> >>>>>>>> them
> >>>>>>>> and
> >>>>>>>> if one could give topics aliases so that their produces with the
> >> old
> >>>>>>>> topic
> >>>>>>>> will arrive in the new topic.
> >>>>>>>>
> >>>>>>>> The downsides are obvious I guess ( having the same data twice for
> >>> the
> >>>>>>>> transition period, but kafka tends to scale well with datasize).
> So
> >>>>>>>> its a
> >>>>>>>> nicer fit into the architecture.
> >>>>>>>>
> >>>>>>>> I further want to argument that the functionality by the KIP can
> >>>>>>>> completely be implementing in "userland" with a custom partitioner
> >>> that
> >>>>>>>> handles the transition as needed. I would appreciate if someone
> >> could
> >>>>>>>> point
> >>>>>>>> out what a custom partitioner couldn't handle in this case?
> >>>>>>>>
> >>>>>>>> With the above approach, shrinking a topic becomes the same steps.
> >>>>>>>> Without
> >>>>>>>> loosing keys in the discontinued partitions.
> >>>>>>>>
> >>>>>>>> Would love to hear what everyone thinks.
> >>>>>>>>
> >>>>>>>> Best Jan
> >>>>>>>>
> >>>>>>>>
> >>>>>>>>
> >>>>>>>>
> >>>>>>>>
> >>>>>>>>
> >>>>>>>>
> >>>>>>>>
> >>>>>>>>
> >>>>>>>>
> >>>>>>>>
> >>>>>>>>
> >>>>>>>>
> >>>>>>>>
> >>>>>>>>
> >>>>>>>>
> >>>>>>>>
> >>>>>>>>
> >>>>>>>> On 11.02.2018 00:35, Dong Lin wrote:
> >>>>>>>>
> >>>>>>>> Hi all,
> >>>>>>>>
> >>>>>>>>> I have created KIP-253: Support in-order message delivery with
> >>>>>>>>> partition
> >>>>>>>>> expansion. See
> >>>>>>>>> https://cwiki.apache.org/confluence/display/KAFKA/KIP-253%
> >>>>>>>>> 3A+Support+in-order+message+delivery+with+partition+expansion
> >>>>>>>>> .
> >>>>>>>>>
> >>>>>>>>> This KIP provides a way to allow messages of the same key from
> the
> >>>>>>>>> same
> >>>>>>>>> producer to be consumed in the same order they are produced even
> >> if
> >>> we
> >>>>>>>>> expand partition of the topic.
> >>>>>>>>>
> >>>>>>>>> Thanks,
> >>>>>>>>> Dong
> >>>>>>>>>
> >>>>>>>>>
> >>>>>>>>>
> >>>>>>>>>
> >>>>
> >>>
> >>
> >
>
>

Re: [DISCUSS] KIP-253: Support in-order message delivery with partition expansion

Posted by "Matthias J. Sax" <ma...@confluent.io>.
Jun,

thanks for your comment. This should actually work for Streams, because
we don't rely on producer "hashing" but specify the partition number
explicitly on send().

About not allowing to change the number of partition for changelog
topics: for Streams, this seems to imply that we need to create a second
changelog topic for each store with the new partition count. However, it
would be unclear when/if we can delete the old topic. Thus, it moves the
"problem" into the application layer. It's hard to judge for me atm what
the impact would be, but it's something we should pay attention to.


-Matthias

On 3/6/18 3:45 PM, Jun Rao wrote:
> Hi, Mattias,
> 
> Regarding your comment "If it would be time-delay based, it might be
> problematic
> for Kafka Streams: if we get the information that the new input partitions
> are available for producing, we need to enable the new changelog partitions
> for producing, too. If those would not be available yet, because the
> time-delay did not trigger yet, it would be problematic to avoid
> crashing.", could you just enable the changelog topic to write to its new
> partitions immediately?  The input topic can be configured with a delay in
> writing to the new partitions. Initially, there won't be new data produced
> into the newly added partitions in the input topic. However, we could
> prebuild the state for the new input partition and write the state changes
> to the corresponding new partitions in the changelog topic.
> 
> Hi, Jan,
> 
> For a compacted topic, garbage collecting the old keys in the existing
> partitions after partition expansion can be tricky as your pointed out. A
> few options here. (a) Let brokers exchange keys across brokers during
> compaction. This will add complexity on the broker side. (b) Build an
> external tool that scans the compacted topic and drop the prefix of a
> partition if all records in the prefix are removable. The admin can then
> run this tool when the unneeded space needs to be reclaimed. (c) Don't
> support partition change in a compacted topic. This might be ok since most
> compacted topics are not high volume.
> 
> Thanks,
> 
> Jun
> 
> 
> On Tue, Mar 6, 2018 at 10:38 AM, Dong Lin <li...@gmail.com> wrote:
> 
>> Hi everyone,
>>
>> Thanks for all the comments! It appears that everyone prefers linear
>> hashing because it reduces the amount of state that needs to be moved
>> between consumers (for stream processing). The KIP has been updated to use
>> linear hashing.
>>
>> Regarding the migration endeavor: it seems that migrating producer library
>> to use linear hashing should be pretty straightforward without
>> much operational endeavor. If we don't upgrade client library to use this
>> KIP, we can not support in-order delivery after partition is changed
>> anyway. Suppose we upgrade client library to use this KIP, if partition
>> number is not changed, the key -> partition mapping will be exactly the
>> same as it is now because it is still determined using murmur_hash(key) %
>> original_partition_num. In other words, this change is backward compatible.
>>
>> Regarding the load distribution: if we use linear hashing, the load may be
>> unevenly distributed because those partitions which are not split may
>> receive twice as much traffic as other partitions that are split. This
>> issue can be mitigated by creating topic with partitions that are several
>> times the number of consumers. And there will be no imbalance if the
>> partition number is always doubled. So this imbalance seems acceptable.
>>
>> Regarding storing the partition strategy as per-topic config: It seems not
>> necessary since we can still use murmur_hash as the default hash function
>> and additionally apply the linear hashing algorithm if the partition number
>> has increased. Not sure if there is any use-case for producer to use a
>> different hash function. Jason, can you check if there is some use-case
>> that I missed for using the per-topic partition strategy?
>>
>> Regarding how to reduce latency (due to state store/load) in stream
>> processing consumer when partition number changes: I need to read the Kafka
>> Stream code to understand how Kafka Stream currently migrate state between
>> consumers when the application is added/removed for a given job. I will
>> reply after I finish reading the documentation and code.
>>
>>
>> Thanks,
>> Dong
>>
>>
>> On Mon, Mar 5, 2018 at 10:43 AM, Jason Gustafson <ja...@confluent.io>
>> wrote:
>>
>>> Great discussion. I think I'm wondering whether we can continue to leave
>>> Kafka agnostic to the partitioning strategy. The challenge is
>> communicating
>>> the partitioning logic from producers to consumers so that the
>> dependencies
>>> between each epoch can be determined. For the sake of discussion, imagine
>>> you did something like the following:
>>>
>>> 1. The name (and perhaps version) of a partitioning strategy is stored in
>>> topic configuration when a topic is created.
>>> 2. The producer looks up the partitioning strategy before writing to a
>>> topic and includes it in the produce request (for fencing). If it doesn't
>>> have an implementation for the configured strategy, it fails.
>>> 3. The consumer also looks up the partitioning strategy and uses it to
>>> determine dependencies when reading a new epoch. It could either fail or
>>> make the most conservative dependency assumptions if it doesn't know how
>> to
>>> implement the partitioning strategy. For the consumer, the new interface
>>> might look something like this:
>>>
>>> // Return the partition dependencies following an epoch bump
>>> Map<Integer, List<Integer>> dependencies(int
>> numPartitionsBeforeEpochBump,
>>> int numPartitionsAfterEpochBump)
>>>
>>> The unordered case then is just a particular implementation which never
>> has
>>> any epoch dependencies. To implement this, we would need some way for the
>>> consumer to find out how many partitions there were in each epoch, but
>>> maybe that's not too unreasonable.
>>>
>>> Thanks,
>>> Jason
>>>
>>>
>>> On Mon, Mar 5, 2018 at 4:51 AM, Jan Filipiak <Ja...@trivago.com>
>>> wrote:
>>>
>>>> Hi Dong
>>>>
>>>> thank you very much for your questions.
>>>>
>>>> regarding the time spend copying data across:
>>>> It is correct that copying data from a topic with one partition mapping
>>> to
>>>> a topic with a different partition mapping takes way longer than we can
>>>> stop producers. Tens of minutes is a very optimistic estimate here.
>> Many
>>>> people can not afford copy full steam and therefore will have some rate
>>>> limiting in place, this can bump the timespan into the day's. The good
>>> part
>>>> is that the vast majority of the data can be copied while the producers
>>> are
>>>> still going. One can then, piggyback the consumers ontop of this
>>> timeframe,
>>>> by the method mentioned (provide them an mapping from their old offsets
>>> to
>>>> new offsets in their repartitioned topics. In that way we separate
>>>> migration of consumers from migration of producers (decoupling these is
>>>> what kafka is strongest at). The time to actually swap over the
>> producers
>>>> should be kept minimal by ensuring that when a swap attempt is started
>>> the
>>>> consumer copying over should be very close to the log end and is
>> expected
>>>> to finish within the next fetch. The operation should have a time-out
>> and
>>>> should be "reattemtable".
>>>>
>>>> Importance of logcompaction:
>>>> If a producer produces key A, to partiton 0, its forever gonna be
>> there,
>>>> unless it gets deleted. The record might sit in there for years. A new
>>>> producer started with the new partitions will fail to delete the record
>>> in
>>>> the correct partition. Th record will be there forever and one can not
>>>> reliable bootstrap new consumers. I cannot see how linear hashing can
>>> solve
>>>> this.
>>>>
>>>> Regarding your skipping of userland copying:
>>>> 100%, copying the data across in userland is, as far as i can see,
>> only a
>>>> usecase for log compacted topics. Even for logcompaction + retentions
>> it
>>>> should only be opt-in. Why did I bring it up? I think log compaction
>> is a
>>>> very important feature to really embrace kafka as a "data plattform".
>> The
>>>> point I also want to make is that copying data this way is completely
>>>> inline with the kafka architecture. it only consists of reading and
>>> writing
>>>> to topics.
>>>>
>>>> I hope it clarifies more why I think we should aim for more than the
>>>> current KIP. I fear that once the KIP is done not much more effort will
>>> be
>>>> taken.
>>>>
>>>>
>>>>
>>>>
>>>> On 04.03.2018 02:28, Dong Lin wrote:
>>>>
>>>>> Hey Jan,
>>>>>
>>>>> In the current proposal, the consumer will be blocked on waiting for
>>> other
>>>>> consumers of the group to consume up to a given offset. In most cases,
>>> all
>>>>> consumers should be close to the LEO of the partitions when the
>>> partition
>>>>> expansion happens. Thus the time waiting should not be long e.g. on
>> the
>>>>> order of seconds. On the other hand, it may take a long time to wait
>> for
>>>>> the entire partition to be copied -- the amount of time is
>> proportional
>>> to
>>>>> the amount of existing data in the partition, which can take tens of
>>>>> minutes. So the amount of time that we stop consumers may not be on
>> the
>>>>> same order of magnitude.
>>>>>
>>>>> If we can implement this suggestion without copying data over in purse
>>>>> userland, it will be much more valuable. Do you have ideas on how this
>>> can
>>>>> be done?
>>>>>
>>>>> Not sure why the current KIP not help people who depend on log
>>> compaction.
>>>>> Could you elaborate more on this point?
>>>>>
>>>>> Thanks,
>>>>> Dong
>>>>>
>>>>> On Wed, Feb 28, 2018 at 10:55 PM, Jan Filipiak<Jan.Filipiak@trivago.
>> com
>>>>
>>>>> wrote:
>>>>>
>>>>> Hi Dong,
>>>>>>
>>>>>> I tried to focus on what the steps are one can currently perform to
>>>>>> expand
>>>>>> or shrink a keyed topic while maintaining a top notch semantics.
>>>>>> I can understand that there might be confusion about "stopping the
>>>>>> consumer". It is exactly the same as proposed in the KIP. there needs
>>> to
>>>>>> be
>>>>>> a time the producers agree on the new partitioning. The extra
>>> semantics I
>>>>>> want to put in there is that we have a possibility to wait until all
>>> the
>>>>>> existing data
>>>>>> is copied over into the new partitioning scheme. When I say stopping
>> I
>>>>>> think more of having a memory barrier that ensures the ordering. I am
>>>>>> still
>>>>>> aming for latencies  on the scale of leader failovers.
>>>>>>
>>>>>> Consumers have to explicitly adapt the new partitioning scheme in the
>>>>>> above scenario. The reason is that in these cases where you are
>>> dependent
>>>>>> on a particular partitioning scheme, you also have other topics that
>>> have
>>>>>> co-partition enforcements or the kind -frequently. Therefore all your
>>>>>> other
>>>>>> input topics might need to grow accordingly.
>>>>>>
>>>>>>
>>>>>> What I was suggesting was to streamline all these operations as best
>> as
>>>>>> possible to have "real" partition grow and shrinkage going on.
>>> Migrating
>>>>>> the producers to a new partitioning scheme can be much more
>> streamlined
>>>>>> with proper broker support for this. Migrating consumer is a step
>> that
>>>>>> might be made completly unnecessary if - for example streams - takes
>>> the
>>>>>> gcd as partitioning scheme instead of enforcing 1 to 1. Connect
>>> consumers
>>>>>> and other consumers should be fine anyways.
>>>>>>
>>>>>> I hope this makes more clear where I was aiming at. The rest needs to
>>> be
>>>>>> figured out. The only danger i see is that when we are introducing
>> this
>>>>>> feature as supposed in the KIP, it wont help any people depending on
>>> log
>>>>>> compaction.
>>>>>>
>>>>>> The other thing I wanted to mention is that I believe the current
>>>>>> suggestion (without copying data over) can be implemented in pure
>>>>>> userland
>>>>>> with a custom partitioner and a small feedbackloop from
>> ProduceResponse
>>>>>> =>
>>>>>> Partitionier in coorporation with a change management system.
>>>>>>
>>>>>> Best Jan
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> On 28.02.2018 07:13, Dong Lin wrote:
>>>>>>
>>>>>> Hey Jan,
>>>>>>>
>>>>>>> I am not sure if it is acceptable for producer to be stopped for a
>>>>>>> while,
>>>>>>> particularly for online application which requires low latency. I am
>>>>>>> also
>>>>>>> not sure how consumers can switch to a new topic. Does user
>>> application
>>>>>>> needs to explicitly specify a different topic for producer/consumer
>> to
>>>>>>> subscribe to? It will be helpful for discussion if you can provide
>>> more
>>>>>>> detail on the interface change for this solution.
>>>>>>>
>>>>>>> Thanks,
>>>>>>> Dong
>>>>>>>
>>>>>>> On Mon, Feb 26, 2018 at 12:48 AM, Jan Filipiak<Jan.Filipiak@trivago.
>>> com
>>>>>>>>
>>>>>>> wrote:
>>>>>>>
>>>>>>> Hi,
>>>>>>>
>>>>>>>> just want to throw my though in. In general the functionality is
>> very
>>>>>>>> usefull, we should though not try to find the architecture to hard
>>>>>>>> while
>>>>>>>> implementing.
>>>>>>>>
>>>>>>>> The manual steps would be to
>>>>>>>>
>>>>>>>> create a new topic
>>>>>>>> the mirrormake from the new old topic to the new topic
>>>>>>>> wait for mirror making to catch up.
>>>>>>>> then put the consumers onto the new topic
>>>>>>>>       (having mirrormaker spit out a mapping from old offsets to
>> new
>>>>>>>> offsets:
>>>>>>>>           if topic is increased by factor X there is gonna be a
>> clean
>>>>>>>> mapping from 1 offset in the old topic to X offsets in the new
>> topic,
>>>>>>>>           if there is no factor then there is no chance to
>> generate a
>>>>>>>> mapping that can be reasonable used for continuing)
>>>>>>>>       make consumers stop at appropriate points and continue
>>>>>>>> consumption
>>>>>>>> with offsets from the mapping.
>>>>>>>> have the producers stop for a minimal time.
>>>>>>>> wait for mirrormaker to finish
>>>>>>>> let producer produce with the new metadata.
>>>>>>>>
>>>>>>>>
>>>>>>>> Instead of implementing the approach suggest in the KIP which will
>>>>>>>> leave
>>>>>>>> log compacted topic completely crumbled and unusable.
>>>>>>>> I would much rather try to build infrastructure to support the
>>>>>>>> mentioned
>>>>>>>> above operations more smoothly.
>>>>>>>> Especially having producers stop and use another topic is difficult
>>> and
>>>>>>>> it would be nice if one can trigger "invalid metadata" exceptions
>> for
>>>>>>>> them
>>>>>>>> and
>>>>>>>> if one could give topics aliases so that their produces with the
>> old
>>>>>>>> topic
>>>>>>>> will arrive in the new topic.
>>>>>>>>
>>>>>>>> The downsides are obvious I guess ( having the same data twice for
>>> the
>>>>>>>> transition period, but kafka tends to scale well with datasize). So
>>>>>>>> its a
>>>>>>>> nicer fit into the architecture.
>>>>>>>>
>>>>>>>> I further want to argument that the functionality by the KIP can
>>>>>>>> completely be implementing in "userland" with a custom partitioner
>>> that
>>>>>>>> handles the transition as needed. I would appreciate if someone
>> could
>>>>>>>> point
>>>>>>>> out what a custom partitioner couldn't handle in this case?
>>>>>>>>
>>>>>>>> With the above approach, shrinking a topic becomes the same steps.
>>>>>>>> Without
>>>>>>>> loosing keys in the discontinued partitions.
>>>>>>>>
>>>>>>>> Would love to hear what everyone thinks.
>>>>>>>>
>>>>>>>> Best Jan
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> On 11.02.2018 00:35, Dong Lin wrote:
>>>>>>>>
>>>>>>>> Hi all,
>>>>>>>>
>>>>>>>>> I have created KIP-253: Support in-order message delivery with
>>>>>>>>> partition
>>>>>>>>> expansion. See
>>>>>>>>> https://cwiki.apache.org/confluence/display/KAFKA/KIP-253%
>>>>>>>>> 3A+Support+in-order+message+delivery+with+partition+expansion
>>>>>>>>> .
>>>>>>>>>
>>>>>>>>> This KIP provides a way to allow messages of the same key from the
>>>>>>>>> same
>>>>>>>>> producer to be consumed in the same order they are produced even
>> if
>>> we
>>>>>>>>> expand partition of the topic.
>>>>>>>>>
>>>>>>>>> Thanks,
>>>>>>>>> Dong
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>
>>>
>>
> 


Re: [DISCUSS] KIP-253: Support in-order message delivery with partition expansion

Posted by Guozhang Wang <wa...@gmail.com>.
If we want to maintain ordering than for a pluggable producer-side
partitioner, it needs to coherent with the linear hashing scheme, i.e. we
effectively restrict what kind of customization users can do. However such
restrictions are hard to enforce programmatically unless we change the API,
so maybe we can only document / educate users to do that when they do
customize the partitioner after the upgrade.


Guozhang

On Wed, Mar 7, 2018 at 10:43 AM, Jason Gustafson <ja...@confluent.io> wrote:

> Hi Dong,
>
> What is not clear to me is how the use of linear hashing affects the
> partitioning logic in the producer, which the user is currently allowed to
> customize through the Partitioner interface. It sounds like we are
> effectively deprecating that interface since we will only provide ordering
> guarantees across partition changes if linear hashing is used. Maybe you
> can clarify whether that is the intention? Basically I am wondering how
> much additional work it would be to leave that partitioning logic pluggable
> and whether it is worthwhile to do so. One potential downside I can think
> of is that it may complicate compaction, but we don't have a concrete
> proposal for handling that at the moment anyway, so it's hard to say.
>
> Thanks,
> Jason
>
>
> On Tue, Mar 6, 2018 at 3:45 PM, Jun Rao <ju...@confluent.io> wrote:
>
> > Hi, Mattias,
> >
> > Regarding your comment "If it would be time-delay based, it might be
> > problematic
> > for Kafka Streams: if we get the information that the new input
> partitions
> > are available for producing, we need to enable the new changelog
> partitions
> > for producing, too. If those would not be available yet, because the
> > time-delay did not trigger yet, it would be problematic to avoid
> > crashing.", could you just enable the changelog topic to write to its new
> > partitions immediately?  The input topic can be configured with a delay
> in
> > writing to the new partitions. Initially, there won't be new data
> produced
> > into the newly added partitions in the input topic. However, we could
> > prebuild the state for the new input partition and write the state
> changes
> > to the corresponding new partitions in the changelog topic.
> >
> > Hi, Jan,
> >
> > For a compacted topic, garbage collecting the old keys in the existing
> > partitions after partition expansion can be tricky as your pointed out. A
> > few options here. (a) Let brokers exchange keys across brokers during
> > compaction. This will add complexity on the broker side. (b) Build an
> > external tool that scans the compacted topic and drop the prefix of a
> > partition if all records in the prefix are removable. The admin can then
> > run this tool when the unneeded space needs to be reclaimed. (c) Don't
> > support partition change in a compacted topic. This might be ok since
> most
> > compacted topics are not high volume.
> >
> > Thanks,
> >
> > Jun
> >
> >
> > On Tue, Mar 6, 2018 at 10:38 AM, Dong Lin <li...@gmail.com> wrote:
> >
> > > Hi everyone,
> > >
> > > Thanks for all the comments! It appears that everyone prefers linear
> > > hashing because it reduces the amount of state that needs to be moved
> > > between consumers (for stream processing). The KIP has been updated to
> > use
> > > linear hashing.
> > >
> > > Regarding the migration endeavor: it seems that migrating producer
> > library
> > > to use linear hashing should be pretty straightforward without
> > > much operational endeavor. If we don't upgrade client library to use
> this
> > > KIP, we can not support in-order delivery after partition is changed
> > > anyway. Suppose we upgrade client library to use this KIP, if partition
> > > number is not changed, the key -> partition mapping will be exactly the
> > > same as it is now because it is still determined using
> murmur_hash(key) %
> > > original_partition_num. In other words, this change is backward
> > compatible.
> > >
> > > Regarding the load distribution: if we use linear hashing, the load may
> > be
> > > unevenly distributed because those partitions which are not split may
> > > receive twice as much traffic as other partitions that are split. This
> > > issue can be mitigated by creating topic with partitions that are
> several
> > > times the number of consumers. And there will be no imbalance if the
> > > partition number is always doubled. So this imbalance seems acceptable.
> > >
> > > Regarding storing the partition strategy as per-topic config: It seems
> > not
> > > necessary since we can still use murmur_hash as the default hash
> function
> > > and additionally apply the linear hashing algorithm if the partition
> > number
> > > has increased. Not sure if there is any use-case for producer to use a
> > > different hash function. Jason, can you check if there is some use-case
> > > that I missed for using the per-topic partition strategy?
> > >
> > > Regarding how to reduce latency (due to state store/load) in stream
> > > processing consumer when partition number changes: I need to read the
> > Kafka
> > > Stream code to understand how Kafka Stream currently migrate state
> > between
> > > consumers when the application is added/removed for a given job. I will
> > > reply after I finish reading the documentation and code.
> > >
> > >
> > > Thanks,
> > > Dong
> > >
> > >
> > > On Mon, Mar 5, 2018 at 10:43 AM, Jason Gustafson <ja...@confluent.io>
> > > wrote:
> > >
> > > > Great discussion. I think I'm wondering whether we can continue to
> > leave
> > > > Kafka agnostic to the partitioning strategy. The challenge is
> > > communicating
> > > > the partitioning logic from producers to consumers so that the
> > > dependencies
> > > > between each epoch can be determined. For the sake of discussion,
> > imagine
> > > > you did something like the following:
> > > >
> > > > 1. The name (and perhaps version) of a partitioning strategy is
> stored
> > in
> > > > topic configuration when a topic is created.
> > > > 2. The producer looks up the partitioning strategy before writing to
> a
> > > > topic and includes it in the produce request (for fencing). If it
> > doesn't
> > > > have an implementation for the configured strategy, it fails.
> > > > 3. The consumer also looks up the partitioning strategy and uses it
> to
> > > > determine dependencies when reading a new epoch. It could either fail
> > or
> > > > make the most conservative dependency assumptions if it doesn't know
> > how
> > > to
> > > > implement the partitioning strategy. For the consumer, the new
> > interface
> > > > might look something like this:
> > > >
> > > > // Return the partition dependencies following an epoch bump
> > > > Map<Integer, List<Integer>> dependencies(int
> > > numPartitionsBeforeEpochBump,
> > > > int numPartitionsAfterEpochBump)
> > > >
> > > > The unordered case then is just a particular implementation which
> never
> > > has
> > > > any epoch dependencies. To implement this, we would need some way for
> > the
> > > > consumer to find out how many partitions there were in each epoch,
> but
> > > > maybe that's not too unreasonable.
> > > >
> > > > Thanks,
> > > > Jason
> > > >
> > > >
> > > > On Mon, Mar 5, 2018 at 4:51 AM, Jan Filipiak <
> Jan.Filipiak@trivago.com
> > >
> > > > wrote:
> > > >
> > > > > Hi Dong
> > > > >
> > > > > thank you very much for your questions.
> > > > >
> > > > > regarding the time spend copying data across:
> > > > > It is correct that copying data from a topic with one partition
> > mapping
> > > > to
> > > > > a topic with a different partition mapping takes way longer than we
> > can
> > > > > stop producers. Tens of minutes is a very optimistic estimate here.
> > > Many
> > > > > people can not afford copy full steam and therefore will have some
> > rate
> > > > > limiting in place, this can bump the timespan into the day's. The
> > good
> > > > part
> > > > > is that the vast majority of the data can be copied while the
> > producers
> > > > are
> > > > > still going. One can then, piggyback the consumers ontop of this
> > > > timeframe,
> > > > > by the method mentioned (provide them an mapping from their old
> > offsets
> > > > to
> > > > > new offsets in their repartitioned topics. In that way we separate
> > > > > migration of consumers from migration of producers (decoupling
> these
> > is
> > > > > what kafka is strongest at). The time to actually swap over the
> > > producers
> > > > > should be kept minimal by ensuring that when a swap attempt is
> > started
> > > > the
> > > > > consumer copying over should be very close to the log end and is
> > > expected
> > > > > to finish within the next fetch. The operation should have a
> time-out
> > > and
> > > > > should be "reattemtable".
> > > > >
> > > > > Importance of logcompaction:
> > > > > If a producer produces key A, to partiton 0, its forever gonna be
> > > there,
> > > > > unless it gets deleted. The record might sit in there for years. A
> > new
> > > > > producer started with the new partitions will fail to delete the
> > record
> > > > in
> > > > > the correct partition. Th record will be there forever and one can
> > not
> > > > > reliable bootstrap new consumers. I cannot see how linear hashing
> can
> > > > solve
> > > > > this.
> > > > >
> > > > > Regarding your skipping of userland copying:
> > > > > 100%, copying the data across in userland is, as far as i can see,
> > > only a
> > > > > usecase for log compacted topics. Even for logcompaction +
> retentions
> > > it
> > > > > should only be opt-in. Why did I bring it up? I think log
> compaction
> > > is a
> > > > > very important feature to really embrace kafka as a "data
> plattform".
> > > The
> > > > > point I also want to make is that copying data this way is
> completely
> > > > > inline with the kafka architecture. it only consists of reading and
> > > > writing
> > > > > to topics.
> > > > >
> > > > > I hope it clarifies more why I think we should aim for more than
> the
> > > > > current KIP. I fear that once the KIP is done not much more effort
> > will
> > > > be
> > > > > taken.
> > > > >
> > > > >
> > > > >
> > > > >
> > > > > On 04.03.2018 02:28, Dong Lin wrote:
> > > > >
> > > > >> Hey Jan,
> > > > >>
> > > > >> In the current proposal, the consumer will be blocked on waiting
> for
> > > > other
> > > > >> consumers of the group to consume up to a given offset. In most
> > cases,
> > > > all
> > > > >> consumers should be close to the LEO of the partitions when the
> > > > partition
> > > > >> expansion happens. Thus the time waiting should not be long e.g.
> on
> > > the
> > > > >> order of seconds. On the other hand, it may take a long time to
> wait
> > > for
> > > > >> the entire partition to be copied -- the amount of time is
> > > proportional
> > > > to
> > > > >> the amount of existing data in the partition, which can take tens
> of
> > > > >> minutes. So the amount of time that we stop consumers may not be
> on
> > > the
> > > > >> same order of magnitude.
> > > > >>
> > > > >> If we can implement this suggestion without copying data over in
> > purse
> > > > >> userland, it will be much more valuable. Do you have ideas on how
> > this
> > > > can
> > > > >> be done?
> > > > >>
> > > > >> Not sure why the current KIP not help people who depend on log
> > > > compaction.
> > > > >> Could you elaborate more on this point?
> > > > >>
> > > > >> Thanks,
> > > > >> Dong
> > > > >>
> > > > >> On Wed, Feb 28, 2018 at 10:55 PM, Jan
> Filipiak<Jan.Filipiak@trivago.
> > > com
> > > > >
> > > > >> wrote:
> > > > >>
> > > > >> Hi Dong,
> > > > >>>
> > > > >>> I tried to focus on what the steps are one can currently perform
> to
> > > > >>> expand
> > > > >>> or shrink a keyed topic while maintaining a top notch semantics.
> > > > >>> I can understand that there might be confusion about "stopping
> the
> > > > >>> consumer". It is exactly the same as proposed in the KIP. there
> > needs
> > > > to
> > > > >>> be
> > > > >>> a time the producers agree on the new partitioning. The extra
> > > > semantics I
> > > > >>> want to put in there is that we have a possibility to wait until
> > all
> > > > the
> > > > >>> existing data
> > > > >>> is copied over into the new partitioning scheme. When I say
> > stopping
> > > I
> > > > >>> think more of having a memory barrier that ensures the ordering.
> I
> > am
> > > > >>> still
> > > > >>> aming for latencies  on the scale of leader failovers.
> > > > >>>
> > > > >>> Consumers have to explicitly adapt the new partitioning scheme in
> > the
> > > > >>> above scenario. The reason is that in these cases where you are
> > > > dependent
> > > > >>> on a particular partitioning scheme, you also have other topics
> > that
> > > > have
> > > > >>> co-partition enforcements or the kind -frequently. Therefore all
> > your
> > > > >>> other
> > > > >>> input topics might need to grow accordingly.
> > > > >>>
> > > > >>>
> > > > >>> What I was suggesting was to streamline all these operations as
> > best
> > > as
> > > > >>> possible to have "real" partition grow and shrinkage going on.
> > > > Migrating
> > > > >>> the producers to a new partitioning scheme can be much more
> > > streamlined
> > > > >>> with proper broker support for this. Migrating consumer is a step
> > > that
> > > > >>> might be made completly unnecessary if - for example streams -
> > takes
> > > > the
> > > > >>> gcd as partitioning scheme instead of enforcing 1 to 1. Connect
> > > > consumers
> > > > >>> and other consumers should be fine anyways.
> > > > >>>
> > > > >>> I hope this makes more clear where I was aiming at. The rest
> needs
> > to
> > > > be
> > > > >>> figured out. The only danger i see is that when we are
> introducing
> > > this
> > > > >>> feature as supposed in the KIP, it wont help any people depending
> > on
> > > > log
> > > > >>> compaction.
> > > > >>>
> > > > >>> The other thing I wanted to mention is that I believe the current
> > > > >>> suggestion (without copying data over) can be implemented in pure
> > > > >>> userland
> > > > >>> with a custom partitioner and a small feedbackloop from
> > > ProduceResponse
> > > > >>> =>
> > > > >>> Partitionier in coorporation with a change management system.
> > > > >>>
> > > > >>> Best Jan
> > > > >>>
> > > > >>>
> > > > >>>
> > > > >>>
> > > > >>>
> > > > >>>
> > > > >>>
> > > > >>>
> > > > >>> On 28.02.2018 07:13, Dong Lin wrote:
> > > > >>>
> > > > >>> Hey Jan,
> > > > >>>>
> > > > >>>> I am not sure if it is acceptable for producer to be stopped
> for a
> > > > >>>> while,
> > > > >>>> particularly for online application which requires low latency.
> I
> > am
> > > > >>>> also
> > > > >>>> not sure how consumers can switch to a new topic. Does user
> > > > application
> > > > >>>> needs to explicitly specify a different topic for
> > producer/consumer
> > > to
> > > > >>>> subscribe to? It will be helpful for discussion if you can
> provide
> > > > more
> > > > >>>> detail on the interface change for this solution.
> > > > >>>>
> > > > >>>> Thanks,
> > > > >>>> Dong
> > > > >>>>
> > > > >>>> On Mon, Feb 26, 2018 at 12:48 AM, Jan
> > Filipiak<Jan.Filipiak@trivago.
> > > > com
> > > > >>>> >
> > > > >>>> wrote:
> > > > >>>>
> > > > >>>> Hi,
> > > > >>>>
> > > > >>>>> just want to throw my though in. In general the functionality
> is
> > > very
> > > > >>>>> usefull, we should though not try to find the architecture to
> > hard
> > > > >>>>> while
> > > > >>>>> implementing.
> > > > >>>>>
> > > > >>>>> The manual steps would be to
> > > > >>>>>
> > > > >>>>> create a new topic
> > > > >>>>> the mirrormake from the new old topic to the new topic
> > > > >>>>> wait for mirror making to catch up.
> > > > >>>>> then put the consumers onto the new topic
> > > > >>>>>       (having mirrormaker spit out a mapping from old offsets
> to
> > > new
> > > > >>>>> offsets:
> > > > >>>>>           if topic is increased by factor X there is gonna be a
> > > clean
> > > > >>>>> mapping from 1 offset in the old topic to X offsets in the new
> > > topic,
> > > > >>>>>           if there is no factor then there is no chance to
> > > generate a
> > > > >>>>> mapping that can be reasonable used for continuing)
> > > > >>>>>       make consumers stop at appropriate points and continue
> > > > >>>>> consumption
> > > > >>>>> with offsets from the mapping.
> > > > >>>>> have the producers stop for a minimal time.
> > > > >>>>> wait for mirrormaker to finish
> > > > >>>>> let producer produce with the new metadata.
> > > > >>>>>
> > > > >>>>>
> > > > >>>>> Instead of implementing the approach suggest in the KIP which
> > will
> > > > >>>>> leave
> > > > >>>>> log compacted topic completely crumbled and unusable.
> > > > >>>>> I would much rather try to build infrastructure to support the
> > > > >>>>> mentioned
> > > > >>>>> above operations more smoothly.
> > > > >>>>> Especially having producers stop and use another topic is
> > difficult
> > > > and
> > > > >>>>> it would be nice if one can trigger "invalid metadata"
> exceptions
> > > for
> > > > >>>>> them
> > > > >>>>> and
> > > > >>>>> if one could give topics aliases so that their produces with
> the
> > > old
> > > > >>>>> topic
> > > > >>>>> will arrive in the new topic.
> > > > >>>>>
> > > > >>>>> The downsides are obvious I guess ( having the same data twice
> > for
> > > > the
> > > > >>>>> transition period, but kafka tends to scale well with
> datasize).
> > So
> > > > >>>>> its a
> > > > >>>>> nicer fit into the architecture.
> > > > >>>>>
> > > > >>>>> I further want to argument that the functionality by the KIP
> can
> > > > >>>>> completely be implementing in "userland" with a custom
> > partitioner
> > > > that
> > > > >>>>> handles the transition as needed. I would appreciate if someone
> > > could
> > > > >>>>> point
> > > > >>>>> out what a custom partitioner couldn't handle in this case?
> > > > >>>>>
> > > > >>>>> With the above approach, shrinking a topic becomes the same
> > steps.
> > > > >>>>> Without
> > > > >>>>> loosing keys in the discontinued partitions.
> > > > >>>>>
> > > > >>>>> Would love to hear what everyone thinks.
> > > > >>>>>
> > > > >>>>> Best Jan
> > > > >>>>>
> > > > >>>>>
> > > > >>>>>
> > > > >>>>>
> > > > >>>>>
> > > > >>>>>
> > > > >>>>>
> > > > >>>>>
> > > > >>>>>
> > > > >>>>>
> > > > >>>>>
> > > > >>>>>
> > > > >>>>>
> > > > >>>>>
> > > > >>>>>
> > > > >>>>>
> > > > >>>>>
> > > > >>>>>
> > > > >>>>> On 11.02.2018 00:35, Dong Lin wrote:
> > > > >>>>>
> > > > >>>>> Hi all,
> > > > >>>>>
> > > > >>>>>> I have created KIP-253: Support in-order message delivery with
> > > > >>>>>> partition
> > > > >>>>>> expansion. See
> > > > >>>>>> https://cwiki.apache.org/confluence/display/KAFKA/KIP-253%
> > > > >>>>>> 3A+Support+in-order+message+delivery+with+partition+expansion
> > > > >>>>>> .
> > > > >>>>>>
> > > > >>>>>> This KIP provides a way to allow messages of the same key from
> > the
> > > > >>>>>> same
> > > > >>>>>> producer to be consumed in the same order they are produced
> even
> > > if
> > > > we
> > > > >>>>>> expand partition of the topic.
> > > > >>>>>>
> > > > >>>>>> Thanks,
> > > > >>>>>> Dong
> > > > >>>>>>
> > > > >>>>>>
> > > > >>>>>>
> > > > >>>>>>
> > > > >
> > > >
> > >
> >
>



-- 
-- Guozhang

Re: [DISCUSS] KIP-253: Support in-order message delivery with partition expansion

Posted by Jason Gustafson <ja...@confluent.io>.
Hi Dong,

What is not clear to me is how the use of linear hashing affects the
partitioning logic in the producer, which the user is currently allowed to
customize through the Partitioner interface. It sounds like we are
effectively deprecating that interface since we will only provide ordering
guarantees across partition changes if linear hashing is used. Maybe you
can clarify whether that is the intention? Basically I am wondering how
much additional work it would be to leave that partitioning logic pluggable
and whether it is worthwhile to do so. One potential downside I can think
of is that it may complicate compaction, but we don't have a concrete
proposal for handling that at the moment anyway, so it's hard to say.

Thanks,
Jason


On Tue, Mar 6, 2018 at 3:45 PM, Jun Rao <ju...@confluent.io> wrote:

> Hi, Mattias,
>
> Regarding your comment "If it would be time-delay based, it might be
> problematic
> for Kafka Streams: if we get the information that the new input partitions
> are available for producing, we need to enable the new changelog partitions
> for producing, too. If those would not be available yet, because the
> time-delay did not trigger yet, it would be problematic to avoid
> crashing.", could you just enable the changelog topic to write to its new
> partitions immediately?  The input topic can be configured with a delay in
> writing to the new partitions. Initially, there won't be new data produced
> into the newly added partitions in the input topic. However, we could
> prebuild the state for the new input partition and write the state changes
> to the corresponding new partitions in the changelog topic.
>
> Hi, Jan,
>
> For a compacted topic, garbage collecting the old keys in the existing
> partitions after partition expansion can be tricky as your pointed out. A
> few options here. (a) Let brokers exchange keys across brokers during
> compaction. This will add complexity on the broker side. (b) Build an
> external tool that scans the compacted topic and drop the prefix of a
> partition if all records in the prefix are removable. The admin can then
> run this tool when the unneeded space needs to be reclaimed. (c) Don't
> support partition change in a compacted topic. This might be ok since most
> compacted topics are not high volume.
>
> Thanks,
>
> Jun
>
>
> On Tue, Mar 6, 2018 at 10:38 AM, Dong Lin <li...@gmail.com> wrote:
>
> > Hi everyone,
> >
> > Thanks for all the comments! It appears that everyone prefers linear
> > hashing because it reduces the amount of state that needs to be moved
> > between consumers (for stream processing). The KIP has been updated to
> use
> > linear hashing.
> >
> > Regarding the migration endeavor: it seems that migrating producer
> library
> > to use linear hashing should be pretty straightforward without
> > much operational endeavor. If we don't upgrade client library to use this
> > KIP, we can not support in-order delivery after partition is changed
> > anyway. Suppose we upgrade client library to use this KIP, if partition
> > number is not changed, the key -> partition mapping will be exactly the
> > same as it is now because it is still determined using murmur_hash(key) %
> > original_partition_num. In other words, this change is backward
> compatible.
> >
> > Regarding the load distribution: if we use linear hashing, the load may
> be
> > unevenly distributed because those partitions which are not split may
> > receive twice as much traffic as other partitions that are split. This
> > issue can be mitigated by creating topic with partitions that are several
> > times the number of consumers. And there will be no imbalance if the
> > partition number is always doubled. So this imbalance seems acceptable.
> >
> > Regarding storing the partition strategy as per-topic config: It seems
> not
> > necessary since we can still use murmur_hash as the default hash function
> > and additionally apply the linear hashing algorithm if the partition
> number
> > has increased. Not sure if there is any use-case for producer to use a
> > different hash function. Jason, can you check if there is some use-case
> > that I missed for using the per-topic partition strategy?
> >
> > Regarding how to reduce latency (due to state store/load) in stream
> > processing consumer when partition number changes: I need to read the
> Kafka
> > Stream code to understand how Kafka Stream currently migrate state
> between
> > consumers when the application is added/removed for a given job. I will
> > reply after I finish reading the documentation and code.
> >
> >
> > Thanks,
> > Dong
> >
> >
> > On Mon, Mar 5, 2018 at 10:43 AM, Jason Gustafson <ja...@confluent.io>
> > wrote:
> >
> > > Great discussion. I think I'm wondering whether we can continue to
> leave
> > > Kafka agnostic to the partitioning strategy. The challenge is
> > communicating
> > > the partitioning logic from producers to consumers so that the
> > dependencies
> > > between each epoch can be determined. For the sake of discussion,
> imagine
> > > you did something like the following:
> > >
> > > 1. The name (and perhaps version) of a partitioning strategy is stored
> in
> > > topic configuration when a topic is created.
> > > 2. The producer looks up the partitioning strategy before writing to a
> > > topic and includes it in the produce request (for fencing). If it
> doesn't
> > > have an implementation for the configured strategy, it fails.
> > > 3. The consumer also looks up the partitioning strategy and uses it to
> > > determine dependencies when reading a new epoch. It could either fail
> or
> > > make the most conservative dependency assumptions if it doesn't know
> how
> > to
> > > implement the partitioning strategy. For the consumer, the new
> interface
> > > might look something like this:
> > >
> > > // Return the partition dependencies following an epoch bump
> > > Map<Integer, List<Integer>> dependencies(int
> > numPartitionsBeforeEpochBump,
> > > int numPartitionsAfterEpochBump)
> > >
> > > The unordered case then is just a particular implementation which never
> > has
> > > any epoch dependencies. To implement this, we would need some way for
> the
> > > consumer to find out how many partitions there were in each epoch, but
> > > maybe that's not too unreasonable.
> > >
> > > Thanks,
> > > Jason
> > >
> > >
> > > On Mon, Mar 5, 2018 at 4:51 AM, Jan Filipiak <Jan.Filipiak@trivago.com
> >
> > > wrote:
> > >
> > > > Hi Dong
> > > >
> > > > thank you very much for your questions.
> > > >
> > > > regarding the time spend copying data across:
> > > > It is correct that copying data from a topic with one partition
> mapping
> > > to
> > > > a topic with a different partition mapping takes way longer than we
> can
> > > > stop producers. Tens of minutes is a very optimistic estimate here.
> > Many
> > > > people can not afford copy full steam and therefore will have some
> rate
> > > > limiting in place, this can bump the timespan into the day's. The
> good
> > > part
> > > > is that the vast majority of the data can be copied while the
> producers
> > > are
> > > > still going. One can then, piggyback the consumers ontop of this
> > > timeframe,
> > > > by the method mentioned (provide them an mapping from their old
> offsets
> > > to
> > > > new offsets in their repartitioned topics. In that way we separate
> > > > migration of consumers from migration of producers (decoupling these
> is
> > > > what kafka is strongest at). The time to actually swap over the
> > producers
> > > > should be kept minimal by ensuring that when a swap attempt is
> started
> > > the
> > > > consumer copying over should be very close to the log end and is
> > expected
> > > > to finish within the next fetch. The operation should have a time-out
> > and
> > > > should be "reattemtable".
> > > >
> > > > Importance of logcompaction:
> > > > If a producer produces key A, to partiton 0, its forever gonna be
> > there,
> > > > unless it gets deleted. The record might sit in there for years. A
> new
> > > > producer started with the new partitions will fail to delete the
> record
> > > in
> > > > the correct partition. Th record will be there forever and one can
> not
> > > > reliable bootstrap new consumers. I cannot see how linear hashing can
> > > solve
> > > > this.
> > > >
> > > > Regarding your skipping of userland copying:
> > > > 100%, copying the data across in userland is, as far as i can see,
> > only a
> > > > usecase for log compacted topics. Even for logcompaction + retentions
> > it
> > > > should only be opt-in. Why did I bring it up? I think log compaction
> > is a
> > > > very important feature to really embrace kafka as a "data plattform".
> > The
> > > > point I also want to make is that copying data this way is completely
> > > > inline with the kafka architecture. it only consists of reading and
> > > writing
> > > > to topics.
> > > >
> > > > I hope it clarifies more why I think we should aim for more than the
> > > > current KIP. I fear that once the KIP is done not much more effort
> will
> > > be
> > > > taken.
> > > >
> > > >
> > > >
> > > >
> > > > On 04.03.2018 02:28, Dong Lin wrote:
> > > >
> > > >> Hey Jan,
> > > >>
> > > >> In the current proposal, the consumer will be blocked on waiting for
> > > other
> > > >> consumers of the group to consume up to a given offset. In most
> cases,
> > > all
> > > >> consumers should be close to the LEO of the partitions when the
> > > partition
> > > >> expansion happens. Thus the time waiting should not be long e.g. on
> > the
> > > >> order of seconds. On the other hand, it may take a long time to wait
> > for
> > > >> the entire partition to be copied -- the amount of time is
> > proportional
> > > to
> > > >> the amount of existing data in the partition, which can take tens of
> > > >> minutes. So the amount of time that we stop consumers may not be on
> > the
> > > >> same order of magnitude.
> > > >>
> > > >> If we can implement this suggestion without copying data over in
> purse
> > > >> userland, it will be much more valuable. Do you have ideas on how
> this
> > > can
> > > >> be done?
> > > >>
> > > >> Not sure why the current KIP not help people who depend on log
> > > compaction.
> > > >> Could you elaborate more on this point?
> > > >>
> > > >> Thanks,
> > > >> Dong
> > > >>
> > > >> On Wed, Feb 28, 2018 at 10:55 PM, Jan Filipiak<Jan.Filipiak@trivago.
> > com
> > > >
> > > >> wrote:
> > > >>
> > > >> Hi Dong,
> > > >>>
> > > >>> I tried to focus on what the steps are one can currently perform to
> > > >>> expand
> > > >>> or shrink a keyed topic while maintaining a top notch semantics.
> > > >>> I can understand that there might be confusion about "stopping the
> > > >>> consumer". It is exactly the same as proposed in the KIP. there
> needs
> > > to
> > > >>> be
> > > >>> a time the producers agree on the new partitioning. The extra
> > > semantics I
> > > >>> want to put in there is that we have a possibility to wait until
> all
> > > the
> > > >>> existing data
> > > >>> is copied over into the new partitioning scheme. When I say
> stopping
> > I
> > > >>> think more of having a memory barrier that ensures the ordering. I
> am
> > > >>> still
> > > >>> aming for latencies  on the scale of leader failovers.
> > > >>>
> > > >>> Consumers have to explicitly adapt the new partitioning scheme in
> the
> > > >>> above scenario. The reason is that in these cases where you are
> > > dependent
> > > >>> on a particular partitioning scheme, you also have other topics
> that
> > > have
> > > >>> co-partition enforcements or the kind -frequently. Therefore all
> your
> > > >>> other
> > > >>> input topics might need to grow accordingly.
> > > >>>
> > > >>>
> > > >>> What I was suggesting was to streamline all these operations as
> best
> > as
> > > >>> possible to have "real" partition grow and shrinkage going on.
> > > Migrating
> > > >>> the producers to a new partitioning scheme can be much more
> > streamlined
> > > >>> with proper broker support for this. Migrating consumer is a step
> > that
> > > >>> might be made completly unnecessary if - for example streams -
> takes
> > > the
> > > >>> gcd as partitioning scheme instead of enforcing 1 to 1. Connect
> > > consumers
> > > >>> and other consumers should be fine anyways.
> > > >>>
> > > >>> I hope this makes more clear where I was aiming at. The rest needs
> to
> > > be
> > > >>> figured out. The only danger i see is that when we are introducing
> > this
> > > >>> feature as supposed in the KIP, it wont help any people depending
> on
> > > log
> > > >>> compaction.
> > > >>>
> > > >>> The other thing I wanted to mention is that I believe the current
> > > >>> suggestion (without copying data over) can be implemented in pure
> > > >>> userland
> > > >>> with a custom partitioner and a small feedbackloop from
> > ProduceResponse
> > > >>> =>
> > > >>> Partitionier in coorporation with a change management system.
> > > >>>
> > > >>> Best Jan
> > > >>>
> > > >>>
> > > >>>
> > > >>>
> > > >>>
> > > >>>
> > > >>>
> > > >>>
> > > >>> On 28.02.2018 07:13, Dong Lin wrote:
> > > >>>
> > > >>> Hey Jan,
> > > >>>>
> > > >>>> I am not sure if it is acceptable for producer to be stopped for a
> > > >>>> while,
> > > >>>> particularly for online application which requires low latency. I
> am
> > > >>>> also
> > > >>>> not sure how consumers can switch to a new topic. Does user
> > > application
> > > >>>> needs to explicitly specify a different topic for
> producer/consumer
> > to
> > > >>>> subscribe to? It will be helpful for discussion if you can provide
> > > more
> > > >>>> detail on the interface change for this solution.
> > > >>>>
> > > >>>> Thanks,
> > > >>>> Dong
> > > >>>>
> > > >>>> On Mon, Feb 26, 2018 at 12:48 AM, Jan
> Filipiak<Jan.Filipiak@trivago.
> > > com
> > > >>>> >
> > > >>>> wrote:
> > > >>>>
> > > >>>> Hi,
> > > >>>>
> > > >>>>> just want to throw my though in. In general the functionality is
> > very
> > > >>>>> usefull, we should though not try to find the architecture to
> hard
> > > >>>>> while
> > > >>>>> implementing.
> > > >>>>>
> > > >>>>> The manual steps would be to
> > > >>>>>
> > > >>>>> create a new topic
> > > >>>>> the mirrormake from the new old topic to the new topic
> > > >>>>> wait for mirror making to catch up.
> > > >>>>> then put the consumers onto the new topic
> > > >>>>>       (having mirrormaker spit out a mapping from old offsets to
> > new
> > > >>>>> offsets:
> > > >>>>>           if topic is increased by factor X there is gonna be a
> > clean
> > > >>>>> mapping from 1 offset in the old topic to X offsets in the new
> > topic,
> > > >>>>>           if there is no factor then there is no chance to
> > generate a
> > > >>>>> mapping that can be reasonable used for continuing)
> > > >>>>>       make consumers stop at appropriate points and continue
> > > >>>>> consumption
> > > >>>>> with offsets from the mapping.
> > > >>>>> have the producers stop for a minimal time.
> > > >>>>> wait for mirrormaker to finish
> > > >>>>> let producer produce with the new metadata.
> > > >>>>>
> > > >>>>>
> > > >>>>> Instead of implementing the approach suggest in the KIP which
> will
> > > >>>>> leave
> > > >>>>> log compacted topic completely crumbled and unusable.
> > > >>>>> I would much rather try to build infrastructure to support the
> > > >>>>> mentioned
> > > >>>>> above operations more smoothly.
> > > >>>>> Especially having producers stop and use another topic is
> difficult
> > > and
> > > >>>>> it would be nice if one can trigger "invalid metadata" exceptions
> > for
> > > >>>>> them
> > > >>>>> and
> > > >>>>> if one could give topics aliases so that their produces with the
> > old
> > > >>>>> topic
> > > >>>>> will arrive in the new topic.
> > > >>>>>
> > > >>>>> The downsides are obvious I guess ( having the same data twice
> for
> > > the
> > > >>>>> transition period, but kafka tends to scale well with datasize).
> So
> > > >>>>> its a
> > > >>>>> nicer fit into the architecture.
> > > >>>>>
> > > >>>>> I further want to argument that the functionality by the KIP can
> > > >>>>> completely be implementing in "userland" with a custom
> partitioner
> > > that
> > > >>>>> handles the transition as needed. I would appreciate if someone
> > could
> > > >>>>> point
> > > >>>>> out what a custom partitioner couldn't handle in this case?
> > > >>>>>
> > > >>>>> With the above approach, shrinking a topic becomes the same
> steps.
> > > >>>>> Without
> > > >>>>> loosing keys in the discontinued partitions.
> > > >>>>>
> > > >>>>> Would love to hear what everyone thinks.
> > > >>>>>
> > > >>>>> Best Jan
> > > >>>>>
> > > >>>>>
> > > >>>>>
> > > >>>>>
> > > >>>>>
> > > >>>>>
> > > >>>>>
> > > >>>>>
> > > >>>>>
> > > >>>>>
> > > >>>>>
> > > >>>>>
> > > >>>>>
> > > >>>>>
> > > >>>>>
> > > >>>>>
> > > >>>>>
> > > >>>>>
> > > >>>>> On 11.02.2018 00:35, Dong Lin wrote:
> > > >>>>>
> > > >>>>> Hi all,
> > > >>>>>
> > > >>>>>> I have created KIP-253: Support in-order message delivery with
> > > >>>>>> partition
> > > >>>>>> expansion. See
> > > >>>>>> https://cwiki.apache.org/confluence/display/KAFKA/KIP-253%
> > > >>>>>> 3A+Support+in-order+message+delivery+with+partition+expansion
> > > >>>>>> .
> > > >>>>>>
> > > >>>>>> This KIP provides a way to allow messages of the same key from
> the
> > > >>>>>> same
> > > >>>>>> producer to be consumed in the same order they are produced even
> > if
> > > we
> > > >>>>>> expand partition of the topic.
> > > >>>>>>
> > > >>>>>> Thanks,
> > > >>>>>> Dong
> > > >>>>>>
> > > >>>>>>
> > > >>>>>>
> > > >>>>>>
> > > >
> > >
> >
>

Re: [DISCUSS] KIP-253: Support in-order message delivery with partition expansion

Posted by Jun Rao <ju...@confluent.io>.
Hi, Mattias,

Regarding your comment "If it would be time-delay based, it might be
problematic
for Kafka Streams: if we get the information that the new input partitions
are available for producing, we need to enable the new changelog partitions
for producing, too. If those would not be available yet, because the
time-delay did not trigger yet, it would be problematic to avoid
crashing.", could you just enable the changelog topic to write to its new
partitions immediately?  The input topic can be configured with a delay in
writing to the new partitions. Initially, there won't be new data produced
into the newly added partitions in the input topic. However, we could
prebuild the state for the new input partition and write the state changes
to the corresponding new partitions in the changelog topic.

Hi, Jan,

For a compacted topic, garbage collecting the old keys in the existing
partitions after partition expansion can be tricky as your pointed out. A
few options here. (a) Let brokers exchange keys across brokers during
compaction. This will add complexity on the broker side. (b) Build an
external tool that scans the compacted topic and drop the prefix of a
partition if all records in the prefix are removable. The admin can then
run this tool when the unneeded space needs to be reclaimed. (c) Don't
support partition change in a compacted topic. This might be ok since most
compacted topics are not high volume.

Thanks,

Jun


On Tue, Mar 6, 2018 at 10:38 AM, Dong Lin <li...@gmail.com> wrote:

> Hi everyone,
>
> Thanks for all the comments! It appears that everyone prefers linear
> hashing because it reduces the amount of state that needs to be moved
> between consumers (for stream processing). The KIP has been updated to use
> linear hashing.
>
> Regarding the migration endeavor: it seems that migrating producer library
> to use linear hashing should be pretty straightforward without
> much operational endeavor. If we don't upgrade client library to use this
> KIP, we can not support in-order delivery after partition is changed
> anyway. Suppose we upgrade client library to use this KIP, if partition
> number is not changed, the key -> partition mapping will be exactly the
> same as it is now because it is still determined using murmur_hash(key) %
> original_partition_num. In other words, this change is backward compatible.
>
> Regarding the load distribution: if we use linear hashing, the load may be
> unevenly distributed because those partitions which are not split may
> receive twice as much traffic as other partitions that are split. This
> issue can be mitigated by creating topic with partitions that are several
> times the number of consumers. And there will be no imbalance if the
> partition number is always doubled. So this imbalance seems acceptable.
>
> Regarding storing the partition strategy as per-topic config: It seems not
> necessary since we can still use murmur_hash as the default hash function
> and additionally apply the linear hashing algorithm if the partition number
> has increased. Not sure if there is any use-case for producer to use a
> different hash function. Jason, can you check if there is some use-case
> that I missed for using the per-topic partition strategy?
>
> Regarding how to reduce latency (due to state store/load) in stream
> processing consumer when partition number changes: I need to read the Kafka
> Stream code to understand how Kafka Stream currently migrate state between
> consumers when the application is added/removed for a given job. I will
> reply after I finish reading the documentation and code.
>
>
> Thanks,
> Dong
>
>
> On Mon, Mar 5, 2018 at 10:43 AM, Jason Gustafson <ja...@confluent.io>
> wrote:
>
> > Great discussion. I think I'm wondering whether we can continue to leave
> > Kafka agnostic to the partitioning strategy. The challenge is
> communicating
> > the partitioning logic from producers to consumers so that the
> dependencies
> > between each epoch can be determined. For the sake of discussion, imagine
> > you did something like the following:
> >
> > 1. The name (and perhaps version) of a partitioning strategy is stored in
> > topic configuration when a topic is created.
> > 2. The producer looks up the partitioning strategy before writing to a
> > topic and includes it in the produce request (for fencing). If it doesn't
> > have an implementation for the configured strategy, it fails.
> > 3. The consumer also looks up the partitioning strategy and uses it to
> > determine dependencies when reading a new epoch. It could either fail or
> > make the most conservative dependency assumptions if it doesn't know how
> to
> > implement the partitioning strategy. For the consumer, the new interface
> > might look something like this:
> >
> > // Return the partition dependencies following an epoch bump
> > Map<Integer, List<Integer>> dependencies(int
> numPartitionsBeforeEpochBump,
> > int numPartitionsAfterEpochBump)
> >
> > The unordered case then is just a particular implementation which never
> has
> > any epoch dependencies. To implement this, we would need some way for the
> > consumer to find out how many partitions there were in each epoch, but
> > maybe that's not too unreasonable.
> >
> > Thanks,
> > Jason
> >
> >
> > On Mon, Mar 5, 2018 at 4:51 AM, Jan Filipiak <Ja...@trivago.com>
> > wrote:
> >
> > > Hi Dong
> > >
> > > thank you very much for your questions.
> > >
> > > regarding the time spend copying data across:
> > > It is correct that copying data from a topic with one partition mapping
> > to
> > > a topic with a different partition mapping takes way longer than we can
> > > stop producers. Tens of minutes is a very optimistic estimate here.
> Many
> > > people can not afford copy full steam and therefore will have some rate
> > > limiting in place, this can bump the timespan into the day's. The good
> > part
> > > is that the vast majority of the data can be copied while the producers
> > are
> > > still going. One can then, piggyback the consumers ontop of this
> > timeframe,
> > > by the method mentioned (provide them an mapping from their old offsets
> > to
> > > new offsets in their repartitioned topics. In that way we separate
> > > migration of consumers from migration of producers (decoupling these is
> > > what kafka is strongest at). The time to actually swap over the
> producers
> > > should be kept minimal by ensuring that when a swap attempt is started
> > the
> > > consumer copying over should be very close to the log end and is
> expected
> > > to finish within the next fetch. The operation should have a time-out
> and
> > > should be "reattemtable".
> > >
> > > Importance of logcompaction:
> > > If a producer produces key A, to partiton 0, its forever gonna be
> there,
> > > unless it gets deleted. The record might sit in there for years. A new
> > > producer started with the new partitions will fail to delete the record
> > in
> > > the correct partition. Th record will be there forever and one can not
> > > reliable bootstrap new consumers. I cannot see how linear hashing can
> > solve
> > > this.
> > >
> > > Regarding your skipping of userland copying:
> > > 100%, copying the data across in userland is, as far as i can see,
> only a
> > > usecase for log compacted topics. Even for logcompaction + retentions
> it
> > > should only be opt-in. Why did I bring it up? I think log compaction
> is a
> > > very important feature to really embrace kafka as a "data plattform".
> The
> > > point I also want to make is that copying data this way is completely
> > > inline with the kafka architecture. it only consists of reading and
> > writing
> > > to topics.
> > >
> > > I hope it clarifies more why I think we should aim for more than the
> > > current KIP. I fear that once the KIP is done not much more effort will
> > be
> > > taken.
> > >
> > >
> > >
> > >
> > > On 04.03.2018 02:28, Dong Lin wrote:
> > >
> > >> Hey Jan,
> > >>
> > >> In the current proposal, the consumer will be blocked on waiting for
> > other
> > >> consumers of the group to consume up to a given offset. In most cases,
> > all
> > >> consumers should be close to the LEO of the partitions when the
> > partition
> > >> expansion happens. Thus the time waiting should not be long e.g. on
> the
> > >> order of seconds. On the other hand, it may take a long time to wait
> for
> > >> the entire partition to be copied -- the amount of time is
> proportional
> > to
> > >> the amount of existing data in the partition, which can take tens of
> > >> minutes. So the amount of time that we stop consumers may not be on
> the
> > >> same order of magnitude.
> > >>
> > >> If we can implement this suggestion without copying data over in purse
> > >> userland, it will be much more valuable. Do you have ideas on how this
> > can
> > >> be done?
> > >>
> > >> Not sure why the current KIP not help people who depend on log
> > compaction.
> > >> Could you elaborate more on this point?
> > >>
> > >> Thanks,
> > >> Dong
> > >>
> > >> On Wed, Feb 28, 2018 at 10:55 PM, Jan Filipiak<Jan.Filipiak@trivago.
> com
> > >
> > >> wrote:
> > >>
> > >> Hi Dong,
> > >>>
> > >>> I tried to focus on what the steps are one can currently perform to
> > >>> expand
> > >>> or shrink a keyed topic while maintaining a top notch semantics.
> > >>> I can understand that there might be confusion about "stopping the
> > >>> consumer". It is exactly the same as proposed in the KIP. there needs
> > to
> > >>> be
> > >>> a time the producers agree on the new partitioning. The extra
> > semantics I
> > >>> want to put in there is that we have a possibility to wait until all
> > the
> > >>> existing data
> > >>> is copied over into the new partitioning scheme. When I say stopping
> I
> > >>> think more of having a memory barrier that ensures the ordering. I am
> > >>> still
> > >>> aming for latencies  on the scale of leader failovers.
> > >>>
> > >>> Consumers have to explicitly adapt the new partitioning scheme in the
> > >>> above scenario. The reason is that in these cases where you are
> > dependent
> > >>> on a particular partitioning scheme, you also have other topics that
> > have
> > >>> co-partition enforcements or the kind -frequently. Therefore all your
> > >>> other
> > >>> input topics might need to grow accordingly.
> > >>>
> > >>>
> > >>> What I was suggesting was to streamline all these operations as best
> as
> > >>> possible to have "real" partition grow and shrinkage going on.
> > Migrating
> > >>> the producers to a new partitioning scheme can be much more
> streamlined
> > >>> with proper broker support for this. Migrating consumer is a step
> that
> > >>> might be made completly unnecessary if - for example streams - takes
> > the
> > >>> gcd as partitioning scheme instead of enforcing 1 to 1. Connect
> > consumers
> > >>> and other consumers should be fine anyways.
> > >>>
> > >>> I hope this makes more clear where I was aiming at. The rest needs to
> > be
> > >>> figured out. The only danger i see is that when we are introducing
> this
> > >>> feature as supposed in the KIP, it wont help any people depending on
> > log
> > >>> compaction.
> > >>>
> > >>> The other thing I wanted to mention is that I believe the current
> > >>> suggestion (without copying data over) can be implemented in pure
> > >>> userland
> > >>> with a custom partitioner and a small feedbackloop from
> ProduceResponse
> > >>> =>
> > >>> Partitionier in coorporation with a change management system.
> > >>>
> > >>> Best Jan
> > >>>
> > >>>
> > >>>
> > >>>
> > >>>
> > >>>
> > >>>
> > >>>
> > >>> On 28.02.2018 07:13, Dong Lin wrote:
> > >>>
> > >>> Hey Jan,
> > >>>>
> > >>>> I am not sure if it is acceptable for producer to be stopped for a
> > >>>> while,
> > >>>> particularly for online application which requires low latency. I am
> > >>>> also
> > >>>> not sure how consumers can switch to a new topic. Does user
> > application
> > >>>> needs to explicitly specify a different topic for producer/consumer
> to
> > >>>> subscribe to? It will be helpful for discussion if you can provide
> > more
> > >>>> detail on the interface change for this solution.
> > >>>>
> > >>>> Thanks,
> > >>>> Dong
> > >>>>
> > >>>> On Mon, Feb 26, 2018 at 12:48 AM, Jan Filipiak<Jan.Filipiak@trivago.
> > com
> > >>>> >
> > >>>> wrote:
> > >>>>
> > >>>> Hi,
> > >>>>
> > >>>>> just want to throw my though in. In general the functionality is
> very
> > >>>>> usefull, we should though not try to find the architecture to hard
> > >>>>> while
> > >>>>> implementing.
> > >>>>>
> > >>>>> The manual steps would be to
> > >>>>>
> > >>>>> create a new topic
> > >>>>> the mirrormake from the new old topic to the new topic
> > >>>>> wait for mirror making to catch up.
> > >>>>> then put the consumers onto the new topic
> > >>>>>       (having mirrormaker spit out a mapping from old offsets to
> new
> > >>>>> offsets:
> > >>>>>           if topic is increased by factor X there is gonna be a
> clean
> > >>>>> mapping from 1 offset in the old topic to X offsets in the new
> topic,
> > >>>>>           if there is no factor then there is no chance to
> generate a
> > >>>>> mapping that can be reasonable used for continuing)
> > >>>>>       make consumers stop at appropriate points and continue
> > >>>>> consumption
> > >>>>> with offsets from the mapping.
> > >>>>> have the producers stop for a minimal time.
> > >>>>> wait for mirrormaker to finish
> > >>>>> let producer produce with the new metadata.
> > >>>>>
> > >>>>>
> > >>>>> Instead of implementing the approach suggest in the KIP which will
> > >>>>> leave
> > >>>>> log compacted topic completely crumbled and unusable.
> > >>>>> I would much rather try to build infrastructure to support the
> > >>>>> mentioned
> > >>>>> above operations more smoothly.
> > >>>>> Especially having producers stop and use another topic is difficult
> > and
> > >>>>> it would be nice if one can trigger "invalid metadata" exceptions
> for
> > >>>>> them
> > >>>>> and
> > >>>>> if one could give topics aliases so that their produces with the
> old
> > >>>>> topic
> > >>>>> will arrive in the new topic.
> > >>>>>
> > >>>>> The downsides are obvious I guess ( having the same data twice for
> > the
> > >>>>> transition period, but kafka tends to scale well with datasize). So
> > >>>>> its a
> > >>>>> nicer fit into the architecture.
> > >>>>>
> > >>>>> I further want to argument that the functionality by the KIP can
> > >>>>> completely be implementing in "userland" with a custom partitioner
> > that
> > >>>>> handles the transition as needed. I would appreciate if someone
> could
> > >>>>> point
> > >>>>> out what a custom partitioner couldn't handle in this case?
> > >>>>>
> > >>>>> With the above approach, shrinking a topic becomes the same steps.
> > >>>>> Without
> > >>>>> loosing keys in the discontinued partitions.
> > >>>>>
> > >>>>> Would love to hear what everyone thinks.
> > >>>>>
> > >>>>> Best Jan
> > >>>>>
> > >>>>>
> > >>>>>
> > >>>>>
> > >>>>>
> > >>>>>
> > >>>>>
> > >>>>>
> > >>>>>
> > >>>>>
> > >>>>>
> > >>>>>
> > >>>>>
> > >>>>>
> > >>>>>
> > >>>>>
> > >>>>>
> > >>>>>
> > >>>>> On 11.02.2018 00:35, Dong Lin wrote:
> > >>>>>
> > >>>>> Hi all,
> > >>>>>
> > >>>>>> I have created KIP-253: Support in-order message delivery with
> > >>>>>> partition
> > >>>>>> expansion. See
> > >>>>>> https://cwiki.apache.org/confluence/display/KAFKA/KIP-253%
> > >>>>>> 3A+Support+in-order+message+delivery+with+partition+expansion
> > >>>>>> .
> > >>>>>>
> > >>>>>> This KIP provides a way to allow messages of the same key from the
> > >>>>>> same
> > >>>>>> producer to be consumed in the same order they are produced even
> if
> > we
> > >>>>>> expand partition of the topic.
> > >>>>>>
> > >>>>>> Thanks,
> > >>>>>> Dong
> > >>>>>>
> > >>>>>>
> > >>>>>>
> > >>>>>>
> > >
> >
>

Re: [DISCUSS] KIP-253: Support in-order message delivery with partition expansion

Posted by Dong Lin <li...@gmail.com>.
Hi everyone,

Thanks for all the comments! It appears that everyone prefers linear
hashing because it reduces the amount of state that needs to be moved
between consumers (for stream processing). The KIP has been updated to use
linear hashing.

Regarding the migration endeavor: it seems that migrating producer library
to use linear hashing should be pretty straightforward without
much operational endeavor. If we don't upgrade client library to use this
KIP, we can not support in-order delivery after partition is changed
anyway. Suppose we upgrade client library to use this KIP, if partition
number is not changed, the key -> partition mapping will be exactly the
same as it is now because it is still determined using murmur_hash(key) %
original_partition_num. In other words, this change is backward compatible.

Regarding the load distribution: if we use linear hashing, the load may be
unevenly distributed because those partitions which are not split may
receive twice as much traffic as other partitions that are split. This
issue can be mitigated by creating topic with partitions that are several
times the number of consumers. And there will be no imbalance if the
partition number is always doubled. So this imbalance seems acceptable.

Regarding storing the partition strategy as per-topic config: It seems not
necessary since we can still use murmur_hash as the default hash function
and additionally apply the linear hashing algorithm if the partition number
has increased. Not sure if there is any use-case for producer to use a
different hash function. Jason, can you check if there is some use-case
that I missed for using the per-topic partition strategy?

Regarding how to reduce latency (due to state store/load) in stream
processing consumer when partition number changes: I need to read the Kafka
Stream code to understand how Kafka Stream currently migrate state between
consumers when the application is added/removed for a given job. I will
reply after I finish reading the documentation and code.


Thanks,
Dong


On Mon, Mar 5, 2018 at 10:43 AM, Jason Gustafson <ja...@confluent.io> wrote:

> Great discussion. I think I'm wondering whether we can continue to leave
> Kafka agnostic to the partitioning strategy. The challenge is communicating
> the partitioning logic from producers to consumers so that the dependencies
> between each epoch can be determined. For the sake of discussion, imagine
> you did something like the following:
>
> 1. The name (and perhaps version) of a partitioning strategy is stored in
> topic configuration when a topic is created.
> 2. The producer looks up the partitioning strategy before writing to a
> topic and includes it in the produce request (for fencing). If it doesn't
> have an implementation for the configured strategy, it fails.
> 3. The consumer also looks up the partitioning strategy and uses it to
> determine dependencies when reading a new epoch. It could either fail or
> make the most conservative dependency assumptions if it doesn't know how to
> implement the partitioning strategy. For the consumer, the new interface
> might look something like this:
>
> // Return the partition dependencies following an epoch bump
> Map<Integer, List<Integer>> dependencies(int numPartitionsBeforeEpochBump,
> int numPartitionsAfterEpochBump)
>
> The unordered case then is just a particular implementation which never has
> any epoch dependencies. To implement this, we would need some way for the
> consumer to find out how many partitions there were in each epoch, but
> maybe that's not too unreasonable.
>
> Thanks,
> Jason
>
>
> On Mon, Mar 5, 2018 at 4:51 AM, Jan Filipiak <Ja...@trivago.com>
> wrote:
>
> > Hi Dong
> >
> > thank you very much for your questions.
> >
> > regarding the time spend copying data across:
> > It is correct that copying data from a topic with one partition mapping
> to
> > a topic with a different partition mapping takes way longer than we can
> > stop producers. Tens of minutes is a very optimistic estimate here. Many
> > people can not afford copy full steam and therefore will have some rate
> > limiting in place, this can bump the timespan into the day's. The good
> part
> > is that the vast majority of the data can be copied while the producers
> are
> > still going. One can then, piggyback the consumers ontop of this
> timeframe,
> > by the method mentioned (provide them an mapping from their old offsets
> to
> > new offsets in their repartitioned topics. In that way we separate
> > migration of consumers from migration of producers (decoupling these is
> > what kafka is strongest at). The time to actually swap over the producers
> > should be kept minimal by ensuring that when a swap attempt is started
> the
> > consumer copying over should be very close to the log end and is expected
> > to finish within the next fetch. The operation should have a time-out and
> > should be "reattemtable".
> >
> > Importance of logcompaction:
> > If a producer produces key A, to partiton 0, its forever gonna be there,
> > unless it gets deleted. The record might sit in there for years. A new
> > producer started with the new partitions will fail to delete the record
> in
> > the correct partition. Th record will be there forever and one can not
> > reliable bootstrap new consumers. I cannot see how linear hashing can
> solve
> > this.
> >
> > Regarding your skipping of userland copying:
> > 100%, copying the data across in userland is, as far as i can see, only a
> > usecase for log compacted topics. Even for logcompaction + retentions it
> > should only be opt-in. Why did I bring it up? I think log compaction is a
> > very important feature to really embrace kafka as a "data plattform". The
> > point I also want to make is that copying data this way is completely
> > inline with the kafka architecture. it only consists of reading and
> writing
> > to topics.
> >
> > I hope it clarifies more why I think we should aim for more than the
> > current KIP. I fear that once the KIP is done not much more effort will
> be
> > taken.
> >
> >
> >
> >
> > On 04.03.2018 02:28, Dong Lin wrote:
> >
> >> Hey Jan,
> >>
> >> In the current proposal, the consumer will be blocked on waiting for
> other
> >> consumers of the group to consume up to a given offset. In most cases,
> all
> >> consumers should be close to the LEO of the partitions when the
> partition
> >> expansion happens. Thus the time waiting should not be long e.g. on the
> >> order of seconds. On the other hand, it may take a long time to wait for
> >> the entire partition to be copied -- the amount of time is proportional
> to
> >> the amount of existing data in the partition, which can take tens of
> >> minutes. So the amount of time that we stop consumers may not be on the
> >> same order of magnitude.
> >>
> >> If we can implement this suggestion without copying data over in purse
> >> userland, it will be much more valuable. Do you have ideas on how this
> can
> >> be done?
> >>
> >> Not sure why the current KIP not help people who depend on log
> compaction.
> >> Could you elaborate more on this point?
> >>
> >> Thanks,
> >> Dong
> >>
> >> On Wed, Feb 28, 2018 at 10:55 PM, Jan Filipiak<Jan.Filipiak@trivago.com
> >
> >> wrote:
> >>
> >> Hi Dong,
> >>>
> >>> I tried to focus on what the steps are one can currently perform to
> >>> expand
> >>> or shrink a keyed topic while maintaining a top notch semantics.
> >>> I can understand that there might be confusion about "stopping the
> >>> consumer". It is exactly the same as proposed in the KIP. there needs
> to
> >>> be
> >>> a time the producers agree on the new partitioning. The extra
> semantics I
> >>> want to put in there is that we have a possibility to wait until all
> the
> >>> existing data
> >>> is copied over into the new partitioning scheme. When I say stopping I
> >>> think more of having a memory barrier that ensures the ordering. I am
> >>> still
> >>> aming for latencies  on the scale of leader failovers.
> >>>
> >>> Consumers have to explicitly adapt the new partitioning scheme in the
> >>> above scenario. The reason is that in these cases where you are
> dependent
> >>> on a particular partitioning scheme, you also have other topics that
> have
> >>> co-partition enforcements or the kind -frequently. Therefore all your
> >>> other
> >>> input topics might need to grow accordingly.
> >>>
> >>>
> >>> What I was suggesting was to streamline all these operations as best as
> >>> possible to have "real" partition grow and shrinkage going on.
> Migrating
> >>> the producers to a new partitioning scheme can be much more streamlined
> >>> with proper broker support for this. Migrating consumer is a step that
> >>> might be made completly unnecessary if - for example streams - takes
> the
> >>> gcd as partitioning scheme instead of enforcing 1 to 1. Connect
> consumers
> >>> and other consumers should be fine anyways.
> >>>
> >>> I hope this makes more clear where I was aiming at. The rest needs to
> be
> >>> figured out. The only danger i see is that when we are introducing this
> >>> feature as supposed in the KIP, it wont help any people depending on
> log
> >>> compaction.
> >>>
> >>> The other thing I wanted to mention is that I believe the current
> >>> suggestion (without copying data over) can be implemented in pure
> >>> userland
> >>> with a custom partitioner and a small feedbackloop from ProduceResponse
> >>> =>
> >>> Partitionier in coorporation with a change management system.
> >>>
> >>> Best Jan
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>
> >>> On 28.02.2018 07:13, Dong Lin wrote:
> >>>
> >>> Hey Jan,
> >>>>
> >>>> I am not sure if it is acceptable for producer to be stopped for a
> >>>> while,
> >>>> particularly for online application which requires low latency. I am
> >>>> also
> >>>> not sure how consumers can switch to a new topic. Does user
> application
> >>>> needs to explicitly specify a different topic for producer/consumer to
> >>>> subscribe to? It will be helpful for discussion if you can provide
> more
> >>>> detail on the interface change for this solution.
> >>>>
> >>>> Thanks,
> >>>> Dong
> >>>>
> >>>> On Mon, Feb 26, 2018 at 12:48 AM, Jan Filipiak<Jan.Filipiak@trivago.
> com
> >>>> >
> >>>> wrote:
> >>>>
> >>>> Hi,
> >>>>
> >>>>> just want to throw my though in. In general the functionality is very
> >>>>> usefull, we should though not try to find the architecture to hard
> >>>>> while
> >>>>> implementing.
> >>>>>
> >>>>> The manual steps would be to
> >>>>>
> >>>>> create a new topic
> >>>>> the mirrormake from the new old topic to the new topic
> >>>>> wait for mirror making to catch up.
> >>>>> then put the consumers onto the new topic
> >>>>>       (having mirrormaker spit out a mapping from old offsets to new
> >>>>> offsets:
> >>>>>           if topic is increased by factor X there is gonna be a clean
> >>>>> mapping from 1 offset in the old topic to X offsets in the new topic,
> >>>>>           if there is no factor then there is no chance to generate a
> >>>>> mapping that can be reasonable used for continuing)
> >>>>>       make consumers stop at appropriate points and continue
> >>>>> consumption
> >>>>> with offsets from the mapping.
> >>>>> have the producers stop for a minimal time.
> >>>>> wait for mirrormaker to finish
> >>>>> let producer produce with the new metadata.
> >>>>>
> >>>>>
> >>>>> Instead of implementing the approach suggest in the KIP which will
> >>>>> leave
> >>>>> log compacted topic completely crumbled and unusable.
> >>>>> I would much rather try to build infrastructure to support the
> >>>>> mentioned
> >>>>> above operations more smoothly.
> >>>>> Especially having producers stop and use another topic is difficult
> and
> >>>>> it would be nice if one can trigger "invalid metadata" exceptions for
> >>>>> them
> >>>>> and
> >>>>> if one could give topics aliases so that their produces with the old
> >>>>> topic
> >>>>> will arrive in the new topic.
> >>>>>
> >>>>> The downsides are obvious I guess ( having the same data twice for
> the
> >>>>> transition period, but kafka tends to scale well with datasize). So
> >>>>> its a
> >>>>> nicer fit into the architecture.
> >>>>>
> >>>>> I further want to argument that the functionality by the KIP can
> >>>>> completely be implementing in "userland" with a custom partitioner
> that
> >>>>> handles the transition as needed. I would appreciate if someone could
> >>>>> point
> >>>>> out what a custom partitioner couldn't handle in this case?
> >>>>>
> >>>>> With the above approach, shrinking a topic becomes the same steps.
> >>>>> Without
> >>>>> loosing keys in the discontinued partitions.
> >>>>>
> >>>>> Would love to hear what everyone thinks.
> >>>>>
> >>>>> Best Jan
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>> On 11.02.2018 00:35, Dong Lin wrote:
> >>>>>
> >>>>> Hi all,
> >>>>>
> >>>>>> I have created KIP-253: Support in-order message delivery with
> >>>>>> partition
> >>>>>> expansion. See
> >>>>>> https://cwiki.apache.org/confluence/display/KAFKA/KIP-253%
> >>>>>> 3A+Support+in-order+message+delivery+with+partition+expansion
> >>>>>> .
> >>>>>>
> >>>>>> This KIP provides a way to allow messages of the same key from the
> >>>>>> same
> >>>>>> producer to be consumed in the same order they are produced even if
> we
> >>>>>> expand partition of the topic.
> >>>>>>
> >>>>>> Thanks,
> >>>>>> Dong
> >>>>>>
> >>>>>>
> >>>>>>
> >>>>>>
> >
>

Re: [DISCUSS] KIP-253: Support in-order message delivery with partition expansion

Posted by Jason Gustafson <ja...@confluent.io>.
Great discussion. I think I'm wondering whether we can continue to leave
Kafka agnostic to the partitioning strategy. The challenge is communicating
the partitioning logic from producers to consumers so that the dependencies
between each epoch can be determined. For the sake of discussion, imagine
you did something like the following:

1. The name (and perhaps version) of a partitioning strategy is stored in
topic configuration when a topic is created.
2. The producer looks up the partitioning strategy before writing to a
topic and includes it in the produce request (for fencing). If it doesn't
have an implementation for the configured strategy, it fails.
3. The consumer also looks up the partitioning strategy and uses it to
determine dependencies when reading a new epoch. It could either fail or
make the most conservative dependency assumptions if it doesn't know how to
implement the partitioning strategy. For the consumer, the new interface
might look something like this:

// Return the partition dependencies following an epoch bump
Map<Integer, List<Integer>> dependencies(int numPartitionsBeforeEpochBump,
int numPartitionsAfterEpochBump)

The unordered case then is just a particular implementation which never has
any epoch dependencies. To implement this, we would need some way for the
consumer to find out how many partitions there were in each epoch, but
maybe that's not too unreasonable.

Thanks,
Jason


On Mon, Mar 5, 2018 at 4:51 AM, Jan Filipiak <Ja...@trivago.com>
wrote:

> Hi Dong
>
> thank you very much for your questions.
>
> regarding the time spend copying data across:
> It is correct that copying data from a topic with one partition mapping to
> a topic with a different partition mapping takes way longer than we can
> stop producers. Tens of minutes is a very optimistic estimate here. Many
> people can not afford copy full steam and therefore will have some rate
> limiting in place, this can bump the timespan into the day's. The good part
> is that the vast majority of the data can be copied while the producers are
> still going. One can then, piggyback the consumers ontop of this timeframe,
> by the method mentioned (provide them an mapping from their old offsets to
> new offsets in their repartitioned topics. In that way we separate
> migration of consumers from migration of producers (decoupling these is
> what kafka is strongest at). The time to actually swap over the producers
> should be kept minimal by ensuring that when a swap attempt is started the
> consumer copying over should be very close to the log end and is expected
> to finish within the next fetch. The operation should have a time-out and
> should be "reattemtable".
>
> Importance of logcompaction:
> If a producer produces key A, to partiton 0, its forever gonna be there,
> unless it gets deleted. The record might sit in there for years. A new
> producer started with the new partitions will fail to delete the record in
> the correct partition. Th record will be there forever and one can not
> reliable bootstrap new consumers. I cannot see how linear hashing can solve
> this.
>
> Regarding your skipping of userland copying:
> 100%, copying the data across in userland is, as far as i can see, only a
> usecase for log compacted topics. Even for logcompaction + retentions it
> should only be opt-in. Why did I bring it up? I think log compaction is a
> very important feature to really embrace kafka as a "data plattform". The
> point I also want to make is that copying data this way is completely
> inline with the kafka architecture. it only consists of reading and writing
> to topics.
>
> I hope it clarifies more why I think we should aim for more than the
> current KIP. I fear that once the KIP is done not much more effort will be
> taken.
>
>
>
>
> On 04.03.2018 02:28, Dong Lin wrote:
>
>> Hey Jan,
>>
>> In the current proposal, the consumer will be blocked on waiting for other
>> consumers of the group to consume up to a given offset. In most cases, all
>> consumers should be close to the LEO of the partitions when the partition
>> expansion happens. Thus the time waiting should not be long e.g. on the
>> order of seconds. On the other hand, it may take a long time to wait for
>> the entire partition to be copied -- the amount of time is proportional to
>> the amount of existing data in the partition, which can take tens of
>> minutes. So the amount of time that we stop consumers may not be on the
>> same order of magnitude.
>>
>> If we can implement this suggestion without copying data over in purse
>> userland, it will be much more valuable. Do you have ideas on how this can
>> be done?
>>
>> Not sure why the current KIP not help people who depend on log compaction.
>> Could you elaborate more on this point?
>>
>> Thanks,
>> Dong
>>
>> On Wed, Feb 28, 2018 at 10:55 PM, Jan Filipiak<Ja...@trivago.com>
>> wrote:
>>
>> Hi Dong,
>>>
>>> I tried to focus on what the steps are one can currently perform to
>>> expand
>>> or shrink a keyed topic while maintaining a top notch semantics.
>>> I can understand that there might be confusion about "stopping the
>>> consumer". It is exactly the same as proposed in the KIP. there needs to
>>> be
>>> a time the producers agree on the new partitioning. The extra semantics I
>>> want to put in there is that we have a possibility to wait until all the
>>> existing data
>>> is copied over into the new partitioning scheme. When I say stopping I
>>> think more of having a memory barrier that ensures the ordering. I am
>>> still
>>> aming for latencies  on the scale of leader failovers.
>>>
>>> Consumers have to explicitly adapt the new partitioning scheme in the
>>> above scenario. The reason is that in these cases where you are dependent
>>> on a particular partitioning scheme, you also have other topics that have
>>> co-partition enforcements or the kind -frequently. Therefore all your
>>> other
>>> input topics might need to grow accordingly.
>>>
>>>
>>> What I was suggesting was to streamline all these operations as best as
>>> possible to have "real" partition grow and shrinkage going on. Migrating
>>> the producers to a new partitioning scheme can be much more streamlined
>>> with proper broker support for this. Migrating consumer is a step that
>>> might be made completly unnecessary if - for example streams - takes the
>>> gcd as partitioning scheme instead of enforcing 1 to 1. Connect consumers
>>> and other consumers should be fine anyways.
>>>
>>> I hope this makes more clear where I was aiming at. The rest needs to be
>>> figured out. The only danger i see is that when we are introducing this
>>> feature as supposed in the KIP, it wont help any people depending on  log
>>> compaction.
>>>
>>> The other thing I wanted to mention is that I believe the current
>>> suggestion (without copying data over) can be implemented in pure
>>> userland
>>> with a custom partitioner and a small feedbackloop from ProduceResponse
>>> =>
>>> Partitionier in coorporation with a change management system.
>>>
>>> Best Jan
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>> On 28.02.2018 07:13, Dong Lin wrote:
>>>
>>> Hey Jan,
>>>>
>>>> I am not sure if it is acceptable for producer to be stopped for a
>>>> while,
>>>> particularly for online application which requires low latency. I am
>>>> also
>>>> not sure how consumers can switch to a new topic. Does user application
>>>> needs to explicitly specify a different topic for producer/consumer to
>>>> subscribe to? It will be helpful for discussion if you can provide more
>>>> detail on the interface change for this solution.
>>>>
>>>> Thanks,
>>>> Dong
>>>>
>>>> On Mon, Feb 26, 2018 at 12:48 AM, Jan Filipiak<Jan.Filipiak@trivago.com
>>>> >
>>>> wrote:
>>>>
>>>> Hi,
>>>>
>>>>> just want to throw my though in. In general the functionality is very
>>>>> usefull, we should though not try to find the architecture to hard
>>>>> while
>>>>> implementing.
>>>>>
>>>>> The manual steps would be to
>>>>>
>>>>> create a new topic
>>>>> the mirrormake from the new old topic to the new topic
>>>>> wait for mirror making to catch up.
>>>>> then put the consumers onto the new topic
>>>>>       (having mirrormaker spit out a mapping from old offsets to new
>>>>> offsets:
>>>>>           if topic is increased by factor X there is gonna be a clean
>>>>> mapping from 1 offset in the old topic to X offsets in the new topic,
>>>>>           if there is no factor then there is no chance to generate a
>>>>> mapping that can be reasonable used for continuing)
>>>>>       make consumers stop at appropriate points and continue
>>>>> consumption
>>>>> with offsets from the mapping.
>>>>> have the producers stop for a minimal time.
>>>>> wait for mirrormaker to finish
>>>>> let producer produce with the new metadata.
>>>>>
>>>>>
>>>>> Instead of implementing the approach suggest in the KIP which will
>>>>> leave
>>>>> log compacted topic completely crumbled and unusable.
>>>>> I would much rather try to build infrastructure to support the
>>>>> mentioned
>>>>> above operations more smoothly.
>>>>> Especially having producers stop and use another topic is difficult and
>>>>> it would be nice if one can trigger "invalid metadata" exceptions for
>>>>> them
>>>>> and
>>>>> if one could give topics aliases so that their produces with the old
>>>>> topic
>>>>> will arrive in the new topic.
>>>>>
>>>>> The downsides are obvious I guess ( having the same data twice for the
>>>>> transition period, but kafka tends to scale well with datasize). So
>>>>> its a
>>>>> nicer fit into the architecture.
>>>>>
>>>>> I further want to argument that the functionality by the KIP can
>>>>> completely be implementing in "userland" with a custom partitioner that
>>>>> handles the transition as needed. I would appreciate if someone could
>>>>> point
>>>>> out what a custom partitioner couldn't handle in this case?
>>>>>
>>>>> With the above approach, shrinking a topic becomes the same steps.
>>>>> Without
>>>>> loosing keys in the discontinued partitions.
>>>>>
>>>>> Would love to hear what everyone thinks.
>>>>>
>>>>> Best Jan
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> On 11.02.2018 00:35, Dong Lin wrote:
>>>>>
>>>>> Hi all,
>>>>>
>>>>>> I have created KIP-253: Support in-order message delivery with
>>>>>> partition
>>>>>> expansion. See
>>>>>> https://cwiki.apache.org/confluence/display/KAFKA/KIP-253%
>>>>>> 3A+Support+in-order+message+delivery+with+partition+expansion
>>>>>> .
>>>>>>
>>>>>> This KIP provides a way to allow messages of the same key from the
>>>>>> same
>>>>>> producer to be consumed in the same order they are produced even if we
>>>>>> expand partition of the topic.
>>>>>>
>>>>>> Thanks,
>>>>>> Dong
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>

Re: [DISCUSS] KIP-253: Support in-order message delivery with partition expansion

Posted by Jan Filipiak <Ja...@trivago.com>.
Hi Dong

thank you very much for your questions.

regarding the time spend copying data across:
It is correct that copying data from a topic with one partition mapping 
to a topic with a different partition mapping takes way longer than we 
can stop producers. Tens of minutes is a very optimistic estimate here. 
Many people can not afford copy full steam and therefore will have some 
rate limiting in place, this can bump the timespan into the day's. The 
good part is that the vast majority of the data can be copied while the 
producers are still going. One can then, piggyback the consumers ontop 
of this timeframe, by the method mentioned (provide them an mapping from 
their old offsets to new offsets in their repartitioned topics. In that 
way we separate migration of consumers from migration of producers 
(decoupling these is what kafka is strongest at). The time to actually 
swap over the producers should be kept minimal by ensuring that when a 
swap attempt is started the consumer copying over should be very close 
to the log end and is expected to finish within the next fetch. The 
operation should have a time-out and should be "reattemtable".

Importance of logcompaction:
If a producer produces key A, to partiton 0, its forever gonna be there, 
unless it gets deleted. The record might sit in there for years. A new 
producer started with the new partitions will fail to delete the record 
in the correct partition. Th record will be there forever and one can 
not reliable bootstrap new consumers. I cannot see how linear hashing 
can solve this.

Regarding your skipping of userland copying:
100%, copying the data across in userland is, as far as i can see, only 
a usecase for log compacted topics. Even for logcompaction + retentions 
it should only be opt-in. Why did I bring it up? I think log compaction 
is a very important feature to really embrace kafka as a "data 
plattform". The point I also want to make is that copying data this way 
is completely inline with the kafka architecture. it only consists of 
reading and writing to topics.

I hope it clarifies more why I think we should aim for more than the 
current KIP. I fear that once the KIP is done not much more effort will 
be taken.



On 04.03.2018 02:28, Dong Lin wrote:
> Hey Jan,
>
> In the current proposal, the consumer will be blocked on waiting for other
> consumers of the group to consume up to a given offset. In most cases, all
> consumers should be close to the LEO of the partitions when the partition
> expansion happens. Thus the time waiting should not be long e.g. on the
> order of seconds. On the other hand, it may take a long time to wait for
> the entire partition to be copied -- the amount of time is proportional to
> the amount of existing data in the partition, which can take tens of
> minutes. So the amount of time that we stop consumers may not be on the
> same order of magnitude.
>
> If we can implement this suggestion without copying data over in purse
> userland, it will be much more valuable. Do you have ideas on how this can
> be done?
>
> Not sure why the current KIP not help people who depend on log compaction.
> Could you elaborate more on this point?
>
> Thanks,
> Dong
>
> On Wed, Feb 28, 2018 at 10:55 PM, Jan Filipiak<Ja...@trivago.com>
> wrote:
>
>> Hi Dong,
>>
>> I tried to focus on what the steps are one can currently perform to expand
>> or shrink a keyed topic while maintaining a top notch semantics.
>> I can understand that there might be confusion about "stopping the
>> consumer". It is exactly the same as proposed in the KIP. there needs to be
>> a time the producers agree on the new partitioning. The extra semantics I
>> want to put in there is that we have a possibility to wait until all the
>> existing data
>> is copied over into the new partitioning scheme. When I say stopping I
>> think more of having a memory barrier that ensures the ordering. I am still
>> aming for latencies  on the scale of leader failovers.
>>
>> Consumers have to explicitly adapt the new partitioning scheme in the
>> above scenario. The reason is that in these cases where you are dependent
>> on a particular partitioning scheme, you also have other topics that have
>> co-partition enforcements or the kind -frequently. Therefore all your other
>> input topics might need to grow accordingly.
>>
>>
>> What I was suggesting was to streamline all these operations as best as
>> possible to have "real" partition grow and shrinkage going on. Migrating
>> the producers to a new partitioning scheme can be much more streamlined
>> with proper broker support for this. Migrating consumer is a step that
>> might be made completly unnecessary if - for example streams - takes the
>> gcd as partitioning scheme instead of enforcing 1 to 1. Connect consumers
>> and other consumers should be fine anyways.
>>
>> I hope this makes more clear where I was aiming at. The rest needs to be
>> figured out. The only danger i see is that when we are introducing this
>> feature as supposed in the KIP, it wont help any people depending on  log
>> compaction.
>>
>> The other thing I wanted to mention is that I believe the current
>> suggestion (without copying data over) can be implemented in pure userland
>> with a custom partitioner and a small feedbackloop from ProduceResponse =>
>> Partitionier in coorporation with a change management system.
>>
>> Best Jan
>>
>>
>>
>>
>>
>>
>>
>>
>> On 28.02.2018 07:13, Dong Lin wrote:
>>
>>> Hey Jan,
>>>
>>> I am not sure if it is acceptable for producer to be stopped for a while,
>>> particularly for online application which requires low latency. I am also
>>> not sure how consumers can switch to a new topic. Does user application
>>> needs to explicitly specify a different topic for producer/consumer to
>>> subscribe to? It will be helpful for discussion if you can provide more
>>> detail on the interface change for this solution.
>>>
>>> Thanks,
>>> Dong
>>>
>>> On Mon, Feb 26, 2018 at 12:48 AM, Jan Filipiak<Ja...@trivago.com>
>>> wrote:
>>>
>>> Hi,
>>>> just want to throw my though in. In general the functionality is very
>>>> usefull, we should though not try to find the architecture to hard while
>>>> implementing.
>>>>
>>>> The manual steps would be to
>>>>
>>>> create a new topic
>>>> the mirrormake from the new old topic to the new topic
>>>> wait for mirror making to catch up.
>>>> then put the consumers onto the new topic
>>>>       (having mirrormaker spit out a mapping from old offsets to new
>>>> offsets:
>>>>           if topic is increased by factor X there is gonna be a clean
>>>> mapping from 1 offset in the old topic to X offsets in the new topic,
>>>>           if there is no factor then there is no chance to generate a
>>>> mapping that can be reasonable used for continuing)
>>>>       make consumers stop at appropriate points and continue consumption
>>>> with offsets from the mapping.
>>>> have the producers stop for a minimal time.
>>>> wait for mirrormaker to finish
>>>> let producer produce with the new metadata.
>>>>
>>>>
>>>> Instead of implementing the approach suggest in the KIP which will leave
>>>> log compacted topic completely crumbled and unusable.
>>>> I would much rather try to build infrastructure to support the mentioned
>>>> above operations more smoothly.
>>>> Especially having producers stop and use another topic is difficult and
>>>> it would be nice if one can trigger "invalid metadata" exceptions for
>>>> them
>>>> and
>>>> if one could give topics aliases so that their produces with the old
>>>> topic
>>>> will arrive in the new topic.
>>>>
>>>> The downsides are obvious I guess ( having the same data twice for the
>>>> transition period, but kafka tends to scale well with datasize). So its a
>>>> nicer fit into the architecture.
>>>>
>>>> I further want to argument that the functionality by the KIP can
>>>> completely be implementing in "userland" with a custom partitioner that
>>>> handles the transition as needed. I would appreciate if someone could
>>>> point
>>>> out what a custom partitioner couldn't handle in this case?
>>>>
>>>> With the above approach, shrinking a topic becomes the same steps.
>>>> Without
>>>> loosing keys in the discontinued partitions.
>>>>
>>>> Would love to hear what everyone thinks.
>>>>
>>>> Best Jan
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> On 11.02.2018 00:35, Dong Lin wrote:
>>>>
>>>> Hi all,
>>>>> I have created KIP-253: Support in-order message delivery with partition
>>>>> expansion. See
>>>>> https://cwiki.apache.org/confluence/display/KAFKA/KIP-253%
>>>>> 3A+Support+in-order+message+delivery+with+partition+expansion
>>>>> .
>>>>>
>>>>> This KIP provides a way to allow messages of the same key from the same
>>>>> producer to be consumed in the same order they are produced even if we
>>>>> expand partition of the topic.
>>>>>
>>>>> Thanks,
>>>>> Dong
>>>>>
>>>>>
>>>>>


Re: [DISCUSS] KIP-253: Support in-order message delivery with partition expansion

Posted by Dong Lin <li...@gmail.com>.
Hey Jan,

In the current proposal, the consumer will be blocked on waiting for other
consumers of the group to consume up to a given offset. In most cases, all
consumers should be close to the LEO of the partitions when the partition
expansion happens. Thus the time waiting should not be long e.g. on the
order of seconds. On the other hand, it may take a long time to wait for
the entire partition to be copied -- the amount of time is proportional to
the amount of existing data in the partition, which can take tens of
minutes. So the amount of time that we stop consumers may not be on the
same order of magnitude.

If we can implement this suggestion without copying data over in purse
userland, it will be much more valuable. Do you have ideas on how this can
be done?

Not sure why the current KIP not help people who depend on log compaction.
Could you elaborate more on this point?

Thanks,
Dong

On Wed, Feb 28, 2018 at 10:55 PM, Jan Filipiak <Ja...@trivago.com>
wrote:

> Hi Dong,
>
> I tried to focus on what the steps are one can currently perform to expand
> or shrink a keyed topic while maintaining a top notch semantics.
> I can understand that there might be confusion about "stopping the
> consumer". It is exactly the same as proposed in the KIP. there needs to be
> a time the producers agree on the new partitioning. The extra semantics I
> want to put in there is that we have a possibility to wait until all the
> existing data
> is copied over into the new partitioning scheme. When I say stopping I
> think more of having a memory barrier that ensures the ordering. I am still
> aming for latencies  on the scale of leader failovers.
>
> Consumers have to explicitly adapt the new partitioning scheme in the
> above scenario. The reason is that in these cases where you are dependent
> on a particular partitioning scheme, you also have other topics that have
> co-partition enforcements or the kind -frequently. Therefore all your other
> input topics might need to grow accordingly.
>
>
> What I was suggesting was to streamline all these operations as best as
> possible to have "real" partition grow and shrinkage going on. Migrating
> the producers to a new partitioning scheme can be much more streamlined
> with proper broker support for this. Migrating consumer is a step that
> might be made completly unnecessary if - for example streams - takes the
> gcd as partitioning scheme instead of enforcing 1 to 1. Connect consumers
> and other consumers should be fine anyways.
>
> I hope this makes more clear where I was aiming at. The rest needs to be
> figured out. The only danger i see is that when we are introducing this
> feature as supposed in the KIP, it wont help any people depending on  log
> compaction.
>
> The other thing I wanted to mention is that I believe the current
> suggestion (without copying data over) can be implemented in pure userland
> with a custom partitioner and a small feedbackloop from ProduceResponse =>
> Partitionier in coorporation with a change management system.
>
> Best Jan
>
>
>
>
>
>
>
>
> On 28.02.2018 07:13, Dong Lin wrote:
>
>> Hey Jan,
>>
>> I am not sure if it is acceptable for producer to be stopped for a while,
>> particularly for online application which requires low latency. I am also
>> not sure how consumers can switch to a new topic. Does user application
>> needs to explicitly specify a different topic for producer/consumer to
>> subscribe to? It will be helpful for discussion if you can provide more
>> detail on the interface change for this solution.
>>
>> Thanks,
>> Dong
>>
>> On Mon, Feb 26, 2018 at 12:48 AM, Jan Filipiak <Ja...@trivago.com>
>> wrote:
>>
>> Hi,
>>>
>>> just want to throw my though in. In general the functionality is very
>>> usefull, we should though not try to find the architecture to hard while
>>> implementing.
>>>
>>> The manual steps would be to
>>>
>>> create a new topic
>>> the mirrormake from the new old topic to the new topic
>>> wait for mirror making to catch up.
>>> then put the consumers onto the new topic
>>>      (having mirrormaker spit out a mapping from old offsets to new
>>> offsets:
>>>          if topic is increased by factor X there is gonna be a clean
>>> mapping from 1 offset in the old topic to X offsets in the new topic,
>>>          if there is no factor then there is no chance to generate a
>>> mapping that can be reasonable used for continuing)
>>>      make consumers stop at appropriate points and continue consumption
>>> with offsets from the mapping.
>>> have the producers stop for a minimal time.
>>> wait for mirrormaker to finish
>>> let producer produce with the new metadata.
>>>
>>>
>>> Instead of implementing the approach suggest in the KIP which will leave
>>> log compacted topic completely crumbled and unusable.
>>> I would much rather try to build infrastructure to support the mentioned
>>> above operations more smoothly.
>>> Especially having producers stop and use another topic is difficult and
>>> it would be nice if one can trigger "invalid metadata" exceptions for
>>> them
>>> and
>>> if one could give topics aliases so that their produces with the old
>>> topic
>>> will arrive in the new topic.
>>>
>>> The downsides are obvious I guess ( having the same data twice for the
>>> transition period, but kafka tends to scale well with datasize). So its a
>>> nicer fit into the architecture.
>>>
>>> I further want to argument that the functionality by the KIP can
>>> completely be implementing in "userland" with a custom partitioner that
>>> handles the transition as needed. I would appreciate if someone could
>>> point
>>> out what a custom partitioner couldn't handle in this case?
>>>
>>> With the above approach, shrinking a topic becomes the same steps.
>>> Without
>>> loosing keys in the discontinued partitions.
>>>
>>> Would love to hear what everyone thinks.
>>>
>>> Best Jan
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>> On 11.02.2018 00:35, Dong Lin wrote:
>>>
>>> Hi all,
>>>>
>>>> I have created KIP-253: Support in-order message delivery with partition
>>>> expansion. See
>>>> https://cwiki.apache.org/confluence/display/KAFKA/KIP-253%
>>>> 3A+Support+in-order+message+delivery+with+partition+expansion
>>>> .
>>>>
>>>> This KIP provides a way to allow messages of the same key from the same
>>>> producer to be consumed in the same order they are produced even if we
>>>> expand partition of the topic.
>>>>
>>>> Thanks,
>>>> Dong
>>>>
>>>>
>>>>
>