You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cassandra.apache.org by Patrick Julien <pj...@gmail.com> on 2011/06/06 17:06:17 UTC

working with time uuid

How does this work exactly?  If you're using generation 1 time uuids
for your keys to get ordering, doesn't this mean the keys need to be
generated all on the same host when you either query or insert?  Or
does cassandra only inspect the bits that represent the time stamp of
the UUID when performing a lookup?

Re: working with time uuid

Posted by Jonathan Ellis <jb...@gmail.com>.
... although it does break "ties" by comparing the other bytes.

On Mon, Jun 6, 2011 at 10:52 AM, Paul Loy <ke...@gmail.com> wrote:
>     private static int compareTimestampBytes(ByteBuffer o1, ByteBuffer o2)
>     {
>         int o1Pos = o1.position();
>         int o2Pos = o2.position();
>
>         int d = (o1.get(o1Pos+6) & 0xF) - (o2.get(o2Pos+6) & 0xF);
>         if (d != 0) return d;
>
>         d = (o1.get(o1Pos+7) & 0xFF) - (o2.get(o2Pos+7) & 0xFF);
>         if (d != 0) return d;
>
>         d = (o1.get(o1Pos+4) & 0xFF) - (o2.get(o2Pos+4) & 0xFF);
>         if (d != 0) return d;
>
>         d = (o1.get(o1Pos+5) & 0xFF) - (o2.get(o2Pos+5) & 0xFF);
>         if (d != 0) return d;
>
>         d = (o1.get(o1Pos) & 0xFF) - (o2.get(o2Pos) & 0xFF);
>         if (d != 0) return d;
>
>         d = (o1.get(o1Pos+1) & 0xFF) - (o2.get(o2Pos+1) & 0xFF);
>         if (d != 0) return d;
>
>         d = (o1.get(o1Pos+2) & 0xFF) - (o2.get(o2Pos+2) & 0xFF);
>         if (d != 0) return d;
>
>         return (o1.get(o1Pos+3) & 0xFF) - (o2.get(o2Pos+3) & 0xFF);
>     }
>
> Looks like it's only comparing the timestamp bytes.
>
> On Mon, Jun 6, 2011 at 4:06 PM, Patrick Julien <pj...@gmail.com> wrote:
>>
>> How does this work exactly?  If you're using generation 1 time uuids
>> for your keys to get ordering, doesn't this mean the keys need to be
>> generated all on the same host when you either query or insert?  Or
>> does cassandra only inspect the bits that represent the time stamp of
>> the UUID when performing a lookup?
>
>
>
> --
> ---------------------------------------------
> Paul Loy
> paul@keteracel.com
> http://uk.linkedin.com/in/paulloy
>



-- 
Jonathan Ellis
Project Chair, Apache Cassandra
co-founder of DataStax, the source for professional Cassandra support
http://www.datastax.com

Re: working with time uuid

Posted by Patrick Julien <pj...@gmail.com>.
thanks

On Mon, Jun 6, 2011 at 11:52 AM, Paul Loy <ke...@gmail.com> wrote:
>     private static int compareTimestampBytes(ByteBuffer o1, ByteBuffer o2)
>     {
>         int o1Pos = o1.position();
>         int o2Pos = o2.position();
>
>         int d = (o1.get(o1Pos+6) & 0xF) - (o2.get(o2Pos+6) & 0xF);
>         if (d != 0) return d;
>
>         d = (o1.get(o1Pos+7) & 0xFF) - (o2.get(o2Pos+7) & 0xFF);
>         if (d != 0) return d;
>
>         d = (o1.get(o1Pos+4) & 0xFF) - (o2.get(o2Pos+4) & 0xFF);
>         if (d != 0) return d;
>
>         d = (o1.get(o1Pos+5) & 0xFF) - (o2.get(o2Pos+5) & 0xFF);
>         if (d != 0) return d;
>
>         d = (o1.get(o1Pos) & 0xFF) - (o2.get(o2Pos) & 0xFF);
>         if (d != 0) return d;
>
>         d = (o1.get(o1Pos+1) & 0xFF) - (o2.get(o2Pos+1) & 0xFF);
>         if (d != 0) return d;
>
>         d = (o1.get(o1Pos+2) & 0xFF) - (o2.get(o2Pos+2) & 0xFF);
>         if (d != 0) return d;
>
>         return (o1.get(o1Pos+3) & 0xFF) - (o2.get(o2Pos+3) & 0xFF);
>     }
>
> Looks like it's only comparing the timestamp bytes.
>
> On Mon, Jun 6, 2011 at 4:06 PM, Patrick Julien <pj...@gmail.com> wrote:
>>
>> How does this work exactly?  If you're using generation 1 time uuids
>> for your keys to get ordering, doesn't this mean the keys need to be
>> generated all on the same host when you either query or insert?  Or
>> does cassandra only inspect the bits that represent the time stamp of
>> the UUID when performing a lookup?
>
>
>
> --
> ---------------------------------------------
> Paul Loy
> paul@keteracel.com
> http://uk.linkedin.com/in/paulloy
>

