Search in sources :

Example 6 with IndexStatus

use of herddb.storage.IndexStatus in project herddb by diennea.

the class BRINIndexManager method start.

@Override
public void start(LogSequenceNumber sequenceNumber) throws DataStorageManagerException {
    LOGGER.log(Level.SEVERE, " start index {0} uuid {1}", new Object[] { index.name, index.uuid });
    bootSequenceNumber = sequenceNumber;
    if (LogSequenceNumber.START_OF_TIME.equals(sequenceNumber)) {
        /* Empty index (booting from the start) */
        this.data.boot(new BlockRangeIndexMetadata<>(Collections.emptyList()));
        LOGGER.log(Level.SEVERE, "loaded empty index {0}", new Object[] { index.name });
    } else {
        IndexStatus status;
        try {
            status = dataStorageManager.getIndexStatus(tableSpaceUUID, index.uuid, sequenceNumber);
        } catch (DataStorageManagerException e) {
            LOGGER.log(Level.SEVERE, "cannot load index {0} due to {1}, it will be rebuilt", new Object[] { index.name, e });
            this.data.boot(new BlockRangeIndexMetadata<>(Collections.emptyList()));
            rebuild();
            return;
        }
        try {
            PageContents metadataBlock = PageContents.deserialize(status.indexData);
            this.data.boot(new BlockRangeIndexMetadata<>(metadataBlock.metadata));
        } catch (IOException e) {
            throw new DataStorageManagerException(e);
        }
        newPageId.set(status.newPageId);
        LOGGER.log(Level.SEVERE, "loaded index {0} {1} blocks", new Object[] { index.name, this.data.getNumBlocks() });
    }
}
Also used : IndexStatus(herddb.storage.IndexStatus) DataStorageManagerException(herddb.storage.DataStorageManagerException) IOException(java.io.IOException)

Example 7 with IndexStatus

use of herddb.storage.IndexStatus in project herddb by diennea.

the class BLinkKeyToPageIndex method checkpoint.

@Override
public List<PostCheckpointAction> checkpoint(LogSequenceNumber sequenceNumber, boolean pin) throws DataStorageManagerException {
    try {
        /* Tree can be null if no data was inserted (tree creation deferred to check evaluate key size) */
        final BLink<Bytes, Long> tree = this.tree;
        if (tree == null) {
            return Collections.emptyList();
        }
        BLinkMetadata<Bytes> metadata = getTree().checkpoint();
        byte[] metaPage = MetadataSerializer.INSTANCE.write(metadata);
        Set<Long> activePages = new HashSet<>();
        metadata.nodes.forEach(node -> activePages.add(node.storeId));
        IndexStatus indexStatus = new IndexStatus(indexName, sequenceNumber, newPageId.get(), activePages, metaPage);
        List<PostCheckpointAction> result = new ArrayList<>();
        result.addAll(dataStorageManager.indexCheckpoint(tableSpace, indexName, indexStatus, pin));
        LOGGER.log(Level.INFO, "checkpoint index {0} finished: logpos {1}, {2} pages", new Object[] { indexName, sequenceNumber, Integer.toString(metadata.nodes.size()) });
        LOGGER.log(Level.FINE, "checkpoint index {0} finished: logpos {1}, pages {2}", new Object[] { indexName, sequenceNumber, activePages.toString() });
        return result;
    } catch (IOException err) {
        throw new DataStorageManagerException(err);
    }
}
Also used : DataStorageManagerException(herddb.storage.DataStorageManagerException) ArrayList(java.util.ArrayList) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) PostCheckpointAction(herddb.core.PostCheckpointAction) Bytes(herddb.utils.Bytes) IndexStatus(herddb.storage.IndexStatus) AtomicLong(java.util.concurrent.atomic.AtomicLong) HashSet(java.util.HashSet)

Example 8 with IndexStatus

use of herddb.storage.IndexStatus in project herddb by diennea.

the class BLinkKeyToPageIndex method start.

