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 95BE0175C3 for ; Fri, 3 Oct 2014 16:29:52 +0000 (UTC) Received: (qmail 61559 invoked by uid 500); 3 Oct 2014 16:29:50 -0000 Delivered-To: apmail-hbase-user-archive@hbase.apache.org Received: (qmail 61483 invoked by uid 500); 3 Oct 2014 16:29:50 -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 61470 invoked by uid 99); 3 Oct 2014 16:29:50 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 03 Oct 2014 16:29:50 +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 (athena.apache.org: domain of serega.sheypak@gmail.com designates 209.85.217.182 as permitted sender) Received: from [209.85.217.182] (HELO mail-lb0-f182.google.com) (209.85.217.182) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 03 Oct 2014 16:29:44 +0000 Received: by mail-lb0-f182.google.com with SMTP id z11so1311711lbi.27 for ; Fri, 03 Oct 2014 09:29:23 -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=E5aOKDWJmIDDJGo+7XD+g/uX6eqYEmF+V/nipadyrp4=; b=pLFGIgQcNdEM5avl37322rQuET4s7j1ybS9TX8/aIZDg2zldASrGaVbe9J84DyyJi6 AsjKxNeV9s9gjL1rTzpT7uhOyJe8dOl2ON9m4kpkzvavB3l/ZTGepTCkPHF7v9BMTw+0 t94sOxntWFy72psjXL+ghOIVFJr7I6QJdfT8ypM63Qiwztgh1q1gy5X7lhpGKmmFB7xl TyBWj+ipDzmmSvhXFhVpsFtztE2O+swkMrNvNS43MVW6LPVlSbn2jN6m1PCzp3Lf2ioh dsyPu0Zu4Wa9g66tIePjcLHiKqIdIUnO8GTpq/Cjtu868c/tc/WDLXBd3bEEejJGGKHL niuQ== X-Received: by 10.152.28.8 with SMTP id x8mr7198625lag.80.1412353763454; Fri, 03 Oct 2014 09:29:23 -0700 (PDT) MIME-Version: 1.0 Received: by 10.112.157.131 with HTTP; Fri, 3 Oct 2014 09:29:03 -0700 (PDT) In-Reply-To: References: From: Serega Sheypak Date: Fri, 3 Oct 2014 20:29:03 +0400 Message-ID: Subject: Re: Splits are not preserved during table copy using getAdmin().createTable(tableDescriptor); To: user Content-Type: multipart/alternative; boundary=089e0158c9645e342c0504873cd2 X-Virus-Checked: Checked by ClamAV on apache.org --089e0158c9645e342c0504873cd2 Content-Type: text/plain; charset=UTF-8 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. > > > > > > > > > > > > > > > --089e0158c9645e342c0504873cd2--