use of org.apache.ignite.internal.schema.BinaryRow 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.schema.BinaryRow in project ignite-3 by apache.
the class ItInternalTableScanTest method invalidRequestNtest.
/**
* Checks whether {@link IllegalArgumentException} is thrown and inner storage cursor is closes in case of invalid requested amount of
* items.
*
* @param reqAmount Amount of rows to request at a time.
* @throws Exception If Any.
*/
private void invalidRequestNtest(int reqAmount) throws InterruptedException {
// The latch that allows to await Subscriber.onComplete() before asserting test invariants
// and avoids the race between closing the cursor and stopping the node.
CountDownLatch subscriberFinishedLatch = new CountDownLatch(2);
when(mockStorage.scan(any())).thenAnswer(invocation -> {
var cursor = mock(Cursor.class);
doAnswer(invocationClose -> {
subscriberFinishedLatch.countDown();
return null;
}).when(cursor).close();
when(cursor.hasNext()).thenAnswer(hnInvocation -> {
throw new StorageException("test");
});
return cursor;
});
AtomicReference<Throwable> gotException = new AtomicReference<>();
internalTbl.scan(0, null).subscribe(new Subscriber<>() {
@Override
public void onSubscribe(Subscription subscription) {
subscription.request(reqAmount);
}
@Override
public void onNext(BinaryRow item) {
fail("Should never get here.");
}
@Override
public void onError(Throwable throwable) {
gotException.set(throwable);
subscriberFinishedLatch.countDown();
}
@Override
public void onComplete() {
fail("Should never get here.");
}
});
subscriberFinishedLatch.await();
assertThrows(IllegalArgumentException.class, () -> {
throw gotException.get();
});
}
use of org.apache.ignite.internal.schema.BinaryRow in project ignite-3 by apache.
the class ItTablePersistenceTest method snapshotCheckClosure.
/**
* {@inheritDoc}
*/
@Override
public BooleanSupplier snapshotCheckClosure(JraftServerImpl restarted, boolean interactedAfterSnapshot) {
VersionedRowStore storage = getListener(restarted, raftGroupId()).getStorage();
Row key = interactedAfterSnapshot ? SECOND_KEY : FIRST_KEY;
Row value = interactedAfterSnapshot ? SECOND_VALUE : FIRST_VALUE;
return () -> {
BinaryRow read = storage.get(key, null);
if (read == null) {
return false;
}
return Arrays.equals(value.bytes(), read.bytes());
};
}
use of org.apache.ignite.internal.schema.BinaryRow in project ignite-3 by apache.
the class PrefixComparator method compare.
/**
* Compares a given row with the configured prefix.
*
* @param binaryRow Row to compare.
* @return the value {@code 0} if the given row starts with the configured prefix;
* a value less than {@code 0} if the row's prefix is smaller than the prefix; and
* a value greater than {@code 0} if the row's prefix is larger than the prefix.
*/
int compare(BinaryRow binaryRow) {
var row = new Row(descriptor.asSchemaDescriptor(), binaryRow);
for (int i = 0; i < prefix.length; ++i) {
ColumnDescriptor columnDescriptor = descriptor.indexRowColumns().get(i);
int compare = compare(columnDescriptor.column(), row, prefix[i]);
if (compare != 0) {
return columnDescriptor.asc() ? compare : -compare;
}
}
return 0;
}
use of org.apache.ignite.internal.schema.BinaryRow in project ignite-3 by apache.
the class KeyValueBinaryViewImpl method removeAllAsync.
/**
* {@inheritDoc}
*/
@Override
@NotNull
public CompletableFuture<Collection<Tuple>> removeAllAsync(@Nullable Transaction tx, @NotNull Collection<Tuple> keys) {
Objects.requireNonNull(keys);
List<BinaryRow> keyRows = new ArrayList<>(keys.size());
for (Tuple keyRec : keys) {
final Row keyRow = marshal(keyRec, null);
keyRows.add(keyRow);
}
return tbl.deleteAll(keyRows, (InternalTransaction) tx).thenApply(t -> t.stream().filter(Objects::nonNull).map(this::wrap).map(TableRow::valueTuple).collect(Collectors.toList()));
}
Aggregations