Java Code Examples for com.sleepycat.je.DatabaseConfig#setTransactional()

The following examples show how to use com.sleepycat.je.DatabaseConfig#setTransactional() . 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: DatabaseTemplate.java    From qpid-broker-j with Apache License 2.0 6 votes vote down vote up
public <T> T call(DatabaseCallable<T> databaseCallable)
{
    Database sourceDatabase = null;
    Database targetDatabase = null;
    try
    {
        DatabaseConfig dbConfig = new DatabaseConfig();
        dbConfig.setTransactional(true);
        dbConfig.setAllowCreate(true);

        sourceDatabase = _environment.openDatabase(_parentTransaction, _sourceDatabaseName, dbConfig);

        if (_targetDatabaseName != null)
        {
            targetDatabase = _environment.openDatabase(_parentTransaction, _targetDatabaseName, dbConfig);
        }

        return databaseCallable.call(sourceDatabase, targetDatabase, _parentTransaction);
    }
    finally
    {
        closeDatabase(sourceDatabase);
        closeDatabase(targetDatabase);
    }
}
 
Example 2
Source File: BerkeleyKeyValueStore.java    From BIMserver with GNU Affero General Public License v3.0 6 votes vote down vote up
public boolean openTable(DatabaseSession databaseSession, String tableName, boolean transactional) throws BimserverDatabaseException {
		if (tables.containsKey(tableName)) {
			throw new BimserverDatabaseException("Table " + tableName + " already opened");
		}
		DatabaseConfig databaseConfig = new DatabaseConfig();
		databaseConfig.setKeyPrefixing(keyPrefixing);
		databaseConfig.setAllowCreate(false);
		boolean finalTransactional = transactional && useTransactions;
//		if (!transactional) {
//			databaseConfig.setCacheMode(CacheMode.EVICT_BIN);
//		}
		databaseConfig.setDeferredWrite(!finalTransactional);
		databaseConfig.setTransactional(finalTransactional);
		databaseConfig.setSortedDuplicates(false);
		Database database = environment.openDatabase(null, tableName, databaseConfig);
		if (database == null) {
			throw new BimserverDatabaseException("Table " + tableName + " not found in database");
		}
		tables.put(tableName, new TableWrapper(database, finalTransactional));
		return true;
	}
 
Example 3
Source File: UpgraderFailOnNewerVersionTest.java    From qpid-broker-j with Apache License 2.0 6 votes vote down vote up
private int getStoreVersion()
{
    DatabaseConfig dbConfig = new DatabaseConfig();
    dbConfig.setTransactional(true);
    dbConfig.setAllowCreate(true);
    int storeVersion = -1;
    try(Database versionDb = _environment.openDatabase(null, Upgrader.VERSION_DB_NAME, dbConfig);
        Cursor cursor = versionDb.openCursor(null, null))
    {
        DatabaseEntry key = new DatabaseEntry();
        DatabaseEntry value = new DatabaseEntry();
        while (cursor.getNext(key, value, null) == OperationStatus.SUCCESS)
        {
            int version = IntegerBinding.entryToInt(key);
            if (storeVersion < version)
            {
                storeVersion = version;
            }
        }
    }
    return storeVersion;
}
 
Example 4
Source File: UpgraderTest.java    From qpid-broker-j with Apache License 2.0 6 votes vote down vote up
private int getStoreVersion(Environment environment)
{
    DatabaseConfig dbConfig = new DatabaseConfig();
    dbConfig.setTransactional(true);
    dbConfig.setAllowCreate(true);
    int storeVersion = -1;
    try(Database versionDb = environment.openDatabase(null, Upgrader.VERSION_DB_NAME, dbConfig);
        Cursor cursor = versionDb.openCursor(null, null))
    {
        DatabaseEntry key = new DatabaseEntry();
        DatabaseEntry value = new DatabaseEntry();
        while (cursor.getNext(key, value, null) == OperationStatus.SUCCESS)
        {
            int version = IntegerBinding.entryToInt(key);
            if (storeVersion < version)
            {
                storeVersion = version;
            }
        }
    }
    return storeVersion;
}
 
