hbase-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Rohit Nigam" <rni...@decarta.com>
Subject RE: version mismatch exception
Date Wed, 24 Aug 2011 04:15:22 GMT
Hi Guys
Would like to post the source code as per the steps described by St.Ack. to edit one of the
ENDKEY of a record in .META. table 

import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.hadoop.hbase.client.Get;
import java.io.IOException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.HRegionInfo;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.client.Delete;
import org.apache.hadoop.hbase.client.HTable;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.Writables;
import org.apache.hadoop.hbase.client.HBaseAdmin;


public class FixMetaTable {

    public static String regionNameKey = "RegionName";

    public static void main(String[] args) throws InterruptedException {
        try {
            System.out.println("Entering the Program to Edit .META. table");
            Configuration hConfig = HBaseConfiguration.create();
            hConfig.set("hbase.zookeeper.quorum", System.getProperty("zk"));

            HBaseAdmin admin = new HBaseAdmin(hConfig);
            
            HTable hTable = new HTable(hConfig, Bytes.toBytes(".META."));
            Get get = new Get(Bytes.toBytes("regionNameKey"));
            Result result = hTable.get(get);
            byte[] bytes = result.getValue(HConstants.CATALOG_FAMILY, HConstants.REGIONINFO_QUALIFIER);

            HRegionInfo closedRegion = Writables.getHRegionInfo(bytes);
            admin.closeRegion(closedRegion.getRegionName(), null);//. Close the existing region
if open.
            System.out.println("Closed the Region " + closedRegion.getRegionNameAsString());




            HTable readTable = new HTable(hConfig, Bytes.toBytes(".META."));
            Get readGet = new Get(Bytes.toBytes(regionNameKey));
            Result readResult = readTable.get(readGet);
            byte[] readBytes = readResult.getValue(HConstants.CATALOG_FAMILY, HConstants.REGIONINFO_QUALIFIER);

            HRegionInfo existingRegion = Writables.getHRegionInfo(readBytes); //Read the existing
hregioninfo.

            System.out.println("Read the existing region info after closing " + existingRegion.getRegionNameAsString());

            HTableDescriptor descriptor = new HTableDescriptor(existingRegion.getTableDesc());
//Use existing hregioninfo htabledescriptor and this construction
            // Just changing the End key , nothing else
            HRegionInfo newRegion = new HRegionInfo(descriptor, Bytes.toBytes("STARTKEY"),
Bytes.toBytes("ENDKEY")); //byte[], byte[]),

            byte[] value = Writables.getBytes(newRegion);

            Put put = new Put(newRegion.getRegionName()); //  Same time stamp from the record.
            put.add(HConstants.CATALOG_FAMILY, HConstants.REGIONINFO_QUALIFIER, value);//Insert
the new entry in .META. using new hregioninfo name as row key and add an info:regioninfo whose
contents is the serialized new hregioninfo.
            HTable metaTable = new HTable(hConfig, ".META.");
            metaTable.put(put);
            System.out.println("Put a new Region " + newRegion.getRegionNameAsString() + "
End key is " + Bytes.toString(newRegion.getEndKey()));


            Delete del = new Delete(closedRegion.getRegionName());//Delete the original row
from .META.
            metaTable.delete(del);

            System.out.println("Deleted the closed region " + closedRegion.getRegionNameAsString());

            admin.assign(newRegion.getRegionName(), true); //Assign the new region.
            System.out.println("Assigned the new region " + newRegion.getRegionNameAsString());

        } catch (IOException ex) {
            Logger.getLogger(FixMetaTable.class.getName()).log(Level.SEVERE, null, ex);
        }

    }
}

Before running this code please  take a copy of the files from the actual table in the file
system using the encodedid which can be figured out in the .META. for the region which is
getting changed.Once the new Region is formed copy the data back in the file system under
the new encodedid generated from the new region.

Thanks
Rohit

-----Original Message-----
From: saint.ack@gmail.com [mailto:saint.ack@gmail.com] On Behalf Of Stack
Sent: Thursday, August 18, 2011 2:45 PM
To: Rohit Nigam
Cc: Geoff Hendrey; user@hbase.apache.org; Search
Subject: Re: version mismatch exception

What you think caused it?
St.Ack

On Thu, Aug 18, 2011 at 2:43 PM, Rohit Nigam <rnigam@decarta.com> wrote:
> Thanks St.Ack
> This really worked , was able to fix the hole .
> Thanks
> Rohit
>
> -----Original Message-----
> From: saint.ack@gmail.com [mailto:saint.ack@gmail.com] On Behalf Of Stack
> Sent: Thursday, August 18, 2011 11:29 AM
> To: Rohit Nigam
> Cc: Geoff Hendrey; user@hbase.apache.org; Search
> Subject: Re: version mismatch exception
>
> On Wed, Aug 17, 2011 at 1:12 PM, Rohit Nigam <rnigam@decarta.com> wrote:
>> Hi St.Ack
>> The region in the file System are good, all I am looking is to change the end key
of that region in the .META. table so that chaining problem goes away .The way I am planning
to do is to get the HRegionInfo object for that existing region key from the .META. table
. Create a new HRegionInfo obj with the updated endkey , start key and regionid being the
same as from the result above and do a put in the .META. table. I think I just change the
endkey and nothing else it will not create  a new row in .META. table and would just update
the existing row. Please confirm if my theory is right.
>
> 1. Close the existing region if open.
> 2. Read the existing hregioninfo.
> 3. Use existing hregioninfo htabledescriptor and this construction,
> http://hbase.apache.org/apidocs/org/apache/hadoop/hbase/HRegionInfo.html#HRegionInfo(org.apache.hadoop.hbase.HTableDescriptor,
> byte[], byte[]), to  make a new hregioninfo.   It will have a
> different encoding to the original.
> 4. Insert the new entry in .META. using new hregioninfo name as row
> key and add an info:regioninfo whose contents is the serialized new
> hregioninfo.
> 5. Delete the original row from .META.
> 6. Assign the new region.
>
> If you want the data from the old region in the new region, then you
> should copy any files in that are under the old entries directory into
> the new region directory (find the regions by using the encoded name;
> the encoded name is an attribute of hregioninfo).  After copying in
> the data, you'll need to reassign the region.  The files are only
> noticed on region open.
>
> St.Ack
>

Mime
View raw message