Search in sources :

Example 1 with StorageManagerException

use of org.bboxdb.storage.StorageManagerException in project bboxdb by jnidzwetzki.

the class SSTableWriter method open.

/**
 * Open all required files
 * @throws StorageManagerException
 */
public void open() throws StorageManagerException {
    final String directoryName = SSTableHelper.getSSTableDir(directory, name);
    final File directoryHandle = new File(directoryName);
    if (!directoryHandle.isDirectory()) {
        final String error = "Directory for SSTable " + name + " does not exist: " + directoryName;
        logger.error(error);
        throw new StorageManagerException(error);
    }
    final String sstableOutputFileName = SSTableHelper.getSSTableFilename(directory, name, tablenumber);
    sstableFile = new File(sstableOutputFileName);
    final String outputIndexFileName = SSTableHelper.getSSTableIndexFilename(directory, name, tablenumber);
    sstableIndexFile = new File(outputIndexFileName);
    // Don't overwrite old data
    if (sstableFile.exists()) {
        throw new StorageManagerException("Table file already exists: " + sstableOutputFileName);
    }
    if (sstableIndexFile.exists()) {
        throw new StorageManagerException("Table file already exists: " + sstableIndexFile);
    }
    if (sstableBloomFilterFile.exists()) {
        throw new StorageManagerException("Bloom filter file already exists: " + sstableBloomFilterFile);
    }
    try {
        logger.info("Writing new SSTable for relation: {} file: {}", name.getFullname(), sstableOutputFileName);
        final BufferedOutputStream sstableFileOutputStream = new BufferedOutputStream(new FileOutputStream(sstableFile));
        sstableOutputStream = new CountingOutputStream(sstableFileOutputStream);
        sstableOutputStream.write(SSTableConst.MAGIC_BYTES);
        sstableIndexOutputStream = new BufferedOutputStream(new FileOutputStream(sstableIndexFile));
        sstableIndexOutputStream.write(SSTableConst.MAGIC_BYTES_INDEX);
    } catch (FileNotFoundException e) {
        exceptionDuringWrite = true;
        throw new StorageManagerException("Unable to open output file", e);
    } catch (IOException e) {
        exceptionDuringWrite = true;
        throw new StorageManagerException("Unable to write into output file", e);
    }
}
Also used : CountingOutputStream(com.google.common.io.CountingOutputStream) FileOutputStream(java.io.FileOutputStream) FileNotFoundException(java.io.FileNotFoundException) StorageManagerException(org.bboxdb.storage.StorageManagerException) IOException(java.io.IOException) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream)

Example 2 with StorageManagerException

use of org.bboxdb.storage.StorageManagerException in project bboxdb by jnidzwetzki.

the class SSTableWriter method close.

/**
 * Close all open file handles and write the meta data
 */
public void close() throws StorageManagerException {
    try {
        logger.debug("Closing new written SSTable for relation: {} number {}. File: {} ", name.getFullname(), tablenumber, sstableFile.getName());
        if (sstableOutputStream != null) {
            sstableOutputStream.close();
            sstableOutputStream = null;
        }
        if (sstableIndexOutputStream != null) {
            sstableIndexOutputStream.close();
            sstableIndexOutputStream = null;
        }
        writeSpatialIndex();
        writeBloomFilter();
        writeMetadata();
    } catch (IOException e) {
        exceptionDuringWrite = true;
        throw new StorageManagerException("Exception while closing streams", e);
    } finally {
        checkForWriteException();
    }
}
Also used : IOException(java.io.IOException) StorageManagerException(org.bboxdb.storage.StorageManagerException)

Example 3 with StorageManagerException

use of org.bboxdb.storage.StorageManagerException in project bboxdb by jnidzwetzki.

the class SSTableWriter method addData.

/**
 * Add the list of tuples to the sstable
 * @param tuples
 * @throws StorageManagerException
 */
public void addData(final List<Tuple> tuples) throws StorageManagerException {
    if (sstableOutputStream == null) {
        final String error = "Trying to add a memtable to a non ready SSTable writer";
        logger.error(error);
        throw new StorageManagerException(error);
    }
    try {
        for (final Tuple tuple : tuples) {
            addNextTuple(tuple);
        }
    } catch (StorageManagerException e) {
        exceptionDuringWrite = true;
        throw e;
    }
}
Also used : StorageManagerException(org.bboxdb.storage.StorageManagerException) Tuple(org.bboxdb.storage.entity.Tuple)

Example 4 with StorageManagerException

use of org.bboxdb.storage.StorageManagerException in project bboxdb by jnidzwetzki.

the class SSTableWriter method addNextTuple.

/**
 * Add the next tuple into the result sstable
 * @param tuple
 * @throws IOException
 * @throws StorageManagerException
 */
