Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.util.Set;
import java.util.stream.Collectors;

import org.apache.accumulo.core.client.admin.servers.ServerId;
import org.apache.accumulo.core.client.security.SecurityErrorCode;
import org.apache.accumulo.core.clientImpl.ClientContext;
import org.apache.accumulo.core.data.ConstraintViolationSummary;
Expand All @@ -41,7 +42,7 @@ public class MutationsRejectedException extends AccumuloException {

private final ArrayList<ConstraintViolationSummary> cvsl = new ArrayList<>();
private final HashMap<TabletId,Set<SecurityErrorCode>> af = new HashMap<>();
private final HashSet<String> es = new HashSet<>();
private final HashSet<ServerId> es = new HashSet<>();
private final int unknownErrors;

/**
Expand All @@ -56,7 +57,7 @@ public class MutationsRejectedException extends AccumuloException {
* @since 2.0.0
*/
public MutationsRejectedException(AccumuloClient client, List<ConstraintViolationSummary> cvsList,
Map<TabletId,Set<SecurityErrorCode>> hashMap, Collection<String> serverSideErrors,
Map<TabletId,Set<SecurityErrorCode>> hashMap, Collection<ServerId> serverSideErrors,
int unknownErrors, Throwable cause) {
super(
"constraint violation codes : "
Expand Down Expand Up @@ -108,7 +109,7 @@ public Map<TabletId,Set<SecurityErrorCode>> getSecurityErrorCodes() {
* @return A list of servers that had internal errors when mutations were written
*
*/
public Collection<String> getErrorServers() {
public Collection<ServerId> getErrorServers() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method is public API. Its in a dark corner of the API, could change it. May be easiest to just leave itas string.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally, my concern about leaving these types of things as String, is that there is not enough information to reconstitute a ServerId in the event that it's needed.

return es;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,26 @@
import java.util.HashSet;
import java.util.Set;

import org.apache.accumulo.core.client.admin.servers.ServerId;

/**
* @since 1.5.0
*/
public class TimedOutException extends RuntimeException {

private final HashSet<String> timedoutServers = new HashSet<>();
private final HashSet<ServerId> timedoutServers = new HashSet<>();

private static final long serialVersionUID = 1L;

private static String shorten(Set<String> set) {
private static String shorten(Set<ServerId> set) {
if (set.size() < 10) {
return set.toString();
}

return new ArrayList<>(set).subList(0, 10) + " ... " + (set.size() - 10) + " servers not shown";
}

public TimedOutException(Set<String> timedoutServers) {
public TimedOutException(Set<ServerId> timedoutServers) {
super("Servers timed out " + shorten(timedoutServers));
this.timedoutServers.addAll(timedoutServers);

Expand All @@ -50,7 +52,7 @@ public TimedOutException(String msg) {
super(msg);
}

public Set<String> getTimedOutSevers() {
public Set<ServerId> getTimedOutSevers() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could leave this as string since this is a public API method

return Collections.unmodifiableSet(timedoutServers);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.List;
import java.util.Map;

import org.apache.accumulo.core.client.admin.servers.ServerId;
import org.apache.accumulo.core.data.Range;
import org.apache.accumulo.core.data.TabletId;

Expand Down Expand Up @@ -50,5 +51,5 @@ public interface Locations {
*
* @return A tablet server location in the form of {@code <host>:<port>}
*/
String getTabletLocation(TabletId tabletId);
ServerId getTabletLocation(TabletId tabletId);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could leave this as string also since its public API

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,33 +18,48 @@
*/
package org.apache.accumulo.core.client.admin.servers;

import static org.apache.accumulo.core.util.LazySingletons.GSON;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.Serializable;
import java.util.Objects;

import org.apache.accumulo.core.clientImpl.ServerIdUtil;
import org.apache.accumulo.core.clientImpl.ServerIdUtil.ServerIdInfo;
import org.apache.accumulo.core.conf.PropertyType.PortRange;
import org.apache.accumulo.core.data.ResourceGroupId;

import com.google.common.base.Preconditions;
import com.google.common.net.HostAndPort;

/**
* Object representing the type, resource group, and address of a server process.
*
* @since 4.0.0
*/
public final class ServerId implements Comparable<ServerId> {
public final class ServerId implements Comparable<ServerId>, Serializable {

/**
* Server process type names.
*
* @since 4.0.0
*/
public enum Type {
MANAGER, MONITOR, GARBAGE_COLLECTOR, COMPACTOR, SCAN_SERVER, TABLET_SERVER;
MANAGER, MINI, MONITOR, GARBAGE_COLLECTOR, COMPACTOR, SCAN_SERVER, TABLET_SERVER;
}

private static final long serialVersionUID = 1L;

public static final ServerId deserialize(String json) {
return GSON.get().fromJson(json, ServerIdInfo.class).getServerId();
}

private final Type type;
private final ResourceGroupId resourceGroup;
private final String host;
private final int port;
private transient HostAndPort hostPort;

public ServerId(Type type, ResourceGroupId resourceGroup, String host, int port) {
super();
Expand All @@ -54,6 +69,7 @@ public ServerId(Type type, ResourceGroupId resourceGroup, String host, int port)
this.resourceGroup = Objects.requireNonNull(resourceGroup);
this.host = Objects.requireNonNull(host);
this.port = port;
this.hostPort = HostAndPort.fromParts(host, port);
}

public Type getType() {
Expand All @@ -72,6 +88,13 @@ public int getPort() {
return port;
}

private synchronized HostAndPort getHostPort() {
if (hostPort == null) {
hostPort = HostAndPort.fromParts(host, port);
}
return hostPort;
}

@Override
public int compareTo(ServerId other) {
if (this == other) {
Expand Down Expand Up @@ -117,6 +140,15 @@ public String toString() {
}

public String toHostPortString() {
return host + ":" + port;
return getHostPort().toString();
}

public String serialize() {
return GSON.get().toJson(ServerIdUtil.toServerIdInfo(this));
}

private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
in.defaultReadObject();
this.hostPort = HostAndPort.fromParts(host, port);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,30 @@
package org.apache.accumulo.core.clientImpl;

import org.apache.accumulo.core.client.AccumuloException;
import org.apache.accumulo.core.client.admin.servers.ServerId;
import org.apache.thrift.TApplicationException;

/**
* This class is intended to encapsulate errors that occurred on the server side.
*/
public class AccumuloServerException extends AccumuloException {
private static final long serialVersionUID = 1L;
private String server;
private static final long serialVersionUID = 2L;
private ServerId server;

AccumuloServerException(final AccumuloServerException cause) {
super("Error on server " + cause.getServer(), cause);
}

public AccumuloServerException(final String server, final TApplicationException tae) {
public AccumuloServerException(final ServerId server, final TApplicationException tae) {
super("Error on server " + server, tae);
this.setServer(server);
}

private void setServer(final String server) {
private void setServer(final ServerId server) {
this.server = server;
}

public String getServer() {
public ServerId getServer() {
return server;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
import org.apache.accumulo.core.client.admin.ResourceGroupOperations;
import org.apache.accumulo.core.client.admin.SecurityOperations;
import org.apache.accumulo.core.client.admin.TableOperations;
import org.apache.accumulo.core.client.admin.servers.ServerId;
import org.apache.accumulo.core.client.security.tokens.AuthenticationToken;
import org.apache.accumulo.core.conf.AccumuloConfiguration;
import org.apache.accumulo.core.conf.ClientProperty;
Expand Down Expand Up @@ -126,6 +127,7 @@

import com.github.benmanes.caffeine.cache.Cache;
import com.google.common.base.Suppliers;
import com.google.common.net.HostAndPort;

import io.micrometer.core.instrument.MeterRegistry;

Expand Down Expand Up @@ -225,13 +227,9 @@ public Supplier<Collection<ScanServerInfo>> getScanServers() {
.getScanServer(ResourceGroupPredicate.ANY, AddressSelector.all(), true).stream()
.map(entry -> new ScanServerInfo() {
@Override
public String getAddress() {
return entry.getServer();
}

@Override
public ResourceGroupId getGroup() {
return entry.getResourceGroup();
public ServerId getServer() {
HostAndPort hp = HostAndPort.fromString(entry.getServer());
return ServerIdUtil.sserver(entry.getResourceGroup(), hp.getHost(), hp.getPort());
}
}).collect(Collectors.toSet());
}
Expand Down Expand Up @@ -455,9 +453,9 @@ public ScanServerSelector getScanServerSelector() {
/**
* @return map of live scan server addresses to lock uuids.
*/
public Map<String,Pair<UUID,ResourceGroupId>> getScanServers() {
public Map<ServerId,Pair<UUID,ResourceGroupId>> getScanServers() {
ensureOpen();
Map<String,Pair<UUID,ResourceGroupId>> liveScanServers = new HashMap<>();
Map<ServerId,Pair<UUID,ResourceGroupId>> liveScanServers = new HashMap<>();
Set<ServiceLockPath> scanServerPaths =
getServerPaths().getScanServer(ResourceGroupPredicate.ANY, AddressSelector.all(), true);
for (ServiceLockPath path : scanServerPaths) {
Expand All @@ -466,7 +464,7 @@ public Map<String,Pair<UUID,ResourceGroupId>> getScanServers() {
Optional<ServiceLockData> sld = ServiceLock.getLockData(getZooCache(), path, stat);
if (sld.isPresent()) {
final ServiceLockData data = sld.orElseThrow();
final String addr = data.getAddressString(ThriftService.TABLET_SCAN);
final ServerId addr = data.getServer(ThriftService.TABLET_SCAN);
final UUID uuid = data.getServerUUID(ThriftService.TABLET_SCAN);
final ResourceGroupId group = data.getGroup(ThriftService.TABLET_SCAN);
liveScanServers.put(addr, new Pair<>(uuid, group));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,11 @@
import org.apache.accumulo.core.client.InvalidTabletHostingRequestException;
import org.apache.accumulo.core.client.TableNotFoundException;
import org.apache.accumulo.core.client.admin.TabletAvailability;
import org.apache.accumulo.core.client.admin.servers.ServerId;
import org.apache.accumulo.core.data.Mutation;
import org.apache.accumulo.core.data.Range;
import org.apache.accumulo.core.dataImpl.KeyExtent;
import org.apache.accumulo.core.metadata.TServerInstance;
import org.apache.accumulo.core.util.Interner;
import org.apache.accumulo.core.util.Timer;
import org.apache.accumulo.core.util.UtilWaitThread;
Expand Down Expand Up @@ -128,7 +130,7 @@ public CachedTablet findTabletWithRetry(ClientContext context, Text row, boolean
}

public abstract <T extends Mutation> void binMutations(ClientContext context, List<T> mutations,
Map<String,TabletServerMutations<T>> binnedMutations, List<T> failures)
Map<ServerId,TabletServerMutations<T>> binnedMutations, List<T> failures)
throws AccumuloException, AccumuloSecurityException, TableNotFoundException,
InvalidTabletHostingRequestException;

Expand Down Expand Up @@ -165,7 +167,7 @@ public abstract List<Range> findTablets(ClientContext context, List<Range> range
* hosted tablets with a location.
*/
public List<Range> binRanges(ClientContext context, List<Range> ranges,
Map<String,Map<KeyExtent,List<Range>>> binnedRanges) throws AccumuloException,
Map<ServerId,Map<KeyExtent,List<Range>>> binnedRanges) throws AccumuloException,
AccumuloSecurityException, TableNotFoundException, InvalidTabletHostingRequestException {
return findTablets(context, ranges, ((cachedTablet, range) -> ClientTabletCacheImpl
.addRange(binnedRanges, cachedTablet, range)), LocationNeed.REQUIRED);
Expand Down Expand Up @@ -201,30 +203,30 @@ public static class CachedTablet {
private static final Interner<String> interner = new Interner<>();

private final KeyExtent tablet_extent;
private final String tserverLocation;
private final ServerId tserverLocation;
private final String tserverSession;
private final TabletAvailability availability;
private final boolean hostingRequested;

private final Timer creationTimer = Timer.startNew();

public CachedTablet(KeyExtent tablet_extent, String tablet_location, String session,
public CachedTablet(KeyExtent tablet_extent, ServerId tablet_location, String session,
TabletAvailability availability, boolean hostingRequested) {
checkArgument(tablet_extent != null, "tablet_extent is null");
checkArgument(tablet_location != null, "tablet_location is null");
checkArgument(session != null, "session is null");
this.tablet_extent = tablet_extent;
this.tserverLocation = interner.intern(tablet_location);
this.tserverLocation = tablet_location;
this.tserverSession = interner.intern(session);
this.availability = Objects.requireNonNull(availability);
this.hostingRequested = hostingRequested;
}

public CachedTablet(KeyExtent tablet_extent, Optional<String> tablet_location,
public CachedTablet(KeyExtent tablet_extent, Optional<ServerId> tablet_location,
Optional<String> session, TabletAvailability availability, boolean hostingRequested) {
checkArgument(tablet_extent != null, "tablet_extent is null");
this.tablet_extent = tablet_extent;
this.tserverLocation = tablet_location.map(interner::intern).orElse(null);
this.tserverLocation = tablet_location.orElse(null);
this.tserverSession = session.map(interner::intern).orElse(null);
this.availability = Objects.requireNonNull(availability);
this.hostingRequested = hostingRequested;
Expand Down Expand Up @@ -268,7 +270,7 @@ public KeyExtent getExtent() {
return tablet_extent;
}

public Optional<String> getTserverLocation() {
public Optional<ServerId> getTserverLocation() {
return Optional.ofNullable(tserverLocation);
}

Expand Down Expand Up @@ -300,9 +302,9 @@ public boolean wasHostingRequested() {

public static class TabletServerMutations<T extends Mutation> {
private final Map<KeyExtent,List<T>> mutations;
private final String tserverSession;
private final TServerInstance tserverSession;

public TabletServerMutations(String tserverSession) {
public TabletServerMutations(TServerInstance tserverSession) {
this.tserverSession = tserverSession;
this.mutations = new HashMap<>();
}
Expand All @@ -316,7 +318,7 @@ public Map<KeyExtent,List<T>> getMutations() {
return mutations;
}

final String getSession() {
public TServerInstance getTServerInstance() {
return tserverSession;
}
}
Expand Down
Loading