@Override
public void start(LogSequenceNumber sequenceNumber, boolean created) throws DataStorageManagerException {
    if (!created) {
        LOGGER.log(Level.INFO, " start index {0}", new Object[] { indexName });
    }
    /* Actually the same size */
    final long pageSize = memoryManager.getMaxLogicalPageSize();
    if (LogSequenceNumber.START_OF_TIME.equals(sequenceNumber)) {
        /* Empty index (booting from the start) */
        tree = new BLink<>(pageSize, SizeEvaluatorImpl.INSTANCE, memoryManager.getPKPageReplacementPolicy(), indexDataStorage);
        if (!created) {
            LOGGER.log(Level.INFO, "loaded empty index {0}", new Object[] { indexName });
        }
    } else {
        IndexStatus status = dataStorageManager.getIndexStatus(tableSpace, indexName, sequenceNumber);
        try {
            BLinkMetadata<Bytes> metadata = MetadataSerializer.INSTANCE.read(status.indexData);
            tree = new BLink<>(pageSize, SizeEvaluatorImpl.INSTANCE, memoryManager.getPKPageReplacementPolicy(), indexDataStorage, metadata);
        } catch (IOException e) {
            throw new DataStorageManagerException(e);
        }
        newPageId.set(status.newPageId);
        LOGGER.log(Level.INFO, "loaded index {0}: {1} keys", new Object[] { indexName, tree.size() });
    }
}
Also used : Bytes(herddb.utils.Bytes) IndexStatus(herddb.storage.IndexStatus) DataStorageManagerException(herddb.storage.DataStorageManagerException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException)

Example 9 with IndexStatus

use of herddb.storage.IndexStatus in project herddb by diennea.

the class BRINIndexManager method checkpoint.

@Override
public List<PostCheckpointAction> checkpoint(LogSequenceNumber sequenceNumber, boolean pin) throws DataStorageManagerException {
    try {
        BlockRangeIndexMetadata<Bytes> metadata = data.checkpoint();
        /* Checks metadata consistency with actual data structure */
        if (VALIDATE_CHECKPOINT_METADATA) {
            boolean invalid = false;
            /*
                 * Metadata are saved/recovered in reverse order so "next" block has been already created
                 */
            Long nextID = null;
            for (BlockRangeIndexMetadata.BlockMetadata<Bytes> blockData : metadata.getBlocksMetadata()) {
                /* Medatada safety check (do not trust blindly ordering) */
                if (blockData.nextBlockId != null) {
                    if (nextID == null) {
                        LOGGER.log(Level.WARNING, "Wrong next block on index {0}, expected notingh but {0} found", new Object[] { index.name, blockData.nextBlockId });
                        invalid = true;
                    } else if (nextID != blockData.nextBlockId.longValue()) {
                        LOGGER.log(Level.WARNING, "Wrong next block on index {0}, expected {1} but {2} found", new Object[] { index.name, nextID, blockData.nextBlockId });
                        invalid = true;
                    }
                } else {
                    if (nextID != null) {
                        LOGGER.log(Level.WARNING, "Wrong next block on index {0}, expected {1} but nothing found", new Object[] { index.name, nextID });
                        invalid = true;
                    }
                }
                nextID = blockData.blockId;
            }
            if (invalid) {
                LOGGER.log(Level.WARNING, data.generateDetailedInternalStatus());
            }
        }
        PageContents page = new PageContents();
        page.type = PageContents.TYPE_METADATA;
        page.metadata = metadata.getBlocksMetadata();
        byte[] contents = page.serialize();
        Set<Long> activePages = new HashSet<>();
        page.metadata.forEach(b -> {
            activePages.add(b.pageId);
        });
        IndexStatus indexStatus = new IndexStatus(index.name, sequenceNumber, newPageId.get(), activePages, contents);
        List<PostCheckpointAction> result = new ArrayList<>();
        result.addAll(dataStorageManager.indexCheckpoint(tableSpaceUUID, index.uuid, indexStatus, pin));
        LOGGER.log(Level.INFO, "checkpoint index {0} finished: logpos {1}, {2} blocks", new Object[] { index.name, sequenceNumber, Integer.toString(page.metadata.size()) });
        LOGGER.log(Level.FINE, "checkpoint index {0} finished: logpos {1}, pages {2}", new Object[] { index.name, sequenceNumber, activePages });
        return result;
    } catch (IOException err) {
        throw new DataStorageManagerException(err);
    }
}
Also used : DataStorageManagerException(herddb.storage.DataStorageManagerException) ArrayList(java.util.ArrayList) IOException(java.io.IOException) PostCheckpointAction(herddb.core.PostCheckpointAction) Bytes(herddb.utils.Bytes) IndexStatus(herddb.storage.IndexStatus) AtomicLong(java.util.concurrent.atomic.AtomicLong) HashSet(java.util.HashSet)

