use of com.google.common.net.HostAndPort in project torodb by torodb.
the class TopologyService method chooseNewSyncSource.
public CompletableFuture<Optional<HostAndPort>> chooseNewSyncSource(Optional<OpTime> lastFetchedOpTime) {
return executor.onAnyVersion().mapAsync(coord -> {
Instant now = clock.instant();
HostAndPort currentSyncSource = coord.getSyncSourceAddress().orElse(null);
boolean shouldChange = currentSyncSource == null || coord.shouldChangeSyncSource(currentSyncSource, now);
if (shouldChange) {
return coord.chooseNewSyncSource(clock.instant(), lastFetchedOpTime);
} else {
return coord.getSyncSourceAddress();
}
});
}
use of com.google.common.net.HostAndPort in project torodb by torodb.
the class TopologyService method shouldChangeSyncSource.
CompletableFuture<Boolean> shouldChangeSyncSource() {
return executor.onAnyVersion().mapAsync(coord -> {
Instant now = clock.instant();
HostAndPort currentSyncSource = coord.getSyncSourceAddress().orElse(null);
return currentSyncSource == null || coord.shouldChangeSyncSource(currentSyncSource, now);
});
}
use of com.google.common.net.HostAndPort in project torodb by torodb.
the class TopologyCoordinator method executeReplSetSyncFrom.
ReplSetSyncFromReply executeReplSetSyncFrom(ErrorCode status, HostAndPort target, OpTime lastOpApplied) throws MongoException {
if (status == ErrorCode.CALLBACK_CANCELED) {
throw new ShutdownInProgressException("replication system is shutting down");
}
final HostAndPort syncFromRequested = target;
MemberConfig targetConfig = null;
int targetIndex;
for (targetIndex = 0; targetIndex < _rsConfig.getMembers().size(); targetIndex++) {
MemberConfig it = _rsConfig.getMembers().get(targetIndex);
if (it.getHostAndPort().equals(target)) {
targetConfig = it;
break;
}
}
if (targetConfig == null) {
throw new NodeNotFoundException("Could not find member \"" + target + "\" in replica set");
}
if (targetConfig.isArbiter()) {
throw new InvalidOptionsException("Cannot sync from \"" + target + "\" because it is an arbiter");
}
String warning = null;
MemberHeartbeatData hbdata = _hbdata.get(targetIndex);
if (hbdata.isAuthIssue()) {
throw new UnauthorizedException("not authorized to communicate with " + target);
}
if (hbdata.getHealth() == Health.UNREACHABLE) {
throw new HostUnreachableException("I cannot reach the requested member: " + target);
}
assert hbdata.getOpTime() != null;
if (hbdata.getOpTime().getSecs() + 10 < lastOpApplied.getSecs()) {
LOGGER.warn("attempting to sync from {}, but its latest opTime is {} and ours is {} " + "so this may not work", target, hbdata.getOpTime().getSecs(), lastOpApplied.getSecs());
warning = "requested member \"" + target + "\" is more than 10 seconds behind us";
}
HostAndPort prevSyncSource = getSyncSourceAddress().orElse(null);
setForceSyncSourceIndex(targetIndex);
return new ReplSetSyncFromReply(prevSyncSource, syncFromRequested, warning);
}
use of com.google.common.net.HostAndPort in project torodb by torodb.
the class MemberConfig method fromDocument.
public static MemberConfig fromDocument(BsonDocument bson) throws TypesMismatchException, NoSuchKeyException, BadValueException {
int id = BsonReaderTool.getNumeric(bson, "_id").intValue();
HostAndPort host = BsonReaderTool.getHostAndPort(bson, "host");
Builder builder = new Builder(id, host).setVotes(BsonReaderTool.getInteger(bson, "votes", DEFAULT_VOTES)).setPriority(BsonReaderTool.getDouble(bson, "priority", DEFAULT_PRIORITY)).setArbiterOnly(BsonReaderTool.getBooleanOrNumeric(bson, "arbiterOnly", DEFAULT_ARBITER_ONLY)).setSlaveDelay(BsonReaderTool.getNumeric(bson, "slaveDelay", DEFAULT_SLAVE_DELAY).longValue()).setHidden(BsonReaderTool.getBooleanOrNumeric(bson, "hidden", DEFAULT_HIDDEN)).setBuildIndexes(BsonReaderTool.getBooleanOrNumeric(bson, "buildIndexes", DEFAULT_BUILD_INDEXES));
BsonDocument castedTags = BsonReaderTool.getDocument(bson, "tags");
for (Entry entry : castedTags) {
BsonValue value = entry.getValue();
if (value.isString()) {
throw new TypesMismatchException(entry.getKey(), "string", value.getType());
}
String castedValue = value.asString().getValue();
builder.putTag(entry.getKey(), castedValue);
}
return builder.build();
}
use of com.google.common.net.HostAndPort in project graylog2-server by Graylog2.
the class MongoProbe method mongoStats.
public MongoStats mongoStats() {
final List<ServerAddress> serverAddresses = mongoClient.getServerAddressList();
final List<HostAndPort> servers = Lists.newArrayListWithCapacity(serverAddresses.size());
for (ServerAddress serverAddress : serverAddresses) {
servers.add(HostAndPort.fromParts(serverAddress.getHost(), serverAddress.getPort()));
}
final DatabaseStats dbStats;
final CommandResult dbStatsResult = db.command("dbStats");
if (dbStatsResult.ok()) {
final BasicDBObject extentFreeListMap = (BasicDBObject) dbStatsResult.get("extentFreeList");
final DatabaseStats.ExtentFreeList extentFreeList;
if (extentFreeListMap == null) {
extentFreeList = null;
} else {
extentFreeList = DatabaseStats.ExtentFreeList.create(extentFreeListMap.getInt("num"), extentFreeListMap.getInt("totalSize"));
}
final BasicDBObject dataFileVersionMap = (BasicDBObject) dbStatsResult.get("dataFileVersion");
final DatabaseStats.DataFileVersion dataFileVersion;
if (dataFileVersionMap == null) {
dataFileVersion = null;
} else {
dataFileVersion = DatabaseStats.DataFileVersion.create(dataFileVersionMap.getInt("major"), dataFileVersionMap.getInt("minor"));
}
dbStats = DatabaseStats.create(dbStatsResult.getString("db"), dbStatsResult.getLong("collections"), dbStatsResult.getLong("objects"), dbStatsResult.getDouble("avgObjSize"), dbStatsResult.getLong("dataSize"), dbStatsResult.getLong("storageSize"), dbStatsResult.getLong("numExtents"), dbStatsResult.getLong("indexes"), dbStatsResult.getLong("indexSize"), dbStatsResult.containsField("fileSize") ? dbStatsResult.getLong("fileSize") : null, dbStatsResult.containsField("nsSizeMB") ? dbStatsResult.getLong("nsSizeMB") : null, extentFreeList, dataFileVersion);
} else {
LOG.debug("Couldn't retrieve MongoDB dbStats: {}", dbStatsResult.getErrorMessage());
dbStats = null;
}
final ServerStatus serverStatus;
final CommandResult serverStatusResult = adminDb.command("serverStatus");
if (serverStatusResult.ok()) {
final BasicDBObject connectionsMap = (BasicDBObject) serverStatusResult.get("connections");
final ServerStatus.Connections connections = ServerStatus.Connections.create(connectionsMap.getInt("current"), connectionsMap.getInt("available"), connectionsMap.containsField("totalCreated") ? connectionsMap.getLong("totalCreated") : null);
final BasicDBObject networkMap = (BasicDBObject) serverStatusResult.get("network");
final ServerStatus.Network network = ServerStatus.Network.create(networkMap.getInt("bytesIn"), networkMap.getInt("bytesOut"), networkMap.getInt("numRequests"));
final BasicDBObject memoryMap = (BasicDBObject) serverStatusResult.get("mem");
final ServerStatus.Memory memory = ServerStatus.Memory.create(memoryMap.getInt("bits"), memoryMap.getInt("resident"), memoryMap.getInt("virtual"), memoryMap.getBoolean("supported"), memoryMap.getInt("mapped"), memoryMap.getInt("mappedWithJournal", -1));
final BasicDBObject storageEngineMap = (BasicDBObject) serverStatusResult.get("storageEngine");
final ServerStatus.StorageEngine storageEngine;
if (storageEngineMap == null) {
storageEngine = ServerStatus.StorageEngine.DEFAULT;
} else {
storageEngine = ServerStatus.StorageEngine.create(storageEngineMap.getString("name"));
}
final int uptime = serverStatusResult.getInt("uptime", 0);
serverStatus = ServerStatus.create(serverStatusResult.getString("host"), serverStatusResult.getString("version"), serverStatusResult.getString("process"), serverStatusResult.getLong("pid", 0), uptime, serverStatusResult.getLong("uptimeMillis", uptime * 1000L), serverStatusResult.getInt("uptimeEstimate"), new DateTime(serverStatusResult.getDate("localTime")), connections, network, memory, storageEngine);
} else {
LOG.debug("Couldn't retrieve MongoDB serverStatus: {}", serverStatusResult.getErrorMessage());
serverStatus = null;
}
// TODO Collection stats? http://docs.mongodb.org/manual/reference/command/collStats/
return MongoStats.create(servers, buildInfo, hostInfo, serverStatus, dbStats);
}
Aggregations