Add more informative toString method to StoreDirectory
This commit is contained in:
parent
a89230945f
commit
dbaf39c792
|
@ -143,7 +143,14 @@ public final class RateLimitedFSDirectory extends Directory {
|
|||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "RateLimitedDirectoryWrapper(" + delegate.toString() + ")";
|
||||
StoreRateLimiting rateLimiting = rateLimitingProvider.rateLimiting();
|
||||
StoreRateLimiting.Type type = rateLimiting.getType();
|
||||
RateLimiter limiter = rateLimiting.getRateLimiter();
|
||||
if (type == StoreRateLimiting.Type.NONE || limiter == null) {
|
||||
return StoreUtils.toString(delegate);
|
||||
} else {
|
||||
return "rate_limited(" + StoreUtils.toString(delegate) + ", type=" + type.name() + ", rate=" + limiter.getMbPerSec() + ")";
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
/*
|
||||
* Licensed to ElasticSearch and Shay Banon under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. ElasticSearch licenses this
|
||||
* file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.lucene.store;
|
||||
|
||||
/**
|
||||
*/
|
||||
public final class StoreUtils {
|
||||
|
||||
private StoreUtils() {
|
||||
|
||||
}
|
||||
|
||||
public static String toString(Directory directory) {
|
||||
if (directory instanceof NIOFSDirectory) {
|
||||
NIOFSDirectory niofsDirectory = (NIOFSDirectory)directory;
|
||||
return "niofs(" + niofsDirectory.getDirectory() + ")";
|
||||
}
|
||||
if (directory instanceof MMapDirectory) {
|
||||
MMapDirectory mMapDirectory = (MMapDirectory)directory;
|
||||
return "mmapfs(" + mMapDirectory.getDirectory() + ")";
|
||||
}
|
||||
if (directory instanceof SimpleFSDirectory) {
|
||||
SimpleFSDirectory simpleFSDirectory = (SimpleFSDirectory)directory;
|
||||
return "simplefs(" + simpleFSDirectory.getDirectory() + ")";
|
||||
}
|
||||
return directory.toString();
|
||||
}
|
||||
}
|
|
@ -151,6 +151,11 @@ public class ByteBufferDirectory extends Directory {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "byte_buffer";
|
||||
}
|
||||
|
||||
void releaseBuffer(ByteBuffer byteBuffer) {
|
||||
allocator.release(byteBuffer);
|
||||
}
|
||||
|
|
|
@ -528,6 +528,11 @@ public class Store extends AbstractIndexShardComponent implements CloseableIndex
|
|||
public void forceSync(String name) throws IOException {
|
||||
sync(ImmutableList.of(name));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "store(" + distributor.toString() + ")";
|
||||
}
|
||||
}
|
||||
|
||||
class StoreIndexOutput extends IndexOutput {
|
||||
|
|
|
@ -25,6 +25,7 @@ import org.apache.lucene.store.RateLimitedFSDirectory;
|
|||
import org.elasticsearch.index.store.DirectoryService;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
|
||||
public abstract class AbstractDistributor implements Distributor {
|
||||
|
||||
|
@ -62,6 +63,13 @@ public abstract class AbstractDistributor implements Distributor {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name() + Arrays.toString(delegates);
|
||||
}
|
||||
|
||||
protected abstract Directory doAny();
|
||||
|
||||
protected abstract String name();
|
||||
|
||||
}
|
||||
|
|
|
@ -57,6 +57,11 @@ public class LeastUsedDistributor extends AbstractDistributor {
|
|||
}
|
||||
|
||||
return directory;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String name() {
|
||||
return "least_used";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -59,4 +59,10 @@ public class RandomWeightedDistributor extends AbstractDistributor {
|
|||
// TODO: size is 0 - should we bail out or fall back on random distribution?
|
||||
return delegates[ThreadLocalRandom.current().nextInt(delegates.length)];
|
||||
}
|
||||
|
||||
@Override
|
||||
public String name() {
|
||||
return "random";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -19,20 +19,21 @@
|
|||
|
||||
package org.elasticsearch.test.integration.indices.store;
|
||||
|
||||
import org.apache.lucene.store.Directory;
|
||||
import org.elasticsearch.common.unit.TimeValue;
|
||||
import org.elasticsearch.env.Environment;
|
||||
import org.elasticsearch.index.shard.service.InternalIndexShard;
|
||||
import org.elasticsearch.indices.IndexMissingException;
|
||||
import org.elasticsearch.indices.IndicesService;
|
||||
import org.elasticsearch.node.internal.InternalNode;
|
||||
import org.elasticsearch.test.integration.AbstractNodesTests;
|
||||
import org.testng.annotations.AfterClass;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Test;
|
||||
import org.testng.annotations.*;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -40,13 +41,13 @@ import static org.hamcrest.Matchers.equalTo;
|
|||
public class SimpleDistributorTests extends AbstractNodesTests {
|
||||
protected Environment environment;
|
||||
|
||||
@BeforeClass
|
||||
@BeforeMethod
|
||||
public void getTestEnvironment() {
|
||||
environment = ((InternalNode) startNode("node0")).injector().getInstance(Environment.class);
|
||||
closeNode("node0");
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
@AfterMethod
|
||||
public void closeNodes() {
|
||||
closeAllNodes();
|
||||
}
|
||||
|
@ -58,22 +59,100 @@ public class SimpleDistributorTests extends AbstractNodesTests {
|
|||
File dataRoot = environment.dataFiles()[0];
|
||||
startNode("node1", settingsBuilder().putArray("path.data", new File(dataRoot, "data1").getAbsolutePath(), new File(dataRoot, "data2").getAbsolutePath()));
|
||||
for (String store : STORE_TYPES) {
|
||||
try {
|
||||
client("node1").admin().indices().prepareDelete("test").execute().actionGet();
|
||||
} catch (IndexMissingException ex) {
|
||||
// Ignore
|
||||
}
|
||||
client("node1").admin().indices().prepareCreate("test")
|
||||
.setSettings(settingsBuilder()
|
||||
.put("index.store.distributor", StrictDistributor.class.getCanonicalName())
|
||||
.put("index.store.type", store)
|
||||
.put("index.number_of_replicas", 0)
|
||||
.put("index.number_of_shards", 1)
|
||||
)
|
||||
.execute().actionGet();
|
||||
assertThat(client("node1").admin().cluster().prepareHealth("test").setWaitForGreenStatus()
|
||||
.setTimeout(TimeValue.timeValueSeconds(5)).execute().actionGet().isTimedOut(), equalTo(false));
|
||||
createIndexWithStoreType("node1", "test", store, StrictDistributor.class.getCanonicalName());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDirectoryToString() {
|
||||
File dataRoot = environment.dataFiles()[0];
|
||||
String dataPath1 = new File(dataRoot, "data1").getAbsolutePath();
|
||||
String dataPath2 = new File(dataRoot, "data2").getAbsolutePath();
|
||||
startNode("node1", settingsBuilder().putArray("path.data", dataPath1, dataPath2));
|
||||
|
||||
createIndexWithStoreType("node1", "test", "niofs", "least_used");
|
||||
String storeString = getStoreDirectory("node1", "test", 0).toString();
|
||||
logger.info(storeString);
|
||||
assertThat(storeString, startsWith("store(least_used[niofs(" + dataPath1 ));
|
||||
assertThat(storeString, containsString("), niofs(" + dataPath2));
|
||||
assertThat(storeString, endsWith(")])"));
|
||||
|
||||
createIndexWithStoreType("node1", "test", "niofs", "random");
|
||||
storeString = getStoreDirectory("node1", "test", 0).toString();
|
||||
logger.info(storeString);
|
||||
assertThat(storeString, startsWith("store(random[niofs(" + dataPath1 ));
|
||||
assertThat(storeString, containsString("), niofs(" + dataPath2));
|
||||
assertThat(storeString, endsWith(")])"));
|
||||
|
||||
createIndexWithStoreType("node1", "test", "mmapfs", "least_used");
|
||||
storeString = getStoreDirectory("node1", "test", 0).toString();
|
||||
logger.info(storeString);
|
||||
assertThat(storeString, startsWith("store(least_used[mmapfs(" + dataPath1));
|
||||
assertThat(storeString, containsString("), mmapfs(" + dataPath2));
|
||||
assertThat(storeString, endsWith(")])"));
|
||||
|
||||
createIndexWithStoreType("node1", "test", "simplefs", "least_used");
|
||||
storeString = getStoreDirectory("node1", "test", 0).toString();
|
||||
logger.info(storeString);
|
||||
assertThat(storeString, startsWith("store(least_used[simplefs(" + dataPath1));
|
||||
assertThat(storeString, containsString("), simplefs(" + dataPath2));
|
||||
assertThat(storeString, endsWith(")])"));
|
||||
|
||||
createIndexWithStoreType("node1", "test", "memory", "least_used");
|
||||
storeString = getStoreDirectory("node1", "test", 0).toString();
|
||||
logger.info(storeString);
|
||||
assertThat(storeString, equalTo("store(least_used[byte_buffer])"));
|
||||
|
||||
createIndexWithRateLimitingStoreType("node1", "test", "niofs", "least_used", "5mb");
|
||||
storeString = getStoreDirectory("node1", "test", 0).toString();
|
||||
logger.info(storeString);
|
||||
assertThat(storeString, startsWith("store(least_used[rate_limited(niofs(" + dataPath1 ));
|
||||
assertThat(storeString, containsString("), rate_limited(niofs(" + dataPath2));
|
||||
assertThat(storeString, endsWith(", type=MERGE, rate=5.0)])"));
|
||||
}
|
||||
|
||||
private void createIndexWithStoreType(String nodeId, String index, String storeType, String distributor) {
|
||||
try {
|
||||
client(nodeId).admin().indices().prepareDelete(index).execute().actionGet();
|
||||
} catch (IndexMissingException ex) {
|
||||
// Ignore
|
||||
}
|
||||
client(nodeId).admin().indices().prepareCreate(index)
|
||||
.setSettings(settingsBuilder()
|
||||
.put("index.store.distributor", distributor)
|
||||
.put("index.store.type", storeType)
|
||||
.put("index.number_of_replicas", 0)
|
||||
.put("index.number_of_shards", 1)
|
||||
)
|
||||
.execute().actionGet();
|
||||
assertThat(client("node1").admin().cluster().prepareHealth("test").setWaitForGreenStatus()
|
||||
.setTimeout(TimeValue.timeValueSeconds(5)).execute().actionGet().isTimedOut(), equalTo(false));
|
||||
}
|
||||
|
||||
private void createIndexWithRateLimitingStoreType(String nodeId, String index, String storeType, String distributor, String limit) {
|
||||
try {
|
||||
client(nodeId).admin().indices().prepareDelete(index).execute().actionGet();
|
||||
} catch (IndexMissingException ex) {
|
||||
// Ignore
|
||||
}
|
||||
client(nodeId).admin().indices().prepareCreate(index)
|
||||
.setSettings(settingsBuilder()
|
||||
.put("index.store.distributor", distributor)
|
||||
.put("index.store.type", storeType)
|
||||
.put("index.store.throttle.type", "merge")
|
||||
.put("index.store.throttle.max_bytes_per_sec", limit)
|
||||
.put("index.number_of_replicas", 0)
|
||||
.put("index.number_of_shards", 1)
|
||||
)
|
||||
.execute().actionGet();
|
||||
assertThat(client("node1").admin().cluster().prepareHealth("test").setWaitForGreenStatus()
|
||||
.setTimeout(TimeValue.timeValueSeconds(5)).execute().actionGet().isTimedOut(), equalTo(false));
|
||||
}
|
||||
|
||||
private Directory getStoreDirectory(String nodeId, String index, int shardId) {
|
||||
IndicesService indicesService = ((InternalNode) node(nodeId)).injector().getInstance(IndicesService.class);
|
||||
InternalIndexShard indexShard = (InternalIndexShard) (indicesService.indexService(index).shard(shardId));
|
||||
return indexShard.store().directory();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -46,4 +46,10 @@ public class StrictDistributor extends AbstractDistributor {
|
|||
}
|
||||
return primary();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String name() {
|
||||
return "strict";
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue