hashPartitionColumns.add(KEY); builder.addHashPartitions(hashPartitionColumns, numTablets); builder.setNumReplicas(numReplicas);
builder.setNumReplicas(replicas); builder.setRangePartitionColumns(Arrays.asList("key")); for (int i = 1; i < tablets; i++) {
public static CreateTableOptions getCreateTableOptions(Schema schema, int numReplicas, int rangePartitions, int hashPartitions) { Preconditions.checkArgument(rangePartitions > 0); Preconditions.checkArgument(hashPartitions > 0); CreateTableOptions options = new CreateTableOptions().setNumReplicas(numReplicas); if (rangePartitions > 1) { options.setRangePartitionColumns(ImmutableList.of(COLUMN_KEY_ONE)); BigInteger min = BigInteger.valueOf(Long.MIN_VALUE); BigInteger max = BigInteger.valueOf(Long.MAX_VALUE); BigInteger step = max.multiply(BigInteger.valueOf(2)) .divide(BigInteger.valueOf(rangePartitions)); PartialRow splitRow = schema.newPartialRow(); for (int i = 1; i < rangePartitions; i++) { long key = min.add(step.multiply(BigInteger.valueOf(i))).longValue(); splitRow.addLong(COLUMN_KEY_ONE_IDX, key); options.addSplitRow(splitRow); } } else { options.setRangePartitionColumns(Collections.<String>emptyList()); } if (hashPartitions > 1) { options.addHashPartitions(ImmutableList.of(COLUMN_KEY_ONE), hashPartitions); } return options; }
public CreateTableOptions getCreateTableOptions() { CreateTableOptions options = new CreateTableOptions(); if(replicas!=null){ options.setNumReplicas(replicas); } if(hasColummns()) { List<String> rangeKeys = new ArrayList<>(); List<String> hashKeys = new ArrayList<>(); for(KuduColumnInfo column : columns){ if(column.isRangeKey()){ rangeKeys.add(column.name()); } if(column.isHashKey()){ hashKeys.add(column.name()); } } options.setRangePartitionColumns(rangeKeys); options.addHashPartitions(hashKeys, replicas*2); } return options; }
@Before public void setUp() throws Exception { CreateTableOptions options = getBasicCreateTableOptions().setNumReplicas(1); table = harness.getClient().createTable(TABLE_NAME, getBasicSchema(), options); }
@Before public void setUp() throws Exception { String runtimeProp = System.getProperty(RUNTIME_PROPERTY_NAME); runtimeInSeconds = runtimeProp == null ? DEFAULT_RUNTIME_SECONDS : Long.parseLong(runtimeProp); if (runtimeInSeconds < TEST_MIN_RUNTIME_SECONDS || runtimeInSeconds > TEST_TIMEOUT_SECONDS) { Assert.fail("This test needs to run more than " + TEST_MIN_RUNTIME_SECONDS + " seconds" + " and less than " + TEST_TIMEOUT_SECONDS + " seconds"); } LOG.info ("Test running for {} seconds", runtimeInSeconds); // Client we're using has low tolerance for read timeouts but a // higher overall operation timeout. localAsyncClient = new AsyncKuduClient.AsyncKuduClientBuilder(harness.getMasterAddressesAsString()) .defaultSocketReadTimeoutMs(500) .build(); localClient = new KuduClient(localAsyncClient); CreateTableOptions builder = new CreateTableOptions().setNumReplicas(3); builder.setRangePartitionColumns(ImmutableList.of("key")); table = localClient.createTable(TABLE_NAME, getBasicSchema(), builder); }
private void createAndFillSchemasTable() throws KuduException { List<String> existingSchemaNames = listSchemaNamesFromTablets(); ColumnSchema tenantColumnSchema = new ColumnSchema.ColumnSchemaBuilder("tenant", Type.STRING) .key(true).build(); ColumnSchema schemaColumnSchema = new ColumnSchema.ColumnSchemaBuilder("schema", Type.STRING) .key(true).build(); Schema schema = new Schema(ImmutableList.of(tenantColumnSchema, schemaColumnSchema)); CreateTableOptions options = new CreateTableOptions(); options.setNumReplicas(1); // TODO config options.addHashPartitions(ImmutableList.of(tenantColumnSchema.getName()), 2); KuduTable schemasTable = client.createTable(rawSchemasTableName, schema, options); KuduSession session = client.newSession(); session.setFlushMode(SessionConfiguration.FlushMode.AUTO_FLUSH_BACKGROUND); try { for (String schemaName : existingSchemaNames) { Insert insert = schemasTable.newInsert(); fillSchemaRow(insert.getRow(), schemaName); session.apply(insert); } } finally { session.close(); } }
@Test(timeout = 100000) public void testNumReplicas() throws Exception { for (int i = 1; i <= 3; i++) { // Ignore even numbers. if (i % 2 != 0) { String tableName = "testNumReplicas" + "-" + i; CreateTableOptions options = getBasicCreateTableOptions(); options.setNumReplicas(i); client.createTable(tableName, basicSchema, options); KuduTable table = client.openTable(tableName); assertEquals(i, table.getNumReplicas()); } } } }
/** * Creates a new table with two int columns, c0 and c1. c0 is the primary key. * The table is hash partitioned on c0 into two buckets, and range partitioned * with the provided bounds. */ private KuduTable createTable(List<Pair<Integer, Integer>> bounds) throws KuduException { // Create initial table with single range partition covering the entire key // space, and two hash buckets. ArrayList<ColumnSchema> columns = new ArrayList<>(1); columns.add(new ColumnSchema.ColumnSchemaBuilder("c0", Type.INT32) .nullable(false) .key(true) .build()); columns.add(new ColumnSchema.ColumnSchemaBuilder("c1", Type.INT32) .nullable(false) .build()); Schema schema = new Schema(columns); CreateTableOptions createOptions = new CreateTableOptions().setRangePartitionColumns(ImmutableList.of("c0")) .setNumReplicas(1) .addHashPartitions(ImmutableList.of("c0"), 2); for (Pair<Integer, Integer> bound : bounds) { PartialRow lower = schema.newPartialRow(); PartialRow upper = schema.newPartialRow(); lower.addInt("c0", bound.getFirst()); upper.addInt("c0", bound.getSecond()); createOptions.addRangePartition(lower, upper); } return client.createTable(tableName, schema, createOptions); }
@Test(timeout = 10000) public void testInsertAutoFlushSyncNonCoveredRange() throws Exception { CreateTableOptions createOptions = getBasicTableOptionsWithNonCoveredRange(); createOptions.setNumReplicas(1); client.createTable(tableName, basicSchema, createOptions); KuduTable table = client.openTable(tableName); KuduSession session = client.newSession(); session.setFlushMode(SessionConfiguration.FlushMode.AUTO_FLUSH_SYNC); List<Integer> nonCoveredKeys = ImmutableList.of(350, 300, 199, 150, 100, -1, -50); for (int key : nonCoveredKeys) { OperationResponse response = session.apply(createBasicSchemaInsert(table, key)); assertTrue(response.hasRowError()); assertTrue(response.getRowError().getErrorStatus().isNotFound()); } }
@Test(timeout = 10000) public void testInsertManualFlushResponseOrder() throws Exception { CreateTableOptions createOptions = getBasicTableOptionsWithNonCoveredRange(); createOptions.setNumReplicas(1); client.createTable(tableName, basicSchema, createOptions); KuduTable table = client.openTable(tableName); KuduSession session = client.newSession(); session.setFlushMode(SessionConfiguration.FlushMode.MANUAL_FLUSH); // Insert a batch of some valid and some invalid. for (int i = 0; i < 10; i++) { assertNull(session.apply(createBasicSchemaInsert(table, 100 + i * 10))); assertNull(session.apply(createBasicSchemaInsert(table, 200 + i * 10))); } List<OperationResponse> results = session.flush(); assertEquals(20, results.size()); for (int i = 0; i < 20; i++) { OperationResponse result = results.get(i); if (i % 2 == 0) { assertTrue(result.hasRowError()); assertTrue(result.getRowError().getErrorStatus().isNotFound()); } else { assertTrue(!result.hasRowError()); } } }
@Test(timeout = 10000) public void testInsertManualFlushNonCoveredRange() throws Exception { CreateTableOptions createOptions = getBasicTableOptionsWithNonCoveredRange(); createOptions.setNumReplicas(1); client.createTable(tableName, basicSchema, createOptions); KuduTable table = client.openTable(tableName);
CreateTableOptions createOptions = new CreateTableOptions(); createOptions.setRangePartitionColumns(ImmutableList.<String>of()); createOptions.setNumReplicas(1); client.createTable(testTableName, schema, createOptions);
"non-replicated", schema, getBasicCreateTableOptions().setNumReplicas(1));
@Test(timeout = 10000) public void testInsertAutoFlushBackgrounNonCoveredRange() throws Exception { CreateTableOptions createOptions = getBasicTableOptionsWithNonCoveredRange(); createOptions.setNumReplicas(1); client.createTable(tableName, basicSchema, createOptions); KuduTable table = client.openTable(tableName); AsyncKuduSession session = asyncClient.newSession(); session.setFlushMode(SessionConfiguration.FlushMode.AUTO_FLUSH_BACKGROUND); List<Integer> nonCoveredKeys = ImmutableList.of(350, 300, 199, 150, 100, -1, -50); for (int key : nonCoveredKeys) { OperationResponse result = session.apply(createBasicSchemaInsert(table, key)).join(5000); assertTrue(result.hasRowError()); assertTrue(result.getRowError().getErrorStatus().isNotFound()); } RowErrorsAndOverflowStatus errors = session.getPendingErrors(); assertEquals(nonCoveredKeys.size(), errors.getRowErrors().length); for (RowError error : errors.getRowErrors()) { assertTrue(error.getErrorStatus().isNotFound()); } // Insert a batch of some valid and some invalid. for (int key = 90; key < 110; key++) { session.apply(createBasicSchemaInsert(table, key)); } session.flush(); errors = session.getPendingErrors(); assertEquals(10, errors.getRowErrors().length); for (RowError error : errors.getRowErrors()) { assertTrue(error.getErrorStatus().isNotFound()); } }
@Test(timeout = 100000) public void testDisconnect() throws Exception { CreateTableOptions options = getBasicCreateTableOptions().setNumReplicas(1); KuduTable table = client.createTable( "testDisconnect-" + System.currentTimeMillis(),