use of org.apache.ignite.internal.tx.TxManager in project ignite-3 by apache.
the class ItTablePersistenceTest method createListener.
/**
* {@inheritDoc}
*/
@Override
public RaftGroupListener createListener(ClusterService service, Path workDir) {
return paths.entrySet().stream().filter(entry -> entry.getValue().equals(workDir)).map(Map.Entry::getKey).findAny().orElseGet(() -> {
TableTxManagerImpl txManager = new TableTxManagerImpl(service, new HeapLockManager());
// Init listener.
txManager.start();
PartitionListener listener = new PartitionListener(UUID.randomUUID(), new VersionedRowStore(new ConcurrentHashMapPartitionStorage(), txManager));
paths.put(listener, workDir);
return listener;
});
}
use of org.apache.ignite.internal.tx.TxManager in project ignite-3 by apache.
the class ItTablePersistenceTest method afterSnapshot.
/**
* {@inheritDoc}
*/
@Override
public void afterSnapshot(RaftGroupService service) throws Exception {
TxManager txManager = new TxManagerImpl(clientService(), new HeapLockManager());
managers.add(txManager);
txManager.start();
var table = new InternalTableImpl("table", UUID.randomUUID(), Int2ObjectMaps.singleton(0, service), 1, NetworkAddress::toString, txManager, mock(TableStorage.class));
table.upsert(SECOND_VALUE, null).get();
assertNotNull(table.get(SECOND_KEY, null).join());
txManager.stop();
}
use of org.apache.ignite.internal.tx.TxManager in project ignite-3 by apache.
the class RecordBinaryViewOperationsTest method createTableImpl.
@NotNull
private TableImpl createTableImpl(SchemaDescriptor schema) {
ClusterService clusterService = Mockito.mock(ClusterService.class, RETURNS_DEEP_STUBS);
Mockito.when(clusterService.topologyService().localMember().address()).thenReturn(DummyInternalTableImpl.ADDR);
LockManager lockManager = new HeapLockManager();
TxManager txManager = new TxManagerImpl(clusterService, lockManager);
MessagingService messagingService = MessagingServiceTestUtils.mockMessagingService(txManager);
Mockito.when(clusterService.messagingService()).thenReturn(messagingService);
DummyInternalTableImpl table = new DummyInternalTableImpl(new VersionedRowStore(new ConcurrentHashMapPartitionStorage(), txManager), txManager);
return new TableImpl(table, new DummySchemaManagerImpl(schema));
}
use of org.apache.ignite.internal.tx.TxManager in project ignite-3 by apache.
the class RecordViewOperationsTest method recordView.
/**
* Creates RecordView.
*/
private RecordViewImpl<TestObjectWithAllTypes> recordView() {
ClusterService clusterService = Mockito.mock(ClusterService.class, RETURNS_DEEP_STUBS);
Mockito.when(clusterService.topologyService().localMember().address()).thenReturn(DummyInternalTableImpl.ADDR);
TxManager txManager = new TxManagerImpl(clusterService, new HeapLockManager());
MessagingService messagingService = MessagingServiceTestUtils.mockMessagingService(txManager);
Mockito.when(clusterService.messagingService()).thenReturn(messagingService);
DummyInternalTableImpl table = new DummyInternalTableImpl(new VersionedRowStore(new ConcurrentHashMapPartitionStorage(), txManager), txManager);
Mapper<TestObjectWithAllTypes> recMapper = Mapper.of(TestObjectWithAllTypes.class);
Column[] valCols = { new Column("primitiveByteCol".toUpperCase(), INT8, false), new Column("primitiveShortCol".toUpperCase(), INT16, false), new Column("primitiveIntCol".toUpperCase(), INT32, false), new Column("primitiveFloatCol".toUpperCase(), FLOAT, false), new Column("primitiveDoubleCol".toUpperCase(), DOUBLE, false), new Column("byteCol".toUpperCase(), INT8, true), new Column("shortCol".toUpperCase(), INT16, true), new Column("intCol".toUpperCase(), INT32, true), new Column("longCol".toUpperCase(), INT64, true), new Column("nullLongCol".toUpperCase(), INT64, true), new Column("floatCol".toUpperCase(), FLOAT, true), new Column("doubleCol".toUpperCase(), DOUBLE, true), new Column("dateCol".toUpperCase(), DATE, true), new Column("timeCol".toUpperCase(), time(), true), new Column("dateTimeCol".toUpperCase(), datetime(), true), new Column("timestampCol".toUpperCase(), timestamp(), true), new Column("uuidCol".toUpperCase(), NativeTypes.UUID, true), new Column("bitmaskCol".toUpperCase(), NativeTypes.bitmaskOf(42), true), new Column("stringCol".toUpperCase(), STRING, true), new Column("nullBytesCol".toUpperCase(), BYTES, true), new Column("bytesCol".toUpperCase(), BYTES, true), new Column("numberCol".toUpperCase(), NativeTypes.numberOf(12), true), new Column("decimalCol".toUpperCase(), NativeTypes.decimalOf(19, 3), true) };
SchemaDescriptor schema = new SchemaDescriptor(1, new Column[] { new Column("primitiveLongCol".toUpperCase(), NativeTypes.INT64, false) }, valCols);
// Validate all types are tested.
Set<NativeTypeSpec> testedTypes = Arrays.stream(valCols).map(c -> c.type().spec()).collect(Collectors.toSet());
Set<NativeTypeSpec> missedTypes = Arrays.stream(NativeTypeSpec.values()).filter(t -> !testedTypes.contains(t)).collect(Collectors.toSet());
assertEquals(Collections.emptySet(), missedTypes);
return new RecordViewImpl<>(table, new DummySchemaManagerImpl(schema), recMapper);
}
use of org.apache.ignite.internal.tx.TxManager in project ignite-3 by apache.
the class TableManager method createTableLocally.
/**
* Creates local structures for a table.
*
* @param causalityToken Causality token.
* @param name Table name.
* @param tblId Table id.
* @param assignment Affinity assignment.
*/
private void createTableLocally(long causalityToken, String name, UUID tblId, List<List<ClusterNode>> assignment, SchemaDescriptor schemaDesc) {
int partitions = assignment.size();
var partitionsGroupsFutures = new ArrayList<CompletableFuture<RaftGroupService>>();
Path storageDir = partitionsStoreDir.resolve(name);
try {
Files.createDirectories(storageDir);
} catch (IOException e) {
throw new IgniteInternalException("Failed to create partitions store directory for " + name + ": " + e.getMessage(), e);
}
TableConfiguration tableCfg = tablesCfg.tables().get(name);
DataRegion dataRegion = dataRegions.computeIfAbsent(tableCfg.dataRegion().value(), dataRegionName -> {
DataRegion newDataRegion = engine.createDataRegion(dataStorageCfg.regions().get(dataRegionName));
try {
newDataRegion.start();
} catch (Exception e) {
try {
newDataRegion.stop();
} catch (Exception stopException) {
e.addSuppressed(stopException);
}
throw e;
}
return newDataRegion;
});
TableStorage tableStorage = engine.createTable(storageDir, tableCfg, dataRegion);
tableStorage.start();
for (int p = 0; p < partitions; p++) {
int partId = p;
try {
partitionsGroupsFutures.add(raftMgr.prepareRaftGroup(raftGroupName(tblId, p), assignment.get(p), () -> new PartitionListener(tblId, new VersionedRowStore(tableStorage.getOrCreatePartition(partId), txManager))));
} catch (NodeStoppingException e) {
throw new AssertionError("Loza was stopped before Table manager", e);
}
}
CompletableFuture.allOf(partitionsGroupsFutures.toArray(CompletableFuture[]::new)).thenRun(() -> {
try {
Int2ObjectOpenHashMap<RaftGroupService> partitionMap = new Int2ObjectOpenHashMap<>(partitions);
for (int p = 0; p < partitions; p++) {
CompletableFuture<RaftGroupService> future = partitionsGroupsFutures.get(p);
assert future.isDone();
RaftGroupService service = future.join();
partitionMap.put(p, service);
}
InternalTableImpl internalTable = new InternalTableImpl(name, tblId, partitionMap, partitions, netAddrResolver, txManager, tableStorage);
var schemaRegistry = new SchemaRegistryImpl(v -> {
if (!busyLock.enterBusy()) {
throw new IgniteException(new NodeStoppingException());
}
try {
return tableSchema(tblId, v);
} finally {
busyLock.leaveBusy();
}
}, () -> {
if (!busyLock.enterBusy()) {
throw new IgniteException(new NodeStoppingException());
}
try {
return latestSchemaVersion(tblId);
} finally {
busyLock.leaveBusy();
}
});
schemaRegistry.onSchemaRegistered(schemaDesc);
var table = new TableImpl(internalTable, schemaRegistry);
tablesVv.update(causalityToken, previous -> {
var val = previous == null ? new HashMap() : new HashMap<>(previous);
val.put(name, table);
return val;
}, th -> {
throw new IgniteInternalException(IgniteStringFormatter.format("Cannot create a table [name={}, id={}]", name, tblId), th);
});
tablesByIdVv.update(causalityToken, previous -> {
var val = previous == null ? new HashMap() : new HashMap<>(previous);
val.put(tblId, table);
return val;
}, th -> {
throw new IgniteInternalException(IgniteStringFormatter.format("Cannot create a table [name={}, id={}]", name, tblId), th);
});
completeApiCreateFuture(table);
fireEvent(TableEvent.CREATE, new TableEventParameters(causalityToken, table), null);
} catch (Exception e) {
fireEvent(TableEvent.CREATE, new TableEventParameters(causalityToken, tblId, name), e);
}
}).join();
}
Aggregations