use of org.neo4j.kernel.ha.cluster.member.ClusterMember in project neo4j by neo4j.
the class SwitchToSlave method checkMyStoreIdAndMastersStoreId.
void checkMyStoreIdAndMastersStoreId(StoreId myStoreId, URI masterUri, DependencyResolver resolver) {
ClusterMembers clusterMembers = resolver.resolveDependency(ClusterMembers.class);
InstanceId serverId = HighAvailabilityModeSwitcher.getServerId(masterUri);
Iterable<ClusterMember> members = clusterMembers.getMembers();
ClusterMember master = firstOrNull(filter(hasInstanceId(serverId), members));
if (master == null) {
throw new IllegalStateException("Cannot find the master among " + members + " with master serverId=" + serverId + " and uri=" + masterUri);
}
StoreId masterStoreId = master.getStoreId();
if (!myStoreId.equals(masterStoreId)) {
throw new MismatchingStoreIdException(myStoreId, master.getStoreId());
} else if (!myStoreId.equalsByUpgradeId(master.getStoreId())) {
throw new BranchedDataException("My store with " + myStoreId + " was updated independently from " + "master's store " + masterStoreId);
}
}
use of org.neo4j.kernel.ha.cluster.member.ClusterMember in project neo4j by neo4j.
the class SwitchToSlaveBranchThenCopyTest method newSwitchToSlaveSpy.
@SuppressWarnings("unchecked")
private SwitchToSlaveBranchThenCopy newSwitchToSlaveSpy(PageCache pageCacheMock, StoreCopyClient storeCopyClient) throws IOException {
ClusterMembers clusterMembers = mock(ClusterMembers.class);
ClusterMember master = mock(ClusterMember.class);
when(master.getStoreId()).thenReturn(storeId);
when(master.getHARole()).thenReturn(HighAvailabilityModeSwitcher.MASTER);
when(master.hasRole(eq(HighAvailabilityModeSwitcher.MASTER))).thenReturn(true);
when(master.getInstanceId()).thenReturn(new InstanceId(1));
when(clusterMembers.getMembers()).thenReturn(singletonList(master));
Dependencies resolver = new Dependencies();
resolver.satisfyDependencies(requestContextFactory, clusterMembers, mock(TransactionObligationFulfiller.class), mock(OnlineBackupKernelExtension.class), mock(IndexConfigStore.class), mock(TransactionCommittingResponseUnpacker.class), mock(DataSourceManager.class), mock(StoreLockerLifecycleAdapter.class), mock(FileSystemWatcherService.class));
NeoStoreDataSource dataSource = mock(NeoStoreDataSource.class);
when(dataSource.getStoreId()).thenReturn(storeId);
TransactionStats transactionCounters = mock(TransactionStats.class);
when(transactionCounters.getNumberOfActiveTransactions()).thenReturn(0L);
Response<HandshakeResult> response = mock(Response.class);
when(response.response()).thenReturn(new HandshakeResult(42, 2));
when(masterClient.handshake(anyLong(), any(StoreId.class))).thenReturn(response);
when(masterClient.getProtocolVersion()).thenReturn(MasterClient320.PROTOCOL_VERSION);
TransactionIdStore transactionIdStoreMock = mock(TransactionIdStore.class);
// note that the checksum (the second member of the array) is the same as the one in the handshake mock above
when(transactionIdStoreMock.getLastCommittedTransaction()).thenReturn(new TransactionId(42, 42, 42));
MasterClientResolver masterClientResolver = mock(MasterClientResolver.class);
when(masterClientResolver.instantiate(anyString(), anyInt(), anyString(), any(Monitors.class), any(StoreId.class), any(LifeSupport.class))).thenReturn(masterClient);
return spy(new SwitchToSlaveBranchThenCopy(new File(""), NullLogService.getInstance(), configMock(), resolver, mock(HaIdGeneratorFactory.class), mock(DelegateInvocationHandler.class), mock(ClusterMemberAvailability.class), requestContextFactory, pullerFactory, masterClientResolver, mock(SwitchToSlave.Monitor.class), storeCopyClient, Suppliers.singleton(dataSource), Suppliers.singleton(transactionIdStoreMock), slave -> {
SlaveServer server = mock(SlaveServer.class);
InetSocketAddress inetSocketAddress = InetSocketAddress.createUnresolved("localhost", 42);
when(server.getSocketAddress()).thenReturn(inetSocketAddress);
return server;
}, updatePuller, pageCacheMock, mock(Monitors.class), transactionCounters));
}
use of org.neo4j.kernel.ha.cluster.member.ClusterMember in project neo4j by neo4j.
the class ClusterManager method allSeesAllAsAvailable.
public static Predicate<ManagedCluster> allSeesAllAsAvailable() {
return new Predicate<ManagedCluster>() {
@Override
public boolean test(ManagedCluster cluster) {
if (!allSeesAllAsJoined().test(cluster)) {
return false;
}
int clusterMembersChecked = 0;
for (HighlyAvailableGraphDatabase database : cluster.getAllMembers()) {
clusterMembersChecked++;
ClusterMembers members = database.getDependencyResolver().resolveDependency(ClusterMembers.class);
for (ClusterMember clusterMember : members.getMembers()) {
if (!cluster.isAvailable(clusterMember)) {
return false;
}
}
}
if (clusterMembersChecked == 0) {
return false;
}
// Everyone sees everyone else as available!
for (HighlyAvailableGraphDatabase database : cluster.getAllMembers()) {
Log log = database.getDependencyResolver().resolveDependency(LogService.class).getInternalLog(getClass());
log.debug(this.toString());
}
return true;
}
@Override
public String toString() {
return "All instances should see all others as available";
}
};
}
use of org.neo4j.kernel.ha.cluster.member.ClusterMember in project neo4j by neo4j.
the class ClusterDatabaseInfoProvider method getInfo.
public ClusterDatabaseInfo getInfo() {
ClusterMember currentMember = members.getCurrentMember();
if (currentMember == null) {
return null;
}
Function<Object, String> nullSafeToString = from -> from == null ? "" : from.toString();
return new ClusterDatabaseInfo(new ClusterMemberInfo(currentMember.getInstanceId().toString(), currentMember.getHAUri() != null, true, currentMember.getHARole(), Iterables.asArray(String.class, Iterables.map(nullSafeToString, currentMember.getRoleURIs())), Iterables.asArray(String.class, Iterables.map(nullSafeToString, currentMember.getRoles()))), txIdGetter.getLastTxId(), lastUpdateTime.getLastUpdateTime());
}
use of org.neo4j.kernel.ha.cluster.member.ClusterMember in project neo4j by neo4j.
the class ClusterMetricsTest method getClusterMembers.
private static Supplier<ClusterMembers> getClusterMembers(String memberRole, HighAvailabilityMemberState memberState) {
HighAvailabilityMemberStateMachine stateMachine = mock(HighAvailabilityMemberStateMachine.class);
when(stateMachine.getCurrentState()).thenReturn(memberState);
ClusterMember clusterMember = spy(new ClusterMember(new InstanceId(1)));
when(clusterMember.getHARole()).thenReturn(memberRole);
ObservedClusterMembers observedClusterMembers = mock(ObservedClusterMembers.class);
when(observedClusterMembers.getCurrentMember()).thenReturn(clusterMember);
return () -> new ClusterMembers(observedClusterMembers, stateMachine);
}
Aggregations