use of herddb.utils.KeyValue in project herddb by diennea.
the class TableSpaceManager method sendTransactionsDump.
private void sendTransactionsDump(List<Transaction> batch, Channel channel, String dumpId, final int timeout) throws TimeoutException, InterruptedException {
if (batch.isEmpty()) {
return;
}
List<KeyValue> encodedTransactions = batch.stream().map(tr -> {
return new KeyValue(Bytes.from_long(tr.transactionId), Bytes.from_array(tr.serialize()));
}).collect(Collectors.toList());
long id = channel.generateRequestId();
try (Pdu response_to_transactionsData = channel.sendMessageWithPduReply(id, PduCodec.TablespaceDumpData.write(id, tableSpaceName, dumpId, "transactions", null, 0, 0, 0, null, encodedTransactions), timeout)) {
if (response_to_transactionsData.type != Pdu.TYPE_ACK) {
LOGGER.log(Level.SEVERE, "error response at transactionsData command");
}
}
batch.clear();
}
use of herddb.utils.KeyValue in project herddb by diennea.
the class TableSpaceRestoreSourceFromFile method nextTableDataChunk.
@Override
public List<KeyValue> nextTableDataChunk() throws DataStorageManagerException {
try {
int numRecords = in.readVInt();
if (Integer.MIN_VALUE == numRecords) {
// EndOfTableMarker
listener.log("tablefinished", "table finished after " + currentTableSize + " records", Collections.singletonMap("count", numRecords));
return null;
}
listener.log("sendtabledata", "sending " + numRecords + ", total " + currentTableSize, Collections.singletonMap("count", numRecords));
List<KeyValue> records = new ArrayList<>(numRecords);
for (int i = 0; i < numRecords; i++) {
Bytes key = in.readBytes();
Bytes value = in.readBytes();
records.add(new KeyValue(key, value));
}
currentTableSize += numRecords;
return records;
} catch (IOException err) {
throw new DataStorageManagerException(err);
}
}
use of herddb.utils.KeyValue in project herddb by diennea.
the class TableSpaceManager method sendDumpedCommitLog.
private void sendDumpedCommitLog(List<DumpedLogEntry> txlogentries, Channel channel, String dumpId, final int timeout) throws TimeoutException, InterruptedException {
List<KeyValue> batch = new ArrayList<>();
for (DumpedLogEntry e : txlogentries) {
batch.add(new KeyValue(Bytes.from_array(e.logSequenceNumber.serialize()), Bytes.from_array(e.entryData)));
}
long id = channel.generateRequestId();
try (Pdu response_to_txlog = channel.sendMessageWithPduReply(id, PduCodec.TablespaceDumpData.write(id, tableSpaceName, dumpId, "txlog", null, 0, 0, 0, null, batch), timeout)) {
if (response_to_txlog.type != Pdu.TYPE_ACK) {
LOGGER.log(Level.SEVERE, "error response at txlog command");
}
}
}
use of herddb.utils.KeyValue in project herddb by diennea.
the class TableSpaceRestoreSourceFromFile method nextTransactionLogChunk.
@Override
public List<KeyValue> nextTransactionLogChunk() throws DataStorageManagerException {
try {
int numRecords = in.readVInt();
listener.log("nexttxchunk", "sending " + numRecords + " tx log entries", Collections.singletonMap("count", numRecords));
List<KeyValue> records = new ArrayList<>(numRecords);
for (int i = 0; i < numRecords; i++) {
long ledgerId = in.readVLong();
long offset = in.readVLong();
Bytes value = in.readBytes();
records.add(new KeyValue(Bytes.from_array(new LogSequenceNumber(ledgerId, offset).serialize()), value));
}
return records;
} catch (IOException err) {
throw new DataStorageManagerException(err);
}
}
Aggregations