@Override public Status delete(final String table, final String key) { try { if (!COLUMN_FAMILIES.containsKey(table)) { createColumnFamily(table); } final ColumnFamilyHandle cf = COLUMN_FAMILIES.get(table).getHandle(); rocksDb.delete(cf, key.getBytes(UTF_8)); return Status.OK; } catch(final RocksDBException e) { LOGGER.error(e.getMessage(), e); return Status.ERROR; } }
public DBSharder getDB(Long timestamp) { try { Long timeshard = DateTimeHelper.getTimesMorning(timestamp); //log.info("timestamp:" + timestamp + " shard:" + timeshard + " befor:" + DateTimeHelper.getBeforeDay(fieryConfig.getKeepdataday())); if (timeshard > DateTimeHelper.getBeforeDay(fieryConfig.getKeepdataday()) && timeshard <= DateTimeHelper.getCurrentTime()) { if (dbSharderList.containsKey(timeshard)) { return dbSharderList.get(timeshard); } dbSharderList.put(timeshard, new DBSharder(fieryConfig.getDbpath(), timeshard)); return dbSharderList.get(timeshard); } else { log.info("out of the date:" + timeshard); return null; } } catch (RocksDBException e) { e.printStackTrace(); log.error(e.getMessage()); return null; } }
private void flagVisitedVariant(byte[] key, VariantAvro variantAvro) { // The annotation.additionalAttributes field is initialized with an empty map to flag this variant as // already visited variantAvro.getAnnotation().setAdditionalAttributes(Collections.emptyMap()); try { dbIndex.put(key, jsonObjectWriter.writeValueAsBytes(variantAvro)); } catch (RocksDBException e) { e.printStackTrace(); } catch (JsonProcessingException e) { e.printStackTrace(); } }
public RocksDB openDB(final DBOptions dboptions, final String path, final List<ColumnFamilyDescriptor> columnNames, List<ColumnFamilyHandle> familyHandles) throws RocksDBException { boolean printLockMessage = true; while (true) { try { return RocksDB.open(dboptions, path, columnNames, familyHandles); } catch (RocksDBException e) { if (e.getStatus().getCode() != Status.Code.IOError || !e.getStatus().getState().contains("While lock")) { throw e; } if (printLockMessage) { LOGGER.info("Lock file to RocksDB is currently hold by another process. Will wait until lock is freed."); System.out.println("Lock file to RocksDB is currently hold by another process. Will wait until lock is freed."); printLockMessage = false; } } // Add some wait until the next attempt try { TimeUnit.MILLISECONDS.sleep(ROCKSDB_OPEN_SLEEP_MILLIS); } catch (InterruptedException e) { throw new RocksDBException(new Status(Status.Code.TryAgain, Status.SubCode.None, "While open db")); } } }
private Object[] getDBConnection(String dbLocation, boolean forceCreate) { boolean indexingNeeded = forceCreate || !Files.exists(Paths.get(dbLocation)); // a static method that loads the RocksDB C++ library. RocksDB.loadLibrary(); // the Options class contains a set of configurable DB options // that determines the behavior of a database. Options options = new Options().setCreateIfMissing(true); RocksDB db = null; try { // a factory method that returns a RocksDB instance if (indexingNeeded) { db = RocksDB.open(options, dbLocation); } else { db = RocksDB.openReadOnly(options, dbLocation); } // do something } catch (RocksDBException e) { // do some error handling e.printStackTrace(); System.exit(1); } return new Object[]{db, options, dbLocation, indexingNeeded}; }
@Override public Status read(final String table, final String key, final Set<String> fields, final Map<String, ByteIterator> result) { try { if (!COLUMN_FAMILIES.containsKey(table)) { createColumnFamily(table); } final ColumnFamilyHandle cf = COLUMN_FAMILIES.get(table).getHandle(); final byte[] values = rocksDb.get(cf, key.getBytes(UTF_8)); if(values == null) { return Status.NOT_FOUND; } deserializeValues(values, fields, result); return Status.OK; } catch(final RocksDBException e) { LOGGER.error(e.getMessage(), e); return Status.ERROR; } }
private Object[] getDBConnection(String dbLocation, boolean forceCreate) { boolean indexingNeeded = forceCreate || !Files.exists(Paths.get(dbLocation)); // a static method that loads the RocksDB C++ library. RocksDB.loadLibrary(); // the Options class contains a set of configurable DB options // that determines the behavior of a database. Options options = new Options().setCreateIfMissing(true); if (maxOpenFiles > 0) { options.setMaxOpenFiles(maxOpenFiles); } RocksDB db = null; try { // a factory method that returns a RocksDB instance if (indexingNeeded) { db = RocksDB.open(options, dbLocation); } else { db = RocksDB.openReadOnly(options, dbLocation); } // do something } catch (RocksDBException e) { // do some error handling e.printStackTrace(); System.exit(1); } return new Object[]{db, options, dbLocation, indexingNeeded}; }
/** * Flush the data in memtable of RocksDB into disk, and then create checkpoint * * @param checkpointId */ @Override public void checkpoint(long checkpointId) { long startTime = System.currentTimeMillis(); try { rocksDB.flush(new FlushOptions()); Checkpoint cp = Checkpoint.create(rocksDB); cp.createCheckpoint(getRocksDbCheckpointPath(checkpointId)); } catch (RocksDBException e) { LOG.error(String.format("Failed to create checkpoint for checkpointId-%d", checkpointId), e); throw new RuntimeException(e.getMessage()); } if (isEnableMetrics && JStormMetrics.enabled) rocksDbFlushAndCpLatency.update(System.currentTimeMillis() - startTime); }
exonSequence = fastaIndexManager.query(gtf.getSequenceName(), gtf.getStart(), gtf.getEnd()); } catch (RocksDBException e) { e.printStackTrace();
@Override public Status scan(final String table, final String startkey, final int recordcount, final Set<String> fields, final Vector<HashMap<String, ByteIterator>> result) { try { if (!COLUMN_FAMILIES.containsKey(table)) { createColumnFamily(table); } final ColumnFamilyHandle cf = COLUMN_FAMILIES.get(table).getHandle(); try(final RocksIterator iterator = rocksDb.newIterator(cf)) { int iterations = 0; for (iterator.seek(startkey.getBytes(UTF_8)); iterator.isValid() && iterations < recordcount; iterator.next()) { final HashMap<String, ByteIterator> values = new HashMap<>(); deserializeValues(iterator.value(), fields, values); result.add(values); iterations++; } } return Status.OK; } catch(final RocksDBException e) { LOGGER.error(e.getMessage(), e); return Status.ERROR; } }
db = RocksDB.open(options, dbPath.toString()); } catch (RocksDBException e) { logger.error(e.getMessage(), e); throw new RuntimeException("Failed to initialize database", e);
} catch (RocksDBException e) { if (dbs.containsKey(dataPath)) { if (e.getMessage().contains("No locks available")) { if (e.getMessage().contains("Column family not found")) { LOG.info("Failed to open RocksDB '{}' with database '{}', " + "try to init CF later", dataPath, this.database);
@Override protected synchronized void doClose() { final String NO_ENTRIES = "Cannot create sst file with no entries"; for (SstFileWriter sst : this.tables.values()) { E.checkState(sst.isOwningHandle(), "SstFileWriter closed"); try { sst.finish(); } catch (RocksDBException e) { if (e.getMessage().equals(NO_ENTRIES)) { continue; } throw new BackendException("Failed to close SstFileWriter", e); } sst.close(); } this.tables.clear(); }
static void removeEvent(final String eventKey) throws Exception{ try { final byte[] keyBytes = eventKey.getBytes(StandardCharsets.UTF_8); byte[] value = transientStateDB.get(keyBytes); if (value != null) { transientStateDB.remove(keyBytes); } } catch (RocksDBException ex) { //would want to log this occurring throw new Exception(ex.getMessage()); } }
static void addEvent(final String eventKey, final byte[] eventData)throws Exception{ try { final byte[] keyBytes = eventKey.getBytes(StandardCharsets.UTF_8); byte[] value = transientStateDB.get(keyBytes); if (value != null) { transientStateDB.put(keyBytes, eventData); } } catch (RocksDBException ex) { //would want to log this occuring throw new Exception(ex.getMessage()); } }
public ExampleMessage.GetResponse get(ExampleMessage.GetRequest request) { try { ExampleMessage.GetResponse.Builder responseBuilder = ExampleMessage.GetResponse.newBuilder(); byte[] keyBytes = request.getKey().getBytes(); byte[] valueBytes = db.get(keyBytes); if (valueBytes != null) { String value = new String(valueBytes); responseBuilder.setValue(value); } ExampleMessage.GetResponse response = responseBuilder.build(); return response; } catch (RocksDBException ex) { LOG.warn("read rockdb error, msg={}", ex.getMessage()); return null; } }
} catch (RocksDBException e) { if (dbs.containsKey(dataPath)) { if (e.getMessage().contains("No locks available")) { if (e.getMessage().contains("Column family not found")) { LOG.info("Failed to open RocksDB '{}' with database '{}', " + "try to init CF later", dataPath, this.database);
@Override protected synchronized void doClose() { final String NO_ENTRIES = "Cannot create sst file with no entries"; for (SstFileWriter sst : this.tables.values()) { E.checkState(sst.isOwningHandle(), "SstFileWriter closed"); try { sst.finish(); } catch (RocksDBException e) { if (e.getMessage().equals(NO_ENTRIES)) { continue; } throw new BackendException("Failed to close SstFileWriter", e); } sst.close(); } this.tables.clear(); }