@Override public void mutateMany(Map<String, Map<ByteBuffer, KCVMutation>> mutations, StoreTransaction txh) throws StorageException { final long delTS = System.currentTimeMillis(); final long putTS = delTS + 1; Map<ByteBuffer, Pair<Put, Delete>> commandsPerKey = convertToCommands(mutations, putTS, delTS); List<Row> batch = new ArrayList<Row>(commandsPerKey.size()); // actual batch operation // convert sorted commands into representation required for 'batch' operation for (Pair<Put, Delete> commands : commandsPerKey.values()) { if (commands.getFirst() != null) batch.add(commands.getFirst()); if (commands.getSecond() != null) batch.add(commands.getSecond()); } try { HTableInterface table = null; try { table = connectionPool.getTable(tableName); table.batch(batch); table.flushCommits(); } finally { IOUtils.closeQuietly(table); } } catch (IOException e) { throw new TemporaryStorageException(e); } catch (InterruptedException e) { throw new TemporaryStorageException(e); } waitUntil(putTS); }
/** * Deletes the specified table with all its columns. ATTENTION: Invoking this method will delete * the table if it exists and therefore causes data loss. */ @Override public void clearStorage() throws StorageException { HBaseAdmin adm = getAdminInterface(); try { // first of all, check if table exists, if not - we are done if (!adm.tableExists(tableName)) { logger.debug("clearStorage() called before table {} was created, skipping.", tableName); return; } } catch (IOException e) { throw new TemporaryStorageException(e); } HTable table = null; try { table = new HTable(hconf, tableName); Scan scan = new Scan(); scan.setBatch(100); scan.setCacheBlocks(false); scan.setCaching(2000); ResultScanner scanner = null; try { scanner = table.getScanner(scan); for (Result res : scanner) { table.delete(new Delete(res.getRow())); } } finally { IOUtils.closeQuietly(scanner); } } catch (IOException e) { throw new TemporaryStorageException(e); } finally { IOUtils.closeQuietly(table); } }
private void watchLogForStartup(long duration, TimeUnit unit) throws InterruptedException { long startMS = System.currentTimeMillis(); long durationMS = TimeUnit.MILLISECONDS.convert(duration, unit); long elapsedMS; File logFile = new File( homedir + File.separator + "target" + File.separator + "es-logs" + File.separator + "elasticsearch.log"); log.info("Watching ES logfile {} for startup token", logFile); while ((elapsedMS = System.currentTimeMillis() - startMS) < durationMS) { // Grep for a logline ending in "started" and assume that means ES is ready BufferedReader br = null; try { br = new BufferedReader(new FileReader(logFile)); String line; while (null != (line = br.readLine())) { if (line.endsWith(" started")) { log.debug("Read line \"{}\" from ES logfile {}", line, logFile); log.info("Elasticsearch started in {} {}", elapsedMS, TimeUnit.MILLISECONDS); return; } } } catch (FileNotFoundException e) { log.debug("Elasticsearch logfile {} not found", logFile, e); } catch (IOException e) { log.debug("Elasticsearch logfile {} could not be read", logFile, e); } finally { IOUtils.closeQuietly(br); } Thread.sleep(500L); } log.info("Elasticsearch startup timeout ({} {})", elapsedMS, TimeUnit.MILLISECONDS); }
@BeforeClass public static void killElasticsearch() { IOUtils.deleteDirectory(new File("es"), true); ElasticsearchRunner esr = new ElasticsearchRunner(); esr.stop(); }