Search in sources :

Example 11 with ThreadInterruptedException

use of org.apache.lucene.util.ThreadInterruptedException in project lucene-solr by apache.

the class TestIndexWriter method testCloseDuringCommit.

/** Make sure that close waits for any still-running commits. */
public void testCloseDuringCommit() throws Exception {
    final CountDownLatch startCommit = new CountDownLatch(1);
    final CountDownLatch finishCommit = new CountDownLatch(1);
    Directory dir = newDirectory();
    IndexWriterConfig iwc = new IndexWriterConfig(null);
    // use an infostream that "takes a long time" to commit
    final IndexWriter iw = RandomIndexWriter.mockIndexWriter(random(), dir, iwc, new RandomIndexWriter.TestPoint() {

        @Override
        public void apply(String message) {
            if (message.equals("finishStartCommit")) {
                startCommit.countDown();
                try {
                    Thread.sleep(10);
                } catch (InterruptedException ie) {
                    throw new ThreadInterruptedException(ie);
                }
            }
        }
    });
    new Thread() {

        @Override
        public void run() {
            try {
                iw.commit();
                finishCommit.countDown();
            } catch (IOException ioe) {
                throw new RuntimeException(ioe);
            }
        }
    }.start();
    startCommit.await();
    try {
        iw.close();
    } catch (IllegalStateException ise) {
    // OK, but not required (depends on thread scheduling)
    }
    finishCommit.await();
    iw.close();
    dir.close();
}
Also used : ThreadInterruptedException(org.apache.lucene.util.ThreadInterruptedException) IOException(java.io.IOException) CountDownLatch(java.util.concurrent.CountDownLatch) ThreadInterruptedException(org.apache.lucene.util.ThreadInterruptedException) MMapDirectory(org.apache.lucene.store.MMapDirectory) Directory(org.apache.lucene.store.Directory) RAMDirectory(org.apache.lucene.store.RAMDirectory) FSDirectory(org.apache.lucene.store.FSDirectory) SimpleFSDirectory(org.apache.lucene.store.SimpleFSDirectory) NIOFSDirectory(org.apache.lucene.store.NIOFSDirectory)

Example 12 with ThreadInterruptedException

use of org.apache.lucene.util.ThreadInterruptedException in project lucene-solr by apache.

the class TestRateLimiter method testOverflowInt.

// LUCENE-6075
public void testOverflowInt() throws Exception {
    Thread t = new Thread() {

        @Override
        public void run() {
            try {
                new SimpleRateLimiter(1).pause((long) (1.5 * Integer.MAX_VALUE * 1024 * 1024 / 1000));
                fail("should have been interrupted");
            } catch (ThreadInterruptedException tie) {
            // expected
            }
        }
    };
    t.start();
    Thread.sleep(10);
    t.interrupt();
}
Also used : SimpleRateLimiter(org.apache.lucene.store.RateLimiter.SimpleRateLimiter) ThreadInterruptedException(org.apache.lucene.util.ThreadInterruptedException)

Example 13 with ThreadInterruptedException

use of org.apache.lucene.util.ThreadInterruptedException in project lucene-solr by apache.

the class TestRateLimiter method testThreads.

