use of io.crate.blob.v2.BlobAdminClient in project crate by crate.
the class ShardStatsTest method testTableNameBlobTable.
@Test
public void testTableNameBlobTable() throws Exception {
BlobAdminClient blobAdminClient = internalCluster().getInstance(BlobAdminClient.class);
Settings indexSettings = Settings.builder().put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 1).put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1).build();
blobAdminClient.createBlobTable("blobs", indexSettings).get();
ensureGreen();
execute("select schema_name, table_name from sys.shards where table_name = 'blobs'");
assertThat(response.rowCount(), is(2L));
for (int i = 0; i < response.rowCount(); i++) {
assertThat((String) response.rows()[i][0], is("blob"));
assertThat((String) response.rows()[i][1], is("blobs"));
}
execute("create blob table sbolb clustered into 4 shards with (number_of_replicas=3)");
ensureYellow();
execute("select schema_name, table_name from sys.shards where table_name = 'sbolb'");
assertThat(response.rowCount(), is(16L));
for (int i = 0; i < response.rowCount(); i++) {
assertThat((String) response.rows()[i][0], is("blob"));
assertThat((String) response.rows()[i][1], is("sbolb"));
}
execute("select count(*) from sys.shards " + "where schema_name='blob' and table_name != 'blobs' " + "and table_name != 'sbolb'");
assertThat(response.rowCount(), is(1L));
assertThat((Long) response.rows()[0][0], is(0L));
}
use of io.crate.blob.v2.BlobAdminClient in project crate by crate.
the class SysShardsTest method initTestData.
@Before
public void initTestData() throws Exception {
Setup setup = new Setup(sqlExecutor);
setup.groupBySetup();
sqlExecutor.exec("create table quotes (id integer primary key, quote string) with(number_of_replicas=1)");
BlobAdminClient blobAdminClient = internalCluster().getInstance(BlobAdminClient.class);
Settings indexSettings = Settings.builder().put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 1).put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 5).build();
blobAdminClient.createBlobTable("blobs", indexSettings);
sqlExecutor.ensureGreen();
}
use of io.crate.blob.v2.BlobAdminClient in project crate by crate.
the class RecoveryTests method testPrimaryRelocationWhileIndexing.
@Test
public void testPrimaryRelocationWhileIndexing() throws Exception {
final int numberOfRelocations = 1;
final int numberOfWriters = 2;
final String node1 = internalCluster().startNode();
BlobAdminClient blobAdminClient = internalCluster().getInstance(BlobAdminClient.class, node1);
logger.trace("--> creating test index ...");
Settings indexSettings = Settings.builder().put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0).put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1).put(IndexMetadata.SETTING_AUTO_EXPAND_REPLICAS, "false").build();
blobAdminClient.createBlobTable("test", indexSettings).get();
logger.trace("--> starting [node2] ...");
final String node2 = internalCluster().startNode();
ensureGreen();
final AtomicLong idGenerator = new AtomicLong();
final AtomicLong indexCounter = new AtomicLong();
final AtomicBoolean stop = new AtomicBoolean(false);
Thread[] writers = new Thread[numberOfWriters];
final CountDownLatch stopLatch = new CountDownLatch(writers.length);
logger.trace("--> starting {} blob upload threads", writers.length);
final List<String> uploadedDigests = Collections.synchronizedList(new ArrayList<String>(writers.length));
for (int i = 0; i < writers.length; i++) {
final int indexerId = i;
writers[i] = new Thread() {
@Override
public void run() {
try {
logger.trace("**** starting blob upload thread {}", indexerId);
while (!stop.get()) {
long id = idGenerator.incrementAndGet();
String digest = uploadFile(internalCluster().client(node1), genFile(id));
uploadedDigests.add(digest);
indexCounter.incrementAndGet();
}
logger.trace("**** done indexing thread {}", indexerId);
} catch (Exception e) {
logger.warn("**** failed indexing thread {}", e, indexerId);
} finally {
stopLatch.countDown();
}
}
};
writers[i].setName("blob-uploader-thread");
// dispatch threads from parent, ignoring possible leaking threads
writers[i].setDaemon(true);
writers[i].start();
}
logger.trace("--> waiting for 2 blobs to be uploaded ...");
while (uploadedDigests.size() < 2) {
Thread.sleep(10);
}
logger.trace("--> 2 blobs uploaded");
// increase time between chunks in order to make sure that the upload is taking place while relocating
timeBetweenChunks.set(10);
logger.trace("--> starting relocations...");
for (int i = 0; i < numberOfRelocations; i++) {
String fromNode = (i % 2 == 0) ? node1 : node2;
String toNode = node1.equals(fromNode) ? node2 : node1;
logger.trace("--> START relocate the shard from {} to {}", fromNode, toNode);
internalCluster().client(node1).admin().cluster().prepareReroute().add(new MoveAllocationCommand(BlobIndex.fullIndexName("test"), 0, fromNode, toNode)).execute().actionGet();
ClusterHealthResponse clusterHealthResponse = internalCluster().client(node1).admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForNoRelocatingShards(true).setTimeout(ACCEPTABLE_RELOCATION_TIME).execute().actionGet();
assertThat(clusterHealthResponse.isTimedOut(), equalTo(false));
clusterHealthResponse = internalCluster().client(node2).admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForNoRelocatingShards(true).setTimeout(ACCEPTABLE_RELOCATION_TIME).execute().actionGet();
assertThat(clusterHealthResponse.isTimedOut(), equalTo(false));
logger.trace("--> DONE relocate the shard from {} to {}", fromNode, toNode);
}
logger.trace("--> done relocations");
logger.trace("--> marking and waiting for upload threads to stop ...");
timeBetweenChunks.set(0);
stop.set(true);
assertThat(stopLatch.await(60, TimeUnit.SECONDS), is(true));
logger.trace("--> uploading threads stopped");
logger.trace("--> expected {} got {}", indexCounter.get(), uploadedDigests.size());
assertEquals(indexCounter.get(), uploadedDigests.size());
BlobIndicesService blobIndicesService = internalCluster().getInstance(BlobIndicesService.class, node2);
for (String digest : uploadedDigests) {
BlobShard blobShard = blobIndicesService.localBlobShard(BlobIndex.fullIndexName("test"), digest);
long length = blobShard.blobContainer().getFile(digest).length();
assertThat(length, greaterThanOrEqualTo(1L));
}
for (Thread writer : writers) {
writer.join(6000);
}
}
use of io.crate.blob.v2.BlobAdminClient in project crate by crate.
the class BlobPathITest method launchNodeAndInitClient.
private void launchNodeAndInitClient(Settings settings) throws Exception {
// using numDataNodes = 1 to launch the node doesn't work:
// if globalBlobPath is created within nodeSetting it is sometimes not available for the tests
internalCluster().startNode(settings);
blobAdminClient = internalCluster().getInstance(BlobAdminClient.class);
HttpServerTransport httpServerTransport = internalCluster().getInstance(HttpServerTransport.class);
InetSocketAddress address = httpServerTransport.boundAddress().publishAddress().address();
client = new BlobHttpClient(address);
}
use of io.crate.blob.v2.BlobAdminClient in project crate by crate.
the class BlobHttpIntegrationTest method setup.
@Before
public void setup() throws ExecutionException, InterruptedException {
randomNode = internalCluster().getInstances(HttpServerTransport.class).iterator().next().boundAddress().publishAddress().address();
Iterable<HttpServerTransport> transports = internalCluster().getDataNodeInstances(HttpServerTransport.class);
Iterator<HttpServerTransport> httpTransports = transports.iterator();
dataNode1 = httpTransports.next().boundAddress().publishAddress().address();
dataNode2 = httpTransports.next().boundAddress().publishAddress().address();
BlobAdminClient blobAdminClient = internalCluster().getInstance(BlobAdminClient.class);
Settings indexSettings = Settings.builder().put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0).put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 2).put(IndexMetadata.SETTING_AUTO_EXPAND_REPLICAS, "false").build();
blobAdminClient.createBlobTable("test", indexSettings).get();
blobAdminClient.createBlobTable("test_blobs2", indexSettings).get();
client().admin().indices().prepareCreate("test_no_blobs").setSettings(Settings.builder().put("number_of_shards", 2).put("number_of_replicas", 0).build()).execute().actionGet();
ensureGreen();
}
Aggregations