Search in sources :

Example 16 with Nullable

use of org.elasticsearch.common.Nullable in project elasticsearch by elastic.

the class LongGCDisruptionTest method testBlockDetection.

public void testBlockDetection() throws Exception {
    final String disruptedNodeName = "disrupted_node";
    final String blockedNodeName = "blocked_node";
    CountDownLatch waitForBlockDetectionResult = new CountDownLatch(1);
    AtomicReference<ThreadInfo> blockDetectionResult = new AtomicReference<>();
    LongGCDisruption disruption = new LongGCDisruption(random(), disruptedNodeName) {

        @Override
        protected Pattern[] getUnsafeClasses() {
            return new Pattern[0];
        }

        @Override
        protected void onBlockDetected(ThreadInfo blockedThread, @Nullable ThreadInfo blockingThread) {
            blockDetectionResult.set(blockedThread);
            waitForBlockDetectionResult.countDown();
        }

        @Override
        protected long getBlockDetectionIntervalInMillis() {
            return 10L;
        }
    };
    if (disruption.isBlockDetectionSupported() == false) {
        return;
    }
    final AtomicBoolean stop = new AtomicBoolean();
    final CountDownLatch underLock = new CountDownLatch(1);
    final CountDownLatch pauseUnderLock = new CountDownLatch(1);
    final LockedExecutor lockedExecutor = new LockedExecutor();
    final AtomicLong ops = new AtomicLong();
    try {
        for (int i = 0; i < 5; i++) {
            // at least one locked and one none lock thread
            final boolean lockedExec = (i < 4 && randomBoolean()) || i == 0;
            Thread thread = new Thread(() -> {
                while (stop.get() == false) {
                    if (lockedExec) {
                        lockedExecutor.executeLocked(() -> {
                            try {
                                underLock.countDown();
                                ops.incrementAndGet();
                                pauseUnderLock.await();
                            } catch (InterruptedException e) {
                            }
                        });
                    } else {
                        ops.incrementAndGet();
                    }
                }
            });
            thread.setName("[" + disruptedNodeName + "][" + i + "]");
            thread.start();
        }
        for (int i = 0; i < 5; i++) {
            // at least one locked and one none lock thread
            final boolean lockedExec = (i < 4 && randomBoolean()) || i == 0;
            Thread thread = new Thread(() -> {
                while (stop.get() == false) {
                    if (lockedExec) {
                        lockedExecutor.executeLocked(() -> {
                            ops.incrementAndGet();
                        });
                    } else {
                        ops.incrementAndGet();
                    }
                }
            });
            thread.setName("[" + blockedNodeName + "][" + i + "]");
            thread.start();
        }
        // make sure some threads of test_node are under lock
        underLock.await();
        disruption.startDisrupting();
        waitForBlockDetectionResult.await(30, TimeUnit.SECONDS);
        disruption.stopDisrupting();
        ThreadInfo threadInfo = blockDetectionResult.get();
        assertNotNull(threadInfo);
        assertThat(threadInfo.getThreadName(), containsString("[" + blockedNodeName + "]"));
        assertThat(threadInfo.getLockOwnerName(), containsString("[" + disruptedNodeName + "]"));
        assertThat(threadInfo.getLockInfo().getClassName(), containsString(ReentrantLock.class.getName()));
    } finally {
        stop.set(true);
        pauseUnderLock.countDown();
    }
}
Also used : Pattern(java.util.regex.Pattern) AtomicReference(java.util.concurrent.atomic.AtomicReference) Matchers.containsString(org.hamcrest.Matchers.containsString) CountDownLatch(java.util.concurrent.CountDownLatch) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicLong(java.util.concurrent.atomic.AtomicLong) ThreadInfo(java.lang.management.ThreadInfo) Nullable(org.elasticsearch.common.Nullable)

Example 17 with Nullable

use of org.elasticsearch.common.Nullable in project crate by crate.

the class AzureComputeServiceImpl method networkResourceClient.

@Nullable
@Override
public NetworkResourceProviderClient networkResourceClient() {
    if (networkResourceClient == null) {
        Configuration conf = configuration();
        if (conf == null) {
            return null;
        }
        networkResourceClient = NetworkResourceProviderService.create(conf);
    }
    return networkResourceClient;
}
Also used : ManagementConfiguration(com.microsoft.windowsazure.management.configuration.ManagementConfiguration) Configuration(com.microsoft.windowsazure.Configuration) Nullable(org.elasticsearch.common.Nullable)

Aggregations

Nullable (org.elasticsearch.common.Nullable)17 IOException (java.io.IOException)9 ArrayList (java.util.ArrayList)4 ElasticsearchException (org.elasticsearch.ElasticsearchException)4 IndexSettings (org.elasticsearch.index.IndexSettings)4 IndexWriterConfig (org.apache.lucene.index.IndexWriterConfig)3 Directory (org.apache.lucene.store.Directory)3 IndexMetaData (org.elasticsearch.cluster.metadata.IndexMetaData)3 CodecService (org.elasticsearch.index.codec.CodecService)3 TranslogConfig (org.elasticsearch.index.translog.TranslogConfig)3 Configuration (com.microsoft.windowsazure.Configuration)2 ManagementConfiguration (com.microsoft.windowsazure.management.configuration.ManagementConfiguration)2 HashSet (java.util.HashSet)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 LiveIndexWriterConfig (org.apache.lucene.index.LiveIndexWriterConfig)2 AlreadyClosedException (org.apache.lucene.store.AlreadyClosedException)2 BytesRef (org.apache.lucene.util.BytesRef)2 BytesStreamOutput (org.elasticsearch.common.io.stream.BytesStreamOutput)2 Engine (org.elasticsearch.index.engine.Engine)2 DirectoryService (org.elasticsearch.index.store.DirectoryService)2