Re: sample code for customised Partition logic
Hi, It is look like correct implementation. How do you come to conclusion, which something wrong? On Mon, Oct 17, 2016 at 6:29 AM, minisoft_rm <minisoft...@hotmail.com> wrote: > Hi Val, > the reason is that "assignPartitions()" returns same > "List<List>" usually even I start two ignite nodes. > > last Friday, I refactor it as below:[ > > @Override > public List<List> assignPartitions(final > AffinityFunctionContext affCtx) > { > final List nodes = affCtx. > currentTopologySnapshot(); > int tmpi = 0; > final List<List> assignments = new > ArrayList<>(2); > for (int i = 0; i < 2; i++) > { > final List partAssignment = new > ArrayList(); > > partAssignment.add(nodes.get(tmpi)); > > if (tmpi < nodes.size() - 1) > { > tmpi++; > } > > assignments.add(partAssignment); > > } > return assignments; > } > ] > > and it return result like: > list[0] -> node1; > list[1] -> node2. > > it is what I want. > > I don't think the original "assignPartitions()" has bug. (there are > lots > of people use it without error, right?) > but why "assignPartitions()" returns to me the same node# List ? > > > > > -- > View this message in context: http://apache-ignite-users. > 70518.x6.nabble.com/sample-code-for-customised-Partition- > logic-tp8270p8317.html > Sent from the Apache Ignite Users mailing list archive at Nabble.com. > -- Vladislav Pyatkov
Re: sample code for customised Partition logic
Hi Val, the reason is that "assignPartitions()" returns same "List<ListClusterNode>>" usually even I start two ignite nodes. last Friday, I refactor it as below:[ @Override public List<ListClusterNode>> assignPartitions(final AffinityFunctionContext affCtx) { final List nodes = affCtx.currentTopologySnapshot(); int tmpi = 0; final List<ListClusterNode>> assignments = new ArrayList<>(2); for (int i = 0; i < 2; i++) { final List partAssignment = new ArrayList(); partAssignment.add(nodes.get(tmpi)); if (tmpi < nodes.size() - 1) { tmpi++; } assignments.add(partAssignment); } return assignments; } ] and it return result like: list[0] -> node1; list[1] -> node2. it is what I want. I don't think the original "assignPartitions()" has bug. (there are lots of people use it without error, right?) but why "assignPartitions()" returns to me the same node# List ? -- View this message in context: http://apache-ignite-users.70518.x6.nabble.com/sample-code-for-customised-Partition-logic-tp8270p8317.html Sent from the Apache Ignite Users mailing list archive at Nabble.com.
Re: sample code for customised Partition logic
Hi, What exactly are you trying to achieve? Modifying the affinity function can be a challenging task and is generally needed only for very rare specific use cases. -Val -- View this message in context: http://apache-ignite-users.70518.x6.nabble.com/sample-code-for-customised-Partition-logic-tp8270p8277.html Sent from the Apache Ignite Users mailing list archive at Nabble.com.
sample code for customised Partition logic
Dear All, I can not find sample code for how customise partition... and I could almost finish it by myself. however, the most wired thing is it work occasionally !!?? most of time it doesn't work my code is:[ public class UCSRendezvousAffinityFunction extends RendezvousAffinityFunction { public int partitions() { return 2; //only test 2 partitions :-) } public int partition(final Object key) { ... return xxx % 2; } //this API is...correct?? public List<ListClusterNode>> assignPartitions(final AffinityFunctionContext affCtx) { final List<ListClusterNode>> assignments = new ArrayList<>(partitions()); final boolean exclNeighbors = false; final Map<UUID, CollectionClusterNode>> neighborhoodCache = exclNeighbors ? GridCacheUtils.neighbors(affCtx.currentTopologySnapshot()) : null; for (int i = 0; i < partitions(); i++) { final List partAssignment = assignPartition(i, affCtx.currentTopologySnapshot(), affCtx.backups(), neighborhoodCache); assignments.add(partAssignment); } return assignments; } } ] So as I said... it works from time to timewhy. and could you show me if my API of "assignPartitions()" is right or maybe do me a favour what is your code? thanks a lot. -- View this message in context: http://apache-ignite-users.70518.x6.nabble.com/sample-code-for-customised-Partition-logic-tp8270.html Sent from the Apache Ignite Users mailing list archive at Nabble.com.