use of io.atomix.utils.config.ConfigurationException in project atomix by atomix.
the class MultiRaftProtocol method newProxy.
@Override
public <S> ProxyClient<S> newProxy(String primitiveName, PrimitiveType primitiveType, Class<S> serviceType, ServiceConfig serviceConfig, PartitionService partitionService) {
PartitionGroup partitionGroup = partitionService.getPartitionGroup(this);
if (partitionGroup == null) {
throw new ConfigurationException("No Raft partition group matching the configured protocol exists");
}
Collection<SessionClient> partitions = partitionGroup.getPartitions().stream().map(partition -> ((RaftPartition) partition).getClient().sessionBuilder(primitiveName, primitiveType, serviceConfig).withMinTimeout(config.getMinTimeout()).withMaxTimeout(config.getMaxTimeout()).withReadConsistency(config.getReadConsistency()).withCommunicationStrategy(config.getCommunicationStrategy()).withRecoveryStrategy(config.getRecoveryStrategy()).withMaxRetries(config.getMaxRetries()).withRetryDelay(config.getRetryDelay()).build()).collect(Collectors.toList());
return new DefaultProxyClient<>(primitiveName, primitiveType, this, serviceType, partitions, config.getPartitioner());
}
use of io.atomix.utils.config.ConfigurationException in project atomix by atomix.
the class RaftServiceContext method installSnapshot.
/**
* Installs a snapshot.
*/
public void installSnapshot(SnapshotReader reader) {
log.debug("Installing snapshot {}", reader.snapshot().index());
// Skip the service ID
reader.skip(Bytes.LONG);
PrimitiveType primitiveType;
try {
primitiveType = raft.getPrimitiveTypes().getPrimitiveType(reader.readString());
} catch (ConfigurationException e) {
log.error(e.getMessage(), e);
return;
}
String serviceName = reader.readString();
currentIndex = reader.readLong();
currentTimestamp = reader.readLong();
timestampDelta = reader.readLong();
int sessionCount = reader.readInt();
for (int i = 0; i < sessionCount; i++) {
SessionId sessionId = SessionId.from(reader.readLong());
MemberId node = MemberId.from(reader.readString());
ReadConsistency readConsistency = ReadConsistency.valueOf(reader.readString());
long minTimeout = reader.readLong();
long maxTimeout = reader.readLong();
long sessionTimestamp = reader.readLong();
// Only create a new session if one does not already exist. This is necessary to ensure only a single session
// is ever opened and exposed to the state machine.
RaftSession session = raft.getSessions().addSession(new RaftSession(sessionId, node, serviceName, primitiveType, readConsistency, minTimeout, maxTimeout, sessionTimestamp, service.serializer(), this, raft, threadContextFactory));
session.setRequestSequence(reader.readLong());
session.setCommandSequence(reader.readLong());
session.setEventIndex(reader.readLong());
session.setLastCompleted(reader.readLong());
session.setLastApplied(reader.snapshot().index());
session.setLastUpdated(sessionTimestamp);
session.open();
service.register(sessions.addSession(session));
}
service.restore(new DefaultBackupInput(reader, service.serializer()));
}
use of io.atomix.utils.config.ConfigurationException in project atomix by atomix.
the class RaftServiceManager method installService.
/**
* Restores the service associated with the given snapshot.
*
* @param reader the snapshot reader
*/
private void installService(SnapshotReader reader) {
PrimitiveId primitiveId = PrimitiveId.from(reader.readLong());
try {
PrimitiveType primitiveType = raft.getPrimitiveTypes().getPrimitiveType(reader.readString());
String serviceName = reader.readString();
byte[] serviceConfig = reader.readBytes(reader.readInt());
// Get or create the service associated with the snapshot.
logger.debug("Installing service {} {}", primitiveId, serviceName);
RaftServiceContext service = initializeService(primitiveId, primitiveType, serviceName, serviceConfig);
if (service != null) {
try {
service.installSnapshot(reader);
} catch (Exception e) {
logger.error("Failed to install snapshot for service {}", serviceName, e);
}
}
} catch (ConfigurationException e) {
logger.error(e.getMessage(), e);
}
}
use of io.atomix.utils.config.ConfigurationException in project atomix by atomix.
the class DefaultPartitionService method start.
@Override
@SuppressWarnings("unchecked")
public CompletableFuture<PartitionService> start() {
groupMembershipService.addListener(groupMembershipEventListener);
return groupMembershipService.start().thenCompose(v -> {
PartitionGroupMembership systemGroupMembership = groupMembershipService.getSystemMembership();
if (systemGroupMembership != null) {
if (systemGroup == null) {
systemGroup = ((PartitionGroup.Type) systemGroupMembership.config().getType()).newPartitionGroup(systemGroupMembership.config());
}
systemElectionService = new DefaultPrimaryElectionService(systemGroup);
systemSessionIdService = new ReplicatedSessionIdService(systemGroup);
electionService = new HashBasedPrimaryElectionService(clusterMembershipService, groupMembershipService, communicationService);
return electionService.start().thenCompose(s -> {
PartitionManagementService managementService = new DefaultPartitionManagementService(clusterMembershipService, communicationService, primitiveTypeRegistry, electionService, new DefaultSessionIdService());
if (systemGroupMembership.members().contains(clusterMembershipService.getLocalMember().id())) {
return systemGroup.join(managementService);
} else {
return systemGroup.connect(managementService);
}
});
} else {
return Futures.exceptionalFuture(new ConfigurationException("No system partition group found"));
}
}).thenCompose(v -> systemElectionService.start().thenCompose(v2 -> systemSessionIdService.start()).thenApply(v2 -> new DefaultPartitionManagementService(clusterMembershipService, communicationService, primitiveTypeRegistry, systemElectionService, systemSessionIdService))).thenCompose(managementService -> {
this.partitionManagementService = (PartitionManagementService) managementService;
List<CompletableFuture> futures = groupMembershipService.getMemberships().stream().map(membership -> {
ManagedPartitionGroup group;
synchronized (groups) {
group = groups.get(membership.group());
if (group == null) {
group = ((PartitionGroup.Type) membership.config().getType()).newPartitionGroup(membership.config());
groups.put(group.name(), group);
}
}
if (membership.members().contains(clusterMembershipService.getLocalMember().id())) {
return group.join(partitionManagementService);
} else {
return group.connect(partitionManagementService);
}
}).collect(Collectors.toList());
return CompletableFuture.allOf(futures.toArray(new CompletableFuture[futures.size()])).thenApply(v -> {
LOGGER.info("Started");
started.set(true);
return this;
});
});
}
use of io.atomix.utils.config.ConfigurationException in project atomix by atomix.
the class DefaultPartitionGroupMembershipService method updatePartitionGroups.
private void updatePartitionGroups(PartitionGroupInfo info) {
if (systemGroup == null && info.systemGroup != null) {
systemGroup = info.systemGroup;
post(new PartitionGroupMembershipEvent(MEMBERS_CHANGED, systemGroup));
LOGGER.info("{} - Bootstrapped management group {} from {}", membershipService.getLocalMember().id(), systemGroup, info.memberId);
} else if (systemGroup != null && info.systemGroup != null) {
if (!systemGroup.group().equals(info.systemGroup.group()) || !systemGroup.config().getType().name().equals(info.systemGroup.config().getType().name())) {
throw new ConfigurationException("Duplicate system group detected");
} else {
Set<MemberId> newMembers = Stream.concat(systemGroup.members().stream(), info.systemGroup.members().stream()).filter(memberId -> membershipService.getMember(memberId) != null).collect(Collectors.toSet());
if (!Sets.difference(newMembers, systemGroup.members()).isEmpty()) {
systemGroup = new PartitionGroupMembership(systemGroup.group(), systemGroup.config(), ImmutableSet.copyOf(newMembers), true);
post(new PartitionGroupMembershipEvent(MEMBERS_CHANGED, systemGroup));
LOGGER.debug("{} - Updated management group {} from {}", membershipService.getLocalMember().id(), systemGroup, info.memberId);
}
}
}
for (PartitionGroupMembership newMembership : info.groups) {
PartitionGroupMembership oldMembership = groups.get(newMembership.group());
if (oldMembership == null) {
groups.put(newMembership.group(), newMembership);
post(new PartitionGroupMembershipEvent(MEMBERS_CHANGED, newMembership));
LOGGER.info("{} - Bootstrapped partition group {} from {}", membershipService.getLocalMember().id(), newMembership, info.memberId);
} else if (!oldMembership.group().equals(newMembership.group()) || !oldMembership.config().getType().name().equals(newMembership.config().getType().name())) {
throw new ConfigurationException("Duplicate partition group " + newMembership.group() + " detected");
} else {
Set<MemberId> newMembers = Stream.concat(oldMembership.members().stream(), newMembership.members().stream()).filter(memberId -> membershipService.getMember(memberId) != null).collect(Collectors.toSet());
if (!Sets.difference(newMembers, oldMembership.members()).isEmpty()) {
PartitionGroupMembership newGroup = new PartitionGroupMembership(oldMembership.group(), oldMembership.config(), ImmutableSet.copyOf(newMembers), false);
groups.put(oldMembership.group(), newGroup);
post(new PartitionGroupMembershipEvent(MEMBERS_CHANGED, newGroup));
LOGGER.debug("{} - Updated partition group {} from {}", membershipService.getLocalMember().id(), newGroup, info.memberId);
}
}
}
}
Aggregations