Search in sources :

Example 6 with BufferObject

use of com.srotya.sidewinder.core.storage.BufferObject in project sidewinder by srotya.

the class MemMalloc method createNewBuffer.

public BufferObject createNewBuffer(LinkedByteString seriesId, Integer tsBucket, int newSize) throws IOException {
    ByteBuffer allocateDirect = ByteBuffer.allocateDirect(newSize);
    LinkedByteString str = new LinkedByteString().concat(seriesId);
    str.concat(STR2).concat(String.valueOf(tsBucket));
    return new BufferObject(str, allocateDirect);
}
Also used : BufferObject(com.srotya.sidewinder.core.storage.BufferObject) LinkedByteString(com.srotya.sidewinder.core.storage.LinkedByteString) ByteBuffer(java.nio.ByteBuffer)

Example 7 with BufferObject

use of com.srotya.sidewinder.core.storage.BufferObject in project sidewinder by srotya.

the class PersistentMeasurement method loadTimeseriesFromMeasurements.

@Override
public void loadTimeseriesFromMeasurements() throws IOException {
    String mdFilePath = getMetadataPath();
    File file = new File(mdFilePath);
    if (!file.exists()) {
        logger.warning("Metadata file missing for measurement:" + measurementName);
        return;
    } else {
        logger.fine("Metadata file exists:" + file.getAbsolutePath());
    }
    List<String> seriesEntries = MiscUtils.readAllLines(file);
    try {
        loadSeriesEntries(seriesEntries);
    } catch (Exception e) {
        throw new IOException(e);
    }
    Map<String, List<Entry<String, BufferObject>>> seriesBuffers = malloc.seriesBufferMap();
    for (Entry<String, List<Entry<String, BufferObject>>> entry : seriesBuffers.entrySet()) {
        String[] split = entry.getKey().split(SERIESID_SEPARATOR);
        Integer seriesId = seriesMap.get(split[0]);
        SeriesFieldMap ts = seriesList.get(seriesId);
        List<Entry<String, BufferObject>> list = entry.getValue();
        if (list != null) {
            try {
                ts.get(split[1]).loadBucketMap(list);
            } catch (Exception e) {
                logger.log(Level.SEVERE, "Failed to load bucket map for:" + entry.getKey() + ":" + measurementName, e);
            }
        }
    }
    if (compactOnStart) {
        compact();
    }
    logger.info("Loaded measurement:" + measurementName);
}
Also used : BufferObject(com.srotya.sidewinder.core.storage.BufferObject) IOException(java.io.IOException) SeriesFieldMap(com.srotya.sidewinder.core.storage.SeriesFieldMap) IOException(java.io.IOException) Entry(java.util.Map.Entry) ArrayList(java.util.ArrayList) List(java.util.List) File(java.io.File)

Example 8 with BufferObject

use of com.srotya.sidewinder.core.storage.BufferObject in project sidewinder by srotya.

the class DiskMalloc method sliceMappedBuffersForBuckets.

private void sliceMappedBuffersForBuckets(Map<String, MappedByteBuffer> bufferMap, Map<ByteString, List<Entry<Integer, BufferObject>>> seriesBuffers) throws IOException {
    ptrCounter = 0;
    initializePtrFile();
    for (int i = 0; i < ptrCounter; i++) {
        String line = MiscUtils.getStringFromBuffer(ptrBuf).trim();
        String[] splits = line.split("\\" + SEPARATOR);
        logger.finer("Reading line:" + Arrays.toString(splits));
        String fileName = splits[1];
        int positionOffset = Integer.parseInt(splits[3]);
        String seriesIdStr = splits[0];
        int pointer = Integer.parseInt(splits[2]);
        int size = Integer.parseInt(splits[4]);
        MappedByteBuffer buf = bufferMap.get(fileName);
        int position = positionOffset + pointer;
        buf.position(position);
        String tsBucket = splits[5];
        ByteBuffer slice = buf.slice();
        slice.limit(size);
        ByteString seriesId = new ByteString(seriesIdStr);
        LinkedByteString bsLine = new LinkedByteString(BUF_PARTS_LENGTH);
        bsLine.concat(seriesId).concat(SEPARATOR).concat(cache.get(new ByteString(splits[1]))).concat(SEPARATOR).concat(new ByteString(splits[2])).concat(SEPARATOR).concat(new ByteString(splits[3])).concat(SEPARATOR).concat(new ByteString(splits[4]));
        List<Entry<Integer, BufferObject>> list = seriesBuffers.get(seriesId);
        if (list == null) {
            list = new ArrayList<>();
            seriesBuffers.put(seriesId, list);
        }
        list.add(new AbstractMap.SimpleEntry<>(Integer.parseInt(tsBucket, 16), new BufferObject(bsLine, slice)));
    }
}
Also used : BufferObject(com.srotya.sidewinder.core.storage.BufferObject) LinkedByteString(com.srotya.sidewinder.core.storage.LinkedByteString) ByteString(com.srotya.sidewinder.core.storage.ByteString) LinkedByteString(com.srotya.sidewinder.core.storage.LinkedByteString) ByteString(com.srotya.sidewinder.core.storage.ByteString) ByteBuffer(java.nio.ByteBuffer) MappedByteBuffer(java.nio.MappedByteBuffer) AbstractMap(java.util.AbstractMap) Entry(java.util.Map.Entry) MappedByteBuffer(java.nio.MappedByteBuffer) LinkedByteString(com.srotya.sidewinder.core.storage.LinkedByteString)

Aggregations

BufferObject (com.srotya.sidewinder.core.storage.BufferObject)8 ByteBuffer (java.nio.ByteBuffer)5 MappedByteBuffer (java.nio.MappedByteBuffer)5 ByteString (com.srotya.sidewinder.core.storage.ByteString)4 LinkedByteString (com.srotya.sidewinder.core.storage.LinkedByteString)4 Entry (java.util.Map.Entry)4 File (java.io.File)3 IOException (java.io.IOException)3 RandomAccessFile (java.io.RandomAccessFile)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 AbstractMap (java.util.AbstractMap)2 ByteStringCache (com.srotya.sidewinder.core.storage.ByteString.ByteStringCache)1 Series (com.srotya.sidewinder.core.storage.Series)1 SeriesFieldMap (com.srotya.sidewinder.core.storage.SeriesFieldMap)1 FileNotFoundException (java.io.FileNotFoundException)1 FilenameFilter (java.io.FilenameFilter)1 HashMap (java.util.HashMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1