Example 5
Source File: BerkeleyKeyValueStore.java    From BIMserver with GNU Affero General Public License v3.0 6 votes vote down vote up
public boolean createIndexTable(String tableName, DatabaseSession databaseSession, boolean transactional) throws BimserverDatabaseException {
		if (tables.containsKey(tableName)) {
			throw new BimserverDatabaseException("Table " + tableName + " already created");
		}
		DatabaseConfig databaseConfig = new DatabaseConfig();
		databaseConfig.setKeyPrefixing(keyPrefixing);
		databaseConfig.setAllowCreate(true);
		boolean finalTransactional = transactional && useTransactions;
//		if (!transactional) {
//			databaseConfig.setCacheMode(CacheMode.EVICT_BIN);
//		}
		databaseConfig.setDeferredWrite(!finalTransactional);
		databaseConfig.setTransactional(finalTransactional);
		databaseConfig.setSortedDuplicates(true);
		Database database = environment.openDatabase(null, tableName, databaseConfig);
		if (database == null) {
			return false;
		}
		tables.put(tableName, new TableWrapper(database, finalTransactional));
		
		return true;
	}
 
Example 6
Source File: TestKDTreeSplit.java    From bboxdb with Apache License 2.0 6 votes vote down vote up
public TestKDTreeSplit(final File tmpDir, final List<Pair<String, String>> filesAndFormats,
		final List<Integer> experimentSize) {

	this.filesAndFormats = filesAndFormats;
	this.experimentSize = experimentSize;

	this.elements = new HashMap<>();
	this.elementCounter = new HashMap<>();
	this.boxDimension = new HashMap<>();

	// Setup database dir
	tmpDir.mkdirs();
	FileUtil.deleteDirOnExit(tmpDir.toPath());

	final EnvironmentConfig envConfig = new EnvironmentConfig();
	envConfig.setTransactional(false);
	envConfig.setAllowCreate(true);
    envConfig.setSharedCache(true);
	dbEnv = new Environment(tmpDir, envConfig);

	dbConfig = new DatabaseConfig();
	dbConfig.setTransactional(false);
	dbConfig.setAllowCreate(true);
}
 
Example 7
Source File: BerkeleyKeyValueStore.java    From BIMserver with GNU Affero General Public License v3.0 6 votes vote down vote up
public boolean createTable(String tableName, DatabaseSession databaseSession, boolean transactional) throws BimserverDatabaseException {
		if (tables.containsKey(tableName)) {
			throw new BimserverDatabaseException("Table " + tableName + " already created");
		}
		DatabaseConfig databaseConfig = new DatabaseConfig();
		databaseConfig.setKeyPrefixing(keyPrefixing);
		databaseConfig.setAllowCreate(true);
		boolean finalTransactional = transactional && useTransactions;
		databaseConfig.setDeferredWrite(!finalTransactional);
//		if (!transactional) {
//			databaseConfig.setCacheMode(CacheMode.EVICT_BIN);
//		}
		databaseConfig.setTransactional(finalTransactional);
		databaseConfig.setSortedDuplicates(false);
		Database database = environment.openDatabase(null, tableName, databaseConfig);
		if (database == null) {
			return false;
		}
		tables.put(tableName, new TableWrapper(database, finalTransactional));
		
		return true;
	}
 
Example 8
Source File: FileLineIndex.java    From bboxdb with Apache License 2.0 6 votes vote down vote up
/**
 * Open the Berkeley DB
 * @throws IOException
 */
protected void openDatabase() throws IOException {
	final EnvironmentConfig envConfig = new EnvironmentConfig();
	envConfig.setTransactional(false);
	envConfig.setAllowCreate(true);
    envConfig.setSharedCache(true);

    tmpDatabaseDir = Files.createTempDirectory(null);
	dbEnv = new Environment(tmpDatabaseDir.toFile(), envConfig);

	logger.info("Database dir is {}", tmpDatabaseDir);

	// Delete database on exit
	FileUtil.deleteDirOnExit(tmpDatabaseDir);

	final DatabaseConfig dbConfig = new DatabaseConfig();
	dbConfig.setTransactional(false);
	dbConfig.setAllowCreate(true);
	dbConfig.setDeferredWrite(true);

	database = dbEnv.openDatabase(null, "lines", dbConfig);
}
 
