use of com.questdb.std.str.Path in project questdb by bluestreak01.
the class TableReader method openPartition0.
private long openPartition0(int partitionIndex) {
try {
Path path = partitionPathGenerator.generate(this, partitionIndex);
if (ff.exists(path)) {
path.chopZ();
final long partitionSize = partitionIndex == partitionCount - 1 ? transientRowCount : readPartitionSize(ff, path, tempMem8b);
LOG.info().$("open partition ").utf8(path.$()).$(" [rowCount=").$(partitionSize).$(", transientRowCount=").$(transientRowCount).$(", partitionIndex=").$(partitionIndex).$(", partitionCount=").$(partitionCount).$(']').$();
if (partitionSize > 0) {
openPartitionColumns(path, getColumnBase(partitionIndex), partitionSize);
partitionRowCounts.setQuick(partitionIndex, partitionSize);
if (maxTimestamp != Numbers.LONG_NaN) {
if (reloadMethod == FIRST_TIME_PARTITIONED_RELOAD_METHOD) {
reloadMethod = PARTITIONED_RELOAD_METHOD;
} else if (reloadMethod == FIRST_TIME_NON_PARTITIONED_RELOAD_METHOD) {
reloadMethod = NON_PARTITIONED_RELOAD_METHOD;
}
}
}
return partitionSize;
}
return -1;
} finally {
path.trimTo(rootLen);
}
}
use of com.questdb.std.str.Path in project questdb by bluestreak01.
the class TableReader method reshuffleColumns.
private void reshuffleColumns(int columnCount, long pTransitionIndex) {
final long pIndexBase = pTransitionIndex + 8;
final long pState = pIndexBase + columnCount * 8;
for (int partitionIndex = 0; partitionIndex < partitionCount; partitionIndex++) {
int base = getColumnBase(partitionIndex);
try {
Path path = partitionPathGenerator.generate(this, partitionIndex);
final long partitionRowCount = partitionRowCounts.getQuick(partitionIndex);
Unsafe.getUnsafe().setMemory(pState, columnCount, (byte) 0);
for (int i = 0; i < columnCount; i++) {
if (isEntryToBeProcessed(pState, i)) {
final int copyFrom = Unsafe.getUnsafe().getInt(pIndexBase + i * 8) - 1;
if (copyFrom == i) {
// It appears that column hasn't changed its position. There are three possibilities here:
// 1. Column has been deleted and re-added by the same name. We must check if file
// descriptor is still valid. If it isn't, reload the column from disk
// 2. Column has been forced out of the reader via closeColumnForRemove(). This is required
// on Windows before column can be deleted. In this case we must check for marker
// instance and the column from disk
// 3. Column hasn't been altered and we can skip to next column.
ReadOnlyColumn col = columns.getQuick(getPrimaryColumnIndex(base, i));
if ((col instanceof ReadOnlyMemory && col.isDeleted()) || col instanceof ForceNullColumn) {
reloadColumnAt(path, columns, columnTops, bitmapIndexes, base, i, partitionRowCount);
}
continue;
}
if (copyFrom > -1) {
fetchColumnsFrom(this.columns, this.columnTops, this.bitmapIndexes, base, copyFrom);
copyColumnsTo(this.columns, this.columnTops, this.bitmapIndexes, base, i, partitionRowCount);
int copyTo = Unsafe.getUnsafe().getInt(pIndexBase + i * 8 + 4) - 1;
while (copyTo > -1 && isEntryToBeProcessed(pState, copyTo)) {
copyColumnsTo(this.columns, this.columnTops, this.bitmapIndexes, base, copyTo, partitionRowCount);
copyTo = Unsafe.getUnsafe().getInt(pIndexBase + (copyTo - 1) * 8 + 4);
}
Misc.free(tempCopyStruct.mem1);
Misc.free(tempCopyStruct.mem2);
Misc.free(tempCopyStruct.bitmapIndexReader);
} else {
// new instance
reloadColumnAt(path, columns, columnTops, bitmapIndexes, base, i, partitionRowCount);
}
}
}
for (int i = columnCount; i < this.columnCount; i++) {
Misc.free(columns.getQuick(getPrimaryColumnIndex(base, i)));
Misc.free(columns.getQuick(getSecondaryColumnIndex(base, i)));
}
} finally {
path.trimTo(rootLen);
}
}
}
use of com.questdb.std.str.Path in project questdb by bluestreak01.
the class TableReader method countDefaultPartitions.
private void countDefaultPartitions() {
if (maxTimestamp == Numbers.LONG_NaN) {
partitionCount = 0;
} else {
Path path = pathGenDefault();
partitionCount = ff.exists(path) ? 1 : 0;
path.trimTo(rootLen);
}
}
use of com.questdb.std.str.Path in project questdb by bluestreak01.
the class Files method mkdirs.
public static int mkdirs(LPSZ path, int mode) {
try (Path pp = new Path()) {
for (int i = 0, n = path.length(); i < n; i++) {
char c = path.charAt(i);
if (c == File.separatorChar) {
if (i == 2 && Os.type == Os.WINDOWS && path.charAt(1) == ':') {
pp.put(c);
continue;
}
pp.$();
if (pp.length() > 0 && !Files.exists(pp)) {
int r = Files.mkdir(pp, mode);
if (r != 0) {
return r;
}
}
pp.chopZ();
}
pp.put(c);
}
}
return 0;
}
use of com.questdb.std.str.Path in project questdb by bluestreak01.
the class $ColsRecordSource method prepareCursor.
@Override
public RecordCursor prepareCursor(ReaderFactory factory, CancellationHandler cancellationHandler) {
records.clear();
NativeLPSZ name = tlNativeLpsz.get();
int bufSz = metaSize;
long buf = Unsafe.malloc(bufSz);
DirectCharSequence dcs = tlDcs.get();
try {
String base = factory.getConfiguration().getJournalBase().getAbsolutePath();
Path path = tlPath.get().of(base).$();
long find = Files.findFirst(path);
if (find > 0) {
try {
long p = -1;
Path compositePath = tlCompositePath.get();
do {
cancellationHandler.check();
if (Files.findType(find) == Files.DT_DIR) {
name.of(Files.findName(find));
if (Files.isDots(name)) {
continue;
}
compositePath.of(base).concat(name).concat(JournalConfiguration.FILE_NAME).$();
if (Files.exists(compositePath)) {
long fd = Files.openRO(compositePath);
if (fd < 0) {
LOG.error().$("Cannot open: ").$(compositePath).$(" [").$(Os.errno()).$(']').$();
continue;
}
int columnCount;
int partitionBy;
int timestampIndex;
try {
long len = Files.length(compositePath);
// don't bother with huge meta files. There is a high chance of them being fake.
if (len > maxMetaSize) {
LOG.error().$("File : ").$(compositePath).$(" is too large [").$(len).$(']').$();
continue;
}
if (len > bufSz) {
Unsafe.free(buf, bufSz);
buf = Unsafe.malloc(bufSz = (int) len);
}
Files.read(fd, buf, (int) len, 0);
// skip over append offset
long readPtr = buf + 8;
// skip over ID string
readPtr += Unsafe.getUnsafe().getInt(readPtr) * 2 + 4;
// // skip over location string
// readPtr += Unsafe.getUnsafe().getInt(readPtr) * 2 + 4;
partitionBy = Unsafe.getUnsafe().getInt(readPtr);
columnCount = Unsafe.getUnsafe().getInt(readPtr + 4);
timestampIndex = Unsafe.getUnsafe().getInt(readPtr + 8);
readPtr += 12;
for (int i = 0; i < columnCount; i++) {
p = records.beginRecord(p);
// table_name
records.appendStr(name);
// column_name
int l = Unsafe.getUnsafe().getInt(readPtr) * 2;
readPtr += 4;
records.appendStr(dcs.of(readPtr, readPtr + l));
readPtr += l;
// column_type
records.appendInt(Unsafe.getUnsafe().getInt(readPtr));
// skip size and avgsize
readPtr += 12;
// timestamp
records.appendBool(i == timestampIndex);
// partition_by
records.appendInt(i == timestampIndex ? partitionBy : SymbolTable.VALUE_IS_NULL);
// indexed
records.appendBool(Unsafe.getBool(readPtr));
// skip 2 ints
readPtr += 9;
// index_buckets
records.appendInt(Unsafe.getUnsafe().getInt(readPtr));
readPtr += 4;
l = Unsafe.getUnsafe().getInt(readPtr);
readPtr += 4;
if (l > -1) {
readPtr += (l * 2);
}
readPtr += 1;
}
} finally {
Files.close(fd);
}
}
}
} while (Files.findNext(find) > 0);
} finally {
Files.findClose(find);
}
}
} finally {
Unsafe.free(buf, bufSz);
}
records.toTop();
return records;
}
Aggregations