Search in sources :

Example 1 with SealedSegmentsMapShard

use of io.pravega.controller.store.stream.records.SealedSegmentsMapShard in project pravega by pravega.

the class PersistentStreamBase method updateSealedSegmentSizes.

private CompletableFuture<Void> updateSealedSegmentSizes(Map<Long, Long> sealedSegmentSizes, OperationContext context) {
    Map<Integer, List<Long>> shards = sealedSegmentSizes.keySet().stream().collect(Collectors.groupingBy(this::getShardNumber));
    return Futures.allOf(shards.entrySet().stream().map(x -> {
        int shard = x.getKey();
        List<Long> segments = x.getValue();
        return Futures.exceptionallyComposeExpecting(getSealedSegmentSizesMapShardData(shard, context), DATA_NOT_FOUND_PREDICATE, () -> createSealedSegmentSizeMapShardIfAbsent(shard, context).thenCompose(v -> getSealedSegmentSizesMapShardData(shard, context))).thenCompose(mapShardData -> {
            SealedSegmentsMapShard mapShard = mapShardData.getObject();
            segments.forEach(z -> mapShard.addSealedSegmentSize(z, sealedSegmentSizes.get(z)));
            return updateSealedSegmentSizesMapShardData(shard, new VersionedMetadata<>(mapShard, mapShardData.getVersion()), context);
        });
    }).collect(Collectors.toList()));
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SealedSegmentsMapShard(io.pravega.controller.store.stream.records.SealedSegmentsMapShard) AtomicLong(java.util.concurrent.atomic.AtomicLong) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) LinkedList(java.util.LinkedList)

Example 2 with SealedSegmentsMapShard

use of io.pravega.controller.store.stream.records.SealedSegmentsMapShard in project pravega by pravega.

the class StreamMetadataStoreTest method testSealedSegmentSizeMapShard.

@Test(timeout = 30000)
public void testSealedSegmentSizeMapShard() throws Exception {
    String scope = "sealedMap";
    String stream = "sealedMap";
    createAndScaleStream(store, scope, stream, 2);
    SealedSegmentsMapShard shard = store.getSealedSegmentSizeMapShard(scope, stream, 0, null, executor).join();
    assertEquals(shard.getSize(NameUtils.computeSegmentId(0, 0)).longValue(), 0L);
    assertEquals(shard.getSize(NameUtils.computeSegmentId(1, 1)).longValue(), 1L);
    assertNull(shard.getSize(NameUtils.computeSegmentId(2, 2)));
}
Also used : SealedSegmentsMapShard(io.pravega.controller.store.stream.records.SealedSegmentsMapShard) Test(org.junit.Test)

Example 3 with SealedSegmentsMapShard

use of io.pravega.controller.store.stream.records.SealedSegmentsMapShard in project pravega by pravega.

the class StreamTestBase method testSealedSegmentSizesMapShards.

/**
 * Stream history.
 * epoch0 = 0, 1, 2, 3, 4
 * epoch1 = 5, 1, 2, 3, 4
 * epoch2 = 5, 6, 2, 3, 4
 * epoch3 = 5, 6, 7, 3, 4
 * epoch4 = 5, 6, 7, 8, 4
 * epoch5 = 5, 6, 7, 8, 9
 * epoch6 = 0`, 1`, 2`, 3`, 4`
 * epoch7 = 5`, 6`, 7`, 8`, 9`
 * epoch8 = 10, 6`, 7`, 8`, 9`
 * epoch9 = 10, 11, 7`, 8`, 9`
 * epoch10 = 10, 11, 12, 8`, 9`
 * epoch11 = 10, 11, 12, 13, 9`
 * epoch12 = 10, 11, 12, 13, 14
 */
