Return-Path: X-Original-To: apmail-hbase-user-archive@www.apache.org Delivered-To: apmail-hbase-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 9FD4217875 for ; Fri, 3 Oct 2014 17:58:46 +0000 (UTC) Received: (qmail 50479 invoked by uid 500); 3 Oct 2014 17:58:44 -0000 Delivered-To: apmail-hbase-user-archive@hbase.apache.org Received: (qmail 50418 invoked by uid 500); 3 Oct 2014 17:58:44 -0000 Mailing-List: contact user-help@hbase.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user@hbase.apache.org Delivered-To: mailing list user@hbase.apache.org Received: (qmail 50394 invoked by uid 99); 3 Oct 2014 17:58:44 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 03 Oct 2014 17:58:44 +0000 X-ASF-Spam-Status: No, hits=1.5 required=5.0 tests=HTML_MESSAGE,RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of serega.sheypak@gmail.com designates 209.85.215.51 as permitted sender) Received: from [209.85.215.51] (HELO mail-la0-f51.google.com) (209.85.215.51) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 03 Oct 2014 17:58:17 +0000 Received: by mail-la0-f51.google.com with SMTP id ge10so1472686lab.24 for ; Fri, 03 Oct 2014 10:58:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=uyejcIMr1xQ4LOPF2rupHSC47QCrIY5PcMLlWYxzAKg=; b=075PMSRzPsdqJmZIJv20WoF9g58fAbB++f9cdsH0jnaoAuAWL+8FNahW64JPdsvSui Bk+z0/cQQ4kUBjvmVBUZ0eOdvAsMy1X9TFUQ6Bx58R0gjnE9loG93vKoS47OLswbl/El NgMBS41oyOrByltnR2wSyjWRRm29BBTRe8wvuq3zeDdP/Fpiie7rxRIdEgc6anQ9VC8d CLbn+HTEta9vqLwLqamb+TZGO4qzDIQffBb+anzUazw18hht1RmVjfwHoBjHWQE6sx/f oBerwXQc0DXBRRhCrC5HO1jfkbcFoHvVnUrZFqDIsTD8hWyxBwQQSprEp/exzBY5/7cn mg/A== X-Received: by 10.152.87.10 with SMTP id t10mr7782629laz.22.1412359096582; Fri, 03 Oct 2014 10:58:16 -0700 (PDT) MIME-Version: 1.0 Received: by 10.112.157.131 with HTTP; Fri, 3 Oct 2014 10:57:56 -0700 (PDT) In-Reply-To: References: From: Serega Sheypak Date: Fri, 3 Oct 2014 21:57:56 +0400 Message-ID: Subject: Re: Splits are not preserved during table copy using getAdmin().createTable(tableDescriptor); To: user Content-Type: multipart/alternative; boundary=001a11c364363f46e60504887acd X-Virus-Checked: Checked by ClamAV on apache.org --001a11c364363f46e60504887acd Content-Type: text/plain; charset=UTF-8 Do I have to pass an array of startKeys or an array of endKeys? 2014-10-03 20:29 GMT+04:00 Serega Sheypak : > So easy, thanks :) I've missed that method. > > 2014-10-03 20:23 GMT+04:00 Ted Yu : > >> You can simplify your code by utilizing the following from HTable: >> >> public byte [][] getStartKeys() throws IOException { >> >> No need to sort the keys. >> >> Cheers >> >> On Fri, Oct 3, 2014 at 9:10 AM, Serega Sheypak >> wrote: >> >> > Thanks, I'm already updated my end-to-end test, waiting for the result. >> > >> > Here is my code snippet, is it ok? >> > >> > @SneakyThrows(IOException.class) >> > private byte[][] collectSplits(String tableName){ >> > HTable table = new HTable(configuration, tableName); >> > int splitSize = >> > table.getRegionLocations().descendingKeySet().size(); >> > >> > if(splitSize < 2){ >> > LOG.info(String.format("There is only one region for a >> > table[%s]. No splits to recreate", tableName)); >> > return new byte[][]{}; >> > } >> > LOG.info(String.format("There are [%s] regions for a table[%s]. >> > Skip pre-splitting", splitSize, tableName)); >> > >> > byte[][] splits = new byte[splitSize][]; >> > * Iterator itr = >> > table.getRegionLocations().descendingKeySet().iterator();* >> > * int index = 0;* >> > * while (itr.hasNext()){* >> > * splits[index] = itr.next().getStartKey();* >> > * index++;* >> > * }* >> > >> > table.close(); >> > >> > Arrays.sort(splits, Bytes.BYTES_COMPARATOR); >> > return splits; >> > } >> > >> > >> > 2014-10-03 20:02 GMT+04:00 Ted Yu : >> > >> > > Take a look at this method in HTable: >> > > >> > > public Pair getStartEndKeys() throws IOException >> { >> > > >> > > You would see that the first dimension corresponds to the number of >> > > regions. >> > > >> > > >> > > Cheers >> > > >> > > On Fri, Oct 3, 2014 at 8:33 AM, Serega Sheypak < >> serega.sheypak@gmail.com >> > > >> > > wrote: >> > > >> > > > Ok, I found them: >> > > > hTable.getRegionLocations().descendingKeySet() >> > > > and >> > > > HRegionInfo has startKey and endKey >> > > > I have to prepare splits[][]. >> > > > I'm confused a little, how keys should be placed there? splits[][] >> > shoud >> > > by >> > > > and array with length=region count and width = 2? >> > > > >> > > > >> > > > 2014-10-03 17:57 GMT+04:00 Serega Sheypak > >: >> > > > >> > > > > Hi, here is my code: >> > > > > >> > > > > public void dropIfExistsAndCreate(String sourceTableName, String >> > > > > newTableName) throws IOException { >> > > > > LOG.info(String.format("Use [%s] to create [%s]", >> > > > sourceTableName, >> > > > > newTableName)); >> > > > > HTableDescriptor descriptor = >> getDescriptor(sourceTableName); >> > > > > dropIfExists(newTableName); // doesn't matter >> > > > > createTable(descriptor, newTableName); >> > > > > } >> > > > > >> > > > > private void createTable(HTableDescriptor descriptor, String >> > > > > newTableName) throws IOException { >> > > > > descriptor.setName(Bytes.toBytes(newTableName)); >> > > > > getAdmin().createTable(descriptor); >> > > > > LOG.info(String.format("Table created[%s]", >> newTableName)); >> > > > > } >> > > > > >> > > > > My source table has 256 regions, newly created table has no >> splits. >> > > > > Is there any possibility to copy splits from source table? >> > > > > >> > > > > I supposed, that HTableDescriptor encasulates splits, but it was >> bad >> > > > > assumption. >> > > > > >> > > > >> > > >> > >> > > --001a11c364363f46e60504887acd--