コード例 #1
0
  private void dataPersistenceOfPR(String partitionClause) throws Exception {
    Properties props = new Properties();
    Connection conn = TestUtil.getConnection(props);
    char fileSeparator = System.getProperty("file.separator").charAt(0);
    GemFireCacheImpl cache = Misc.getGemFireCache();
    Statement stmt = conn.createStatement();
    if (cache.findDiskStore("TestPersistenceDiskStore") == null) {

      String path = "." + fileSeparator + "test_dir";
      File file = new File(path);
      if (!file.mkdirs() && !file.isDirectory()) {
        throw new DiskAccessException(
            "Could not create directory for " + " default disk store : " + file.getAbsolutePath(),
            (Region) null);
      }
      try {
        Connection conn1;
        conn1 = TestUtil.getConnection();
        Statement stmt1 = conn1.createStatement();
        stmt1.execute("Create DiskStore " + "TestPersistenceDiskStore" + "'" + path + "'");
        conn1.close();
      } catch (SQLException e) {
        throw GemFireXDRuntimeException.newRuntimeException(null, e);
      }
    }

    stmt.execute("create schema trade");
    stmt.execute(
        "create table trade.customers (cid int not null, cust_name varchar(100), tid int, "
            + "primary key (cid))   "
            + partitionClause
            + "  PERSISTENT "
            + "'"
            + "TestPersistenceDiskStore"
            + "'");
    PreparedStatement ps = conn.prepareStatement("insert into trade.customers values (?,?,?)");
    for (int i = 1; i < 31; ++i) {
      ps.setInt(1, i);
      ps.setString(2, "name" + i);
      ps.setInt(3, i);
      ps.executeUpdate();
    }

    conn.close();
    shutDown();

    conn = TestUtil.getConnection();
    stmt = conn.createStatement();

    ResultSet rs = stmt.executeQuery("select * from trade.customers");
    int expected = 465;
    int actual = 0;
    while (rs.next()) {
      int val = rs.getInt(1);
      actual += val;
    }
    assertEquals(expected, actual);
  }
コード例 #2
0
 @Override
 public Object[] getPrimaryKey() {
   Object[] retVal = null;
   Object key = extractKey();
   try {
     if (key instanceof RegionKey) {
       final RegionKey rk = (RegionKey) key;
       final int size = rk.nCols();
       retVal = new Object[size];
       rk.getKeyColumns(retVal);
     } else {
       retVal = new Object[] {key};
     }
   } catch (Exception e) {
     throw GemFireXDRuntimeException.newRuntimeException(
         "exception encountered while retrieving primary key for event =" + this.toString(), e);
   }
   return retVal;
 }
コード例 #3
0
  public void testBug45816() throws Exception {
    // Test DROP DISKSTORE when a table using default diskstore exists in database

    try {
      Connection conn;
      conn = TestUtil.getConnection();
      Statement stmt = conn.createStatement();
      // Create a table that uses the default diskstore
      stmt.execute("create table mytab1 (col1 int not null)");

      // Now, create a basic diskstore with no options
      stmt.execute("Create diskstore MYDISKSTORE1");

      stmt.execute("Drop diskstore MYDISKSTORE1");

      // Get rid of the table too
      stmt.execute("drop table mytab1");
      conn.close();
    } catch (SQLException e) {
      // Any news is bad news.
      throw GemFireXDRuntimeException.newRuntimeException(null, e);
    }
  }
コード例 #4
0
  public synchronized void start(
      final InetAddress thriftAddress,
      final int thriftPort,
      int maxThreads,
      final boolean isServer,
      final boolean useBinaryProtocol,
      final boolean useSSL,
      final SocketParameters socketParams,
      final ConnectionListener listener)
      throws TTransportException {

    this.thriftAddress = thriftAddress;
    this.thriftPort = thriftPort;

    if (isServing()) {
      throw GemFireXDRuntimeException.newRuntimeException(
          "A thrift server is already running", null);
    }

    final TServerTransport serverTransport;
    final InetSocketAddress bindAddress;
    final String hostAddress;
    if (this.thriftAddress != null) {
      bindAddress = new InetSocketAddress(this.thriftAddress, this.thriftPort);
    } else {
      try {
        bindAddress = new InetSocketAddress(SocketCreator.getLocalHost(), this.thriftPort);
      } catch (UnknownHostException uhe) {
        throw new TTransportException(
            "Could not determine localhost for default bind address.", uhe);
      }
    }

    serverTransport =
        useSSL
            ? GfxdTSSLServerSocketFactory.getServerSocket(bindAddress, socketParams)
            : new GfxdTServerSocket(bindAddress, true, true, socketParams);
    hostAddress = bindAddress.getAddress().toString();

    final TProcessor processor;
    if (isServer) {
      GFXDServiceImpl service = new GFXDServiceImpl(hostAddress, this.thriftPort);
      processor = new GFXDServiceImpl.Processor(service);
      this.service = service;
    } else {
      // only locator service on non-server VMs
      LocatorServiceImpl service = new LocatorServiceImpl(hostAddress, this.thriftPort);
      processor = new LocatorServiceImpl.Processor(service);
      this.service = service;
    }

    final int parallelism = Math.max(Runtime.getRuntime().availableProcessors(), 4);
    if (useSSL || !ThriftUtils.isThriftSelectorServer()) {
      final GfxdThriftServerThreadPool.Args serverArgs =
          new GfxdThriftServerThreadPool.Args(serverTransport);
      TProtocolFactory protocolFactory =
          useBinaryProtocol ? new TBinaryProtocol.Factory() : new TCompactProtocol.Factory();

      serverArgs.processor(processor).protocolFactory(protocolFactory);
      this.thriftExecutor =
          new ThreadPoolExecutor(
              parallelism * 2, maxThreads, 30L, TimeUnit.SECONDS, new SynchronousQueue<Runnable>());
      serverArgs.setExecutorService(this.thriftExecutor).setConnectionListener(listener);

      this.thriftServer = new GfxdThriftServerThreadPool(serverArgs);
    } else {
      // selector and per-thread hybrid server
      final GfxdThriftServerSelector.Args serverArgs =
          new GfxdThriftServerSelector.Args(serverTransport);
      TProtocolFactory protocolFactory =
          useBinaryProtocol ? new TBinaryProtocol.Factory() : new TCompactProtocol.Factory();

      final int numSelectors = parallelism * 2;
      final int numThreads = parallelism * 2;
      serverArgs
          .processor(processor)
          .protocolFactory(protocolFactory)
          .setNumSelectors(numSelectors)
          .setConnectionListener(listener);
      this.thriftExecutor =
          new ThreadPoolExecutor(
              1, maxThreads, 30L, TimeUnit.SECONDS, new SynchronousQueue<Runnable>());
      this.thriftThreadPerConnExecutor =
          new ThreadPoolExecutor(
              1, numThreads, 30L, TimeUnit.SECONDS, new SynchronousQueue<Runnable>());
      serverArgs.setExecutorService(this.thriftExecutor);
      serverArgs.setThreadPerConnExecutor(this.thriftThreadPerConnExecutor);
      this.thriftServer = new GfxdThriftServerSelector(serverArgs);
    }
    thriftMainThread =
        new Thread(
            new Runnable() {
              @Override
              public void run() {
                thriftServer.serve();
              }
            },
            "ThriftServerThread");

    thriftMainThread.setDaemon(true);
    thriftMainThread.start();
  }