@Test public void testWithOldHistoryNoPreviousIsPartiallyRepaired() throws UnknownHostException { MockedHost host1 = new MockedHost("127.0.0.1"); MockedHost host2 = new MockedHost("127.0.0.2"); LongTokenRange longTokenRange1 = new LongTokenRange(1, 2); LongTokenRange longTokenRange2 = new LongTokenRange(2, 3); ImmutableSet<Host> replicas = getReplicas(host1, host2); ImmutableSet<InetAddress> replicaAddresses = getReplicaAddresses(host1, host2); Map<LongTokenRange, ImmutableSet<Host>> tokenToHostMap = new HashMap<>(); tokenToHostMap.put(longTokenRange1, replicas); tokenToHostMap.put(longTokenRange2, replicas); long range1RepairedAt = 1; long range2RepairedAt = 2; RepairEntry repairEntry1 = new RepairEntry(longTokenRange1, range1RepairedAt, replicaAddresses, "SUCCESS"); RepairEntry repairEntry2 = new RepairEntry(longTokenRange2, range2RepairedAt, Collections.singleton(host1.getAddress()), "SUCCESS"); when(mockReplicationState.getTokenRangeToReplicas(eq(TABLE_REFERENCE))).thenReturn(tokenToHostMap); RepairHistoryProvider repairHistoryProvider = new MockedRepairHistoryProvider(TABLE_REFERENCE, repairEntry1, repairEntry2); VnodeRepairStates expectedVnodeRepairStates = VnodeRepairStates.newBuilder(Arrays.asList( new VnodeRepairState(longTokenRange1, replicas, range1RepairedAt), new VnodeRepairState(longTokenRange2, replicas, VnodeRepairState.UNREPAIRED))) .build(); VnodeRepairStateFactory vnodeRepairStateFactory = new VnodeRepairStateFactoryImpl(mockReplicationState, repairHistoryProvider); VnodeRepairStates actualVnodeRepairStates = vnodeRepairStateFactory.calculateNewState(TABLE_REFERENCE, null); assertThat(actualVnodeRepairStates).isEqualTo(expectedVnodeRepairStates); }
@Override public VnodeRepairStates calculateNewState(TableReference tableReference, RepairStateSnapshot previous) { Map<LongTokenRange, ImmutableSet<Host>> tokenRangeToReplicaMap = myReplicationState.getTokenRangeToReplicas(tableReference); long lastRepairedAt = previousLastRepairedAt(previous, tokenRangeToReplicaMap); long now = System.currentTimeMillis(); Iterator<RepairEntry> repairEntryIterator; if (lastRepairedAt == VnodeRepairState.UNREPAIRED) { LOG.debug("No last repaired at found for {}, iterating over all repair entries", tableReference); repairEntryIterator = myRepairHistoryProvider.iterate(tableReference, now, (repairEntry) -> acceptRepairEntries(repairEntry, tokenRangeToReplicaMap)); } else { LOG.debug("Table {} last repaired at {}, iterating repir entries until that time", tableReference, lastRepairedAt); repairEntryIterator = myRepairHistoryProvider.iterate(tableReference, now, lastRepairedAt, (repairEntry) -> acceptRepairEntries(repairEntry, tokenRangeToReplicaMap)); } return generateVnodeRepairStates(lastRepairedAt, previous, repairEntryIterator, tokenRangeToReplicaMap); }
VnodeRepairStateFactoryImpl implements VnodeRepairStateFactory { @Override public VnodeRepairStates calculateNewState(TableReference tableReference, RepairStateSnapshot previous) { Map<LongTokenRange, ImmutableSet<Host>> tokenRangeToReplicaMap = myReplicationState.getTokenRangeToReplicas(tableReference); long lastRepairedAt = previousLastRepairedAt(previous, tokenRangeToReplicaMap); long now = System.currentTimeMillis(); Iterator<RepairEntry> repairEntryIterator; if (lastRepairedAt == VnodeRepairState.UNREPAIRED) { LOG.debug("No last repaired at found for {}, iterating over all repair entries", tableReference); repairEntryIterator = myRepairHistoryProvider.iterate(tableReference, now, (repairEntry) -> acceptRepairEntries(repairEntry, tokenRangeToReplicaMap)); } else { LOG.debug("Table {} last repaired at {}, iterating repir entries until that time", tableReference, lastRepairedAt); repairEntryIterator = myRepairHistoryProvider.iterate(tableReference, now, lastRepairedAt, (repairEntry) -> acceptRepairEntries(repairEntry, tokenRangeToReplicaMap)); } return generateVnodeRepairStates(lastRepairedAt, previous, repairEntryIterator, tokenRangeToReplicaMap); } }
VnodeRepairStateFactoryImpl implements VnodeRepairStateFactory { @Override public VnodeRepairStates calculateNewState(TableReference tableReference, RepairStateSnapshot previous) { Map<LongTokenRange, ImmutableSet<Host>> tokenRangeToReplicaMap = myReplicationState.getTokenRangeToReplicas(tableReference); long lastRepairedAt = previousLastRepairedAt(previous, tokenRangeToReplicaMap); long now = System.currentTimeMillis(); Iterator<RepairEntry> repairEntryIterator; if (lastRepairedAt == VnodeRepairState.UNREPAIRED) { LOG.debug("No last repaired at found for {}, iterating over all repair entries", tableReference); repairEntryIterator = myRepairHistoryProvider.iterate(tableReference, now, (repairEntry) -> acceptRepairEntries(repairEntry, tokenRangeToReplicaMap)); } else { LOG.debug("Table {} last repaired at {}, iterating repir entries until that time", tableReference, lastRepairedAt); repairEntryIterator = myRepairHistoryProvider.iterate(tableReference, now, lastRepairedAt, (repairEntry) -> acceptRepairEntries(repairEntry, tokenRangeToReplicaMap)); } return generateVnodeRepairStates(lastRepairedAt, previous, repairEntryIterator, tokenRangeToReplicaMap); } VnodeRepairStateFactoryImpl(ReplicationState replicationState, RepairHistoryProvider repairHistoryProvider); }
VnodeRepairStateFactoryImpl implements VnodeRepairStateFactory { @Override public VnodeRepairStates calculateNewState(TableReference tableReference, RepairStateSnapshot previous) { Map<LongTokenRange, ImmutableSet<Host>> tokenRangeToReplicaMap = myReplicationState.getTokenRangeToReplicas(tableReference); long lastRepairedAt = previousLastRepairedAt(previous, tokenRangeToReplicaMap); long now = System.currentTimeMillis(); Iterator<RepairEntry> repairEntryIterator; if (lastRepairedAt == VnodeRepairState.UNREPAIRED) { LOG.debug("No last repaired at found for {}, iterating over all repair entries", tableReference); repairEntryIterator = myRepairHistoryProvider.iterate(tableReference, now, (repairEntry) -> acceptRepairEntries(repairEntry, tokenRangeToReplicaMap)); } else { LOG.debug("Table {} last repaired at {}, iterating repir entries until that time", tableReference, lastRepairedAt); repairEntryIterator = myRepairHistoryProvider.iterate(tableReference, now, lastRepairedAt, (repairEntry) -> acceptRepairEntries(repairEntry, tokenRangeToReplicaMap)); } return generateVnodeRepairStates(lastRepairedAt, previous, repairEntryIterator, tokenRangeToReplicaMap); } VnodeRepairStateFactoryImpl(ReplicationState replicationState, RepairHistoryProvider repairHistoryProvider); @Override VnodeRepairStates calculateNewState(TableReference tableReference, RepairStateSnapshot previous); }
VnodeRepairStateFactoryImpl implements VnodeRepairStateFactory { @Override public VnodeRepairStates calculateNewState(TableReference tableReference, RepairStateSnapshot previous) { Map<LongTokenRange, ImmutableSet<Host>> tokenRangeToReplicaMap = myReplicationState.getTokenRangeToReplicas(tableReference); long lastRepairedAt = previousLastRepairedAt(previous, tokenRangeToReplicaMap); long now = System.currentTimeMillis(); Iterator<RepairEntry> repairEntryIterator; if (lastRepairedAt == VnodeRepairState.UNREPAIRED) { LOG.debug("No last repaired at found for {}, iterating over all repair entries", tableReference); repairEntryIterator = myRepairHistoryProvider.iterate(tableReference, now, (repairEntry) -> acceptRepairEntries(repairEntry, tokenRangeToReplicaMap)); } else { LOG.debug("Table {} last repaired at {}, iterating repir entries until that time", tableReference, lastRepairedAt); repairEntryIterator = myRepairHistoryProvider.iterate(tableReference, now, lastRepairedAt, (repairEntry) -> acceptRepairEntries(repairEntry, tokenRangeToReplicaMap)); } return generateVnodeRepairStates(lastRepairedAt, previous, repairEntryIterator, tokenRangeToReplicaMap); } VnodeRepairStateFactoryImpl(ReplicationState replicationState, RepairHistoryProvider repairHistoryProvider); @Override VnodeRepairStates calculateNewState(TableReference tableReference, RepairStateSnapshot previous);  }