Search in sources :

Example 6 with Options

use of org.iq80.leveldb.Options in project hadoop by apache.

the class RollingLevelDBTimelineStore method serviceInit.

@Override
@SuppressWarnings("unchecked")
protected void serviceInit(Configuration conf) throws Exception {
    Preconditions.checkArgument(conf.getLong(TIMELINE_SERVICE_TTL_MS, DEFAULT_TIMELINE_SERVICE_TTL_MS) > 0, "%s property value should be greater than zero", TIMELINE_SERVICE_TTL_MS);
    Preconditions.checkArgument(conf.getLong(TIMELINE_SERVICE_LEVELDB_TTL_INTERVAL_MS, DEFAULT_TIMELINE_SERVICE_LEVELDB_TTL_INTERVAL_MS) > 0, "%s property value should be greater than zero", TIMELINE_SERVICE_LEVELDB_TTL_INTERVAL_MS);
    Preconditions.checkArgument(conf.getLong(TIMELINE_SERVICE_LEVELDB_READ_CACHE_SIZE, DEFAULT_TIMELINE_SERVICE_LEVELDB_READ_CACHE_SIZE) >= 0, "%s property value should be greater than or equal to zero", TIMELINE_SERVICE_LEVELDB_READ_CACHE_SIZE);
    Preconditions.checkArgument(conf.getLong(TIMELINE_SERVICE_LEVELDB_START_TIME_READ_CACHE_SIZE, DEFAULT_TIMELINE_SERVICE_LEVELDB_START_TIME_READ_CACHE_SIZE) > 0, " %s property value should be greater than zero", TIMELINE_SERVICE_LEVELDB_START_TIME_READ_CACHE_SIZE);
    Preconditions.checkArgument(conf.getLong(TIMELINE_SERVICE_LEVELDB_START_TIME_WRITE_CACHE_SIZE, DEFAULT_TIMELINE_SERVICE_LEVELDB_START_TIME_WRITE_CACHE_SIZE) > 0, "%s property value should be greater than zero", TIMELINE_SERVICE_LEVELDB_START_TIME_WRITE_CACHE_SIZE);
    Preconditions.checkArgument(conf.getLong(TIMELINE_SERVICE_LEVELDB_MAX_OPEN_FILES, DEFAULT_TIMELINE_SERVICE_LEVELDB_MAX_OPEN_FILES) > 0, "%s property value should be greater than zero", TIMELINE_SERVICE_LEVELDB_MAX_OPEN_FILES);
    Preconditions.checkArgument(conf.getLong(TIMELINE_SERVICE_LEVELDB_WRITE_BUFFER_SIZE, DEFAULT_TIMELINE_SERVICE_LEVELDB_WRITE_BUFFER_SIZE) > 0, "%s property value should be greater than zero", TIMELINE_SERVICE_LEVELDB_WRITE_BUFFER_SIZE);
    Options options = new Options();
    options.createIfMissing(true);
    options.cacheSize(conf.getLong(TIMELINE_SERVICE_LEVELDB_READ_CACHE_SIZE, DEFAULT_TIMELINE_SERVICE_LEVELDB_READ_CACHE_SIZE));
    JniDBFactory factory = new JniDBFactory();
    Path dbPath = new Path(conf.get(TIMELINE_SERVICE_LEVELDB_PATH), FILENAME);
    Path domainDBPath = new Path(dbPath, DOMAIN);
    Path starttimeDBPath = new Path(dbPath, STARTTIME);
    Path ownerDBPath = new Path(dbPath, OWNER);
    FileSystem localFS = null;
    try {
        localFS = FileSystem.getLocal(conf);
        if (!localFS.exists(dbPath)) {
            if (!localFS.mkdirs(dbPath)) {
                throw new IOException("Couldn't create directory for leveldb " + "timeline store " + dbPath);
            }
            localFS.setPermission(dbPath, LEVELDB_DIR_UMASK);
        }
        if (!localFS.exists(domainDBPath)) {
            if (!localFS.mkdirs(domainDBPath)) {
                throw new IOException("Couldn't create directory for leveldb " + "timeline store " + domainDBPath);
            }
            localFS.setPermission(domainDBPath, LEVELDB_DIR_UMASK);
        }
        if (!localFS.exists(starttimeDBPath)) {
            if (!localFS.mkdirs(starttimeDBPath)) {
                throw new IOException("Couldn't create directory for leveldb " + "timeline store " + starttimeDBPath);
            }
            localFS.setPermission(starttimeDBPath, LEVELDB_DIR_UMASK);
        }
        if (!localFS.exists(ownerDBPath)) {
            if (!localFS.mkdirs(ownerDBPath)) {
                throw new IOException("Couldn't create directory for leveldb " + "timeline store " + ownerDBPath);
            }
            localFS.setPermission(ownerDBPath, LEVELDB_DIR_UMASK);
        }
    } finally {
        IOUtils.cleanup(LOG, localFS);
    }
    options.maxOpenFiles(conf.getInt(TIMELINE_SERVICE_LEVELDB_MAX_OPEN_FILES, DEFAULT_TIMELINE_SERVICE_LEVELDB_MAX_OPEN_FILES));
    options.writeBufferSize(conf.getInt(TIMELINE_SERVICE_LEVELDB_WRITE_BUFFER_SIZE, DEFAULT_TIMELINE_SERVICE_LEVELDB_WRITE_BUFFER_SIZE));
    LOG.info("Using leveldb path " + dbPath);
    domaindb = factory.open(new File(domainDBPath.toString()), options);
    entitydb = new RollingLevelDB(ENTITY);
    entitydb.init(conf);
    indexdb = new RollingLevelDB(INDEX);
    indexdb.init(conf);
    starttimedb = factory.open(new File(starttimeDBPath.toString()), options);
    ownerdb = factory.open(new File(ownerDBPath.toString()), options);
    checkVersion();
    startTimeWriteCache = Collections.synchronizedMap(new LRUMap(getStartTimeWriteCacheSize(conf)));
    startTimeReadCache = Collections.synchronizedMap(new LRUMap(getStartTimeReadCacheSize(conf)));
    writeBatchSize = conf.getInt(TIMELINE_SERVICE_LEVELDB_WRITE_BATCH_SIZE, DEFAULT_TIMELINE_SERVICE_LEVELDB_WRITE_BATCH_SIZE);
    super.serviceInit(conf);
}
Also used : Path(org.apache.hadoop.fs.Path) Options(org.iq80.leveldb.Options) ReadOptions(org.iq80.leveldb.ReadOptions) LRUMap(org.apache.commons.collections.map.LRUMap) FileSystem(org.apache.hadoop.fs.FileSystem) JniDBFactory(org.fusesource.leveldbjni.JniDBFactory) IOException(java.io.IOException) File(java.io.File)

