Home | About | Sematext search-lucene.com search-hadoop.com
 Search Hadoop and all its subprojects:

Switch to Threaded View
HBase >> mail # user >> Timestamp as a key good practice?


Copy link to this message
-
Re: Timestamp as a key good practice?
Jean-Marc,

You do realize that this really isn't a good use case for HBase, assuming that what you are describing is a stand alone system.
It would be easier and better if you just used a simple relational database.
Then you would have your table w an ID, and a secondary index on the timestamp.
Retrieve the data in Ascending order by timestamp and take the top 500 off the list.

If you insist on using HBase, yes you will have to have a secondary table.
Then using co-processors...
When you update the row in your base table, you
then get() the row in your index by timestamp, removing the column for that rowid.
Add the new column to the timestamp row.

As you put it.

Now you can just do a partial scan on your index. Because your index table is so small... you shouldn't worry about hotspots.
You may just want to rebuild your index every so often...

HTH

-Mike

On Jun 14, 2012, at 7:22 AM, Jean-Marc Spaggiari wrote:

> Hi Michael,
>
> Thanks for your feedback. Here are more details to describe what I'm
> trying to achieve.
>
> My goal is to store information about files into the database. I need
> to check the oldest files in the database to refresh the information.
>
> The key is an 8 bytes ID of the server name in the network hosting the
> file + MD5 of the file path. Total is a 24 bytes key.
>
> So each time I look at a file and gather the information, I update its
> row in the database based on the key including a "last_update" field.
> I can calculate this key for any file in the drives.
>
> In order to know which file I need to check in the network, I need to
> scan the table by "last_update" field. So the idea is to build another
> table which contain the last_update as a key and the files IDs in
> columns. (Here is the hotspotting)
>
> Each time I work on a file, I will have to update the main table by ID
> and remove the cell from the second table (the index) and put it back
> with the new "last_update" key.
>
> I'm mainly doing 3 operations in the database.
> 1) I retrieve a list of 500 files which need to be update
> 2) I update the information for  those 500 files (bulk update)
> 3) I load new files references to be checked.
>
> For 2 and 3, I use the main table with the file ID as the key. the
> distribution is almost perfect because I'm using hash. The prefix is
> the server ID but it's not always going to the same server since it's
> done by last_update. But this allow a quick access to the list of
> files from one server.
> For 1, I have expected to build this second table with the
> "last_update" as the key.
>
> Regarding the frequency, it really depends on the activities on the
> network, but it should be "often".  The faster the database update
> will be, the more up to date I will be able to keep it.
>
> JM
>
> 2012/6/14, Michael Segel <[EMAIL PROTECTED]>:
>> Actually I think you should revisit your key design....
>>
>> Look at your access path to the data for each of the types of queries you
>> are going to run.
>> From your post:
>> "I have a table with a uniq key, a file path and a "last update" field.
>>>>> I can easily find back the file with the ID and find when it has been
>>>>> updated.
>>>>>
>>>>> But what I need too is to find the files not updated for more than a
>>>>> certain period of time.
>> "
>> So your primary query is going to be against the key.
>> Not sure if you meant to say that your key was a composite key or not...
>> sounds like your key is just the unique key and the rest are columns in the
>> table.
>>
>> The secondary query or path to the data is to find data where the files were
>> not updated for more than a period of time.
>>
>> If you make your key temporal, that is adding time as a component of your
>> key, you will end up creating new rows of data while the old row still
>> exists.
>> Not a good side effect.
>>
>> The other nasty side effect of using time as your key is that you not only
>> have the potential for hot spotting, but that you also have the nasty side