Search in sources :

Example 11 with IndexStatus

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

the class MemoryHashIndexManager method checkpoint.

@Override
public List<PostCheckpointAction> checkpoint(LogSequenceNumber sequenceNumber, boolean pin) throws DataStorageManagerException {
    if (createdInTransaction > 0) {
        LOGGER.log(Level.INFO, "checkpoint for index " + index.name + " skipped, this index is created on transaction " + createdInTransaction + " which is not committed");
        return Collections.emptyList();
    }
    List<PostCheckpointAction> result = new ArrayList<>();
    LOGGER.log(Level.INFO, "flush index {0}", new Object[] { index.name });
    long pageId = newPageId.getAndIncrement();
    Holder<Long> count = new Holder<>();
    dataStorageManager.writeIndexPage(tableSpaceUUID, index.uuid, pageId, (out) -> {
        long entries = 0;
        // version
        out.writeVLong(1);
        // flags for future implementations
        out.writeVLong(0);
        out.writeVInt(data.size());
        for (Map.Entry<Bytes, List<Bytes>> entry : data.entrySet()) {
            out.writeArray(entry.getKey());
            List<Bytes> entrydata = entry.getValue();
            out.writeVInt(entrydata.size());
            for (Bytes v : entrydata) {
                out.writeArray(v);
                ++entries;
            }
        }
        count.value = entries;
    });
    IndexStatus indexStatus = new IndexStatus(index.name, sequenceNumber, newPageId.get(), Collections.singleton(pageId), null);
    result.addAll(dataStorageManager.indexCheckpoint(tableSpaceUUID, index.uuid, indexStatus, pin));
    LOGGER.log(Level.INFO, "checkpoint index {0} finished: logpos {1}, {2} entries, page {3}", new Object[] { index.name, sequenceNumber, Long.toString(count.value), Long.toString(pageId) });
    return result;
}
Also used : Holder(herddb.utils.Holder) ArrayList(java.util.ArrayList) PostCheckpointAction(herddb.core.PostCheckpointAction) Bytes(herddb.utils.Bytes) IndexStatus(herddb.storage.IndexStatus) AtomicLong(java.util.concurrent.atomic.AtomicLong) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

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