public void addNextTuple(final Tuple tuple) throws StorageManagerException {
    try {
        // Add Tuple to the index
        final int tuplePosition = (int) sstableOutputStream.getCount();
        writeIndexEntry(tuplePosition);
        final int newPosition = (int) sstableOutputStream.getCount();
        final int writtenBytes = newPosition - tuplePosition;
        // Add Tuple to the SSTable file
        TupleHelper.writeTupleToStream(tuple, sstableOutputStream);
        metadataBuilder.addTuple(tuple);
        // Add tuple to the bloom filter
        bloomFilter.put(tuple.getKey());
        // Add tuple to the spatial index
        final SpatialIndexEntry sIndexentry = new SpatialIndexEntry(tuple.getBoundingBox(), tuplePosition);
        spatialIndex.insert(sIndexentry);
        writtenTuplesTotal.inc();
        writtenTuplesBytes.inc(writtenBytes);
    } catch (IOException e) {
        exceptionDuringWrite = true;
        throw new StorageManagerException("Unable to write tuple to SSTable", e);
    }
}
Also used : IOException(java.io.IOException) StorageManagerException(org.bboxdb.storage.StorageManagerException) SpatialIndexEntry(org.bboxdb.storage.sstable.spatialindex.SpatialIndexEntry)

Example 5 with StorageManagerException

use of org.bboxdb.storage.StorageManagerException in project bboxdb by jnidzwetzki.

the class SSTableCompactor method executeCompactation.

/**
 * Execute the compactation of the input sstables
 *
 * @return success or failure
 */
public void executeCompactation() throws StorageManagerException {
    try {
        // The iterators
        final List<Iterator<Tuple>> iterators = sstableIndexReader.stream().map(r -> r.iterator()).collect(Collectors.toList());
        final DuplicateResolver<Tuple> newestKeyResolver = TupleDuplicateResolverFactory.build(tupleStoreManager.getTupleStoreConfiguration());
        final SortedIteratorMerger<Tuple> sortedIteratorMerger = new SortedIteratorMerger<>(iterators, TupleHelper.TUPLE_KEY_COMPARATOR, newestKeyResolver);
        for (final Tuple tuple : sortedIteratorMerger) {
            checkForThreadTermination();
            addTupleToWriter(tuple);
        }
        readTuples = sortedIteratorMerger.getReadElements();
    } catch (StorageManagerException e) {
        handleErrorDuringCompact();
        throw e;
    } finally {
        closeSSTableWriter();
    }
}
Also used : SSTableWriter(org.bboxdb.storage.sstable.SSTableWriter) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) Tuple(org.bboxdb.storage.entity.Tuple) TupleHelper(org.bboxdb.storage.util.TupleHelper) LoggerFactory(org.slf4j.LoggerFactory) SSTableConst(org.bboxdb.storage.sstable.SSTableConst) SortedIteratorMerger(org.bboxdb.commons.SortedIteratorMerger) Collectors(java.util.stream.Collectors) TupleDuplicateResolverFactory(org.bboxdb.storage.sstable.duplicateresolver.TupleDuplicateResolverFactory) ArrayList(java.util.ArrayList) DuplicateResolver(org.bboxdb.commons.DuplicateResolver) List(java.util.List) TupleStoreManager(org.bboxdb.storage.tuplestore.manager.TupleStoreManager) SSTableKeyIndexReader(org.bboxdb.storage.sstable.reader.SSTableKeyIndexReader) DeletedTuple(org.bboxdb.storage.entity.DeletedTuple) StorageManagerException(org.bboxdb.storage.StorageManagerException) Iterator(java.util.Iterator) SortedIteratorMerger(org.bboxdb.commons.SortedIteratorMerger) StorageManagerException(org.bboxdb.storage.StorageManagerException) Tuple(org.bboxdb.storage.entity.Tuple) DeletedTuple(org.bboxdb.storage.entity.DeletedTuple)

Aggregations

StorageManagerException (org.bboxdb.storage.StorageManagerException)48 BBoxDBException (org.bboxdb.misc.BBoxDBException)16 IOException (java.io.IOException)14 ArrayList (java.util.ArrayList)14 TupleStoreName (org.bboxdb.storage.entity.TupleStoreName)12 Tuple (org.bboxdb.storage.entity.Tuple)11 TupleStoreManager (org.bboxdb.storage.tuplestore.manager.TupleStoreManager)8 File (java.io.File)7 ZookeeperException (org.bboxdb.distribution.zookeeper.ZookeeperException)7 ReadOnlyTupleStore (org.bboxdb.storage.tuplestore.ReadOnlyTupleStore)6 List (java.util.List)5 RejectedException (org.bboxdb.commons.RejectedException)5 SpatialIndexEntry (org.bboxdb.storage.sstable.spatialindex.SpatialIndexEntry)5 DiskStorage (org.bboxdb.storage.tuplestore.DiskStorage)5 RandomAccessFile (java.io.RandomAccessFile)4 Collectors (java.util.stream.Collectors)4 BoundingBox (org.bboxdb.commons.math.BoundingBox)4 SpacePartitioner (org.bboxdb.distribution.partitioner.SpacePartitioner)4 TupleStoreConfiguration (org.bboxdb.storage.entity.TupleStoreConfiguration)4 SSTableFacade (org.bboxdb.storage.sstable.reader.SSTableFacade)4