Example 9
Source File: JE_Repository.java    From tddl5 with Apache License 2.0 6 votes vote down vote up
public Database getDatabase(String name, boolean isTmp, boolean isSortedDuplicates) {
    DatabaseConfig dbConfig = new DatabaseConfig();
    dbConfig.setAllowCreate(true);
    Environment _env = env;
    if (isTmp) {
        dbConfig.setTemporary(true);
        dbConfig.setSortedDuplicates(isSortedDuplicates);
        _env = getTmpEnv();
    } else {
        if (!config.isTransactional()) {
            dbConfig.setDeferredWrite(config.isCommitSync());
        } else {
            dbConfig.setTransactional(true);
        }
    }

    Database database = buildPrimaryIndex(dbConfig, _env, name);
    return database;
}
 
Example 10
Source File: AbstractFrontier.java    From codes-scratch-crawler with Apache License 2.0 6 votes vote down vote up
public AbstractFrontier(String homeDirectory) {
  EnvironmentConfig envConfig = new EnvironmentConfig();
  envConfig.setTransactional(true);
  envConfig.setAllowCreate(true);
  env = new Environment(new File(homeDirectory), envConfig);
  // 设置databaseconfig
  DatabaseConfig dbConfig = new DatabaseConfig();
  dbConfig.setTransactional(true);
  dbConfig.setAllowCreate(true);
  // 打开
  catalogdatabase = env.openDatabase(null, CLASS_CATALOG, dbConfig);
  javaCatalog = new StoredClassCatalog(catalogdatabase);
  // 设置databaseconfig
  DatabaseConfig dbConfig0 = new DatabaseConfig();
  dbConfig0.setTransactional(true);
  dbConfig0.setAllowCreate(true);
  database = env.openDatabase(null, "URL", dbConfig0);
}
 
Example 11
Source File: PQ.java    From multimedia-indexing with Apache License 2.0 5 votes vote down vote up
/**
 * Advanced constructor.
 * 
 * @param vectorLength
 *            The dimensionality of the VLAD vectors being indexed
 * @param maxNumVectors
 *            The maximum allowable size (number of vectors) of the index
 * @param readOnly
 *            If true the persistent store will opened only for read access (allows multiple opens)
 * @param BDBEnvHome
 *            The BDB environment home directory
 * @param numSubVectors
 *            The number of subvectors
 * @param numProductCentroids
 *            The number of centroids used to quantize each sub-vector
 * @param transformation
 *            The type of transformation to perform on each vector
 * @param countSizeOnLoad
 *            Whether the load counter will be initialized by the size of the persistent store
 * @param loadCounter
 *            The initial value of the load counter
 * @param loadIndexInMemory
 *            Whether to load the index in memory, we can avoid loading the index in memory when we only
 *            want to perform indexing
 * @throws Exception
 */
public PQ(int vectorLength, int maxNumVectors, boolean readOnly, String BDBEnvHome, int numSubVectors,
		int numProductCentroids, TransformationType transformation, boolean countSizeOnLoad,
		int loadCounter, boolean loadIndexInMemory, long cacheSize) throws Exception {
	super(vectorLength, maxNumVectors, readOnly, countSizeOnLoad, loadCounter, loadIndexInMemory,
			cacheSize);
	this.numSubVectors = numSubVectors;
	if (vectorLength % numSubVectors > 0) {
		throw new Exception("The given number of subvectors is not valid!");
	}
	this.subVectorLength = vectorLength / numSubVectors;
	this.numProductCentroids = numProductCentroids;
	this.transformation = transformation;

	if (transformation == TransformationType.RandomRotation) {
		this.rr = new RandomRotation(seed, vectorLength);
	} else if (transformation == TransformationType.RandomPermutation) {
		this.rp = new RandomPermutation(seed, vectorLength);
	}

	createOrOpenBDBEnvAndDbs(BDBEnvHome);

	// configuration of the persistent index
	DatabaseConfig dbConf = new DatabaseConfig();
	dbConf.setReadOnly(readOnly);
	dbConf.setTransactional(transactional);
	dbConf.setAllowCreate(true); // db will be created if it does not exist
	iidToPqDB = dbEnv.openDatabase(null, "adc", dbConf); // create/open the db using config

	if (loadIndexInMemory) {
		// initialize the in-memory data structures and load any existing persistent index in memory
		loadIndexInMemory();
	}
}
 
