why do you care about id's being wasted? This is the purpose of HiLo, reducing id traffic. If there was a way to preserve counter, it would be to store it in DB everytime it is incremented, which is not what we want
Tuna Toksöz Eternal sunshine of the open source mind. http://devlicio.us/blogs/tuna_toksoz http://tunatoksoz.com http://twitter.com/tehlike On Sat, Apr 3, 2010 at 2:51 PM, Visar Uruqi <visar.ur...@gmail.com> wrote: > Hello Diego > > Thank you very much for your detailed explanation > I did some tests and found out many things about the hilo > implementation in nhibernate, > > I have a question regarding the lo value the so called "counter" > You said "Whenever the counter reaches max_lo, it fetches a new Hi > value from the DB." > > Well After I restart my application the counter doesn't continue where > it left, instead > it inserts a new "next_hi" value specifically it increment's the > "next_hi" value in DB, > whereby it wastes many id's, what I'm trying to say, the counter > doesn't reach > necessarily the max_lo, after application restart it fetches a new Hi. > > Is there a way to preserve the counter, so if it doesn't reach the > max_lo, it should > continue where it left on the next start of application and not insert > a new nex_hi value > and whereby waste a whole range of keys? Is there a possibility to > continue where it left? > > Visar > > > On Mar 31, 11:25 pm, Diego Mijelshon <di...@mijelshon.com.ar> wrote: > > Read the post carefully. The second formula is how to determine the value > to > > insert as the initial "next_hi" when migrating from identity. > > > > You can see exactly how the IDs are generated here: > https://nhibernate.svn.sourceforge.net/svnroot/nhibernate/trunk/nhibe... > > . > > They are not random, they are sequential. > > > > And yes, you can potentially run out ofhi numbers. To avoid it, you need > > to: > > - Use long enough Id columns (32 or 64 bits depending on the usage) > > - Adjust the max_lo value to reduce the "wasted" key space when > application > > instances generate much less values than the default (this applies mostly > to > > desktop applications) > > > > Diego > > > > > > > > On Wed, Mar 31, 2010 at 17:36, Visar Uruqi <visar.ur...@gmail.com> > wrote: > > > Thank you very much Diego for your reply. > > > > > I found the following formulas in this link > > > > >http://stackoverflow.com/questions/1390078/is-there-a-practical-way-o. > .. > > > > > hilo-id = high-value * max_lo + low-value > > > > > high-value = ceiling(current-identity / max-lo) > > > > > Can you check if they are ok? Is the hilo-id really by this > > > formulas generated? > > > > > How is the lo-value generated in the clients computer? Randomly? > > > > > Is it true that all numbers might get exhausted? > > > > > Visar > > > > > On Mar 31, 3:58 pm, Diego Mijelshon <di...@mijelshon.com.ar> wrote: > > > > There aren't many steps... it's pretty simple... I'll try to address > your > > > > questions. > > > > > > I did not understood this part "Don’t use this generator with a user- > > > > > > supplied connection". > > > > > > Anybody know what he meant with this? > > > > > > ISessionFactory.OpenSession has overloads that take an IDbConnection. > > > > If you use them, you can't use HiLo, because it needs the > SessionFactory > > > to > > > > be managing connections. > > > > It's an implementation detail, but basically, the hi values are > retrieved > > > in > > > > a separate transaction, as they are SessionFactory-wide and > indepentent > > > of > > > > the Session-initiated transaction. > > > > > > I tried the hilo and it generates a table with the name > > > > > > "hibernate_unique_key" and one > > > > > > column "next_hi" > > > > > > Those are actually configurable. It might help thinking of that table > > > with a > > > > single column and record as a replacement for sequences in databases > that > > > > don't support them. When you use seqhilo, all you have is a sequence > > > name. > > > > > > It also generates high values for ID's like 32772 > > > > > > I would like to understand this in depth, what are they for? > > > > > > The HiLo algorithm is pretty straightforward. > > > > Each identifier is composed by two parts, a Hi value that comes from > the > > > DB, > > > > and a Lo value that is generated locally (an incrementing counter) > > > > The Id is generating by combining those two parts, based on the > max_lo > > > > parameter, which specifies how many values you can generate for each > Hi > > > > value retrieved from the DB. > > > > The default max_lo is 32767, which means the lower 15 bits would be > used > > > for > > > > Lo values (that's why a value like 32772 is generated in the first > > > > transaction). > > > > Whenever the counter reaches max_lo, it fetches a new Hi value from > the > > > DB. > > > > > > For the implications of the HiLo behavior, I recommend this post by > > > Fabio: > > >http://fabiomaulo.blogspot.com/2009/02/nh210-generators-behavior-expl. > .. > > > > > > Diego > > > > > > On Wed, Mar 31, 2010 at 10:10, Visar Uruqi <visar.ur...@gmail.com> > > > wrote: > > > > > Hello > > > > > > > Is there a step by step using hilo article? > > > > > > > I found out that in order to take advantage of batch commands in > > > > > nhibernate > > > > > you have to use hile generator (<generator class="hilo" />) > > > > > I looked at Nh Doc and Nh in Action, it does not say much about it, > > > > > I've came accross this statement: > > > > > > > "Generates identifiers that are unique only for a particular > database. > > > > > A high/low algorithm > > > > > is an efficient way to generate identifiers of any integral type, > > > > > given a table and > > > > > column (by default hibernate_unique_key and next_hi, respectively) > as > > > > > a source of hi > > > > > values. See (Ambler 2002) for more information about the high/low > > > > > approach to unique > > > > > identifiers. Don’t use this generator with a user-supplied > > > > > connection." > > > > > > > I did not understood this part "Don’t use this generator with a > user- > > > > > supplied connection". > > > > > Anybody know what he meant with this? > > > > > > > I tried the hilo and it generates a table with the name > > > > > "hibernate_unique_key" and one > > > > > column "next_hi", It also generates high values for ID's like 32772 > > > > > I would like to understand this in depth, what are they for? > > > > > If anybody knows a link that explains much in detail about hilo? > > > > > I'm very curious to know about this. > > > > > > > Visar > > > > > > > -- > > > > > You received this message because you are subscribed to the Google > > > Groups > > > > > "nhusers" group. > > > > > To post to this group, send email to nhus...@googlegroups.com. > > > > > To unsubscribe from this group, send email to > > > > > nhusers+unsubscr...@googlegroups.com<nhusers%2bunsubscr...@googlegroups.com> > <nhusers%2bunsubscr...@googlegroups.com<nhusers%252bunsubscr...@googlegroups.com>> > > > <nhusers%2bunsubscr...@googlegroups.com<nhusers%252bunsubscr...@googlegroups.com> > <nhusers%252bunsubscr...@googlegroup s.com>> > > > > > . > > > > > For more options, visit this group at > > > > >http://groups.google.com/group/nhusers?hl=en. > > > > > -- > > > You received this message because you are subscribed to the Google > Groups > > > "nhusers" group. > > > To post to this group, send email to nhus...@googlegroups.com. > > > To unsubscribe from this group, send email to > > > nhusers+unsubscr...@googlegroups.com<nhusers%2bunsubscr...@googlegroups.com> > <nhusers%2bunsubscr...@googlegroups.com<nhusers%252bunsubscr...@googlegroups.com>> > > > . > > > For more options, visit this group at > > >http://groups.google.com/group/nhusers?hl=en. > > -- > You received this message because you are subscribed to the Google Groups > "nhusers" group. > To post to this group, send email to nhus...@googlegroups.com. > To unsubscribe from this group, send email to > nhusers+unsubscr...@googlegroups.com<nhusers%2bunsubscr...@googlegroups.com> > . > For more options, visit this group at > http://groups.google.com/group/nhusers?hl=en. > > -- You received this message because you are subscribed to the Google Groups "nhusers" group. To post to this group, send email to nhus...@googlegroups.com. To unsubscribe from this group, send email to nhusers+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/nhusers?hl=en.