Search in sources :

Example 1 with ByteString

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

the class Archiver method deserializeFromStream.

public static TimeSeriesArchivalObject deserializeFromStream(DataInputStream bis) throws IOException {
    TimeSeriesArchivalObject bucketWraper = new TimeSeriesArchivalObject();
    bucketWraper.setDb(bis.readUTF());
    bucketWraper.setMeasurement(bis.readUTF());
    bucketWraper.setSeriesKey(new ByteString(bis.readUTF()));
    bucketWraper.setTsBucket(bis.readInt());
    byte[] buf = new byte[bis.readInt()];
    bis.read(buf);
    bucketWraper.setData(buf);
    return bucketWraper;
}
Also used : ByteString(com.srotya.sidewinder.core.storage.ByteString)

Example 2 with ByteString

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

the class TestMappedBitmapTagIndex method testIndexRecovery.

@Test
public void testIndexRecovery() throws IOException, InterruptedException {
    MiscUtils.delete(new File("target/s9"));
    String indexDir = "target/s9";
    new File(indexDir).mkdirs();
    PersistentMeasurement m = new PersistentMeasurement();
    Map<String, String> conf = new HashMap<>();
    m.configure(conf, engine, 4096, "d", "m", "target/s9/i/bitmap", "target/s9/d/bitmap", new DBMetadata(), null);
    MappedBitmapTagIndex index = new MappedBitmapTagIndex();
    index.configure(conf, "target/s9/i/bitmap", m);
    long ts = System.currentTimeMillis();
    for (int i = 0; i < 10_000; i++) {
        index.index("key", String.valueOf(i), i);
        ByteString valueOf = new ByteString(String.valueOf(i));
        m.getSeriesListAsList().add(new Series(valueOf, i));
    }
    ts = System.currentTimeMillis() - ts;
    System.out.println("Time:" + ts);
    for (int i = 0; i < 10_000; i++) {
        assertEquals(new HashSet<>(Arrays.asList(new ByteString(String.valueOf(i)))), index.searchRowKeysForTagFilter(new SimpleTagFilter(FilterType.EQUALS, "key", String.valueOf(i))));
    }
    for (int k = 0; k < 10; k++) {
        index = new MappedBitmapTagIndex();
        index.configure(conf, "target/s9/i/bitmap", m);
        for (int i = 0; i < 10_000; i++) {
            assertEquals(new HashSet<>(Arrays.asList(new ByteString(String.valueOf(i)))), index.searchRowKeysForTagFilter(new SimpleTagFilter(FilterType.EQUALS, "key", String.valueOf(i))));
        }
    }
}
Also used : DBMetadata(com.srotya.sidewinder.core.storage.DBMetadata) HashMap(java.util.HashMap) ByteString(com.srotya.sidewinder.core.storage.ByteString) SimpleTagFilter(com.srotya.sidewinder.core.filters.SimpleTagFilter) ByteString(com.srotya.sidewinder.core.storage.ByteString) Series(com.srotya.sidewinder.core.storage.Series) File(java.io.File) Test(org.junit.Test)

Example 3 with ByteString

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

the class TestMappedBitmapTagIndex method testMultiIndexRecovery.

@Test
public void testMultiIndexRecovery() throws IOException, InterruptedException {
    MiscUtils.delete(new File("target/s9"));
    String indexDir = "target/s9";
    new File(indexDir).mkdirs();
    PersistentMeasurement m = new PersistentMeasurement();
    Map<String, String> conf = new HashMap<>();
    m.configure(conf, engine, 4096, "d", "m", "target/s9/i/bitmap", "target/s9/d/bitmap", new DBMetadata(), null);
    MappedBitmapTagIndex index = new MappedBitmapTagIndex();
    index.configure(conf, "target/s9/i/bitmap", m);
    long ts = System.currentTimeMillis();
    for (int i = 0; i < 10_000; i++) {
        index.index("key", String.valueOf(i), i);
        index.index("key", String.valueOf(i - 1), i);
        ByteString valueOf = new ByteString(String.valueOf(i));
        m.getSeriesListAsList().add(new Series(valueOf, i));
    }
    ts = System.currentTimeMillis() - ts;
    System.out.println("Time:" + ts);
    for (int i = 0; i < 9999; i++) {
        assertEquals(new HashSet<>(Arrays.asList(new ByteString(String.valueOf(i)), new ByteString(String.valueOf(i + 1)))), index.searchRowKeysForTagFilter(new SimpleTagFilter(FilterType.EQUALS, "key", String.valueOf(i))));
    }
    for (int k = 0; k < 10; k++) {
        index = new MappedBitmapTagIndex();
        index.configure(conf, "target/s9/i/bitmap", m);
        for (int i = 1; i < 9999; i++) {
            assertEquals(new HashSet<>(Arrays.asList(new ByteString(String.valueOf(i)), new ByteString(String.valueOf(i + 1)))), index.searchRowKeysForTagFilter(new SimpleTagFilter(FilterType.EQUALS, "key", String.valueOf(i))));
        }
    }
}
Also used : DBMetadata(com.srotya.sidewinder.core.storage.DBMetadata) HashMap(java.util.HashMap) ByteString(com.srotya.sidewinder.core.storage.ByteString) SimpleTagFilter(com.srotya.sidewinder.core.filters.SimpleTagFilter) ByteString(com.srotya.sidewinder.core.storage.ByteString) Series(com.srotya.sidewinder.core.storage.Series) File(java.io.File) Test(org.junit.Test)

