Search in sources :

Example 1 with Path

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);
    }
}
Also used : Path(com.questdb.std.str.Path)

Example 2 with Path

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);
        }
    }
}
Also used : Path(com.questdb.std.str.Path)

Example 3 with Path

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);
    }
}
Also used : Path(com.questdb.std.str.Path)

Example 4 with Path

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;
}
Also used : Path(com.questdb.std.str.Path)

Example 5 with Path

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;
}
Also used : Path(com.questdb.std.str.Path) DirectCharSequence(com.questdb.std.str.DirectCharSequence) NativeLPSZ(com.questdb.std.str.NativeLPSZ)

Aggregations

Path (com.questdb.std.str.Path)74 Test (org.junit.Test)46 File (java.io.File)8 Rnd (com.questdb.std.Rnd)7 LPSZ (com.questdb.std.str.LPSZ)6 NativeLPSZ (com.questdb.std.str.NativeLPSZ)5 NumericException (com.questdb.common.NumericException)3 RecordColumnMetadata (com.questdb.common.RecordColumnMetadata)3 DirectCharSequence (com.questdb.std.str.DirectCharSequence)3 StringSink (com.questdb.std.str.StringSink)3 RowCursor (com.questdb.common.RowCursor)2 CreateTableModel (com.questdb.griffin.lexer.model.CreateTableModel)2 ObjList (com.questdb.std.ObjList)2 JournalMetadata (com.questdb.store.factory.configuration.JournalMetadata)2 TestMicroClock (com.questdb.test.tools.TestMicroClock)2 ByteBuffer (java.nio.ByteBuffer)2 Record (com.questdb.common.Record)1 RecordCursor (com.questdb.common.RecordCursor)1 Chars (com.questdb.std.Chars)1 FilesFacade (com.questdb.std.FilesFacade)1