private native static long open()

in java/src/main/java/org/rocksdb/RocksDB.java [4341:4691]


  private native static long open(final long optionsHandle,
      final String path) throws RocksDBException;

  /**
   * @param optionsHandle Native handle pointing to an Options object
   * @param path The directory path for the database files
   * @param columnFamilyNames An array of column family names
   * @param columnFamilyOptions An array of native handles pointing to
   *                            ColumnFamilyOptions objects
   *
   * @return An array of native handles, [0] is the handle of the RocksDB object
   *   [1..1+n] are handles of the ColumnFamilyReferences
   *
   * @throws RocksDBException thrown if the database could not be opened
   */
  private native static long[] open(final long optionsHandle,
      final String path, final byte[][] columnFamilyNames,
      final long[] columnFamilyOptions) throws RocksDBException;

  private native static long openROnly(final long optionsHandle, final String path,
      final boolean errorIfWalFileExists) throws RocksDBException;

  /**
   * @param optionsHandle Native handle pointing to an Options object
   * @param path The directory path for the database files
   * @param columnFamilyNames An array of column family names
   * @param columnFamilyOptions An array of native handles pointing to
   *                            ColumnFamilyOptions objects
   *
   * @return An array of native handles, [0] is the handle of the RocksDB object
   *   [1..1+n] are handles of the ColumnFamilyReferences
   *
   * @throws RocksDBException thrown if the database could not be opened
   */
  private native static long[] openROnly(final long optionsHandle, final String path,
      final byte[][] columnFamilyNames, final long[] columnFamilyOptions,
      final boolean errorIfWalFileExists) throws RocksDBException;

  private native static long openAsSecondary(final long optionsHandle, final String path,
      final String secondaryPath) throws RocksDBException;

  private native static long[] openAsSecondary(final long optionsHandle, final String path,
      final String secondaryPath, final byte[][] columnFamilyNames,
      final long[] columnFamilyOptions) throws RocksDBException;

  @Override protected native void disposeInternal(final long handle);

  private native static void closeDatabase(final long handle)
      throws RocksDBException;
  private native static byte[][] listColumnFamilies(final long optionsHandle,
      final String path) throws RocksDBException;
  private native long createColumnFamily(final long handle,
      final byte[] columnFamilyName, final int columnFamilyNamelen,
      final long columnFamilyOptions) throws RocksDBException;
  private native long[] createColumnFamilies(final long handle,
      final long columnFamilyOptionsHandle, final byte[][] columnFamilyNames)
      throws RocksDBException;
  private native long[] createColumnFamilies(final long handle,
      final long columnFamilyOptionsHandles[], final byte[][] columnFamilyNames)
      throws RocksDBException;
  private native void dropColumnFamily(
      final long handle, final long cfHandle) throws RocksDBException;
  private native void dropColumnFamilies(final long handle,
      final long[] cfHandles) throws RocksDBException;
  private native void put(final long handle, final byte[] key,
      final int keyOffset, final int keyLength, final byte[] value,
      final int valueOffset, int valueLength) throws RocksDBException;
  private native void put(final long handle, final byte[] key, final int keyOffset,
      final int keyLength, final byte[] value, final int valueOffset,
      final int valueLength, final long cfHandle) throws RocksDBException;
  private native void put(final long handle, final long writeOptHandle,
      final byte[] key,  final int keyOffset, final int keyLength,
      final byte[] value, final int valueOffset, final int valueLength)
      throws RocksDBException;
  private native void put(final long handle, final long writeOptHandle,
      final byte[] key, final int keyOffset, final int keyLength,
      final byte[] value, final int valueOffset, final int valueLength,
      final long cfHandle) throws RocksDBException;
  private native void delete(final long handle, final byte[] key,
      final int keyOffset, final int keyLength) throws RocksDBException;
  private native void delete(final long handle, final byte[] key,
      final int keyOffset, final int keyLength, final long cfHandle)
      throws RocksDBException;
  private native void delete(final long handle, final long writeOptHandle,
      final byte[] key, final int keyOffset, final int keyLength)
      throws RocksDBException;
  private native void delete(final long handle, final long writeOptHandle,
      final byte[] key, final int keyOffset, final int keyLength,
      final long cfHandle) throws RocksDBException;
  private native void singleDelete(
      final long handle, final byte[] key, final int keyLen)
      throws RocksDBException;
  private native void singleDelete(
      final long handle, final byte[] key, final int keyLen,
      final long cfHandle) throws RocksDBException;
  private native void singleDelete(
      final long handle, final long writeOptHandle, final byte[] key,
      final int keyLen) throws RocksDBException;
  private native void singleDelete(
      final long handle, final long writeOptHandle,
      final byte[] key, final int keyLen, final long cfHandle)
      throws RocksDBException;
  private native void deleteRange(final long handle, final byte[] beginKey,
      final int beginKeyOffset, final int beginKeyLength, final byte[] endKey,
      final int endKeyOffset, final int endKeyLength) throws RocksDBException;
  private native void deleteRange(final long handle, final byte[] beginKey,
      final int beginKeyOffset, final int beginKeyLength, final byte[] endKey,
      final int endKeyOffset, final int endKeyLength, final long cfHandle)
      throws RocksDBException;
  private native void deleteRange(final long handle, final long writeOptHandle,
      final byte[] beginKey, final int beginKeyOffset, final int beginKeyLength,
      final byte[] endKey, final int endKeyOffset, final int endKeyLength)
      throws RocksDBException;
  private native void deleteRange(
      final long handle, final long writeOptHandle, final byte[] beginKey,
      final int beginKeyOffset, final int beginKeyLength, final byte[] endKey,
      final int endKeyOffset, final int endKeyLength, final long cfHandle)
      throws RocksDBException;
  private native void merge(final long handle, final byte[] key,
      final int keyOffset, final int keyLength, final byte[] value,
      final int valueOffset, final int valueLength) throws RocksDBException;
  private native void merge(final long handle, final byte[] key,
      final int keyOffset, final int keyLength, final byte[] value,
      final int valueOffset, final int valueLength, final long cfHandle)
      throws RocksDBException;
  private native void merge(final long handle, final long writeOptHandle,
      final byte[] key, final int keyOffset, final int keyLength,
      final byte[] value, final int valueOffset, final int valueLength)
      throws RocksDBException;
  private native void merge(final long handle, final long writeOptHandle,
      final byte[] key, final int keyOffset, final int keyLength,
      final byte[] value, final int valueOffset, final int valueLength,
      final long cfHandle) throws RocksDBException;
  private native void write0(final long handle, final long writeOptHandle,
      final long wbHandle) throws RocksDBException;
  private native void write1(final long handle, final long writeOptHandle,
      final long wbwiHandle) throws RocksDBException;
  private native int get(final long handle, final byte[] key,
      final int keyOffset, final int keyLength, final byte[] value,
      final int valueOffset, final int valueLength) throws RocksDBException;
  private native int get(final long handle, final byte[] key,
      final int keyOffset, final int keyLength, byte[] value,
      final int valueOffset, final int valueLength, final long cfHandle)
      throws RocksDBException;
  private native int get(final long handle, final long readOptHandle,
      final byte[] key, final int keyOffset, final int keyLength,
      final byte[] value, final int valueOffset, final int valueLength)
      throws RocksDBException;
  private native int get(final long handle, final long readOptHandle,
      final byte[] key, final int keyOffset, final int keyLength,
      final byte[] value, final int valueOffset, final int valueLength,
      final long cfHandle) throws RocksDBException;
  private native byte[] get(final long handle, byte[] key, final int keyOffset,
      final int keyLength) throws RocksDBException;
  private native byte[] get(final long handle, final byte[] key,
      final int keyOffset, final int keyLength, final long cfHandle)
      throws RocksDBException;
  private native byte[] get(final long handle, final long readOptHandle,
      final byte[] key, final int keyOffset, final int keyLength)
      throws RocksDBException;
  private native byte[] get(final long handle,
      final long readOptHandle, final byte[] key, final int keyOffset,
      final int keyLength, final long cfHandle) throws RocksDBException;
  private native byte[][] multiGet(final long dbHandle, final byte[][] keys,
      final int[] keyOffsets, final int[] keyLengths);
  private native byte[][] multiGet(final long dbHandle, final byte[][] keys,
      final int[] keyOffsets, final int[] keyLengths,
      final long[] columnFamilyHandles);
  private native byte[][] multiGet(final long dbHandle, final long rOptHandle,
      final byte[][] keys, final int[] keyOffsets, final int[] keyLengths);
  private native byte[][] multiGet(final long dbHandle, final long rOptHandle,
      final byte[][] keys, final int[] keyOffsets, final int[] keyLengths,
      final long[] columnFamilyHandles);

  private native void multiGet(final long dbHandle, final long rOptHandle,
      final long[] columnFamilyHandles, final ByteBuffer[] keysArray, final int[] keyOffsets,
      final int[] keyLengths, final ByteBuffer[] valuesArray, final int[] valuesSizeArray,
      final Status[] statusArray);

  private native boolean keyMayExist(
      final long handle, final long cfHandle, final long readOptHandle,
      final byte[] key, final int keyOffset, final int keyLength);
  private native byte[][] keyMayExistFoundValue(
      final long handle, final long cfHandle, final long readOptHandle,
      final byte[] key, final int keyOffset, final int keyLength);
  private native void putDirect(long handle, long writeOptHandle, ByteBuffer key, int keyOffset,
      int keyLength, ByteBuffer value, int valueOffset, int valueLength, long cfHandle)
      throws RocksDBException;
  private native long iterator(final long handle);
  private native long iterator(final long handle, final long readOptHandle);
  private native long iteratorCF(final long handle, final long cfHandle);
  private native long iteratorCF(final long handle, final long cfHandle,
      final long readOptHandle);
  private native long[] iterators(final long handle,
      final long[] columnFamilyHandles, final long readOptHandle)
      throws RocksDBException;
  private native long getSnapshot(final long nativeHandle);
  private native void releaseSnapshot(
      final long nativeHandle, final long snapshotHandle);
  private native String getProperty(final long nativeHandle,
      final long cfHandle, final String property, final int propertyLength)
      throws RocksDBException;
  private native Map<String, String> getMapProperty(final long nativeHandle,
      final long cfHandle, final String property, final int propertyLength)
      throws RocksDBException;
  private native int getDirect(long handle, long readOptHandle, ByteBuffer key, int keyOffset,
      int keyLength, ByteBuffer value, int valueOffset, int valueLength, long cfHandle)
      throws RocksDBException;
  private native boolean keyMayExistDirect(final long handle, final long cfHhandle,
      final long readOptHandle, final ByteBuffer key, final int keyOffset, final int keyLength);
  private native int[] keyMayExistDirectFoundValue(final long handle, final long cfHhandle,
      final long readOptHandle, final ByteBuffer key, final int keyOffset, final int keyLength,
      final ByteBuffer value, final int valueOffset, final int valueLength);
  private native void deleteDirect(long handle, long optHandle, ByteBuffer key, int keyOffset,
      int keyLength, long cfHandle) throws RocksDBException;
  private native long getLongProperty(final long nativeHandle,
      final long cfHandle, final String property, final int propertyLength)
      throws RocksDBException;
  private native void resetStats(final long nativeHandle)
      throws RocksDBException;
  private native long getAggregatedLongProperty(final long nativeHandle,
      final String property, int propertyLength) throws RocksDBException;
  private native long[] getApproximateSizes(final long nativeHandle,
      final long columnFamilyHandle, final long[] rangeSliceHandles,
      final byte includeFlags);
  private native long[] getApproximateMemTableStats(final long nativeHandle,
      final long columnFamilyHandle, final long rangeStartSliceHandle,
      final long rangeLimitSliceHandle);
  private native void compactRange(final long handle,
      /* @Nullable */ final byte[] begin, final int beginLen,
      /* @Nullable */ final byte[] end, final int endLen,
      final long compactRangeOptHandle, final long cfHandle)
      throws RocksDBException;
  private native void setOptions(final long handle, final long cfHandle,
      final String[] keys, final String[] values) throws RocksDBException;
  private native String getOptions(final long handle, final long cfHandle);
  private native void setDBOptions(final long handle,
      final String[] keys, final String[] values) throws RocksDBException;
  private native String getDBOptions(final long handle);
  private native String[] compactFiles(final long handle,
      final long compactionOptionsHandle,
      final long columnFamilyHandle,
      final String[] inputFileNames,
      final int outputLevel,
      final int outputPathId,
      final long compactionJobInfoHandle) throws RocksDBException;
  private native void cancelAllBackgroundWork(final long handle,
      final boolean wait);
  private native void pauseBackgroundWork(final long handle)
      throws RocksDBException;
  private native void continueBackgroundWork(final long handle)
      throws RocksDBException;
  private native void enableAutoCompaction(final long handle,
      final long[] columnFamilyHandles) throws RocksDBException;
  private native int numberLevels(final long handle,
      final long columnFamilyHandle);
  private native int maxMemCompactionLevel(final long handle,
      final long columnFamilyHandle);
  private native int level0StopWriteTrigger(final long handle,
      final long columnFamilyHandle);
  private native String getName(final long handle);
  private native long getEnv(final long handle);
  private native void flush(final long handle, final long flushOptHandle,
      /* @Nullable */ final long[] cfHandles) throws RocksDBException;
  private native void flushWal(final long handle, final boolean sync)
      throws RocksDBException;
  private native void syncWal(final long handle) throws RocksDBException;
  private native long getLatestSequenceNumber(final long handle);
  private native void disableFileDeletions(long handle) throws RocksDBException;
  private native void enableFileDeletions(long handle, boolean force)
      throws RocksDBException;
  private native String[] getLiveFiles(final long handle,
      final boolean flushMemtable) throws RocksDBException;
  private native LogFile[] getSortedWalFiles(final long handle)
      throws RocksDBException;
  private native long getUpdatesSince(final long handle,
      final long sequenceNumber) throws RocksDBException;
  private native void deleteFile(final long handle, final String name)
      throws RocksDBException;
  private native LiveFileMetaData[] getLiveFilesMetaData(final long handle);
  private native ColumnFamilyMetaData getColumnFamilyMetaData(
      final long handle, final long columnFamilyHandle);
  private native void ingestExternalFile(final long handle,
      final long columnFamilyHandle,  final String[] filePathList,
      final int filePathListLen, final long ingestExternalFileOptionsHandle)
      throws RocksDBException;
  private native void verifyChecksum(final long handle) throws RocksDBException;
  private native long getDefaultColumnFamily(final long handle);
  private native Map<String, TableProperties> getPropertiesOfAllTables(
      final long handle, final long columnFamilyHandle) throws RocksDBException;
  private native Map<String, TableProperties> getPropertiesOfTablesInRange(
      final long handle, final long columnFamilyHandle,
      final long[] rangeSliceHandles);
  private native long[] suggestCompactRange(final long handle,
      final long columnFamilyHandle) throws RocksDBException;
  private native void promoteL0(final long handle,
      final long columnFamilyHandle, final int tragetLevel)
      throws RocksDBException;
  private native void startTrace(final long handle, final long maxTraceFileSize,
      final long traceWriterHandle) throws RocksDBException;
  private native void endTrace(final long handle) throws RocksDBException;
  private native void tryCatchUpWithPrimary(final long handle) throws RocksDBException;
  private native void deleteFilesInRanges(long handle, long cfHandle, final byte[][] ranges,
      boolean include_end) throws RocksDBException;

  private native static void destroyDB(final String path,
      final long optionsHandle) throws RocksDBException;

  private native static int version();

  protected DBOptionsInterface<?> options_;
  private static Version version;

  public static class Version {
    private final byte major;
    private final byte minor;
    private final byte patch;

    public Version(final byte major, final byte minor, final byte patch) {
      this.major = major;
      this.minor = minor;
      this.patch = patch;
    }

    public int getMajor() {
      return major;
    }

    public int getMinor() {
      return minor;
    }

    public int getPatch() {
      return patch;
    }

    @Override
    public String toString() {
      return getMajor() + "." + getMinor() + "." + getPatch();
    }

    private static Version fromEncodedVersion(int encodedVersion) {
      final byte patch = (byte) (encodedVersion & 0xff);
      encodedVersion >>= 8;
      final byte minor = (byte) (encodedVersion & 0xff);
      encodedVersion >>= 8;
      final byte major = (byte) (encodedVersion & 0xff);

      return new Version(major, minor, patch);
    }
  }