use of io.pravega.controller.store.stream.records.CommittingTransactionsRecord in project pravega by pravega.
the class StreamMetadataStoreTest method scaleWithTxnForInconsistentScanerios.
@Test(timeout = 30000)
public void scaleWithTxnForInconsistentScanerios() throws Exception {
final String scope = "ScopeScaleWithTx";
final String stream = "StreamScaleWithTx1";
final ScalingPolicy policy = ScalingPolicy.fixed(2);
final StreamConfiguration configuration = StreamConfiguration.builder().scalingPolicy(policy).build();
long start = System.currentTimeMillis();
store.createScope(scope, null, executor).get();
store.createStream(scope, stream, configuration, start, null, executor).get();
store.setState(scope, stream, State.ACTIVE, null, executor).get();
UUID txnId = store.generateTransactionId(scope, stream, null, executor).join();
VersionedTransactionData tx1 = store.createTransaction(scope, stream, txnId, 100, 100, null, executor).get();
store.sealTransaction(scope, stream, txnId, true, Optional.of(tx1.getVersion()), "", Long.MIN_VALUE, null, executor).get();
long scaleTs = System.currentTimeMillis();
List<Long> scale1SealedSegments = Collections.singletonList(0L);
// run a scale on segment 1
VersionedMetadata<EpochTransitionRecord> versioned = store.submitScale(scope, stream, scale1SealedSegments, Arrays.asList(new AbstractMap.SimpleEntry<>(0.0, 0.25), new AbstractMap.SimpleEntry<>(0.25, 0.5)), scaleTs, null, null, executor).join();
EpochTransitionRecord response = versioned.getObject();
assertEquals(0, response.getActiveEpoch());
VersionedMetadata<State> state = store.getVersionedState(scope, stream, null, executor).join();
state = store.updateVersionedState(scope, stream, State.SCALING, state, null, executor).join();
store.startScale(scope, stream, false, versioned, state, null, executor).join();
store.scaleCreateNewEpochs(scope, stream, versioned, null, executor).join();
store.scaleSegmentsSealed(scope, stream, scale1SealedSegments.stream().collect(Collectors.toMap(x -> x, x -> 0L)), versioned, null, executor).join();
store.completeScale(scope, stream, versioned, null, executor).join();
store.setState(scope, stream, State.ACTIVE, null, executor).join();
// start second scale
versioned = store.submitScale(scope, stream, Collections.singletonList(1L), Arrays.asList(new AbstractMap.SimpleEntry<>(0.5, 0.75), new AbstractMap.SimpleEntry<>(0.75, 1.0)), scaleTs, null, null, executor).join();
response = versioned.getObject();
assertEquals(1, response.getActiveEpoch());
EpochRecord activeEpoch = store.getActiveEpoch(scope, stream, null, true, executor).join();
VersionedMetadata<CommittingTransactionsRecord> record = store.startCommitTransactions(scope, stream, 100, null, executor).join().getKey();
store.setState(scope, stream, State.COMMITTING_TXN, null, executor).join();
record = store.startRollingTxn(scope, stream, activeEpoch.getEpoch(), record, null, executor).join();
store.rollingTxnCreateDuplicateEpochs(scope, stream, Collections.emptyMap(), System.currentTimeMillis(), record, null, executor).join();
store.completeRollingTxn(scope, stream, Collections.emptyMap(), record, null, executor).join();
store.completeCommitTransactions(scope, stream, record, null, executor, Collections.emptyMap()).join();
store.setState(scope, stream, State.ACTIVE, null, executor).join();
state = store.getVersionedState(scope, stream, null, executor).join();
state = store.updateVersionedState(scope, stream, State.SCALING, state, null, executor).join();
versioned = store.submitScale(scope, stream, Collections.singletonList(1L), Arrays.asList(new AbstractMap.SimpleEntry<>(0.5, 0.75), new AbstractMap.SimpleEntry<>(0.75, 1.0)), scaleTs, null, null, executor).join();
response = versioned.getObject();
assertEquals(1, response.getActiveEpoch());
AssertExtensions.assertFutureThrows("attempting to create new segments against inconsistent epoch transition record", store.startScale(scope, stream, false, versioned, state, null, executor), e -> Exceptions.unwrap(e) instanceof IllegalStateException);
// verify that state is reset to active
State stateVal = store.getState(scope, stream, true, null, executor).join();
assertEquals(State.ACTIVE, stateVal);
}
use of io.pravega.controller.store.stream.records.CommittingTransactionsRecord in project pravega by pravega.
the class StreamTestBase method testCreateStream.
@Test(timeout = 30000L)
public void testCreateStream() {
OperationContext context = getContext();
PersistentStreamBase stream = createStream("scope", "stream", System.currentTimeMillis(), 2, 0);
assertEquals(State.ACTIVE, stream.getState(true, context).join());
EpochRecord activeEpoch = stream.getActiveEpoch(true, context).join();
assertEquals(0, activeEpoch.getEpoch());
assertEquals(2, activeEpoch.getSegments().size());
VersionedMetadata<StreamTruncationRecord> truncationRecord = stream.getTruncationRecord(context).join();
assertEquals(StreamTruncationRecord.EMPTY, truncationRecord.getObject());
VersionedMetadata<EpochTransitionRecord> etr = stream.getEpochTransition(context).join();
assertEquals(EpochTransitionRecord.EMPTY, etr.getObject());
VersionedMetadata<CommittingTransactionsRecord> ctr = stream.getVersionedCommitTransactionsRecord(context).join();
assertEquals(CommittingTransactionsRecord.EMPTY, ctr.getObject());
assertEquals(activeEpoch, stream.getEpochRecord(0, context).join());
AssertExtensions.assertFutureThrows("", stream.getEpochRecord(1, context), e -> Exceptions.unwrap(e) instanceof StoreException.DataNotFoundException);
}
Aggregations