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)));
}
}
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();
}
}
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;
}
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");
}
}
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);
}
}
Aggregations