org.iq80.leveldb.CompressionType Java Examples

The following examples show how to use org.iq80.leveldb.CompressionType. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LevelDB.java    From aion with MIT License 6 votes vote down vote up
private Options setupLevelDbOptions() {
    Options options = new Options();

    options.createIfMissing(true);
    options.compressionType(
            enableDbCompression ? CompressionType.SNAPPY : CompressionType.NONE);
    options.blockSize(this.blockSize);
    options.writeBufferSize(this.writeBufferSize); // (levelDb default: 8mb)
    options.cacheSize(enableDbCache ? this.cacheSize : 0);
    options.paranoidChecks(true);
    options.verifyChecksums(true);
    options.maxOpenFiles(this.maxOpenFiles);

    LOG.info("LevelDb Options: EnableCompression:{} MaxOpenFiles:{} BlockSize:{} WriteBuffer:{} EnableCache:{} CacheSize:{}"
        , enableDbCompression, maxOpenFiles, blockSize, writeBufferSize, enableDbCache, cacheSize);

    return options;
}
 
Example #2
Source File: LevelDB.java    From SPADE with GNU General Public License v3.0 6 votes vote down vote up
public boolean initialize(String arguments)
    {
        try
        {
            WriteOptions writeOptions = new WriteOptions();
            writeOptions.sync(false);

            directoryPath = arguments;
            Options options = new Options();
            options.createIfMissing(true);
            options.compressionType(CompressionType.NONE);
//            scaffoldDatabase = factory.open(new File(directoryPath), options);
            childDatabase = factory.open(new File(directoryPath + "child"), options);
            parentDatabase = factory.open(new File(directoryPath + "parent"), options);
            logger.log(Level.INFO, "Scaffold initialized");
//            globalTxCheckin(true);
        }
        catch(IOException ex)
        {
            logger.log(Level.SEVERE, null, ex);
            return false;
        }

        return true;
    }
 
Example #3
Source File: LevelDbDataSourceImpl.java    From gsc-core with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Deprecated
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;
}
 
Example #4
Source File: StorageTest.java    From gsc-core with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
public void getOptions() {
  Options options = storage.getOptionsByDbName("account");
  Assert.assertTrue(options.createIfMissing());
  Assert.assertTrue(options.paranoidChecks());
  Assert.assertTrue(options.verifyChecksums());
  Assert.assertEquals(CompressionType.SNAPPY, options.compressionType());
  Assert.assertEquals(4096, options.blockSize());
  Assert.assertEquals(10485760, options.writeBufferSize());
  Assert.assertEquals(10485760L, options.cacheSize());
  Assert.assertEquals(100, options.maxOpenFiles());

  options = storage.getOptionsByDbName("test_name");
  Assert.assertFalse(options.createIfMissing());
  Assert.assertFalse(options.paranoidChecks());
  Assert.assertFalse(options.verifyChecksums());
  Assert.assertEquals(CompressionType.SNAPPY, options.compressionType());
  Assert.assertEquals(2, options.blockSize());
  Assert.assertEquals(3, options.writeBufferSize());
  Assert.assertEquals(4L, options.cacheSize());
  Assert.assertEquals(5, options.maxOpenFiles());

  options = storage.getOptionsByDbName("some_name_not_exists");
  Assert.assertTrue(options.createIfMissing());
  Assert.assertTrue(options.paranoidChecks());
  Assert.assertTrue(options.verifyChecksums());
  Assert.assertEquals(CompressionType.SNAPPY, options.compressionType());
  Assert.assertEquals(4 * 1024, options.blockSize());
  Assert.assertEquals(10 * 1024 * 1024, options.writeBufferSize());
  Assert.assertEquals(10 * 1024 * 1024L, options.cacheSize());
  Assert.assertEquals(100, options.maxOpenFiles());
}
 
Example #5
Source File: LevelDBStorage.java    From greycat with Apache License 2.0 5 votes vote down vote up
@Override
public void connect(Graph graph, Callback<Boolean> callback) {
    if (isConnected) {
        if (callback != null) {
            callback.on(null);
        }
        return;
    }
    this.graph = graph;
    //by default activate snappy compression of bytes
    Options options = new Options()
            .createIfMissing(true)
            .compressionType(CompressionType.SNAPPY);
    File location = new File(storagePath);
    if (!location.exists()) {
        location.mkdirs();
    }
    File targetDB = new File(location, "data");
    targetDB.mkdirs();
    try {
        if (useNative) {
            db = JniDBFactory.factory.open(targetDB, options);
        } else {
            db = Iq80DBFactory.factory.open(targetDB, options);
        }
        isConnected = true;
        if (callback != null) {
            callback.on(true);
        }
    } catch (Exception e) {
        e.printStackTrace();
        if (callback != null) {
            callback.on(null);
        }
    }
}
 