@Test(timeout = 30000L)
public void testSealedSegmentSizesMapShards() {
    String scope = "sealedSizeTest";
    String name = "sealedSizeTest";
    int startingSegmentNumber = new Random().nextInt(2000);
    PersistentStreamBase stream = createScaleAndRollStreamForMultiChunkTests(name, scope, startingSegmentNumber, System::currentTimeMillis);
    OperationContext context = getContext();
    SealedSegmentsMapShard shard0 = stream.getSealedSegmentSizeMapShard(0, context).join();
    // 5 segments created in epoch 0 and 1 segment in epoch 1
    assertTrue(shard0.getSealedSegmentsSizeMap().keySet().stream().allMatch(x -> getEpoch(x) == 0 || getEpoch(x) == 1));
    assertEquals(5, shard0.getSealedSegmentsSizeMap().keySet().stream().filter(x -> getEpoch(x) == 0).collect(Collectors.toList()).size());
    assertEquals(1, shard0.getSealedSegmentsSizeMap().keySet().stream().filter(x -> getEpoch(x) == 1).collect(Collectors.toList()).size());
    // 1 segment created in epoch 2 and 1 segment in epoch 3
    SealedSegmentsMapShard shard1 = stream.getSealedSegmentSizeMapShard(1, context).join();
    assertTrue(shard1.getSealedSegmentsSizeMap().keySet().stream().allMatch(x -> getEpoch(x) == 2 || getEpoch(x) == 3));
    assertEquals(1, shard1.getSealedSegmentsSizeMap().keySet().stream().filter(x -> getEpoch(x) == 2).collect(Collectors.toList()).size());
    assertEquals(1, shard1.getSealedSegmentsSizeMap().keySet().stream().filter(x -> getEpoch(x) == 3).collect(Collectors.toList()).size());
    // 1 segment created in epoch 3 and 1 segment in epoch 4
    SealedSegmentsMapShard shard2 = stream.getSealedSegmentSizeMapShard(2, context).join();
    assertTrue(shard2.getSealedSegmentsSizeMap().keySet().stream().allMatch(x -> getEpoch(x) == 4 || getEpoch(x) == 5));
    assertEquals(1, shard2.getSealedSegmentsSizeMap().keySet().stream().filter(x -> getEpoch(x) == 4).count());
    assertEquals(1, shard2.getSealedSegmentsSizeMap().keySet().stream().filter(x -> getEpoch(x) == 5).count());
    // rolling transaction, 10 segments created across two epochs mapped to the shard
    SealedSegmentsMapShard shard3 = stream.getSealedSegmentSizeMapShard(3, context).join();
    assertTrue(shard3.getSealedSegmentsSizeMap().keySet().stream().allMatch(x -> getEpoch(x) == 6 || getEpoch(x) == 7));
    assertEquals(5, shard3.getSealedSegmentsSizeMap().keySet().stream().filter(x -> getEpoch(x) == 6).count());
    assertEquals(5, shard3.getSealedSegmentsSizeMap().keySet().stream().filter(x -> getEpoch(x) == 7).count());
    // 1 segment created in epoch 8 and 1 segment in epoch 9 but they are not sealed yet
    SealedSegmentsMapShard shard4 = stream.getSealedSegmentSizeMapShard(4, context).join();
    assertTrue(shard4.getSealedSegmentsSizeMap().isEmpty());
    // 1 segment created in epoch 10 and 1 segment in epoch 11 but they are not sealed yet
    SealedSegmentsMapShard shard5 = stream.getSealedSegmentSizeMapShard(5, context).join();
    assertTrue(shard5.getSealedSegmentsSizeMap().isEmpty());
    // 1 segment created in epoch 12 but nothing is sealed yet
    SealedSegmentsMapShard shard6 = stream.getSealedSegmentSizeMapShard(6, context).join();
    assertTrue(shard6.getSealedSegmentsSizeMap().isEmpty());
    // now seal all of them again
    EpochRecord activeEpoch = stream.getActiveEpoch(true, context).join();
    List<Map.Entry<Double, Double>> newRanges = new LinkedList<>();
    newRanges.add(new AbstractMap.SimpleEntry<>(0.0, 1.0));
    Map<Long, Long> sealedSizeMap = new HashMap<>();
    activeEpoch.getSegments().forEach(x -> sealedSizeMap.put(x.segmentId(), 100L));
    scaleStream(stream, System.currentTimeMillis(), Lists.newArrayList(activeEpoch.getSegmentIds()), newRanges, sealedSizeMap);
    // 1 segment created in epoch 8 and 1 segment in epoch 9
    shard4 = stream.getSealedSegmentSizeMapShard(4, context).join();
    assertTrue(shard4.getSealedSegmentsSizeMap().keySet().stream().allMatch(x -> getEpoch(x) == 8 || getEpoch(x) == 9));
    assertEquals(1, shard4.getSealedSegmentsSizeMap().keySet().stream().filter(x -> getEpoch(x) == 8).collect(Collectors.toList()).size());
    assertEquals(1, shard4.getSealedSegmentsSizeMap().keySet().stream().filter(x -> getEpoch(x) == 9).collect(Collectors.toList()).size());
    // 1 segment created in epoch 10 and 1 segment in epoch 11
    shard5 = stream.getSealedSegmentSizeMapShard(5, context).join();
    assertTrue(shard5.getSealedSegmentsSizeMap().keySet().stream().allMatch(x -> getEpoch(x) == 10 || getEpoch(x) == 11));
    assertEquals(1, shard5.getSealedSegmentsSizeMap().keySet().stream().filter(x -> getEpoch(x) == 10).collect(Collectors.toList()).size());
    assertEquals(1, shard5.getSealedSegmentsSizeMap().keySet().stream().filter(x -> getEpoch(x) == 11).collect(Collectors.toList()).size());
    // 1 segment created in epoch 12
    shard6 = stream.getSealedSegmentSizeMapShard(6, context).join();
    assertTrue(shard6.getSealedSegmentsSizeMap().keySet().stream().allMatch(x -> getEpoch(x) == 12));
    assertEquals(1, shard6.getSealedSegmentsSizeMap().keySet().stream().filter(x -> getEpoch(x) == 12).collect(Collectors.toList()).size());
}
Also used : TestOperationContext(io.pravega.controller.store.TestOperationContext) StreamSegmentRecord(io.pravega.controller.store.stream.records.StreamSegmentRecord) AssertExtensions(io.pravega.test.common.AssertExtensions) Random(java.util.Random) StreamConfiguration(io.pravega.client.stream.StreamConfiguration) VersionedMetadata(io.pravega.controller.store.VersionedMetadata) Mockito.anyBoolean(org.mockito.Mockito.anyBoolean) Map(java.util.Map) After(org.junit.After) Mockito.doAnswer(org.mockito.Mockito.doAnswer) EpochTransitionRecord(io.pravega.controller.store.stream.records.EpochTransitionRecord) StreamTruncationRecord(io.pravega.controller.store.stream.records.StreamTruncationRecord) ImmutableMap(com.google.common.collect.ImmutableMap) Set(java.util.Set) ActiveTxnRecord(io.pravega.controller.store.stream.records.ActiveTxnRecord) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) List(java.util.List) Optional(java.util.Optional) HistoryTimeSeries(io.pravega.controller.store.stream.records.HistoryTimeSeries) Futures(io.pravega.common.concurrent.Futures) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) CommittingTransactionsRecord(io.pravega.controller.store.stream.records.CommittingTransactionsRecord) NameUtils.computeSegmentId(io.pravega.shared.NameUtils.computeSegmentId) Exceptions(io.pravega.common.Exceptions) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) Mockito.spy(org.mockito.Mockito.spy) AtomicReference(java.util.concurrent.atomic.AtomicReference) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Lists(com.google.common.collect.Lists) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) LinkedList(java.util.LinkedList) SealedSegmentsMapShard(io.pravega.controller.store.stream.records.SealedSegmentsMapShard) Before(org.junit.Before) NameUtils.getEpoch(io.pravega.shared.NameUtils.getEpoch) NameUtils(io.pravega.shared.NameUtils) WriterMark(io.pravega.controller.store.stream.records.WriterMark) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Mockito.times(org.mockito.Mockito.times) Assert.assertNotEquals(org.junit.Assert.assertNotEquals) Mockito.verify(org.mockito.Mockito.verify) AtomicLong(java.util.concurrent.atomic.AtomicLong) StreamConfigurationRecord(io.pravega.controller.store.stream.records.StreamConfigurationRecord) AbstractMap(java.util.AbstractMap) EpochRecord(io.pravega.controller.store.stream.records.EpochRecord) Version(io.pravega.controller.store.Version) TestOperationContext(io.pravega.controller.store.TestOperationContext) ExecutorServiceHelpers(io.pravega.common.concurrent.ExecutorServiceHelpers) Collections(java.util.Collections) ScalingPolicy(io.pravega.client.stream.ScalingPolicy) Assert.assertEquals(org.junit.Assert.assertEquals) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) EpochRecord(io.pravega.controller.store.stream.records.EpochRecord) HashMap(java.util.HashMap) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) LinkedList(java.util.LinkedList) AbstractMap(java.util.AbstractMap) Random(java.util.Random) SealedSegmentsMapShard(io.pravega.controller.store.stream.records.SealedSegmentsMapShard) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) AtomicLong(java.util.concurrent.atomic.AtomicLong) Test(org.junit.Test)

