@Override public String toString() { return "get tablet locations from the master for table " + table.getName(); } }
private synchronized StructType getTableSchema(KuduTable table) throws KuduException { if (tableSchemas == null) { tableSchemas = Maps.newHashMap(); } if (tableSchemas.containsKey(table.getName())) { return tableSchemas.get(table.getName()); } else { StructType tableSchema = schemaFor(table); tableSchemas.put(table.getName(), tableSchema); return tableSchema; } }
@Override public String toString() { final String tablet = this.tablet == null ? "null" : this.tablet.getTabletId(); final StringBuilder buf = new StringBuilder(); buf.append("KuduScanner(table="); buf.append(table.getName()); buf.append(", tablet=").append(tablet); buf.append(", scannerId=").append(Bytes.pretty(scannerId)); buf.append(", scanRequestTimeout=").append(scanRequestTimeout); buf.append(')'); return buf.toString(); }
public boolean deleteTable() throws IOException { String tableName = table.getName(); client.syncClient().deleteTable(tableName); return true; }
/** * 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); }
long ttl) throws KuduException { String tableId = table.getTableId(); String tableName = table.getName();
/** * 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); }
@Override void updateStatistics(Statistics statistics, BatchResponse response) { String tabletId = this.getTablet().getTabletId(); String tableName = this.getTable().getName(); TabletStatistics tabletStatistics = statistics.getTabletStatistics(tableName, tabletId); if (response == null) { tabletStatistics.incrementStatistic(Statistic.OPS_ERRORS, operations.size()); tabletStatistics.incrementStatistic(Statistic.RPC_ERRORS, 1); return; } tabletStatistics.incrementStatistic(Statistic.WRITE_RPCS, 1); for (OperationResponse opResponse : response.getIndividualResponses()) { if (opResponse.hasRowError()) { tabletStatistics.incrementStatistic(Statistic.OPS_ERRORS, 1); } else { tabletStatistics.incrementStatistic(Statistic.WRITE_OPS, 1); } } tabletStatistics.incrementStatistic(Statistic.BYTES_WRITTEN, getRowOperationsSizeBytes()); }
@Override void updateStatistics(Statistics statistics, OperationResponse response) { String tabletId = this.getTablet().getTabletId(); String tableName = this.getTable().getName(); TabletStatistics tabletStatistics = statistics.getTabletStatistics(tableName, tabletId); if (response == null) { tabletStatistics.incrementStatistic(Statistic.OPS_ERRORS, 1); tabletStatistics.incrementStatistic(Statistic.RPC_ERRORS, 1); return; } tabletStatistics.incrementStatistic(Statistic.WRITE_RPCS, 1); if (response.hasRowError()) { // If ignoreAllDuplicateRows is set, the already_present exception will be // discarded and wont't be recorded here tabletStatistics.incrementStatistic(Statistic.OPS_ERRORS, 1); } else { tabletStatistics.incrementStatistic(Statistic.WRITE_OPS, 1); } tabletStatistics.incrementStatistic(Statistic.BYTES_WRITTEN, getRowOperationSizeBytes()); }
proto.setTableName(table.getName());
@Test(timeout = 100000) public void testScanTokenReadMode() throws Exception { ScanTokenPB.Builder pbBuilder = ScanTokenPB.newBuilder(); pbBuilder.setTableName(table.getName()); pbBuilder.setReadMode(Common.ReadMode.READ_YOUR_WRITES); Client.ScanTokenPB scanTokenPB = pbBuilder.build(); final byte[] serializedToken = KuduScanToken.serialize(scanTokenPB); // Deserialize scan tokens and make sure the read mode is updated accordingly. KuduScanner scanner = KuduScanToken.deserializeIntoScanner(serializedToken, client); assertEquals(AsyncKuduScanner.ReadMode.READ_YOUR_WRITES, scanner.getReadMode()); }
@Test(timeout = 100000) public void testScanTokenReplicaSelections() throws Exception { ScanTokenPB.Builder pbBuilder = ScanTokenPB.newBuilder(); pbBuilder.setTableName(table.getName()); pbBuilder.setReplicaSelection(Common.ReplicaSelection.CLOSEST_REPLICA); Client.ScanTokenPB scanTokenPB = pbBuilder.build(); final byte[] serializedToken = KuduScanToken.serialize(scanTokenPB); // Deserialize the scan token into a scanner, and make sure it is using // 'CLOSEST_REPLICA' selection policy. KuduScanner scanner = KuduScanToken.deserializeIntoScanner(serializedToken, client); assertEquals(ReplicaSelection.CLOSEST_REPLICA, scanner.getReplicaSelection()); assertEquals(9, countRowsInScan(scanner)); }
@Test(timeout = 100000) public void testScanTokenPropagatesTimestamp() throws Exception { // Initially, the client does not have the timestamp set. assertEquals(AsyncKuduClient.NO_TIMESTAMP, asyncClient.getLastPropagatedTimestamp()); assertEquals(KuduClient.NO_TIMESTAMP, client.getLastPropagatedTimestamp()); AsyncKuduScanner scanner = asyncClient.newScannerBuilder(table).build(); KuduScanner syncScanner = new KuduScanner(scanner); // Let the client receive the propagated timestamp in the scanner response. syncScanner.nextRows().getNumRows(); final long tsPrev = asyncClient.getLastPropagatedTimestamp(); final long tsPropagated = tsPrev + 1000000; ScanTokenPB.Builder pbBuilder = ScanTokenPB.newBuilder(); pbBuilder.setTableName(table.getName()); pbBuilder.setPropagatedTimestamp(tsPropagated); Client.ScanTokenPB scanTokenPB = pbBuilder.build(); final byte[] serializedToken = KuduScanToken.serialize(scanTokenPB); // Deserialize scan tokens and make sure the client's last propagated // timestamp is updated accordingly. assertEquals(tsPrev, asyncClient.getLastPropagatedTimestamp()); KuduScanToken.deserializeIntoScanner(serializedToken, client); assertEquals(tsPropagated, asyncClient.getLastPropagatedTimestamp()); }