List of usage examples for org.apache.lucene.util Constants FREE_BSD
boolean FREE_BSD
To view the source code for org.apache.lucene.util Constants FREE_BSD.
Click Source Link
From source file:org.elasticsearch.action.admin.HotThreadsIT.java
License:Apache License
public void testIgnoreIdleThreads() throws ExecutionException, InterruptedException { assumeTrue("no support for hot_threads on FreeBSD", Constants.FREE_BSD == false); // First time, don't ignore idle threads: NodesHotThreadsRequestBuilder builder = client().admin().cluster().prepareNodesHotThreads(); builder.setIgnoreIdleThreads(false); builder.setThreads(Integer.MAX_VALUE); NodesHotThreadsResponse response = builder.execute().get(); int totSizeAll = 0; for (NodeHotThreads node : response.getNodesMap().values()) { totSizeAll += node.getHotThreads().length(); }//from w w w .j av a2 s. c o m // Second time, do ignore idle threads: builder = client().admin().cluster().prepareNodesHotThreads(); builder.setThreads(Integer.MAX_VALUE); // Make sure default is true: assertEquals(true, builder.request().ignoreIdleThreads()); response = builder.execute().get(); int totSizeIgnoreIdle = 0; for (NodeHotThreads node : response.getNodesMap().values()) { totSizeIgnoreIdle += node.getHotThreads().length(); } // The filtered stacks should be smaller than unfiltered ones: assertThat(totSizeIgnoreIdle, lessThan(totSizeAll)); }
From source file:org.elasticsearch.action.admin.HotThreadsIT.java
License:Apache License
public void testTimestampAndParams() throws ExecutionException, InterruptedException { NodesHotThreadsResponse response = client().admin().cluster().prepareNodesHotThreads().execute().get(); if (Constants.FREE_BSD) { for (NodeHotThreads node : response.getNodesMap().values()) { String result = node.getHotThreads(); assertTrue(result.indexOf("hot_threads is not supported") != -1); }// w ww.j a va 2s .c om } else { for (NodeHotThreads node : response.getNodesMap().values()) { String result = node.getHotThreads(); assertTrue(result.indexOf("Hot threads at") != -1); assertTrue(result.indexOf("interval=500ms") != -1); assertTrue(result.indexOf("busiestThreads=3") != -1); assertTrue(result.indexOf("ignoreIdleThreads=true") != -1); } } }
From source file:org.elasticsearch.bootstrap.Seccomp.java
License:Apache License
static void bsdImpl() { boolean supported = Constants.FREE_BSD || OPENBSD || Constants.MAC_OS_X; if (supported == false) { throw new IllegalStateException( "bug: should not be trying to initialize RLIMIT_NPROC for an unsupported OS"); }//from w w w . j a v a 2 s. c o m JNACLibrary.Rlimit limit = new JNACLibrary.Rlimit(); limit.rlim_cur.setValue(0); limit.rlim_max.setValue(0); if (JNACLibrary.setrlimit(RLIMIT_NPROC, limit) != 0) { throw new UnsupportedOperationException( "RLIMIT_NPROC unavailable: " + JNACLibrary.strerror(Native.getLastError())); } logger.debug("BSD RLIMIT_NPROC initialization successful"); }
From source file:org.elasticsearch.bootstrap.Seccomp.java
License:Apache License
/** * Attempt to drop the capability to execute for the process. * <p>//from www .ja v a2s . c o m * This is best effort and OS and architecture dependent. It may throw any Throwable. * @return 0 if we can do this for application threads, 1 for the entire process */ static int init(Path tmpFile) throws Throwable { if (Constants.LINUX) { return linuxImpl(); } else if (Constants.MAC_OS_X) { // try to enable both mechanisms if possible bsdImpl(); macImpl(tmpFile); return 1; } else if (Constants.SUN_OS) { solarisImpl(); return 1; } else if (Constants.FREE_BSD || OPENBSD) { bsdImpl(); return 1; } else if (Constants.WINDOWS) { windowsImpl(); return 1; } else { throw new UnsupportedOperationException( "syscall filtering not supported for OS: '" + Constants.OS_NAME + "'"); } }
From source file:org.elasticsearch.bootstrap.SystemCallFilter.java
License:Apache License
/** * Attempt to drop the capability to execute for the process. * <p>// w w w .ja v a2 s . c om * This is best effort and OS and architecture dependent. It may throw any Throwable. * @return 0 if we can do this for application threads, 1 for the entire process */ static int init(Path tmpFile) throws Exception { if (Constants.LINUX) { return linuxImpl(); } else if (Constants.MAC_OS_X) { // try to enable both mechanisms if possible bsdImpl(); macImpl(tmpFile); return 1; } else if (Constants.SUN_OS) { solarisImpl(); return 1; } else if (Constants.FREE_BSD || OPENBSD) { bsdImpl(); return 1; } else if (Constants.WINDOWS) { windowsImpl(); return 1; } else { throw new UnsupportedOperationException( "syscall filtering not supported for OS: '" + Constants.OS_NAME + "'"); } }
From source file:org.elasticsearch.env.ESFileStore.java
License:Apache License
/** * Files.getFileStore(Path) useless here! Don't complain, just try it yourself. *///from ww w.j a v a2 s.c o m @SuppressForbidden(reason = "works around the bugs") static FileStore getMatchingFileStore(Path path, FileStore fileStores[]) throws IOException { if (Constants.WINDOWS) { return getFileStoreWindows(path, fileStores); } final FileStore store; try { store = Files.getFileStore(path); } catch (IOException unexpected) { // give a better error message if a filestore cannot be retrieved from inside a FreeBSD jail. if (Constants.FREE_BSD) { throw new IOException( "Unable to retrieve mount point data for " + path + ". If you are running within a jail, set enforce_statfs=1. See jail(8)", unexpected); } else { throw unexpected; } } try { String mount = getMountPointLinux(store); FileStore sameMountPoint = null; for (FileStore fs : fileStores) { if (mount.equals(getMountPointLinux(fs))) { if (sameMountPoint == null) { sameMountPoint = fs; } else { // more than one filesystem has the same mount point; something is wrong! // fall back to crappy one we got from Files.getFileStore return store; } } } if (sameMountPoint != null) { // ok, we found only one, use it: return sameMountPoint; } else { // fall back to crappy one we got from Files.getFileStore return store; } } catch (Exception e) { // ignore } // fall back to crappy one we got from Files.getFileStore return store; }
From source file:org.elasticsearch.plugin.discovery.multicast.MulticastZenPingTests.java
License:Apache License
public void testSimplePings() throws InterruptedException { assumeTrue("https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=193246", Constants.FREE_BSD == false); Settings settings = Settings.EMPTY;/*from w w w .j av a 2 s . c om*/ settings = buildRandomMulticast(settings); Thread.sleep(30000); ThreadPool threadPool = new ThreadPool("testSimplePings"); final ClusterName clusterName = new ClusterName("test"); final TransportService transportServiceA = new TransportService( new LocalTransport(settings, threadPool, Version.CURRENT, new NamedWriteableRegistry()), threadPool) .start(); final DiscoveryNode nodeA = new DiscoveryNode("A", transportServiceA.boundAddress().publishAddress(), Version.CURRENT); final TransportService transportServiceB = new TransportService( new LocalTransport(settings, threadPool, Version.CURRENT, new NamedWriteableRegistry()), threadPool) .start(); final DiscoveryNode nodeB = new DiscoveryNode("B", transportServiceB.boundAddress().publishAddress(), Version.CURRENT); MulticastZenPing zenPingA = new MulticastZenPing(threadPool, transportServiceA, clusterName, Version.CURRENT); zenPingA.setPingContextProvider(new PingContextProvider() { @Override public DiscoveryNodes nodes() { return DiscoveryNodes.builder().put(nodeA).localNodeId("A").build(); } @Override public NodeService nodeService() { return null; } @Override public boolean nodeHasJoinedClusterOnce() { return false; } }); zenPingA.start(); MulticastZenPing zenPingB = new MulticastZenPing(threadPool, transportServiceB, clusterName, Version.CURRENT); zenPingB.setPingContextProvider(new PingContextProvider() { @Override public DiscoveryNodes nodes() { return DiscoveryNodes.builder().put(nodeB).localNodeId("B").build(); } @Override public NodeService nodeService() { return null; } @Override public boolean nodeHasJoinedClusterOnce() { return true; } }); zenPingB.start(); try { logger.info("ping from A"); ZenPing.PingResponse[] pingResponses = zenPingA.pingAndWait(TimeValue.timeValueSeconds(1)); Assert.assertThat(pingResponses.length, Matchers.equalTo(1)); Assert.assertThat(pingResponses[0].node().id(), Matchers.equalTo("B")); Assert.assertTrue(pingResponses[0].hasJoinedOnce()); logger.info("ping from B"); pingResponses = zenPingB.pingAndWait(TimeValue.timeValueSeconds(1)); Assert.assertThat(pingResponses.length, Matchers.equalTo(1)); Assert.assertThat(pingResponses[0].node().id(), Matchers.equalTo("A")); Assert.assertFalse(pingResponses[0].hasJoinedOnce()); } finally { zenPingA.close(); zenPingB.close(); transportServiceA.close(); transportServiceB.close(); terminate(threadPool); } }
From source file:org.elasticsearch.plugin.discovery.multicast.MulticastZenPingTests.java
License:Apache License
@SuppressForbidden(reason = "I bind to wildcard addresses. I am a total nightmare") public void testExternalPing() throws Exception { assumeTrue("https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=193246", Constants.FREE_BSD == false); Settings settings = Settings.EMPTY;/*from ww w .j a va 2 s . com*/ settings = buildRandomMulticast(settings); final ThreadPool threadPool = new ThreadPool("testExternalPing"); final ClusterName clusterName = new ClusterName("test"); final TransportService transportServiceA = new TransportService( new LocalTransport(settings, threadPool, Version.CURRENT, new NamedWriteableRegistry()), threadPool) .start(); final DiscoveryNode nodeA = new DiscoveryNode("A", transportServiceA.boundAddress().publishAddress(), Version.CURRENT); MulticastZenPing zenPingA = new MulticastZenPing(threadPool, transportServiceA, clusterName, Version.CURRENT); zenPingA.setPingContextProvider(new PingContextProvider() { @Override public DiscoveryNodes nodes() { return DiscoveryNodes.builder().put(nodeA).localNodeId("A").build(); } @Override public NodeService nodeService() { return null; } @Override public boolean nodeHasJoinedClusterOnce() { return false; } }); zenPingA.start(); MulticastSocket multicastSocket = null; try { Loggers.getLogger(MulticastZenPing.class).setLevel("TRACE"); multicastSocket = new MulticastSocket(); multicastSocket.setReceiveBufferSize(2048); multicastSocket.setSendBufferSize(2048); multicastSocket.setSoTimeout(60000); DatagramPacket datagramPacket = new DatagramPacket(new byte[2048], 2048, InetAddress.getByName("224.2.2.4"), 54328); XContentBuilder builder = XContentFactory.jsonBuilder().startObject().startObject("request") .field("cluster_name", "test").endObject().endObject(); datagramPacket.setData(builder.bytes().toBytes()); multicastSocket.send(datagramPacket); Thread.sleep(100); } finally { Loggers.getLogger(MulticastZenPing.class).setLevel("INFO"); if (multicastSocket != null) multicastSocket.close(); zenPingA.close(); terminate(threadPool); } }
From source file:org.elasticsearch.transport.AbstractSimpleTransportTestCase.java
License:Apache License
public void testTimeoutPerConnection() throws IOException { assumeTrue("Works only on BSD network stacks and apparently windows", Constants.MAC_OS_X || Constants.FREE_BSD || Constants.WINDOWS); try (ServerSocket socket = new MockServerSocket()) { // note - this test uses backlog=1 which is implementation specific ie. it might not work on some TCP/IP stacks // on linux (at least newer ones) the listen(addr, backlog=1) should just ignore new connections if the queue is full which // means that once we received an ACK from the client we just drop the packet on the floor (which is what we want) and we run // into a connection timeout quickly. Yet other implementations can for instance can terminate the connection within the 3 way // handshake which I haven't tested yet. socket.bind(new InetSocketAddress(InetAddress.getLocalHost(), 0), 1); socket.setReuseAddress(true);/*from ww w . j a va 2 s .com*/ DiscoveryNode first = new DiscoveryNode("TEST", new TransportAddress(socket.getInetAddress(), socket.getLocalPort()), emptyMap(), emptySet(), version0); DiscoveryNode second = new DiscoveryNode("TEST", new TransportAddress(socket.getInetAddress(), socket.getLocalPort()), emptyMap(), emptySet(), version0); ConnectionProfile.Builder builder = new ConnectionProfile.Builder(); builder.addConnections(1, TransportRequestOptions.Type.BULK, TransportRequestOptions.Type.PING, TransportRequestOptions.Type.RECOVERY, TransportRequestOptions.Type.REG, TransportRequestOptions.Type.STATE); // connection with one connection and a large timeout -- should consume the one spot in the backlog queue try (TransportService service = buildService("TS_TPC", Version.CURRENT, null, Settings.EMPTY, true, false)) { IOUtils.close(service.openConnection(first, builder.build())); builder.setConnectTimeout(TimeValue.timeValueMillis(1)); final ConnectionProfile profile = builder.build(); // now with the 1ms timeout we got and test that is it's applied long startTime = System.nanoTime(); ConnectTransportException ex = expectThrows(ConnectTransportException.class, () -> service.openConnection(second, profile)); final long now = System.nanoTime(); final long timeTaken = TimeValue.nsecToMSec(now - startTime); assertTrue("test didn't timeout quick enough, time taken: [" + timeTaken + "]", timeTaken < TimeValue.timeValueSeconds(5).millis()); assertEquals(ex.getMessage(), "[][" + second.getAddress() + "] connect_timeout[1ms]"); } } }