protected File getStateFile() { return new File(getStateDir(), "getHBase-" + getIdentifier()); }
private void clearState(final DistributedMapCacheClient client) { final File localState = getStateFile(); if (localState.exists()) { localState.delete(); } if (client != null) { try { client.remove(getKey(), new StringSerDe()); } catch (IOException e) { getLogger().warn("Processor state was not cleared from distributed cache due to {}", new Object[]{e}); } } }
List<String> authorizations = getAuthorizations(context, null); context.getStateManager().clear(Scope.CLUSTER); } catch (final IOException ioe) { getLogger().warn("Failed to clear Cluster State", ioe); this.lastResult = getState(context.getStateManager()); final long defaultMinTime = (initialTimeRange.equals(NONE.getValue()) ? 0L : System.currentTimeMillis()); final long minTime = (lastResult == null ? defaultMinTime : lastResult.getTimestamp()); getLogger().debug("latest cell timestamp for row {} is {}, which is earlier than the minimum time of {}", new Object[] {rowKeyString, latestCellTimestamp, minTime}); return; getLogger().debug("all cells for row {} have already been seen", new Object[] { rowKeyString }); return; getLogger().debug("Received {} from HBase with row key {}", new Object[]{flowFile, rowKeyString}); if (++rowsPulled % getBatchSize() == 0) { session.commit(); storeState(lastResult, context.getStateManager()); } catch (final IOException e) { getLogger().error("Failed to receive data from HBase due to {}", e); session.rollback(); } finally {
@OnScheduled public void parseColumns(final ProcessContext context) throws IOException { final StateMap stateMap = context.getStateManager().getState(Scope.CLUSTER); if (stateMap.getVersion() < 0) { // no state has been stored in the State Manager - check if we have state stored in the // DistributedMapCacheClient service and migrate it if so final DistributedMapCacheClient client = context.getProperty(DISTRIBUTED_CACHE_SERVICE).asControllerService(DistributedMapCacheClient.class); final ScanResult scanResult = getState(client); if (scanResult != null) { storeState(scanResult, context.getStateManager()); } clearState(client); } final String columnsValue = context.getProperty(COLUMNS).getValue(); final String[] columns = (columnsValue == null || columnsValue.isEmpty() ? new String[0] : columnsValue.split(",")); this.columns.clear(); for (final String column : columns) { if (column.contains(":")) { final String[] parts = column.split(":"); final byte[] cf = parts[0].getBytes(Charset.forName("UTF-8")); final byte[] cq = parts[1].getBytes(Charset.forName("UTF-8")); this.columns.add(new Column(cf, cq)); } else { final byte[] cf = column.getBytes(Charset.forName("UTF-8")); this.columns.add(new Column(cf, null)); } } }
protected String getKey() { return "getHBase-" + getIdentifier() + "-state"; }
@OnRemoved public void onRemoved(final ProcessContext context) { final DistributedMapCacheClient client = context.getProperty(DISTRIBUTED_CACHE_SERVICE).asControllerService(DistributedMapCacheClient.class); if (client != null) { clearState(client); } }
final Object obj = client.get(getKey(), stringSerDe, objectSerDe); if (obj == null || !(obj instanceof ScanResult)) { scanResult = null; } else { scanResult = (ScanResult) obj; getLogger().debug("Retrieved state from the distributed cache, previous timestamp was {}", new Object[] {scanResult.getTimestamp()}); final File file = getStateFile(); if (file.exists()) { try (final InputStream fis = new FileInputStream(file); if (scanResult == null || localScanResult.getTimestamp() > scanResult.getTimestamp()) { scanResult = localScanResult; getLogger().debug("Using last timestamp from local state because it was newer than the distributed cache, or no value existed in the cache"); getLogger().warn("Failed to recover persisted state from {} due to {}. Assuming that state from distributed cache is correct.", new Object[]{file, ioe});