Example 12
Source File: AbstractSearchStructure.java    From multimedia-indexing with Apache License 2.0 5 votes vote down vote up
/**
 * This method creates and/or opens the BDB databases with the appropriate parameters.
 * 
 * @throws Exception
 */
private void createOrOpenBDBDbs() throws Exception {
	// configuration for the mapping dbs
	DatabaseConfig dbConfig = new DatabaseConfig();
	dbConfig.setAllowCreate(true); // db will be created if it does not exist
	dbConfig.setReadOnly(readOnly);
	dbConfig.setTransactional(transactional);
	// create/open mapping dbs using config
	iidToIdDB = dbEnv.openDatabase(null, "idToName", dbConfig);

	// if countSizeOnLoad is true, the id-name mappings are counted and the loadCounter is initialized
	if (countSizeOnLoad) {
		System.out.println(new Date() + " counting index size started ");
		int idToNameMappings = (int) iidToIdDB.count();
		loadCounter = Math.min(idToNameMappings, maxNumVectors);
		System.out.println(new Date() + " counting index size ended ");
		System.out.println("Index size: " + loadCounter);
	}

	idToIidDB = dbEnv.openDatabase(null, "nameToId", dbConfig);

	if (useGeolocation) {// create/open geolocation db using config
		iidToGeolocationDB = dbEnv.openDatabase(null, "idToGeolocation", dbConfig);
	}

	if (useMetaData) {
		StoreConfig storeConfig = new StoreConfig(); // configuration of the entity store
		storeConfig.setAllowCreate(true); // store will be created if it does not exist
		storeConfig.setReadOnly(readOnly);
		storeConfig.setTransactional(transactional);
		iidToMetadataDB = new EntityStore(dbEnv, "idToMetadata", storeConfig);
		// int nameToMetadataMappings = (int) nameToMetadataBDB.getPrimaryIndex(String.class,
		// MediaFeedData.class).count(); // counting the size of an EntityStore
	}
}
 
Example 13
Source File: BerkeleyDBStore.java    From hypergraphdb with Apache License 2.0 5 votes vote down vote up
@Override
public void init(HazelcastInstance hazelcastInstance, Properties properties, String mapName) {
    _hazelcastInstance = hazelcastInstance;
    _properties = properties;
    _mapName = mapName;

    DatabaseConfig dbConfig = new DatabaseConfig();
    dbConfig.setAllowCreate(true);
    dbConfig.setDeferredWrite(true); //延迟写
    dbConfig.setSortedDuplicates(false);
    dbConfig.setTransactional(false);
    _db = _env.openDatabase(null, _mapName, dbConfig);
    _dbMap.put(_mapName, _db);

    if (_scheduleSync == null) {
        try {
            _syncinterval = Integer.parseInt(_properties.getProperty("syncinterval"));
        } catch (Exception e) {
            _syncinterval = 3;
            _logger.log(Level.WARNING, e.getMessage(), e);
        }
        if (_syncinterval > 0) {
            _scheduleSync = Executors.newSingleThreadScheduledExecutor(); //同步磁盘的Scheduled
            _scheduleSync.scheduleWithFixedDelay(this, 1, _syncinterval, TimeUnit.SECONDS);
        }
    }
    _logger.log(Level.INFO, this.getClass().getCanonicalName() + ":" + _mapName + ":count:" + _db.count());
    _logger.log(Level.INFO, this.getClass().getCanonicalName() + ":" + _mapName + ":初始化完成!");

    //预先把数据加载进Hazelcast集群中
    IMap map = _hazelcastInstance.getMap(mapName);
    Set<K> keySet = privateLoadAllKeys();
    for (K key : keySet) {
        map.putTransient(key, load(key), 0, TimeUnit.SECONDS);
    }
    _logger.log(Level.INFO, this.getClass().getCanonicalName() + ":" + _mapName + ":预先加载数据完成!");

}
 
