private Index createInStore(String bagName, KeyInfo keyInfo) throws JasDBStorageException { if(!indexes.containsKey(bagName)) { loadIndexes(bagName); } Map<String, Index> bagIndexes = this.indexes.get(bagName); if(bagIndexes != null && !bagIndexes.containsKey(keyInfo.getKeyName())) { File indexFile = createIndexFile(bagName, keyInfo.getKeyName(), false); try { Index index = new BTreeIndex(indexFile, keyInfo); configureIndex(IndexTypes.BTREE, index); IndexDefinition definition = new IndexDefinition(keyInfo.getKeyName(), keyInfo.keyAsHeader(), keyInfo.valueAsHeader(), index.getIndexType()); metadataStore.addBagIndex(instanceId, bagName, definition); bagIndexes.put(keyInfo.getKeyName(), index); return index; } catch(ConfigurationException e) { throw new JasDBStorageException("Unable to create index, configuration error", e); } } else if(bagIndexes != null){ return bagIndexes.get(keyInfo.getKeyName()); } else { return null; } }
private Index loadIndex(String bagName, IndexDefinition indexDefinition) throws JasDBStorageException { try { KeyInfo keyInfo = new KeyInfoImpl(indexDefinition.getHeaderDescriptor(), indexDefinition.getValueDescriptor()); File indexFile = createIndexFile(bagName, indexDefinition.getIndexName(), false); switch(IndexTypes.getTypeFor(indexDefinition.getIndexType())) { case BTREE: LOG.debug("Loaded BTree Index for key: {}", indexDefinition.getIndexName()); Index btreeIndex = new BTreeIndex(indexFile, keyInfo); return configureIndex(IndexTypes.BTREE, btreeIndex); default: throw new JasDBStorageException("Reading from this index type: " + indexDefinition.getIndexName() + " is not supported"); } } catch(ConfigurationException e) { throw new JasDBStorageException("Unable to load index, invalid configuration", e); } }
@Override public void openWriter() throws JasDBStorageException { this.keyInfo = new KeyInfoImpl(new SimpleIndexField("__ID", new UUIDKeyType()), new SimpleIndexField("RECORD_POINTER", new LongKeyType())); this.index = new BTreeIndex(indexLocation, keyInfo); this.writer.openWriter(); this.index.openIndex(); }
@Override public void openWriter() throws JasDBStorageException { this.keyInfo = new KeyInfoImpl(new SimpleIndexField("__ID", new UUIDKeyType()), new SimpleIndexField("data", new DataKeyType())); try { this.index = new BTreeIndex(recordStorageLocation, keyInfo); this.index.openIndex(); } catch(OverlappingFileLockException e) { throw new RecordStoreInUseException("Record datastore: " + recordStorageLocation + " is already in use, cannot be opened"); } }