public void testThreads() throws Exception {
    double targetMBPerSec = 10.0 + 20 * random().nextDouble();
    final SimpleRateLimiter limiter = new SimpleRateLimiter(targetMBPerSec);
    final CountDownLatch startingGun = new CountDownLatch(1);
    Thread[] threads = new Thread[TestUtil.nextInt(random(), 3, 6)];
    final AtomicLong totBytes = new AtomicLong();
    for (int i = 0; i < threads.length; i++) {
        threads[i] = new Thread() {

            @Override
            public void run() {
                try {
                    startingGun.await();
                } catch (InterruptedException ie) {
                    throw new ThreadInterruptedException(ie);
                }
                long bytesSinceLastPause = 0;
                for (int i = 0; i < 500; i++) {
                    long numBytes = TestUtil.nextInt(random(), 1000, 10000);
                    totBytes.addAndGet(numBytes);
                    bytesSinceLastPause += numBytes;
                    if (bytesSinceLastPause > limiter.getMinPauseCheckBytes()) {
                        limiter.pause(bytesSinceLastPause);
                        bytesSinceLastPause = 0;
                    }
                }
            }
        };
        threads[i].start();
    }
    long startNS = System.nanoTime();
    startingGun.countDown();
    for (Thread thread : threads) {
        thread.join();
    }
    long endNS = System.nanoTime();
    double actualMBPerSec = (totBytes.get() / 1024 / 1024.) / ((endNS - startNS) / 1000000000.0);
    // TODO: this may false trip .... could be we can only assert that it never exceeds the max, so slow jenkins doesn't trip:
    double ratio = actualMBPerSec / targetMBPerSec;
    // Only enforce that it wasn't too fast; if machine is bogged down (can't schedule threads / sleep properly) then it may falsely be too slow:
    assumeTrue("actualMBPerSec=" + actualMBPerSec + " targetMBPerSec=" + targetMBPerSec, 0.9 <= ratio);
    assertTrue("targetMBPerSec=" + targetMBPerSec + " actualMBPerSec=" + actualMBPerSec, ratio <= 1.1);
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) SimpleRateLimiter(org.apache.lucene.store.RateLimiter.SimpleRateLimiter) ThreadInterruptedException(org.apache.lucene.util.ThreadInterruptedException) CountDownLatch(java.util.concurrent.CountDownLatch) ThreadInterruptedException(org.apache.lucene.util.ThreadInterruptedException)

Example 14 with ThreadInterruptedException

use of org.apache.lucene.util.ThreadInterruptedException in project lucene-solr by apache.

the class PrimaryNode method waitForAllRemotesToClose.

private synchronized void waitForAllRemotesToClose() throws IOException {
    // Wait for replicas to finish or crash:
    while (true) {
        int count = copyingCount.get();
        if (count == 0) {
            return;
        }
        message("pendingCopies: " + count);
        try {
            wait(10);
        } catch (InterruptedException ie) {
            throw new ThreadInterruptedException(ie);
        }
    }
}
Also used : ThreadInterruptedException(org.apache.lucene.util.ThreadInterruptedException) ThreadInterruptedException(org.apache.lucene.util.ThreadInterruptedException)

Example 15 with ThreadInterruptedException

use of org.apache.lucene.util.ThreadInterruptedException in project lucene-solr by apache.

the class SimplePrimaryNode method preCopyMergedSegmentFiles.