Example 14
Source File: OSMBDBNodeStore.java    From bboxdb with Apache License 2.0 5 votes vote down vote up
/**
 * Init a new BDB environment in the given folder
 * @param folder
 */
@SuppressWarnings("unused")
protected void initNewBDBEnvironment(final File folder, final EnvironmentConfig envConfig) {

	final Environment dbEnv = new Environment(folder, envConfig);

	Transaction txn = null;
	if(USE_TRANSACTIONS) {
		txn = dbEnv.beginTransaction(null, null);
	}
	
	final DatabaseConfig dbConfig = new DatabaseConfig();
	dbConfig.setTransactional(USE_TRANSACTIONS);
	dbConfig.setAllowCreate(true);
	dbConfig.setSortedDuplicates(true);
	dbConfig.setDeferredWrite(true);
	//dbConfig.setKeyPrefixing(true);
	//dbConfig.setNodeMaxEntries(128);

	final Database database = dbEnv.openDatabase(txn, "osm", dbConfig);

	if(txn != null) {
		txn.commit();
	}
	
	environments.add(dbEnv);
	databases.add(database);
}
 
Example 15
Source File: BDBTupleStore.java    From bboxdb with Apache License 2.0 5 votes vote down vote up
@Override
public void open() throws Exception {
	final EnvironmentConfig envConfig = new EnvironmentConfig();
	envConfig.setTransactional(USE_TRANSACTIONS);
	envConfig.setAllowCreate(true);

	environment = new Environment(dir, envConfig);

	Transaction txn = null;
	if(USE_TRANSACTIONS) {
		txn = environment.beginTransaction(null, null);
	}
	
	final DatabaseConfig dbConfig = new DatabaseConfig();
	dbConfig.setTransactional(USE_TRANSACTIONS);
	dbConfig.setAllowCreate(true);
	//dbConfig.setSortedDuplicates(true);
	dbConfig.setDeferredWrite(true);
	//dbConfig.setKeyPrefixing(true);
	//dbConfig.setNodeMaxEntries(128);

	database = environment.openDatabase(txn, "test", dbConfig);

	if(txn != null) {
		txn.commit();
	}	
}
 
Example 16
Source File: UpgradeFrom6To7.java    From qpid-broker-j with Apache License 2.0 5 votes vote down vote up
@Override
public void performUpgrade(Environment environment, UpgradeInteractionHandler handler, ConfiguredObject<?> parent)
{
    reportStarting(environment, 6);
    DatabaseConfig dbConfig = new DatabaseConfig();
    dbConfig.setTransactional(true);
    dbConfig.setAllowCreate(true);

    Database versionDb = environment.openDatabase(null, "CONFIG_VERSION", dbConfig);

    if(versionDb.count() == 0L)
    {
        DatabaseEntry key = new DatabaseEntry();
        DatabaseEntry value = new DatabaseEntry();
        IntegerBinding.intToEntry(DEFAULT_CONFIG_VERSION, value);
        ByteBinding.byteToEntry((byte) 0, key);
        OperationStatus status = versionDb.put(null, key, value);
        if (status != OperationStatus.SUCCESS)
        {
            throw new StoreException("Error initialising config version: " + status);
        }
    }

    versionDb.close();

    reportFinished(environment, 7);
}
 