Example 4 with SealedSegmentsMapShard

use of io.pravega.controller.store.stream.records.SealedSegmentsMapShard in project pravega by pravega.

the class ControllerMetadataJsonSerializerTest method testSealedSegmentsMapShard.

@Test
public void testSealedSegmentsMapShard() {
    Map<Long, Long> map = new HashMap<>();
    map.put(0L, 0L);
    map.put(1L, 0L);
    map.put(2L, 0L);
    SealedSegmentsMapShard record = SealedSegmentsMapShard.builder().sealedSegmentsSizeMap(map).build();
    testRecordSerialization(record, SealedSegmentsMapShard.class);
}
Also used : SealedSegmentsMapShard(io.pravega.controller.store.stream.records.SealedSegmentsMapShard) HashMap(java.util.HashMap) Test(org.junit.Test)

Aggregations

SealedSegmentsMapShard (io.pravega.controller.store.stream.records.SealedSegmentsMapShard)4 Test (org.junit.Test)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 LinkedList (java.util.LinkedList)2 List (java.util.List)2 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 Lists (com.google.common.collect.Lists)1 ScalingPolicy (io.pravega.client.stream.ScalingPolicy)1 StreamConfiguration (io.pravega.client.stream.StreamConfiguration)1 Exceptions (io.pravega.common.Exceptions)1 ExecutorServiceHelpers (io.pravega.common.concurrent.ExecutorServiceHelpers)1 Futures (io.pravega.common.concurrent.Futures)1 TestOperationContext (io.pravega.controller.store.TestOperationContext)1 Version (io.pravega.controller.store.Version)1 VersionedMetadata (io.pravega.controller.store.VersionedMetadata)1 ActiveTxnRecord (io.pravega.controller.store.stream.records.ActiveTxnRecord)1 CommittingTransactionsRecord (io.pravega.controller.store.stream.records.CommittingTransactionsRecord)1