Example #6
Source File: MCAFile2LevelDB.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
public MCAFile2LevelDB(File folderFrom, File folderTo) {
        super(folderFrom, folderTo);
        this.startTime = System.currentTimeMillis();
        try {
            if (!folderTo.exists()) {
                folderTo.mkdirs();
            }
            String worldName = folderTo.getName();
            try (PrintStream out = new PrintStream(new FileOutputStream(new File(folderTo, "levelname.txt")))) {
                out.print(worldName);
            }

            this.pool = new ForkJoinPool();
            this.remapper = new ClipboardRemapper(ClipboardRemapper.RemapPlatform.PC, ClipboardRemapper.RemapPlatform.PE);
            BundledBlockData.getInstance().loadFromResource();

            int bufferSize = (int) Math.min(Integer.MAX_VALUE, Math.max((long) (MemUtil.getFreeBytes() * 0.8), 134217728));
            this.db = Iq80DBFactory.factory.open(new File(folderTo, "db"),
                    new Options()
                            .createIfMissing(true)
                            .verifyChecksums(false)
                            .compressionType(CompressionType.ZLIB)
                            .blockSize(262144) // 256K
                            .cacheSize(8388608) // 8MB
                            .writeBufferSize(134217728) // >=512MB
            );
//            try {
//                this.db.suspendCompactions();
//            } catch (InterruptedException e) {
//                e.printStackTrace();
//            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
 
Example #7
Source File: DatabaseImpl.java    From ethereumj with MIT License 5 votes vote down vote up
public DatabaseImpl(String name) {
    	// Initialize Database
        this.name = name;
		Options options = new Options();
		options.createIfMissing(true);
		options.compressionType(CompressionType.NONE);
		try {
			logger.debug("Opening database");
            File dbLocation = new File(System.getProperty("user.dir") + "/" +
                                       SystemProperties.CONFIG.databaseDir() + "/");
            File fileLocation = new File(dbLocation, name);

			if(SystemProperties.CONFIG.databaseReset()) {
				destroyDB(fileLocation);
			}

			logger.debug("Initializing new or existing database: '{}'", name);
			db = factory.open(fileLocation, options);
//			logger.debug("Showing database stats");
//			String stats = DATABASE.getProperty("leveldb.stats");
//			logger.debug(stats);

            if (logger.isTraceEnabled()){

                logger.trace("Dump for: {}", fileLocation.toString());
                DBIterator iter =  db.iterator();

                while(iter.hasNext()){
                    byte[] key   = iter.peekNext().getKey();
                    byte[] value = iter.peekNext().getValue();

                    logger.trace("key={}, value={}", Hex.toHexString(key), Hex.toHexString(value));
                    iter.next();
                }
            }
		} catch (IOException ioe) {
			logger.error(ioe.getMessage(), ioe);
			throw new RuntimeException("Can't initialize database");
		}		
	}
 
Example #8
Source File: LevelDBEntityStoreMixin.java    From attic-polygene-java with Apache License 2.0 4 votes vote down vote up
@Override
public void activateService()
    throws Exception
{
    charset = Charset.forName( "UTF-8" );
    configuration.refresh();
    LevelDBEntityStoreConfiguration config = configuration.get();

    // Choose flavour
    String flavour = config.flavour().get();
    DBFactory factory;
    if( "jni".equalsIgnoreCase( flavour ) )
    {
        factory = newJniDBFactory();
    }
    else if( "java".equalsIgnoreCase( flavour ) )
    {
        factory = newJavaDBFactory();
    }
    else
    {
        factory = newDBFactory();
    }

    // Apply configuration
    Options options = new Options();
    options.createIfMissing( true );
    if( config.blockRestartInterval().get() != null )
    {
        options.blockRestartInterval( config.blockRestartInterval().get() );
    }
    if( config.blockSize().get() != null )
    {
        options.blockSize( config.blockSize().get() );
    }
    if( config.cacheSize().get() != null )
    {
        options.cacheSize( config.cacheSize().get() );
    }
    if( config.compression().get() != null )
    {
        options.compressionType( config.compression().get()
                                 ? CompressionType.SNAPPY
                                 : CompressionType.NONE );
    }
    if( config.maxOpenFiles().get() != null )
    {
        options.maxOpenFiles( config.maxOpenFiles().get() );
    }
    if( config.paranoidChecks().get() != null )
    {
        options.paranoidChecks( config.paranoidChecks().get() );
    }
    if( config.verifyChecksums().get() != null )
    {
        options.verifyChecksums( config.verifyChecksums().get() );
    }
    if( config.writeBufferSize().get() != null )
    {
        options.writeBufferSize( config.writeBufferSize().get() );
    }
    if( config.errorIfExists().get() != null )
    {
        options.errorIfExists( config.errorIfExists().get() );
    }

    // Open/Create the database
    File dbFile = new File( fileConfig.dataDirectory(), descriptor.identity().toString() );
    db = factory.open( dbFile, options );
}