Example 17
Source File: UpgradeFrom8To9.java    From qpid-broker-j with Apache License 2.0 4 votes vote down vote up
@Override
public void performUpgrade(final Environment environment,
                           final UpgradeInteractionHandler handler,
                           final ConfiguredObject<?> parent)
{
    reportStarting(environment, 8);

    DatabaseConfig dbConfig = new DatabaseConfig();
    dbConfig.setTransactional(true);
    dbConfig.setAllowCreate(true);

    final Transaction transaction = environment.beginTransaction(null, null);
    try
    {
        Database userPreferencesDb = environment.openDatabase(transaction, "USER_PREFERENCES", dbConfig);
        userPreferencesDb.close();

        try (Database userPreferencesVersionDb = environment.openDatabase(transaction,
                                                                          "USER_PREFERENCES_VERSION",
                                                                          dbConfig))
        {
            if (userPreferencesVersionDb.count() == 0L)
            {
                DatabaseEntry key = new DatabaseEntry();
                DatabaseEntry value = new DatabaseEntry();
                StringBinding.stringToEntry(DEFAULT_VERSION, key);
                LongBinding.longToEntry(System.currentTimeMillis(), value);
                OperationStatus status = userPreferencesVersionDb.put(transaction, key, value);
                if (status != OperationStatus.SUCCESS)
                {
                    throw new StoreException("Error initialising user preference version: " + status);
                }
            }
        }

        transaction.commit();
        reportFinished(environment, 9);
    }
    catch (RuntimeException e)
    {
        try
        {
            if (transaction.isValid())
            {
                transaction.abort();
            }
        }
        finally
        {
            throw e;
        }
    }
}
 
Example 18
Source File: Linear.java    From multimedia-indexing with Apache License 2.0 4 votes vote down vote up
/**
 * Advanced constructor.
 * 
 * @param vectorLength
 *            The dimensionality of the VLAD vectors being indexed
 * @param maxNumVectors
 *            The maximum allowable size (number of vectors) of the index
 * @param readOnly
 *            If true the persistent store will opened only for read access (allows multiple opens)
 * @param BDBEnvHome
 *            The BDB environment home directory
 * @param loadIndexInMemory
 *            Whether to load the index in memory, we can avoid loading the index in memory when we only
 *            want to perform indexing
 * @param countSizeOnLoad
 *            Whether the load counter will be initialized by the size of the persistent store
 * @param loadCounter
 *            The initial value of the load counter
 * @throws Exception
 */
public Linear(int vectorLength, int maxNumVectors, boolean readOnly, String BDBEnvHome,
		boolean loadIndexInMemory, boolean countSizeOnLoad, int loadCounter) throws Exception {
	super(vectorLength, maxNumVectors, readOnly, countSizeOnLoad, loadCounter, loadIndexInMemory);
	createOrOpenBDBEnvAndDbs(BDBEnvHome);
	// configuration of the persistent index
	DatabaseConfig dbConf = new DatabaseConfig();
	dbConf.setReadOnly(readOnly);
	dbConf.setTransactional(transactional);
	dbConf.setAllowCreate(true); // db will be created if it does not exist
	iidToVectorDB = dbEnv.openDatabase(null, "vlad", dbConf); // create/open the db using config

	if (loadIndexInMemory) {// load the existing persistent index in memory
		// create the memory objects with the appropriate initial size
		vectorsList = new TDoubleArrayList(maxNumVectors * vectorLength);
		loadIndexInMemory();
	}
}
 
Example 19
Source File: IVFPQ.java    From multimedia-indexing with Apache License 2.0 4 votes vote down vote up
/**
 * Advanced constructor.
 * 
 * @param vectorLength
 *            The dimensionality of the VLAD vectors being indexed
 * @param maxNumVectors
 *            The maximum allowable size (number of vectors) of the index
 * @param readOnly
 *            If true the persistent store will opened only for read access (allows multiple opens)
 * @param BDBEnvHome
 *            The BDB environment home directory
 * @param numSubVectors
 *            The number of subvectors
 * @param numProductCentroids
 *            The number of centroids used to quantize each sub-vector
 * @param transformation
 *            The type of transformation to perform on each vector
 * @param numCoarseCentroids
 *            The number of centroids of the coarse quantizer
 * @param countSizeOnLoad
 *            Whether the load counter will be initialized by the size of the persistent store
 * @param loadCounter
 *            The initial value of the load counter
 * @param loadIndexInMemory
 *            Whether to load the index in memory, we can avoid loading the index in memory when we only
 *            want to perform indexing
 * @param cacheSize
 *            the size of the cache in Megabytes
 * @throws Exception
 */