@Override
protected void preCopyMergedSegmentFiles(SegmentCommitInfo info, Map<String, FileMetaData> files) throws IOException {
    int[] replicaTCPPorts = this.replicaTCPPorts;
    if (replicaTCPPorts == null) {
        message("no replicas; skip warming " + info);
        return;
    }
    message("top: warm merge " + info + " to " + replicaTCPPorts.length + " replicas; tcpPort=" + tcpPort + ": files=" + files.keySet());
    MergePreCopy preCopy = new MergePreCopy(files);
    warmingSegments.add(preCopy);
    try {
        Set<String> fileNames = files.keySet();
        // Ask all currently known replicas to pre-copy this newly merged segment's files:
        for (int replicaTCPPort : replicaTCPPorts) {
            try {
                Connection c = new Connection(replicaTCPPort);
                c.out.writeByte(SimpleReplicaNode.CMD_PRE_COPY_MERGE);
                c.out.writeVLong(primaryGen);
                c.out.writeVInt(tcpPort);
                SimpleServer.writeFilesMetaData(c.out, files);
                c.flush();
                c.s.shutdownOutput();
                message("warm connection " + c.s);
                preCopy.connections.add(c);
            } catch (Throwable t) {
                message("top: ignore exception trying to warm to replica port " + replicaTCPPort + ": " + t);
            //t.printStackTrace(System.out);
            }
        }
        long startNS = System.nanoTime();
        long lastWarnNS = startNS;
        // TODO: maybe ... place some sort of time limit on how long we are willing to wait for slow replica(s) to finish copying?
        while (preCopy.finished() == false) {
            try {
                Thread.sleep(10);
            } catch (InterruptedException ie) {
                throw new ThreadInterruptedException(ie);
            }
            if (isClosed()) {
                message("top: primary is closing: now cancel segment warming");
                synchronized (preCopy.connections) {
                    IOUtils.closeWhileHandlingException(preCopy.connections);
                }
                return;
            }
            long ns = System.nanoTime();
            if (ns - lastWarnNS > 1000000000L) {
                message(String.format(Locale.ROOT, "top: warning: still warming merge " + info + " to " + preCopy.connections.size() + " replicas for %.1f sec...", (ns - startNS) / 1000000000.0));
                lastWarnNS = ns;
            }
            // Process keep-alives:
            synchronized (preCopy.connections) {
                Iterator<Connection> it = preCopy.connections.iterator();
                while (it.hasNext()) {
                    Connection c = it.next();
                    try {
                        long nowNS = System.nanoTime();
                        boolean done = false;
                        while (c.sockIn.available() > 0) {
                            byte b = c.in.readByte();
                            if (b == 0) {
                                // keep-alive
                                c.lastKeepAliveNS = nowNS;
                                message("keep-alive for socket=" + c.s + " merge files=" + files.keySet());
                            } else {
                                // merge is done pre-copying to this node
                                if (b != 1) {
                                    throw new IllegalArgumentException();
                                }
                                message("connection socket=" + c.s + " is done warming its merge " + info + " files=" + files.keySet());
                                IOUtils.closeWhileHandlingException(c);
                                it.remove();
                                done = true;
                                break;
                            }
                        }
                        // If > 2 sec since we saw a keep-alive, assume this replica is dead:
                        if (done == false && nowNS - c.lastKeepAliveNS > 2000000000L) {
                            message("top: warning: replica socket=" + c.s + " for segment=" + info + " seems to be dead; closing files=" + files.keySet());
                            IOUtils.closeWhileHandlingException(c);
                            it.remove();
                            done = true;
                        }
                        if (done == false && random.nextInt(1000) == 17) {
                            message("top: warning: now randomly dropping replica from merge warming; files=" + files.keySet());
                            IOUtils.closeWhileHandlingException(c);
                            it.remove();
                            done = true;
                        }
                    } catch (Throwable t) {
                        message("top: ignore exception trying to read byte during warm for segment=" + info + " to replica socket=" + c.s + ": " + t + " files=" + files.keySet());
                        IOUtils.closeWhileHandlingException(c);
                        it.remove();
                    }
                }
            }
        }
    } finally {
        warmingSegments.remove(preCopy);
    }
}
Also used : ThreadInterruptedException(org.apache.lucene.util.ThreadInterruptedException) ThreadInterruptedException(org.apache.lucene.util.ThreadInterruptedException)

Aggregations

ThreadInterruptedException (org.apache.lucene.util.ThreadInterruptedException)17 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)3 CountDownLatch (java.util.concurrent.CountDownLatch)2 ExecutionException (java.util.concurrent.ExecutionException)2 Future (java.util.concurrent.Future)2 SimpleRateLimiter (org.apache.lucene.store.RateLimiter.SimpleRateLimiter)2 BufferedReader (java.io.BufferedReader)1 InputStreamReader (java.io.InputStreamReader)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 Writer (java.io.Writer)1 Path (java.nio.file.Path)1 Callable (java.util.concurrent.Callable)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 Pattern (java.util.regex.Pattern)1 MockAnalyzer (org.apache.lucene.analysis.MockAnalyzer)1 Document (org.apache.lucene.document.Document)1 FieldType (org.apache.lucene.document.FieldType)1 LeafReaderContext (org.apache.lucene.index.LeafReaderContext)1