Search in sources :

Example 16 with BinaryRow

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));
}
Also used : VersionedRowStore(org.apache.ignite.internal.table.distributed.storage.VersionedRowStore) StaticNodeFinder(org.apache.ignite.network.StaticNodeFinder) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) NamedThreadFactory(org.apache.ignite.internal.thread.NamedThreadFactory) Peer(org.apache.ignite.raft.client.Peer) ByteBufferRow(org.apache.ignite.internal.schema.ByteBufferRow) RaftGroupService(org.apache.ignite.raft.client.service.RaftGroupService) BinaryRow(org.apache.ignite.internal.schema.BinaryRow) SimpleDataRow(org.apache.ignite.internal.storage.basic.SimpleDataRow) DataRow(org.apache.ignite.internal.storage.DataRow) Timestamp(org.apache.ignite.internal.tx.Timestamp) RaftServerImpl(org.apache.ignite.internal.raft.server.impl.RaftServerImpl) HeapLockManager(org.apache.ignite.internal.tx.impl.HeapLockManager) PartitionListener(org.apache.ignite.internal.table.distributed.raft.PartitionListener) InternalTableImpl(org.apache.ignite.internal.table.distributed.storage.InternalTableImpl) NetworkAddress(org.apache.ignite.network.NetworkAddress) TxManagerImpl(org.apache.ignite.internal.tx.impl.TxManagerImpl) UUID(java.util.UUID) Nullable(org.jetbrains.annotations.Nullable) PartitionStorage(org.apache.ignite.internal.storage.PartitionStorage) Pair(org.apache.ignite.internal.util.Pair) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 17 with BinaryRow

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();
    });
}
Also used : AtomicReference(java.util.concurrent.atomic.AtomicReference) BinaryRow(org.apache.ignite.internal.schema.BinaryRow) CountDownLatch(java.util.concurrent.CountDownLatch) Subscription(java.util.concurrent.Flow.Subscription) StorageException(org.apache.ignite.internal.storage.StorageException)

Example 18 with BinaryRow

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());
    };
}
Also used : VersionedRowStore(org.apache.ignite.internal.table.distributed.storage.VersionedRowStore) BinaryRow(org.apache.ignite.internal.schema.BinaryRow) Row(org.apache.ignite.internal.schema.row.Row) ByteBufferRow(org.apache.ignite.internal.schema.ByteBufferRow) BinaryRow(org.apache.ignite.internal.schema.BinaryRow)

Example 19 with BinaryRow

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;
}
Also used : ColumnDescriptor(org.apache.ignite.internal.storage.index.SortedIndexDescriptor.ColumnDescriptor) BinaryRow(org.apache.ignite.internal.schema.BinaryRow) Row(org.apache.ignite.internal.schema.row.Row)

Example 20 with BinaryRow

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()));
}
Also used : ArrayList(java.util.ArrayList) Objects(java.util.Objects) BinaryRow(org.apache.ignite.internal.schema.BinaryRow) BinaryRow(org.apache.ignite.internal.schema.BinaryRow) Row(org.apache.ignite.internal.schema.row.Row) InternalTransaction(org.apache.ignite.internal.tx.InternalTransaction) Tuple(org.apache.ignite.table.Tuple) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

BinaryRow (org.apache.ignite.internal.schema.BinaryRow)57 Row (org.apache.ignite.internal.schema.row.Row)34 SchemaDescriptor (org.apache.ignite.internal.schema.SchemaDescriptor)22 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)19 MethodSource (org.junit.jupiter.params.provider.MethodSource)19 Column (org.apache.ignite.internal.schema.Column)18 ArrayList (java.util.ArrayList)13 NotNull (org.jetbrains.annotations.NotNull)11 IgniteException (org.apache.ignite.lang.IgniteException)10 MarshallerException (org.apache.ignite.internal.schema.marshaller.MarshallerException)9 CountDownLatch (java.util.concurrent.CountDownLatch)6 Subscription (java.util.concurrent.Flow.Subscription)6 Test (org.junit.jupiter.api.Test)5 Map (java.util.Map)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 TestObjectWithAllTypes (org.apache.ignite.internal.schema.testobjects.TestObjectWithAllTypes)4 HashMap (java.util.HashMap)3 UUID (java.util.UUID)3 Flow (java.util.concurrent.Flow)3 AtomicReference (java.util.concurrent.atomic.AtomicReference)3