You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@hbase.apache.org by yun peng <pe...@gmail.com> on 2012/10/16 22:24:34 UTC

how to get the timestamp of hfile, like when it's generated.

Hi, All
Given ``hfile`` in ``hbase`` is immutable, I want to know the timestamp
like when the ``hfile`` is generated. Does ``hbase`` have API to allow
user-applications to know this? I  need to know in postCompact() stage.

As a first attempt, I have tried using
``StoreFile.getBulkLoadTimestamp()``. By following code snippet, I
constantly get ``NullPointerException``.
  public void postCompact(ObserverContext<RegionCoprocessorEnvironment> c,
Store store, StoreFile resultFile) {
    if(resultFile == null) {
        return;
    }
    int timestampLastCompact = resultFile.getBulkLoadTimestamp();
    ...
  }

Any ideas are appreciated. Thanks.
Yun

RE: how to get the timestamp of hfile, like when it's generated.

Posted by "Ramkrishna.S.Vasudevan" <ra...@huawei.com>.
Hi Yun Peng

You want to know the creation time? I could see the getModificationTime()
api.  Internally it is used to get a store file with minimum timestamp.
I have not tried it out.  Let me know if it solves your purpose.
Just try it out.

Regards
Ram
> -----Original Message-----
> From: yun peng [mailto:pengyunmomo@gmail.com]
> Sent: Wednesday, October 17, 2012 1:55 AM
> To: user@hbase.apache.org
> Subject: how to get the timestamp of hfile, like when it's generated.
> 
> Hi, All
> Given ``hfile`` in ``hbase`` is immutable, I want to know the timestamp
> like when the ``hfile`` is generated. Does ``hbase`` have API to allow
> user-applications to know this? I  need to know in postCompact() stage.
> 
> As a first attempt, I have tried using
> ``StoreFile.getBulkLoadTimestamp()``. By following code snippet, I
> constantly get ``NullPointerException``.
>   public void postCompact(ObserverContext<RegionCoprocessorEnvironment>
> c,
> Store store, StoreFile resultFile) {
>     if(resultFile == null) {
>         return;
>     }
>     int timestampLastCompact = resultFile.getBulkLoadTimestamp();
>     ...
>   }
> 
> Any ideas are appreciated. Thanks.
> Yun


Re: how to get the timestamp of hfile, like when it's generated.

Posted by yun peng <pe...@gmail.com>.
Hi, Ram and Stack,
It works for me, after an initial try out. Though the name seems a bit
confusing, as hfile in hbase is immutable and not supposed to be "modified"
afterwards, -)
Regards,
Yun

On Wed, Oct 17, 2012 at 1:09 AM, Stack <st...@duboce.net> wrote:

> On Tue, Oct 16, 2012 at 9:06 PM, Ramkrishna.S.Vasudevan
> <ra...@huawei.com> wrote:
> > Hi Yun Peng
> >
> > You want to know the creation time? I could see the getModificationTime()
> > api.  Internally it is used to get a store file with minimum timestamp.
> > I have not tried it out.  Let me know if it solves your purpose.
> > Just try it out.
> >
>
> To add to Rams' response, if you have a reader on the file, you can
> get some of its attributes (which I believe come from metadata block
> -- you should check the code) and you can iterate the metadata too
> which has stuff first and last keys, average size, etc.  See here:
>
> http://hbase.apache.org/apidocs/org/apache/hadoop/hbase/io/hfile/HFile.Reader.html
>  To look at a particular file's metadata, see the hfile tool at
> "9.7.5.2.2. HFile Tool" in the reference guide.
>
> St.Ack
>

Re: how to get the timestamp of hfile, like when it's generated.

Posted by Stack <st...@duboce.net>.
On Tue, Oct 16, 2012 at 9:06 PM, Ramkrishna.S.Vasudevan
<ra...@huawei.com> wrote:
> Hi Yun Peng
>
> You want to know the creation time? I could see the getModificationTime()
> api.  Internally it is used to get a store file with minimum timestamp.
> I have not tried it out.  Let me know if it solves your purpose.
> Just try it out.
>

To add to Rams' response, if you have a reader on the file, you can
get some of its attributes (which I believe come from metadata block
-- you should check the code) and you can iterate the metadata too
which has stuff first and last keys, average size, etc.  See here:
http://hbase.apache.org/apidocs/org/apache/hadoop/hbase/io/hfile/HFile.Reader.html
 To look at a particular file's metadata, see the hfile tool at
"9.7.5.2.2. HFile Tool" in the reference guide.

St.Ack