use of java.time.Instant in project titan by thinkaurelius.
the class KCVSLog method writeMessage.
private Entry writeMessage(KCVSMessage msg) {
StaticBuffer content = msg.getContent();
DataOutput out = manager.serializer.getDataOutput(8 + 8 + manager.senderId.length() + 2 + content.length());
Instant rawTimestamp = msg.getTimestamp();
Preconditions.checkArgument(rawTimestamp.isAfter(Instant.EPOCH));
out.putLong(times.getTime(rawTimestamp));
out.writeObjectNotNull(manager.senderId);
out.putLong(numMsgCounter.incrementAndGet());
final int valuePos = out.getPosition();
out.putBytes(content);
return new StaticArrayEntry(out.getStaticBuffer(), valuePos);
}
use of java.time.Instant in project titan by thinkaurelius.
the class ManagementUtil method awaitIndexUpdate.
private static void awaitIndexUpdate(TitanGraph g, String indexName, String relationTypeName, long time, TemporalUnit unit) {
Preconditions.checkArgument(g != null && g.isOpen(), "Need to provide valid, open graph instance");
Preconditions.checkArgument(time > 0 && unit != null, "Need to provide valid time interval");
Preconditions.checkArgument(StringUtils.isNotBlank(indexName), "Need to provide an index name");
StandardTitanGraph graph = (StandardTitanGraph) g;
TimestampProvider times = graph.getConfiguration().getTimestampProvider();
Instant end = times.getTime().plus(Duration.of(time, unit));
boolean isStable = false;
while (times.getTime().isBefore(end)) {
TitanManagement mgmt = graph.openManagement();
try {
if (StringUtils.isNotBlank(relationTypeName)) {
RelationTypeIndex idx = mgmt.getRelationIndex(mgmt.getRelationType(relationTypeName), indexName);
Preconditions.checkArgument(idx != null, "Index could not be found: %s @ %s", indexName, relationTypeName);
isStable = idx.getIndexStatus().isStable();
} else {
TitanGraphIndex idx = mgmt.getGraphIndex(indexName);
Preconditions.checkArgument(idx != null, "Index could not be found: %s", indexName);
isStable = true;
for (PropertyKey key : idx.getFieldKeys()) {
if (!idx.getIndexStatus(key).isStable())
isStable = false;
}
}
} finally {
mgmt.rollback();
}
if (isStable)
break;
try {
times.sleepFor(Duration.ofMillis(500));
} catch (InterruptedException e) {
}
}
if (!isStable)
throw new TitanException("Index did not stabilize within the given amount of time. For sufficiently long " + "wait periods this is most likely caused by a failed/incorrectly shut down Titan instance or a lingering transaction.");
}
use of java.time.Instant in project torodb by torodb.
the class TopologyCoordinator method lookForSyncSource.
/**
* Looks for an optimal sync source to replicate from.
*
* The first attempt, we ignore those nodes with slave delay higher than our own, hidden nodes,
* and nodes that are excessively lagged. The second attempt includes such nodes, in case those
* are the only ones we can reach. This loop attempts to set 'closestIndex'.
*
* @param now the current time
* @param lastOpAppliedOp the last OpTime this node has apply
* @param onlyOptimal if true, slaves with more delay than ourselve, hidden nodes or
* excessively lagged nodes are ignored
* @param oldestSyncOpTime the oldest optime considered not excessively lagged. Only used if
* onlyOptimal is true.
* @return the new optimal sync source, which is not {@link Optional#isPresent() present} if no
* one can be chosen
*/
private Optional<MemberConfig> lookForSyncSource(Instant now, Optional<OpTime> lastOpAppliedOp, boolean onlyOptimal, OpTime oldestSyncOpTime) {
OpTime lastOpApplied = lastOpAppliedOp.orElse(OpTime.EPOCH);
Stream<MemberHeartbeatData> hbCandidateStream = _hbdata.stream().filter(MemberHeartbeatData::isUp).filter(hbData -> hbData.getState().isReadable()).filter(hbData -> hbData.getOpTime().isAfter(lastOpApplied));
if (onlyOptimal) {
hbCandidateStream = hbCandidateStream.filter(hbData -> hbData.getOpTime().isEqualOrAfter(oldestSyncOpTime));
}
Stream<MemberConfig> mcCandidateStream = hbCandidateStream.map(this::getMemberConfig).filter(mc -> !isBlacklistedMember(mc, now));
if (onlyOptimal) {
mcCandidateStream = mcCandidateStream.filter(mc -> !mc.isHidden()).filter(mc -> mc.getSlaveDelay() < slaveDelaySecs);
}
//If there are several candidates, the one whose ping is lower is returned
return mcCandidateStream.reduce((MemberConfig cand1, MemberConfig cand2) -> {
long ping1 = getPing(cand1.getHostAndPort());
long ping2 = getPing(cand2.getHostAndPort());
if (ping1 < ping2) {
return cand1;
}
return cand2;
});
}
use of java.time.Instant in project torodb by torodb.
the class AkkaDbCloner method postInsertFold.
private Tuple3<Integer, Integer, Instant> postInsertFold(String toDb, String toCol, Tuple3<Integer, Integer, Instant> acum, Pair<Integer, Integer> newBatch) {
Instant lastLogInstant = acum.t3();
long now = clock.millis();
long millisSinceLastLog = now - lastLogInstant.toEpochMilli();
if (shouldLogCollectionCloning(millisSinceLastLog)) {
logCollectionCloning(toDb, toCol, acum.t1(), acum.t2());
lastLogInstant = Instant.ofEpochMilli(now);
}
return new Tuple3<>(acum.t1() + newBatch.first(), acum.t2() + newBatch.second(), lastLogInstant);
}
use of java.time.Instant in project torodb by torodb.
the class TopologyHeartbeatHandler method handleHeartbeatResponse.
@GuardedBy("executor")
private void handleHeartbeatResponse(TopologyCoordinator coord, HostAndPort target, ReplSetHeartbeatArgument request, RemoteCommandResponse<ReplSetHeartbeatReply> response) {
boolean isUnauthorized = (response.getErrorCode() == ErrorCode.UNAUTHORIZED) || (response.getErrorCode() == ErrorCode.AUTHENTICATION_FAILED);
Instant now = clock.instant();
Duration networkTime = Duration.ZERO;
if (response.isOk()) {
networkTime = response.getNetworkTime();
} else {
LOGGER.warn("Error in heartbeat request to {}; {}", target, response.asStatus());
if (response.getBson() != null) {
LOGGER.debug("heartbeat response: ", response.getBson());
}
if (isUnauthorized) {
networkTime = response.getNetworkTime();
}
}
HeartbeatResponseAction action = coord.processHeartbeatResponse(now, networkTime, target, response);
ReplSetHeartbeatReply hbReply = response.getCommandReply().orElse(null);
assert hbReply != null || !response.isOk() : "Recived a null hbReply when the request didn't fail";
scheduleHeartbeatToTarget(target, action.getNextHeartbeatDelay());
handleHeartbeatResponseAction(coord, action, hbReply, response.getErrorCode());
}
Aggregations