use of com.questdb.store.Partition in project questdb by bluestreak01.
the class KvIndexIntLambdaHeadRowSource method prepareCursor.
@Override
public RowCursor prepareCursor(PartitionSlice slice) {
try {
Partition partition = rec.partition = slice.partition.open();
KVIndex index = partition.getIndexForColumn(columnIndex);
FixedColumn col = partition.fixCol(columnIndex);
long lo = slice.lo - 1;
long hi = slice.calcHi ? partition.size() : slice.hi + 1;
rows.clear();
for (int i = 0, n = keys.size(); i < n; i++) {
IndexCursor c = index.cursor(keys.get(i) & buckets);
while (c.hasNext()) {
long r = rec.rowid = c.next();
if (r > lo && r < hi && col.getInt(r) == keys.get(i) && (filter == null || filter.getBool(rec))) {
rows.add(r);
break;
}
}
}
rows.sort();
cursor = 0;
return this;
} catch (JournalException e) {
throw new JournalRuntimeException(e);
}
}
use of com.questdb.store.Partition in project questdb by bluestreak01.
the class KvIndexIntListHeadRowSource method prepareCursor.
@Override
public RowCursor prepareCursor(PartitionSlice slice) {
try {
Partition partition = rec.partition = slice.partition.open();
KVIndex index = partition.getIndexForColumn(columnIndex);
FixedColumn col = partition.fixCol(columnIndex);
long lo = slice.lo - 1;
long hi = slice.calcHi ? partition.size() : slice.hi + 1;
rows.clear();
for (int i = 0, n = values.size(); i < n; i++) {
IndexCursor c = index.cursor(values.get(i) & buckets);
long r = -1;
boolean found = false;
while (c.hasNext()) {
r = rec.rowid = c.next();
if (r > lo && r < hi && col.getInt(r) == values.get(i) && (filter == null || filter.getBool(rec))) {
found = true;
break;
}
}
if (found) {
rows.add(r);
}
}
rows.sort();
keyIndex = 0;
return this;
} catch (JournalException e) {
throw new JournalRuntimeException(e);
}
}
use of com.questdb.store.Partition in project questdb by bluestreak01.
the class KvIndexLongListHeadRowSource method prepareCursor.
@Override
public RowCursor prepareCursor(PartitionSlice slice) {
try {
Partition partition = rec.partition = slice.partition.open();
KVIndex index = partition.getIndexForColumn(columnIndex);
FixedColumn col = partition.fixCol(columnIndex);
long lo = slice.lo - 1;
long hi = slice.calcHi ? partition.size() : slice.hi + 1;
rows.clear();
for (int i = 0, n = values.size(); i < n; i++) {
IndexCursor c = index.cursor((int) (values.get(i) & buckets));
long r = -1;
boolean found = false;
while (c.hasNext()) {
r = rec.rowid = c.next();
if (r > lo && r < hi && col.getLong(r) == values.get(i) && (filter == null || filter.getBool(rec))) {
found = true;
break;
}
}
if (found) {
rows.add(r);
}
}
rows.sort();
keyIndex = 0;
return this;
} catch (JournalException e) {
throw new JournalRuntimeException(e);
}
}
use of com.questdb.store.Partition in project questdb by bluestreak01.
the class JournalDeltaConsumer method doRead.
@Override
@SuppressWarnings("unchecked")
protected void doRead(ReadableByteChannel channel) throws JournalNetworkException {
try {
reset();
journalServerStateConsumer.read(channel);
this.state = journalServerStateConsumer.getValue();
if (state.getTxn() == -1) {
journal.notifyListener(JournalEvents.EVT_JNL_TRANSACTION_REFUSED);
throw new IncompatibleJournalException("Server refused txn for %s", journal.getLocation());
}
if (state.getTxn() < journal.getTxn()) {
journal.rollback(state.getTxn(), state.getTxPin());
return;
}
journal.beginTx();
createPartitions(state);
if (state.isSymbolTables()) {
journalSymbolTableConsumer.read(channel);
}
for (int i = 0, k = state.getNonLagPartitionCount(); i < k; i++) {
JournalServerState.PartitionMetadata meta = state.getMeta(i);
if (meta.getEmpty() == 0) {
PartitionDeltaConsumer partitionDeltaConsumer = getPartitionDeltaConsumer(meta.getPartitionIndex());
partitionDeltaConsumer.read(channel);
}
}
if (state.getLagPartitionName() == null && journal.hasIrregularPartition()) {
// delete lag partition
journal.removeIrregularPartition();
} else if (state.getLagPartitionName() != null) {
if (lagPartitionDeltaConsumer == null || !journal.hasIrregularPartition() || !state.getLagPartitionName().equals(journal.getIrregularPartition().getName())) {
Partition temp = journal.createTempPartition(state.getLagPartitionName());
lagPartitionDeltaConsumer = new PartitionDeltaConsumer(temp.open());
journal.setIrregularPartition(temp);
}
lagPartitionDeltaConsumer.read(channel);
}
} catch (JournalException e) {
throw new JournalNetworkException(e);
}
}
use of com.questdb.store.Partition in project questdb by bluestreak01.
the class JournalDeltaProducer method configure0.
private void configure0(Tx tx) throws JournalException {
if (LOG.isDebugEnabled()) {
LOG.debug().$("Journal ").$(journal.getLocation()).$(" size: ").$(journal.size()).$();
}
int startPartitionIndex;
long localRowID;
journalSymbolTableProducer.configure(tx);
journalServerState.setSymbolTables(journalSymbolTableProducer.hasContent());
// get non lag partition information
int nonLagPartitionCount = journal.nonLagPartitionCount();
if (tx.journalMaxRowID == -1) {
startPartitionIndex = 0;
localRowID = 0;
journalServerState.setNonLagPartitionCount(nonLagPartitionCount);
} else {
startPartitionIndex = Rows.toPartitionIndex(tx.journalMaxRowID);
localRowID = Rows.toLocalRowID(tx.journalMaxRowID);
if (startPartitionIndex < nonLagPartitionCount) {
// and start building fragment from that
if (localRowID >= journal.getPartition(startPartitionIndex, true).size()) {
localRowID = 0;
startPartitionIndex = startPartitionIndex + 1;
}
journalServerState.setNonLagPartitionCount(Math.max(0, nonLagPartitionCount - startPartitionIndex));
} else {
journalServerState.setNonLagPartitionCount(0);
}
}
// non-lag partition producers
partitionDeltaProducers.clear();
for (int i = startPartitionIndex; i < nonLagPartitionCount; i++) {
PartitionDeltaProducer producer = getPartitionDeltaProducer(i);
producer.configure(localRowID);
partitionDeltaProducers.add(producer);
Partition partition = journal.getPartition(i, false);
journalServerState.addPartitionMetadata(partition.getPartitionIndex(), partition.getInterval().getLo(), partition.getInterval().getHi(), (byte) (producer.hasContent() ? 0 : 1));
localRowID = 0;
}
// lag partition information
Partition lag = journal.getIrregularPartition();
journalServerState.setLagPartitionName(null);
if (lag != null) {
if (lagPartitionDeltaProducer == null || lagPartitionDeltaProducer.getPartition() != lag) {
lagPartitionDeltaProducer = new PartitionDeltaProducer(lag.open());
}
if (lag.getName().equals(tx.lagName)) {
lagPartitionDeltaProducer.configure(tx.lagSize);
} else {
lagPartitionDeltaProducer.configure(0);
}
if (lagPartitionDeltaProducer.hasContent()) {
journalServerState.setLagPartitionName(lag.getName());
journalServerState.setLagPartitionMetadata(lag.getPartitionIndex(), lag.getInterval().getLo(), lag.getInterval().getHi(), (byte) 0);
}
} else if (tx.lagName != null) {
journalServerState.setDetachLag(true);
}
}
Aggregations