Search in sources :

Example 11 with ByteString

use of com.srotya.sidewinder.core.storage.ByteString 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)

Example 12 with ByteString

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

the class DiskMalloc method appendBufferPointersToDisk.

protected LinkedByteString appendBufferPointersToDisk(LinkedByteString seriesId, ByteString filename, int curr, long offset, int size, Integer tsBucket) throws IOException {
    lock.lock();
    try {
        ByteString[] split = filename.split("/");
        LinkedByteString line = new LinkedByteString(BUF_PARTS_LENGTH);
        line.concat(seriesId).concat(SEPARATOR).concat(cache.get(split[split.length - 1])).concat(SEPARATOR).concat(String.valueOf(curr)).concat(SEPARATOR).concat(String.valueOf(offset)).concat(SEPARATOR).concat(String.valueOf(size)).concat(SEPARATOR).concat(Integer.toHexString(tsBucket)).concat("\n");
        logger.fine("Measurement(" + measurementName + ")Appending pointer information to ptr file:" + line);
        // resize
        String strLine = line.toString();
        byte[] bytes = strLine.getBytes();
        if (ptrBuf.remaining() < bytes.length + Short.BYTES) {
            logger.fine("Need to resize ptrbuf because ptrBufRem:" + ptrBuf.remaining() + " line:" + bytes.length);
            int pos = ptrBuf.position();
            int newSize = pos + ptrFileIncrement;
            ptrBuf.force();
            ptrBuf = rafPtr.getChannel().map(MapMode.READ_WRITE, 0, newSize);
            // BUGFIX: missing pointer reset caused PTR file corruption
            ptrBuf.position(pos);
            logger.info("Resizing ptr file:" + ptrBuf.getInt(0) + " ptrcount:" + ptrCounter + " inc:" + ptrFileIncrement + " position:" + pos);
        }
        MiscUtils.writeStringToBuffer(strLine, ptrBuf);
        ptrBuf.putInt(0, ++ptrCounter);
        logger.fine(() -> "Measurement(" + measurementName + ") appending pointer information to ptr file:" + line + " pos:" + ptrBuf.position());
        return line;
    } finally {
        lock.unlock();
    }
}
Also used : LinkedByteString(com.srotya.sidewinder.core.storage.LinkedByteString) ByteString(com.srotya.sidewinder.core.storage.ByteString) LinkedByteString(com.srotya.sidewinder.core.storage.LinkedByteString) LinkedByteString(com.srotya.sidewinder.core.storage.LinkedByteString) ByteString(com.srotya.sidewinder.core.storage.ByteString)

Example 13 with ByteString

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

the class MappedBitmapTagIndex method searchRowKeysForTagFilter.

@Override
public Set<ByteString> searchRowKeysForTagFilter(TagFilter tagFilterTree) {
    logger.fine(() -> "Tag query:" + tagFilterTree);
    Set<ByteString> rowKeys = new HashSet<>();
    MutableRoaringBitmap evalFilterForTags = evalFilterForTags(tagFilterTree);
    if (evalFilterForTags != null) {
        bitmapToRowKeys(rowKeys, evalFilterForTags);
    } else {
        logger.fine(() -> "Tag query failed:" + tagFilterTree + " measurement:" + measurement.getDbName() + ":" + measurement.getMeasurementName());
    }
    return rowKeys;
}
Also used : MutableRoaringBitmap(org.roaringbitmap.buffer.MutableRoaringBitmap) ByteString(com.srotya.sidewinder.core.storage.ByteString) HashSet(java.util.HashSet)

Example 14 with ByteString

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

the class MappedBitmapTagIndex method bitmapToRowKeys.

private void bitmapToRowKeys(Collection<ByteString> rowKeys, MutableRoaringBitmap value) {
    logger.finest(() -> "Requesting conversion from bitmap to value");
    List<Series> ref = measurement.getSeriesList();
    for (Iterator<Integer> iterator = value.iterator(); iterator.hasNext(); ) {
        Integer idx = iterator.next();
        ByteString seriesId = (ByteString) ref.get(idx).getSeriesId();
        rowKeys.add(seriesId);
        logger.finest(() -> "Adding idx:" + idx + " resolving to seriesId:" + seriesId + " for bitmap extrapolation");
    }
}
Also used : Series(com.srotya.sidewinder.core.storage.Series) ByteString(com.srotya.sidewinder.core.storage.ByteString)

Example 15 with ByteString

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

the class PersistentMeasurement method loadEntry.

private void loadEntry(String entry) {
    String[] split = entry.split(MD_SEPARATOR);
    String fieldId = split[0];
    logger.fine("Loading Timeseries:" + fieldId);
    try {
        String[] split2 = fieldId.split(SERIESID_SEPARATOR);
        String seriesId = split2[0];
        ByteString key = new ByteString(seriesId);
        Integer seriesIdx = seriesMap.get(key);
        Series series = null;
        if (seriesIdx == null) {
            seriesIdx = Integer.parseInt(split[SERIES_MD_IDX], 16);
            series = new Series(key, seriesIdx);
            seriesMap.put(key, seriesIdx);
            seriesList.add(seriesIdx, series);
        } else {
            series = seriesList.get(seriesIdx);
        }
        if (enableMetricsCapture) {
            metricsTimeSeriesCounter.inc();
        }
        logger.fine("Intialized Timeseries:" + seriesId);
    } catch (NumberFormatException e) {
        logger.log(Level.SEVERE, "Failed to load series:" + entry, e);
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Series(com.srotya.sidewinder.core.storage.Series) ByteString(com.srotya.sidewinder.core.storage.ByteString) ByteString(com.srotya.sidewinder.core.storage.ByteString)

Aggregations

ByteString (com.srotya.sidewinder.core.storage.ByteString)19 LinkedByteString (com.srotya.sidewinder.core.storage.LinkedByteString)9 Series (com.srotya.sidewinder.core.storage.Series)7 Test (org.junit.Test)6 DataPointIterator (com.srotya.sidewinder.core.storage.DataPointIterator)5 Field (com.srotya.sidewinder.core.storage.Field)5 NoLock (com.srotya.sidewinder.core.storage.NoLock)5 TimeField (com.srotya.sidewinder.core.storage.TimeField)5 ValueField (com.srotya.sidewinder.core.storage.ValueField)5 HashMap (java.util.HashMap)5 BufferObject (com.srotya.sidewinder.core.storage.BufferObject)4 File (java.io.File)4 IOException (java.io.IOException)4 DataPoint (com.srotya.sidewinder.core.storage.DataPoint)3 MockMeasurement (com.srotya.sidewinder.core.storage.MockMeasurement)3 MappedByteBuffer (java.nio.MappedByteBuffer)3 HashSet (java.util.HashSet)3 Before (org.junit.Before)3 SimpleTagFilter (com.srotya.sidewinder.core.filters.SimpleTagFilter)2 DownsampleFunction (com.srotya.sidewinder.core.functions.iterative.DownsampleFunction)2