Merge pull request #10798 from mfussenegger/bigarrays
Internal: Change BigArrays to not extend AbstractComponent In order to avoid the getLogger(getClass()) calls in the AbstractComponent constructor. Seems like BigArrays used to be a Singleton but it actually no longer is one. Every time a SearchContext is created a new BigArrays instance is created via the withCircuitBreaking call. closes #10798
This commit is contained in:
commit
1db380cf49
|
@ -39,9 +39,9 @@ import org.elasticsearch.indices.breaker.CircuitBreakerService;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
/** Utility class to work with arrays. */
|
/** Utility class to work with arrays. */
|
||||||
public class BigArrays extends AbstractComponent {
|
public class BigArrays {
|
||||||
|
|
||||||
public static final BigArrays NON_RECYCLING_INSTANCE = new BigArrays(ImmutableSettings.EMPTY, null, null);
|
public static final BigArrays NON_RECYCLING_INSTANCE = new BigArrays(null, null);
|
||||||
|
|
||||||
/** Page size in bytes: 16KB */
|
/** Page size in bytes: 16KB */
|
||||||
public static final int PAGE_SIZE_IN_BYTES = 1 << 14;
|
public static final int PAGE_SIZE_IN_BYTES = 1 << 14;
|
||||||
|
@ -366,13 +366,12 @@ public class BigArrays extends AbstractComponent {
|
||||||
final boolean checkBreaker;
|
final boolean checkBreaker;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public BigArrays(Settings settings, PageCacheRecycler recycler, @Nullable final CircuitBreakerService breakerService) {
|
public BigArrays(PageCacheRecycler recycler, @Nullable final CircuitBreakerService breakerService) {
|
||||||
// Checking the breaker is disabled if not specified
|
// Checking the breaker is disabled if not specified
|
||||||
this(settings, recycler, breakerService, false);
|
this(recycler, breakerService, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public BigArrays(Settings settings, PageCacheRecycler recycler, @Nullable final CircuitBreakerService breakerService, boolean checkBreaker) {
|
public BigArrays(PageCacheRecycler recycler, @Nullable final CircuitBreakerService breakerService, boolean checkBreaker) {
|
||||||
super(settings);
|
|
||||||
this.checkBreaker = checkBreaker;
|
this.checkBreaker = checkBreaker;
|
||||||
this.recycler = recycler;
|
this.recycler = recycler;
|
||||||
this.breakerService = breakerService;
|
this.breakerService = breakerService;
|
||||||
|
@ -415,7 +414,7 @@ public class BigArrays extends AbstractComponent {
|
||||||
* explicitly enabled, instead of only accounting enabled
|
* explicitly enabled, instead of only accounting enabled
|
||||||
*/
|
*/
|
||||||
public BigArrays withCircuitBreaking() {
|
public BigArrays withCircuitBreaking() {
|
||||||
return new BigArrays(this.settings, this.recycler, this.breakerService, true);
|
return new BigArrays(this.recycler, this.breakerService, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private <T extends AbstractBigArray> T resizeInPlace(T array, long newSize) {
|
private <T extends AbstractBigArray> T resizeInPlace(T array, long newSize) {
|
||||||
|
|
|
@ -54,7 +54,7 @@ public class PagedBytesReferenceTest extends ElasticsearchTestCase {
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
super.setUp();
|
super.setUp();
|
||||||
bigarrays = new BigArrays(ImmutableSettings.EMPTY, null, new NoneCircuitBreakerService());
|
bigarrays = new BigArrays(null, new NoneCircuitBreakerService());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -39,7 +39,7 @@ public class BigArraysTests extends ElasticsearchSingleNodeTest {
|
||||||
|
|
||||||
public static BigArrays randombigArrays() {
|
public static BigArrays randombigArrays() {
|
||||||
final PageCacheRecycler recycler = randomBoolean() ? null : ElasticsearchSingleNodeTest.getInstanceFromNode(PageCacheRecycler.class);
|
final PageCacheRecycler recycler = randomBoolean() ? null : ElasticsearchSingleNodeTest.getInstanceFromNode(PageCacheRecycler.class);
|
||||||
return new MockBigArrays(ImmutableSettings.EMPTY, recycler, new NoneCircuitBreakerService());
|
return new MockBigArrays(recycler, new NoneCircuitBreakerService());
|
||||||
}
|
}
|
||||||
|
|
||||||
private BigArrays bigArrays;
|
private BigArrays bigArrays;
|
||||||
|
@ -339,7 +339,7 @@ public class BigArraysTests extends ElasticsearchSingleNodeTest {
|
||||||
.put(HierarchyCircuitBreakerService.REQUEST_CIRCUIT_BREAKER_LIMIT_SETTING, size - 1)
|
.put(HierarchyCircuitBreakerService.REQUEST_CIRCUIT_BREAKER_LIMIT_SETTING, size - 1)
|
||||||
.build(),
|
.build(),
|
||||||
new NodeSettingsService(ImmutableSettings.EMPTY));
|
new NodeSettingsService(ImmutableSettings.EMPTY));
|
||||||
BigArrays bigArrays = new BigArrays(ImmutableSettings.EMPTY, null, hcbs).withCircuitBreaking();
|
BigArrays bigArrays = new BigArrays(null, hcbs).withCircuitBreaking();
|
||||||
Method create = BigArrays.class.getMethod("new" + type + "Array", long.class);
|
Method create = BigArrays.class.getMethod("new" + type + "Array", long.class);
|
||||||
try {
|
try {
|
||||||
create.invoke(bigArrays, size);
|
create.invoke(bigArrays, size);
|
||||||
|
@ -359,7 +359,7 @@ public class BigArraysTests extends ElasticsearchSingleNodeTest {
|
||||||
.put(HierarchyCircuitBreakerService.REQUEST_CIRCUIT_BREAKER_LIMIT_SETTING, maxSize)
|
.put(HierarchyCircuitBreakerService.REQUEST_CIRCUIT_BREAKER_LIMIT_SETTING, maxSize)
|
||||||
.build(),
|
.build(),
|
||||||
new NodeSettingsService(ImmutableSettings.EMPTY));
|
new NodeSettingsService(ImmutableSettings.EMPTY));
|
||||||
BigArrays bigArrays = new BigArrays(ImmutableSettings.EMPTY, null, hcbs).withCircuitBreaking();
|
BigArrays bigArrays = new BigArrays(null, hcbs).withCircuitBreaking();
|
||||||
Method create = BigArrays.class.getMethod("new" + type + "Array", long.class);
|
Method create = BigArrays.class.getMethod("new" + type + "Array", long.class);
|
||||||
final int size = scaledRandomIntBetween(1, 20);
|
final int size = scaledRandomIntBetween(1, 20);
|
||||||
BigArray array = (BigArray) create.invoke(bigArrays, size);
|
BigArray array = (BigArray) create.invoke(bigArrays, size);
|
||||||
|
|
|
@ -76,7 +76,7 @@ public class NettyHttpServerPipeliningTest extends ElasticsearchTestCase {
|
||||||
networkService = new NetworkService(ImmutableSettings.EMPTY);
|
networkService = new NetworkService(ImmutableSettings.EMPTY);
|
||||||
threadPool = new ThreadPool("test");
|
threadPool = new ThreadPool("test");
|
||||||
mockPageCacheRecycler = new MockPageCacheRecycler(ImmutableSettings.EMPTY, threadPool);
|
mockPageCacheRecycler = new MockPageCacheRecycler(ImmutableSettings.EMPTY, threadPool);
|
||||||
bigArrays = new MockBigArrays(ImmutableSettings.EMPTY, mockPageCacheRecycler, new NoneCircuitBreakerService());
|
bigArrays = new MockBigArrays(mockPageCacheRecycler, new NoneCircuitBreakerService());
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
|
|
|
@ -30,7 +30,6 @@ import org.apache.lucene.util.Accountables;
|
||||||
import org.apache.lucene.util.BytesRef;
|
import org.apache.lucene.util.BytesRef;
|
||||||
import org.elasticsearch.cache.recycler.PageCacheRecycler;
|
import org.elasticsearch.cache.recycler.PageCacheRecycler;
|
||||||
import org.elasticsearch.common.inject.Inject;
|
import org.elasticsearch.common.inject.Inject;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
|
||||||
import org.elasticsearch.common.util.BigArray;
|
import org.elasticsearch.common.util.BigArray;
|
||||||
import org.elasticsearch.common.util.BigArrays;
|
import org.elasticsearch.common.util.BigArrays;
|
||||||
import org.elasticsearch.common.util.ByteArray;
|
import org.elasticsearch.common.util.ByteArray;
|
||||||
|
@ -87,18 +86,16 @@ public class MockBigArrays extends BigArrays {
|
||||||
}
|
}
|
||||||
|
|
||||||
private final Random random;
|
private final Random random;
|
||||||
private final Settings settings;
|
|
||||||
private final PageCacheRecycler recycler;
|
private final PageCacheRecycler recycler;
|
||||||
private final CircuitBreakerService breakerService;
|
private final CircuitBreakerService breakerService;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public MockBigArrays(Settings settings, PageCacheRecycler recycler, CircuitBreakerService breakerService) {
|
public MockBigArrays(PageCacheRecycler recycler, CircuitBreakerService breakerService) {
|
||||||
this(settings, recycler, breakerService, false);
|
this(recycler, breakerService, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public MockBigArrays(Settings settings, PageCacheRecycler recycler, CircuitBreakerService breakerService, boolean checkBreaker) {
|
public MockBigArrays(PageCacheRecycler recycler, CircuitBreakerService breakerService, boolean checkBreaker) {
|
||||||
super(settings, recycler, breakerService, checkBreaker);
|
super(recycler, breakerService, checkBreaker);
|
||||||
this.settings = settings;
|
|
||||||
this.recycler = recycler;
|
this.recycler = recycler;
|
||||||
this.breakerService = breakerService;
|
this.breakerService = breakerService;
|
||||||
long seed;
|
long seed;
|
||||||
|
@ -114,7 +111,7 @@ public class MockBigArrays extends BigArrays {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BigArrays withCircuitBreaking() {
|
public BigArrays withCircuitBreaking() {
|
||||||
return new MockBigArrays(this.settings, this.recycler, this.breakerService, true);
|
return new MockBigArrays(this.recycler, this.breakerService, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -61,7 +61,7 @@ public class NettySizeHeaderFrameDecoderTests extends ElasticsearchTestCase {
|
||||||
threadPool = new ThreadPool(settings, new NodeSettingsService(settings));
|
threadPool = new ThreadPool(settings, new NodeSettingsService(settings));
|
||||||
|
|
||||||
NetworkService networkService = new NetworkService(settings);
|
NetworkService networkService = new NetworkService(settings);
|
||||||
BigArrays bigArrays = new MockBigArrays(settings, new MockPageCacheRecycler(settings, threadPool), new NoneCircuitBreakerService());
|
BigArrays bigArrays = new MockBigArrays(new MockPageCacheRecycler(settings, threadPool), new NoneCircuitBreakerService());
|
||||||
nettyTransport = new NettyTransport(settings, threadPool, networkService, bigArrays, Version.CURRENT);
|
nettyTransport = new NettyTransport(settings, threadPool, networkService, bigArrays, Version.CURRENT);
|
||||||
nettyTransport.start();
|
nettyTransport.start();
|
||||||
TransportService transportService = new TransportService(nettyTransport, threadPool);
|
TransportService transportService = new TransportService(nettyTransport, threadPool);
|
||||||
|
|
|
@ -170,7 +170,7 @@ public class NettyTransportMultiPortTests extends ElasticsearchTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
private NettyTransport startNettyTransport(Settings settings, ThreadPool threadPool) {
|
private NettyTransport startNettyTransport(Settings settings, ThreadPool threadPool) {
|
||||||
BigArrays bigArrays = new MockBigArrays(settings, new PageCacheRecycler(settings, threadPool), new NoneCircuitBreakerService());
|
BigArrays bigArrays = new MockBigArrays(new PageCacheRecycler(settings, threadPool), new NoneCircuitBreakerService());
|
||||||
|
|
||||||
NettyTransport nettyTransport = new NettyTransport(settings, threadPool, new NetworkService(settings), bigArrays, Version.CURRENT);
|
NettyTransport nettyTransport = new NettyTransport(settings, threadPool, new NetworkService(settings), bigArrays, Version.CURRENT);
|
||||||
nettyTransport.start();
|
nettyTransport.start();
|
||||||
|
|
Loading…
Reference in New Issue