Example 4 with ByteString

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

the class DiskMalloc method seriesBufferMap.

@Override
public Map<ByteString, List<Entry<Integer, BufferObject>>> seriesBufferMap() throws FileNotFoundException, IOException {
    Map<String, MappedByteBuffer> bufferMap = new ConcurrentHashMap<>();
    File[] listFiles = new File(dataDirectory).listFiles(new FilenameFilter() {

        @Override
        public boolean accept(File dir, String name) {
            return name.endsWith(".dat");
        }
    });
    Arrays.sort(listFiles, new Comparator<File>() {

        @Override
        public int compare(File o1, File o2) {
            return o1.getName().compareTo(o2.getName());
        }
    });
    for (File dataFile : listFiles) {
        try {
            RandomAccessFile raf = new RandomAccessFile(dataFile, "rw");
            MappedByteBuffer map = raf.getChannel().map(MapMode.READ_WRITE, 0, dataFile.length());
            bufferMap.put(dataFile.getName(), map);
            logger.info("Recovering data file:" + dataDirectory + "/" + dataFile.getName());
            raf.close();
        } catch (Exception e) {
            logger.log(Level.SEVERE, "Failed to recover data files for measurement:" + measurementName, e);
        }
    }
    // files and this will prevent them from being overwritten
    if (listFiles.length > 0) {
        fcnt = Integer.parseInt(listFiles[listFiles.length - 1].getName().replace("data-", "").replace(".dat", "")) + 1;
    }
    Map<ByteString, List<Entry<Integer, BufferObject>>> seriesBuffers = new HashMap<>();
    sliceMappedBuffersForBuckets(bufferMap, seriesBuffers);
    return seriesBuffers;
}
Also used : BufferObject(com.srotya.sidewinder.core.storage.BufferObject) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) 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) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) FilenameFilter(java.io.FilenameFilter) MappedByteBuffer(java.nio.MappedByteBuffer) RandomAccessFile(java.io.RandomAccessFile) ArrayList(java.util.ArrayList) List(java.util.List) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File)

Example 5 with ByteString

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

the class DiskMalloc method createNewBuffer.

@Override
public BufferObject createNewBuffer(LinkedByteString fieldId, Integer tsBucket, int newSize) throws IOException {
    logger.fine(() -> "Seriesid:" + fieldId + " requesting buffer of size:" + newSize);
    if (rafActiveFile == null) {
        lock.lock();
        if (rafActiveFile == null) {
            filename = new ByteString(dataDirectory + "/data-" + String.format("%012d", fcnt) + ".dat");
            rafActiveFile = new RandomAccessFile(filename.toString(), "rwd");
            offset = 0;
            logger.info("Creating new datafile for measurement:" + filename);
            memoryMappedBuffer = rafActiveFile.getChannel().map(MapMode.READ_WRITE, 0, fileMapIncrement);
            fcnt++;
            if (enableMetricsCapture) {
                metricsFileRotation.inc();
            }
        }
        lock.unlock();
    }
    lock.lock();
    try {
        if (curr + newSize < 0 || curr + newSize > memoryMappedBuffer.remaining() + 1) {
            curr = 0;
            itr++;
            offset = (((long) (fileMapIncrement)) * itr);
            // requested
            if (offset >= maxFileSize) {
                itr = 0;
                logger.info("Rotating datafile for measurement:" + measurementName + " closing active file:" + filename);
                memoryMappedBuffer.force();
                rafActiveFile.close();
                rafActiveFile = null;
                return createNewBuffer(fieldId, tsBucket, newSize);
            }
            // used for GC testing and debugging
            if (oldBufferReferences != null) {
                oldBufferReferences.put(filename, new WeakReference<MappedByteBuffer>(memoryMappedBuffer));
            }
            memoryMappedBuffer = rafActiveFile.getChannel().map(MapMode.READ_WRITE, offset, fileMapIncrement);
            logger.fine("Buffer expansion:" + offset + "\t\t" + curr);
            if (enableMetricsCapture) {
                metricsBufferResize.inc();
                metricsBufferSize.inc(fileMapIncrement);
            }
        }
        LinkedByteString ptrKey = appendBufferPointersToDisk(fieldId, filename, curr, offset, newSize, tsBucket);
        ByteBuffer buf = memoryMappedBuffer.slice();
        buf.limit(newSize);
        curr = curr + newSize;
        memoryMappedBuffer.position(curr);
        logger.fine(() -> "Position:" + buf.position() + "\t" + buf.limit() + "\t" + buf.capacity());
        if (enableMetricsCapture) {
            metricsBufferCounter.inc();
        }
        return new BufferObject(ptrKey, buf);
    } finally {
        lock.unlock();
    }
}
Also used : BufferObject(com.srotya.sidewinder.core.storage.BufferObject) RandomAccessFile(java.io.RandomAccessFile) MappedByteBuffer(java.nio.MappedByteBuffer) LinkedByteString(com.srotya.sidewinder.core.storage.LinkedByteString) ByteString(com.srotya.sidewinder.core.storage.ByteString) LinkedByteString(com.srotya.sidewinder.core.storage.LinkedByteString) ByteBuffer(java.nio.ByteBuffer) MappedByteBuffer(java.nio.MappedByteBuffer)

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