use of org.apache.ignite.internal.storage.DataRow in project ignite-3 by apache.
the class ItInternalTableScanTest method setUp.
/**
* Prepare test environment.
* <ol>
* <li>Start network node.</li>
* <li>Start raft server.</li>
* <li>Prepare partitioned raft group.</li>
* <li>Prepare partitioned raft group service.</li>
* <li>Prepare internal table as a test object.</li>
* </ol>
*
* @throws Exception If any.
*/
@BeforeEach
public void setUp(TestInfo testInfo) throws Exception {
NetworkAddress nodeNetworkAddress = new NetworkAddress("localhost", 20_000);
network = ClusterServiceTestUtils.clusterService(testInfo, 20_000, new StaticNodeFinder(List.of(nodeNetworkAddress)), NETWORK_FACTORY);
network.start();
raftSrv = new RaftServerImpl(network, FACTORY);
raftSrv.start();
String grpName = "test_part_grp";
List<Peer> conf = List.of(new Peer(nodeNetworkAddress));
mockStorage = mock(PartitionStorage.class);
txManager = new TxManagerImpl(network, new HeapLockManager());
txManager.start();
UUID tblId = UUID.randomUUID();
raftSrv.startRaftGroup(grpName, new PartitionListener(tblId, new VersionedRowStore(mockStorage, txManager) {
@Override
protected Pair<BinaryRow, BinaryRow> versionedRow(@Nullable DataRow row, Timestamp timestamp) {
// Return as is.
return new Pair<>(new ByteBufferRow(row.valueBytes()), null);
}
}), conf);
executor = new ScheduledThreadPoolExecutor(20, new NamedThreadFactory(Loza.CLIENT_POOL_NAME));
RaftGroupService raftGrpSvc = RaftGroupServiceImpl.start(RAFT_GRP_ID, network, FACTORY, 10_000, conf, true, 200, executor).get(3, TimeUnit.SECONDS);
internalTbl = new InternalTableImpl(TEST_TABLE_NAME, tblId, Int2ObjectMaps.singleton(0, raftGrpSvc), 1, NetworkAddress::toString, txManager, mock(TableStorage.class));
}
use of org.apache.ignite.internal.storage.DataRow in project ignite-3 by apache.
the class RocksDbPartitionStorage method invoke.
/**
* {@inheritDoc}
*/
@Nullable
@Override
public <T> T invoke(SearchRow key, InvokeClosure<T> clo) throws StorageException {
try {
byte[] partitionKey = partitionKey(key);
byte[] existingDataBytes = data.get(partitionKey);
clo.call(existingDataBytes == null ? null : new DelegatingDataRow(key, existingDataBytes));
switch(clo.operationType()) {
case WRITE:
DataRow newRow = clo.newRow();
assert newRow != null;
byte[] value = newRow.valueBytes();
assert value != null;
data.put(partitionKey, value);
break;
case REMOVE:
data.delete(partitionKey);
break;
case NOOP:
break;
default:
throw new UnsupportedOperationException(String.valueOf(clo.operationType()));
}
return clo.result();
} catch (RocksDBException e) {
throw new StorageException("Failed to access data in the storage", e);
}
}
use of org.apache.ignite.internal.storage.DataRow in project ignite-3 by apache.
the class RocksDbPartitionStorage method insertAll.
/**
* {@inheritDoc}
*/
@Override
public Collection<DataRow> insertAll(List<? extends DataRow> rows) throws StorageException {
List<DataRow> cantInsert = new ArrayList<>();
try (var batch = new WriteBatch();
var opts = new WriteOptions()) {
for (DataRow row : rows) {
byte[] partitionKey = partitionKey(row);
if (data.get(partitionKey) == null) {
byte[] value = row.valueBytes();
assert value != null;
data.put(batch, partitionKey, value);
} else {
cantInsert.add(row);
}
}
db.write(opts, batch);
} catch (RocksDBException e) {
throw new StorageException("Filed to write data to the storage", e);
}
return cantInsert;
}
use of org.apache.ignite.internal.storage.DataRow in project ignite-3 by apache.
the class RocksDbPartitionStorage method writeAll.
/**
* {@inheritDoc}
*/
@Override
public void writeAll(List<? extends DataRow> rows) throws StorageException {
try (WriteBatch batch = new WriteBatch();
WriteOptions opts = new WriteOptions()) {
for (DataRow row : rows) {
byte[] value = row.valueBytes();
assert value != null;
data.put(batch, partitionKey(row), value);
}
db.write(opts, batch);
} catch (RocksDBException e) {
throw new StorageException("Filed to write data to the storage", e);
}
}
use of org.apache.ignite.internal.storage.DataRow in project ignite-3 by apache.
the class VersionedRowStore method scan.
/**
* Executes a scan.
*
* @param pred The predicate.
* @return The cursor.
*/
public Cursor<BinaryRow> scan(Predicate<SearchRow> pred) {
Cursor<DataRow> delegate = storage.scan(pred);
// TODO asch add tx support IGNITE-15087.
return new Cursor<BinaryRow>() {
@Nullable
private BinaryRow cur = null;
@Override
public void close() throws Exception {
delegate.close();
}
@NotNull
@Override
public Iterator<BinaryRow> iterator() {
return this;
}
@Override
public boolean hasNext() {
if (cur != null) {
return true;
}
if (delegate.hasNext()) {
DataRow row = delegate.next();
cur = versionedRow(row, null).getFirst();
// Skip tombstones.
return cur != null ? true : hasNext();
}
return false;
}
@Override
public BinaryRow next() {
BinaryRow next = cur;
cur = null;
assert next != null;
return next;
}
};
}
Aggregations