Re: working with time uuid

Posted by Paul Loy <ke...@gmail.com>.
well, to clarify, it first checks the timestamp bytes, then the rest so it
doesn;t say they're the same if they came from 2 different servers.


On Mon, Jun 6, 2011 at 4:52 PM, Paul Loy <ke...@gmail.com> wrote:

>     private static int compareTimestampBytes(ByteBuffer o1, ByteBuffer o2)
>     {
>         int o1Pos = o1.position();
>         int o2Pos = o2.position();
>
>         int d = (o1.get(o1Pos+6) & 0xF) - (o2.get(o2Pos+6) & 0xF);
>         if (d != 0) return d;
>
>         d = (o1.get(o1Pos+7) & 0xFF) - (o2.get(o2Pos+7) & 0xFF);
>         if (d != 0) return d;
>
>         d = (o1.get(o1Pos+4) & 0xFF) - (o2.get(o2Pos+4) & 0xFF);
>         if (d != 0) return d;
>
>         d = (o1.get(o1Pos+5) & 0xFF) - (o2.get(o2Pos+5) & 0xFF);
>         if (d != 0) return d;
>
>         d = (o1.get(o1Pos) & 0xFF) - (o2.get(o2Pos) & 0xFF);
>         if (d != 0) return d;
>
>         d = (o1.get(o1Pos+1) & 0xFF) - (o2.get(o2Pos+1) & 0xFF);
>         if (d != 0) return d;
>
>         d = (o1.get(o1Pos+2) & 0xFF) - (o2.get(o2Pos+2) & 0xFF);
>         if (d != 0) return d;
>
>         return (o1.get(o1Pos+3) & 0xFF) - (o2.get(o2Pos+3) & 0xFF);
>     }
>
>
> Looks like it's only comparing the timestamp bytes.
>
>
> On Mon, Jun 6, 2011 at 4:06 PM, Patrick Julien <pj...@gmail.com> wrote:
>
>> How does this work exactly?  If you're using generation 1 time uuids
>> for your keys to get ordering, doesn't this mean the keys need to be
>> generated all on the same host when you either query or insert?  Or
>> does cassandra only inspect the bits that represent the time stamp of
>> the UUID when performing a lookup?
>>
>
>
>
> --
> ---------------------------------------------
> Paul Loy
> paul@keteracel.com
> http://uk.linkedin.com/in/paulloy
>



-- 
---------------------------------------------
Paul Loy
paul@keteracel.com
http://uk.linkedin.com/in/paulloy

Re: working with time uuid

Posted by Paul Loy <ke...@gmail.com>.
    private static int compareTimestampBytes(ByteBuffer o1, ByteBuffer o2)
    {
        int o1Pos = o1.position();
        int o2Pos = o2.position();

        int d = (o1.get(o1Pos+6) & 0xF) - (o2.get(o2Pos+6) & 0xF);
        if (d != 0) return d;

        d = (o1.get(o1Pos+7) & 0xFF) - (o2.get(o2Pos+7) & 0xFF);
        if (d != 0) return d;

        d = (o1.get(o1Pos+4) & 0xFF) - (o2.get(o2Pos+4) & 0xFF);
        if (d != 0) return d;

        d = (o1.get(o1Pos+5) & 0xFF) - (o2.get(o2Pos+5) & 0xFF);
        if (d != 0) return d;

        d = (o1.get(o1Pos) & 0xFF) - (o2.get(o2Pos) & 0xFF);
        if (d != 0) return d;

        d = (o1.get(o1Pos+1) & 0xFF) - (o2.get(o2Pos+1) & 0xFF);
        if (d != 0) return d;

        d = (o1.get(o1Pos+2) & 0xFF) - (o2.get(o2Pos+2) & 0xFF);
        if (d != 0) return d;

        return (o1.get(o1Pos+3) & 0xFF) - (o2.get(o2Pos+3) & 0xFF);
    }


Looks like it's only comparing the timestamp bytes.

On Mon, Jun 6, 2011 at 4:06 PM, Patrick Julien <pj...@gmail.com> wrote:

> How does this work exactly?  If you're using generation 1 time uuids
> for your keys to get ordering, doesn't this mean the keys need to be
> generated all on the same host when you either query or insert?  Or
> does cassandra only inspect the bits that represent the time stamp of
> the UUID when performing a lookup?
>



-- 
---------------------------------------------
Paul Loy
paul@keteracel.com
http://uk.linkedin.com/in/paulloy