private static List<RangePartition> getRangePartitionList(KuduTable table, long deadline) { List<RangePartition> rangePartitions = new ArrayList<>(); if (!table.getPartitionSchema().getRangeSchema().getColumns().isEmpty()) { try { Iterator var4 = table.getTabletsLocations(deadline).iterator(); while (var4.hasNext()) { LocatedTablet tablet = (LocatedTablet) var4.next(); Partition partition = tablet.getPartition(); if (Iterators.all(partition.getHashBuckets().iterator(), Predicates.equalTo(0))) { RangePartition rangePartition = buildRangePartition(table, partition); rangePartitions.add(rangePartition); } } } catch (Exception e) { throw new RuntimeException(e); } } return rangePartitions; }
private void init() { String tableName = kuduScanSpec.getTableName(); Collection<DrillbitEndpoint> endpoints = kuduStoragePlugin.getContext().getBits(); Map<String,DrillbitEndpoint> endpointMap = Maps.newHashMap(); for (DrillbitEndpoint endpoint : endpoints) { endpointMap.put(endpoint.getAddress(), endpoint); } try { List<LocatedTablet> locations = kuduStoragePlugin.getClient().openTable(tableName).getTabletsLocations(10000); for (LocatedTablet tablet : locations) { KuduWork work = new KuduWork(tablet.getPartition().getPartitionKeyStart(), tablet.getPartition().getPartitionKeyEnd()); for (Replica replica : tablet.getReplicas()) { String host = replica.getRpcHost(); DrillbitEndpoint ep = endpointMap.get(host); if (ep != null) { work.getByteMap().add(ep, DEFAULT_TABLET_SIZE); } } kuduWorkList.add(work); } } catch (Exception e) { throw new RuntimeException(e); } }
/** * Get all the tablets for this table. This may query the master multiple times if there * are a lot of tablets. * @param deadline deadline in milliseconds for this method to finish * @return a list containing the metadata and locations for each of the tablets in the * table * @throws Exception * @deprecated use the {@link KuduScanToken} API */ @Deprecated public List<LocatedTablet> getTabletsLocations(long deadline) throws Exception { return getTabletsLocations(null, null, deadline); }
private static List<RangePartition> getRangePartitionList(KuduTable table, long deadline) { List<RangePartition> rangePartitions = new ArrayList(); if (!table.getPartitionSchema().getRangeSchema().getColumns().isEmpty()) { try { Iterator var4 = table.getTabletsLocations(deadline).iterator(); while (var4.hasNext()) { LocatedTablet tablet = (LocatedTablet) var4.next(); Partition partition = tablet.getPartition(); if (Iterators.all(partition.getHashBuckets().iterator(), Predicates.equalTo(0))) { RangePartition rangePartition = buildRangePartition(table, partition); rangePartitions.add(rangePartition); } } } catch (Exception e) { throw new RuntimeException(e); } } return rangePartitions; }
private static List<RangePartition> getRangePartitionList(KuduTable table, long deadline) { List<RangePartition> rangePartitions = new ArrayList<>(); if (!table.getPartitionSchema().getRangeSchema().getColumns().isEmpty()) { try { Iterator var4 = table.getTabletsLocations(deadline).iterator(); while (var4.hasNext()) { LocatedTablet tablet = (LocatedTablet) var4.next(); Partition partition = tablet.getPartition(); if (Iterators.all(partition.getHashBuckets().iterator(), Predicates.equalTo(0))) { RangePartition rangePartition = buildRangePartition(table, partition); rangePartitions.add(rangePartition); } } } catch (Exception e) { throw new RuntimeException(e); } } return rangePartitions; }
/** * Picks at random a tablet server that serves tablets from the passed table and restarts it. * @param table table to query for a TS to restart * @throws Exception */ public void restartTabletServer(KuduTable table) throws Exception { List<LocatedTablet> tablets = table.getTabletsLocations(DEFAULT_SLEEP); if (tablets.isEmpty()) { fail("Table " + table.getName() + " doesn't have any tablets"); } LocatedTablet tablet = tablets.get(0); LocatedTablet.Replica replica = tablet.getReplicas().get(randomForTSRestart.nextInt(tablet.getReplicas().size())); HostAndPort hp = new HostAndPort(replica.getRpcHost(), replica.getRpcPort()); miniCluster.killTabletServer(hp); miniCluster.startTabletServer(hp); }
/** * Helper method to easily kill a tablet server that serves the given table's only tablet's * leader. The currently running test case will be failed if there's more than one tablet, * if the tablet has no leader after some retries, or if the tablet server was already killed. * * This method is thread-safe. * @param table a KuduTable which will get its single tablet's leader killed. * @throws Exception */ public void killTabletLeader(KuduTable table) throws Exception { List<LocatedTablet> tablets = table.getTabletsLocations(DEFAULT_SLEEP); if (tablets.isEmpty() || tablets.size() > 1) { fail("Currently only support killing leaders for tables containing 1 tablet, table " + table.getName() + " has " + tablets.size()); } LocatedTablet tablet = tablets.get(0); if (tablet.getReplicas().size() == 1) { fail("Table " + table.getName() + " only has 1 tablet, please enable replication"); } HostAndPort hp = findLeaderTabletServer(tablet); miniCluster.killTabletServer(hp); }
private KuduTable createTableWithSplitsAndTest(String tableNamePrefix, int splitsCount) throws Exception { String newTableName = tableNamePrefix + "-" + splitsCount; CreateTableOptions builder = getBasicCreateTableOptions(); if (splitsCount != 0) { for (int i = 1; i <= splitsCount; i++) { PartialRow row = BASIC_SCHEMA.newPartialRow(); row.addInt(0, i); builder.addSplitRow(row); } } KuduTable table = client.createTable(newTableName, BASIC_SCHEMA, builder); List<LocatedTablet> tablets = table.getTabletsLocations(DEFAULT_SLEEP); assertEquals(splitsCount + 1, tablets.size()); assertEquals(splitsCount + 1, table.asyncGetTabletsLocations(DEFAULT_SLEEP).join().size()); for (LocatedTablet tablet : tablets) { assertEquals(3, tablet.getReplicas().size()); } return table; }
tablets = table.getTabletsLocations(null, null, 100000); assertEquals(3, tablets.size()); assertArrayEquals(getKeyInBytes(0), tablets.get(0).getPartition().getPartitionKeyStart()); tablets = table.getTabletsLocations(null, getKeyInBytes(50), 100000); assertEquals(1, tablets.size()); assertArrayEquals(getKeyInBytes(0), tablets.get(0).getPartition().getPartitionKeyStart()); tablets = table.getTabletsLocations(getKeyInBytes(300), null, 100000); assertEquals(0, tablets.size()); tablets = table.getTabletsLocations(getKeyInBytes(299), null, 100000); assertEquals(1, tablets.size()); assertArrayEquals(getKeyInBytes(200), tablets.get(0).getPartition().getPartitionKeyStart()); tablets = table.getTabletsLocations(getKeyInBytes(150), getKeyInBytes(250), 100000); assertEquals(1, tablets.size()); assertArrayEquals(getKeyInBytes(200), tablets.get(0).getPartition().getPartitionKeyStart());
while (pruner.hasMorePartitionKeyRanges()) { Pair<byte[], byte[]> partitionRange = pruner.nextPartitionKeyRange(); List<LocatedTablet> newTablets = table.getTabletsLocations( partitionRange.getFirst().length == 0 ? null : partitionRange.getFirst(), partitionRange.getSecond().length == 0 ? null : partitionRange.getSecond(),
List<LocatedTablet> tablets = table.getTabletsLocations(DEFAULT_SLEEP); assertEquals(1, tablets.size()); harness.killTabletLeader(tablets.get(0));
List<LocatedTablet> tablets = table.getTabletsLocations(DEFAULT_SLEEP); assertEquals(1, tablets.size()); harness.killTabletLeader(tablets.get(0));
List<LocatedTablet>tablets = table.getTabletsLocations(null, getKeyInBytes(9), DEFAULT_SLEEP); assertEquals(9, tablets.size()); assertEquals(9, table.asyncGetTabletsLocations(null, getKeyInBytes(9), DEFAULT_SLEEP).join().size()); tablets = table.getTabletsLocations(getKeyInBytes(0), getKeyInBytes(9), DEFAULT_SLEEP); assertEquals(9, tablets.size()); assertEquals(9, table.asyncGetTabletsLocations(getKeyInBytes(0), getKeyInBytes(9), DEFAULT_SLEEP).join().size()); tablets = table.getTabletsLocations(getKeyInBytes(5), getKeyInBytes(9), DEFAULT_SLEEP); assertEquals(4, tablets.size()); assertEquals(4, table.asyncGetTabletsLocations(getKeyInBytes(5), getKeyInBytes(9), DEFAULT_SLEEP).join().size()); tablets = table.getTabletsLocations(getKeyInBytes(5), getKeyInBytes(14), DEFAULT_SLEEP); assertEquals(9, tablets.size()); assertEquals(9, table.asyncGetTabletsLocations(getKeyInBytes(5), getKeyInBytes(14), DEFAULT_SLEEP).join().size()); tablets = table.getTabletsLocations(getKeyInBytes(5), getKeyInBytes(31), DEFAULT_SLEEP); assertEquals(26, tablets.size()); assertEquals(26, table.asyncGetTabletsLocations(getKeyInBytes(5), getKeyInBytes(31), DEFAULT_SLEEP).join().size()); tablets = table.getTabletsLocations(getKeyInBytes(5), null, DEFAULT_SLEEP); assertEquals(26, tablets.size()); assertEquals(26, table.asyncGetTabletsLocations(getKeyInBytes(5), null, DEFAULT_SLEEP).join().size()); tablets = table.getTabletsLocations(null, getKeyInBytes(10000), DEFAULT_SLEEP); assertEquals(31, tablets.size()); assertEquals(31, table.asyncGetTabletsLocations(null, getKeyInBytes(10000), DEFAULT_SLEEP).join().size()); tablets = table.getTabletsLocations(getKeyInBytes(20), getKeyInBytes(10000), DEFAULT_SLEEP);
tablets = table.getTabletsLocations(getKeyInBytes(300), null, 100000); assertEquals(1, tablets.size()); assertArrayEquals(getKeyInBytes(300), tablets.get(0).getPartition().getPartitionKeyStart());
List<LocatedTablet> tablets = table.getTabletsLocations(DEFAULT_SLEEP);