Example 7 with Options

use of org.iq80.leveldb.Options in project camel by apache.

the class LevelDBFile method start.

public void start() {
    if (getFile() == null) {
        throw new IllegalArgumentException("A file must be configured");
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("Starting LevelDB using file: {}", getFile());
    }
    Options options = new Options().writeBufferSize(writeBufferSize).maxOpenFiles(maxOpenFiles).blockRestartInterval(blockRestartInterval).blockSize(blockSize).verifyChecksums(verifyChecksums).paranoidChecks(paranoidChecks).cacheSize(cacheSize);
    if ("snappy".equals(compressionType)) {
        options.compressionType(CompressionType.SNAPPY);
    } else {
        options.compressionType(CompressionType.NONE);
    }
    options.createIfMissing(true);
    try {
        getFile().getParentFile().mkdirs();
        db = factory.open(getFile(), options);
    } catch (IOException ioe) {
        throw new RuntimeException("Error opening LevelDB with file " + getFile(), ioe);
    }
}
Also used : Options(org.iq80.leveldb.Options) WriteOptions(org.iq80.leveldb.WriteOptions) IOException(java.io.IOException)

Example 8 with Options

use of org.iq80.leveldb.Options in project camel by apache.

the class LevelDBFile method getWriteOptions.

public WriteOptions getWriteOptions() {
    WriteOptions options = new WriteOptions();
    options.sync(sync);
    return options;
}
Also used : WriteOptions(org.iq80.leveldb.WriteOptions)

Example 9 with Options

use of org.iq80.leveldb.Options in project java-tron by tronprotocol.

the class LevelDbDataSourceImpl method createDbOptions.

private Options createDbOptions() {
    Options dbOptions = new Options();
    dbOptions.createIfMissing(true);
    dbOptions.compressionType(CompressionType.NONE);
    dbOptions.blockSize(10 * 1024 * 1024);
    dbOptions.writeBufferSize(10 * 1024 * 1024);
    dbOptions.cacheSize(0);
    dbOptions.paranoidChecks(true);
    dbOptions.verifyChecksums(true);
    dbOptions.maxOpenFiles(32);
    return dbOptions;
}
Also used : Options(org.iq80.leveldb.Options)

Example 10 with Options

use of org.iq80.leveldb.Options in project java-tron by tronprotocol.

the class LevelDbDataSourceImpl method destroyDb.

/**
 * destroy database.
 */
public void destroyDb(File fileLocation) {
    resetDbLock.writeLock().lock();
    try {
        logger.debug("Destroying existing database: " + fileLocation);
        Options options = new Options();
        try {
            factory.destroy(fileLocation, options);
        } catch (IOException e) {
            logger.error(e.getMessage(), e);
        }
    } finally {
        resetDbLock.writeLock().unlock();
    }
}
Also used : Options(org.iq80.leveldb.Options) IOException(java.io.IOException)

Aggregations

Options (org.iq80.leveldb.Options)26 File (java.io.File)21 IOException (java.io.IOException)14 DB (org.iq80.leveldb.DB)10 Path (org.apache.hadoop.fs.Path)8 NativeDB (org.fusesource.leveldbjni.internal.NativeDB)6 DBException (org.iq80.leveldb.DBException)6 WriteOptions (org.iq80.leveldb.WriteOptions)5 DB (com.codecademy.eventhub.base.DB)3 Provides (com.google.inject.Provides)3 FileSystem (org.apache.hadoop.fs.FileSystem)3 JniDBFactory (org.fusesource.leveldbjni.JniDBFactory)3 RandomAccessFile (java.io.RandomAccessFile)2 CompoundTag (cn.nukkit.nbt.tag.CompoundTag)1 DistributedLogNamespace (com.twitter.distributedlog.namespace.DistributedLogNamespace)1 FileInputStream (java.io.FileInputStream)1 ObjectInputStream (java.io.ObjectInputStream)1 URI (java.net.URI)1 Map (java.util.Map)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1