@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; } }
@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; } }
/** * 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); }
@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; } }
@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(); }
} 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);
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; } }