public IVFPQ(int vectorLength, int maxNumVectors, boolean readOnly, String BDBEnvHome, int numSubVectors,
		int numProductCentroids, TransformationType transformation, int numCoarseCentroids,
		boolean countSizeOnLoad, int loadCounter, boolean loadIndexInMemory, long cacheSize)
				throws Exception {
	super(vectorLength, maxNumVectors, readOnly, countSizeOnLoad, loadCounter, loadIndexInMemory,
			cacheSize);
	this.numSubVectors = numSubVectors;
	if (vectorLength % numSubVectors > 0) {
		throw new Exception("The given number of subvectors is not valid!");
	}
	this.subVectorLength = vectorLength / numSubVectors;
	this.numProductCentroids = numProductCentroids;
	this.transformation = transformation;
	this.numCoarseCentroids = numCoarseCentroids;
	w = (int) (numCoarseCentroids * 0.1); // by default set w to 10% of the lists

	if (transformation == TransformationType.RandomRotation) {
		this.rr = new RandomRotation(seed, vectorLength);
	} else if (transformation == TransformationType.RandomPermutation) {
		this.rp = new RandomPermutation(seed, vectorLength);
	}

	createOrOpenBDBEnvAndDbs(BDBEnvHome);

	// configuration of the persistent index
	DatabaseConfig dbConf = new DatabaseConfig();
	dbConf.setReadOnly(readOnly);
	dbConf.setTransactional(transactional);
	dbConf.setAllowCreate(true); // db will be created if it does not exist
	iidToIvfpqDB = dbEnv.openDatabase(null, "ivfadc", dbConf); // create/open the db using config

	if (loadIndexInMemory) {// load the existing persistent index in memory
		// create the memory objects with the appropriate initial size
		invertedLists = new TIntArrayList[numCoarseCentroids];

		if (numProductCentroids <= 256) {
			pqByteCodes = new TByteArrayList[numCoarseCentroids];
		} else {
			pqShortCodes = new TShortArrayList[numCoarseCentroids];
		}

		int initialListCapacity = (int) ((double) maxNumVectors / numCoarseCentroids);
		System.out.println("Calculated list size " + initialListCapacity);

		for (int i = 0; i < numCoarseCentroids; i++) {
			if (numProductCentroids <= 256) {
				// fixed initial size allows space efficiency measurements
				// pqByteCodes[i] = new TByteArrayList(initialListCapacity * numSubVectors);
				pqByteCodes[i] = new TByteArrayList();

			} else {
				// fixed initial size allows space efficiency measurements
				// pqShortCodes[i] = new TShortArrayList(initialListCapacity * numSubVectors);
				pqShortCodes[i] = new TShortArrayList();

			}
			// fixed initial size for each list, allows space efficiency measurements
			// invertedLists[i] = new TIntArrayList(initialListCapacity);
			invertedLists[i] = new TIntArrayList();
		}
		// load any existing persistent index in memory
		loadIndexInMemory();
	}
}
 
Example 20
Source File: Upgrader.java    From qpid-broker-j with Apache License 2.0 4 votes vote down vote up
public void upgradeIfNecessary()
{
    boolean isEmpty = _environment.getDatabaseNames().isEmpty();
    DatabaseConfig dbConfig = new DatabaseConfig();
    dbConfig.setTransactional(true);
    dbConfig.setAllowCreate(true);

    Database versionDb = null;
    try
    {
        versionDb = _environment.openDatabase(null, VERSION_DB_NAME, dbConfig);

        if(versionDb.count() == 0L)
        {

            int sourceVersion = isEmpty ? BDBConfigurationStore.VERSION: identifyOldStoreVersion();
            DatabaseEntry key = new DatabaseEntry();
            IntegerBinding.intToEntry(sourceVersion, key);
            DatabaseEntry value = new DatabaseEntry();
            LongBinding.longToEntry(System.currentTimeMillis(), value);

            versionDb.put(null, key, value);
        }

        int version = getSourceVersion(versionDb);

        if (LOGGER.isDebugEnabled())
        {
            LOGGER.debug("Source message store version is " + version);
        }

        if(version > BDBConfigurationStore.VERSION)
        {
            throw new StoreException("Database version " + version
                                        + " is higher than the most recent known version: "
                                        + BDBConfigurationStore.VERSION);
        }
        performUpgradeFromVersion(version, versionDb);
    }
    finally
    {
        if (versionDb != null)
        {
            versionDb.close();
        }
    }
}