private List<Future> getBatches(DataLoadThreadTime dataLoadThreadTime, Scenario scenario) throws Exception { RowCalculator rowCalculator = new RowCalculator(getThreadPoolSize(), scenario.getRowCount()); List<Future> writeBatches = new ArrayList<>(); for (int i = 0; i < getThreadPoolSize(); i++) { List<Column> phxMetaCols = pUtil.getColumnsFromPhoenix( scenario.getSchemaName(), scenario.getTableNameWithoutSchemaName(), pUtil.getConnection()); int threadRowCount = rowCalculator.getNext(); logger.info("Kick off thread (#" + i + ")for upsert with (" + threadRowCount + ") rows."); Future<Info> write = upsertData( scenario, phxMetaCols, scenario.getTableName(), threadRowCount, dataLoadThreadTime); writeBatches.add(write); } if (writeBatches.isEmpty()) { throw new PherfException( "Holy shit snacks! Throwing up hands in disbelief and exiting. Could not write data for some unknown reason."); } return writeBatches; }
/** * Timed query execution * * @throws Exception */ private void timedQuery() throws Exception { boolean isSelectCountStatement = query.getStatement().toUpperCase().trim().contains("COUNT(*)") ? true : false; Connection conn = null; PreparedStatement statement = null; ResultSet rs = null; Long start = System.currentTimeMillis(); Date startDate = Calendar.getInstance().getTime(); String exception = null; long resultRowCount = 0; try { conn = pUtil.getConnection(query.getTenantId()); statement = conn.prepareStatement(query.getStatement()); boolean isQuery = statement.execute(); if (isQuery) { rs = statement.getResultSet(); while (rs.next()) { if (null != query.getExpectedAggregateRowCount()) { if (rs.getLong(1) != query.getExpectedAggregateRowCount()) throw new RuntimeException( "Aggregate count " + rs.getLong(1) + " does not match expected " + query.getExpectedAggregateRowCount()); } if (isSelectCountStatement) { resultRowCount = rs.getLong(1); } else { resultRowCount++; } } } else { conn.commit(); } } catch (Exception e) { e.printStackTrace(); exception = e.getMessage(); } finally { getThreadTime() .getRunTimesInMs() .add( new RunTime( exception, startDate, resultRowCount, (int) (System.currentTimeMillis() - start))); if (rs != null) rs.close(); if (statement != null) statement.close(); if (conn != null) conn.close(); } }