@Override public void truncate() { try { rocksDB.dropColumnFamily(storeHandle); storeHandle.dispose(); storeHandle = rocksDB.createColumnFamily(new ColumnFamilyDescriptor(getName().getBytes(), storeOptions)); } catch (RocksDBException e) { throw new VoldemortException("Failed to truncate DB", e); } }
@Override public void dropTable(String table) throws RocksDBException { this.checkValid(); ColumnFamilyHandle cfh = cf(table); this.rocksdb.dropColumnFamily(cfh); cfh.close(); this.cfs.remove(table); }
public synchronized void drop(String tableName) throws RocksDBException { ColumnFamily cf = cfs.remove(tableName); if (cf != null) { db.dropColumnFamily(cf.handle); cf.handle.dispose(); } }
/** * Drops the column family identified by columnFamilyName. Internal * handles to this column family will be disposed. If the column family * is not known removal will fail. * * @param columnFamilyHandle {@link org.rocksdb.ColumnFamilyHandle} * instance * * @throws RocksDBException thrown if error happens in underlying * native library. */ public void dropColumnFamily(final ColumnFamilyHandle columnFamilyHandle) throws RocksDBException, IllegalArgumentException { // throws RocksDBException if something goes wrong dropColumnFamily(nativeHandle_, columnFamilyHandle.nativeHandle_); // After the drop the native handle is not valid anymore columnFamilyHandle.disOwnNativeHandle(); }
public synchronized void truncate(String tableName) throws InterruptedException, RocksDBException { ColumnFamily oldCf = cfs.get(tableName); if (oldCf == null) { throw new IllegalArgumentException("Table " + tableName + " does not exist."); } long newIndex = (oldCf.index + 1) % 2; String realTableName = String.format("%s__%d", tableName, newIndex); ColumnFamilyDescriptor descriptor = cfFactory.apply(realTableName); ColumnFamilyHandle handle = db.createColumnFamily(descriptor); cfs.put(tableName, new ColumnFamily(newIndex, handle)); while (oldCf.refCount.get() > 0) { Thread.sleep(10); } db.dropColumnFamily(oldCf.handle); oldCf.handle.dispose(); } }
@Override public void dropTable(String table) throws RocksDBException { this.checkValid(); ColumnFamilyHandle cfh = cf(table); this.rocksdb.dropColumnFamily(cfh); cfh.close(); this.cfs.remove(table); }
public void initialize(List<ColumnFamilyDescriptor> cfDescriptors, List<ColumnFamilyHandle> cfHandles) throws RocksDBException { for (int i = 0; i < cfDescriptors.size(); i++) { String fullTableName = new String(cfDescriptors.get(i).columnFamilyName(), Charsets.UTF_8); int nameIndex = fullTableName.lastIndexOf("__"); String tableName; long index; if (nameIndex == -1) { tableName = fullTableName; index = 0; } else { tableName = fullTableName.substring(0, nameIndex); index = Long.parseLong(fullTableName.substring(nameIndex + 2)); } ColumnFamily cf = new ColumnFamily(index, cfHandles.get(i)); ColumnFamily oldCf = cfs.put(tableName, cf); if (oldCf != null && !tableName.equals("default")) { db.dropColumnFamily(oldCf.getHandle()); oldCf.getHandle().dispose(); } } }
@Override @VisibleForTesting public void deleteAllValues() throws IOException { exclusively((deferred) -> { synchronized(this) { deleteAllIterators(deferred); try { db.dropColumnFamily(handle); } catch(RocksDBException ex) { deferred.addException(ex); } deferred.suppressingClose(handle); try { this.handle = db.createColumnFamily(family); } catch (Exception ex) { deferred.addException(ex); } } }); }