Example 10 with IndexStatus

use of herddb.storage.IndexStatus in project herddb by diennea.

the class BRINIndexManager method doStart.

@Override
protected boolean doStart(LogSequenceNumber sequenceNumber) throws DataStorageManagerException {
    LOGGER.log(Level.FINE, " start BRIN index {0} uuid {1}", new Object[] { index.name, index.uuid });
    dataStorageManager.initIndex(tableSpaceUUID, index.uuid);
    bootSequenceNumber = sequenceNumber;
    if (LogSequenceNumber.START_OF_TIME.equals(sequenceNumber)) {
        /* Empty index (booting from the start) */
        this.data.boot(BlockRangeIndexMetadata.empty());
        LOGGER.log(Level.FINE, "loaded empty index {0}", new Object[] { index.name });
        return true;
    } else {
        IndexStatus status;
        try {
            status = dataStorageManager.getIndexStatus(tableSpaceUUID, index.uuid, sequenceNumber);
        } catch (DataStorageManagerException e) {
            LOGGER.log(Level.SEVERE, "cannot load index {0} due to {1}, it will be rebuilt", new Object[] { index.name, e });
            return false;
        }
        try {
            PageContents metadataBlock = PageContents.deserialize(status.indexData);
            this.data.boot(new BlockRangeIndexMetadata<>(metadataBlock.metadata));
        } catch (IOException e) {
            throw new DataStorageManagerException(e);
        } catch (UnsupportedMetadataVersionException e) {
            LOGGER.log(Level.SEVERE, "cannot load index {0} due to an old metadata version ({1}) found, it will be rebuilt", new Object[] { index.name, e.version });
            return false;
        }
        newPageId.set(status.newPageId);
        LOGGER.log(Level.INFO, "loaded index {0} {1} blocks", new Object[] { index.name, this.data.getNumBlocks() });
        return true;
    }
}
Also used : IndexStatus(herddb.storage.IndexStatus) DataStorageManagerException(herddb.storage.DataStorageManagerException) IOException(java.io.IOException)

Aggregations

IndexStatus (herddb.storage.IndexStatus)11 DataStorageManagerException (herddb.storage.DataStorageManagerException)10 IOException (java.io.IOException)8 Bytes (herddb.utils.Bytes)7 ArrayList (java.util.ArrayList)7 PostCheckpointAction (herddb.core.PostCheckpointAction)5 HashMap (java.util.HashMap)4 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)4 UncheckedIOException (java.io.UncheckedIOException)3 List (java.util.List)3 AtomicLong (java.util.concurrent.atomic.AtomicLong)3 LogSequenceNumber (herddb.log.LogSequenceNumber)2 ExtendedDataOutputStream (herddb.utils.ExtendedDataOutputStream)2 XXHash64Utils (herddb.utils.XXHash64Utils)2 HashSet (java.util.HashSet)2 Map (java.util.Map)2 Holder (herddb.utils.Holder)1 ManagedFile (herddb.utils.ManagedFile)1 SimpleBufferedOutputStream (herddb.utils.SimpleBufferedOutputStream)1 VisibleByteArrayOutputStream (herddb.utils.VisibleByteArrayOutputStream)1