Search in sources :

Example 21 with Instant

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);
}
Also used : DataOutput(com.thinkaurelius.titan.graphdb.database.serialize.DataOutput) Instant(java.time.Instant)

Example 22 with Instant

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.");
}
Also used : StandardTitanGraph(com.thinkaurelius.titan.graphdb.database.StandardTitanGraph) TimestampProvider(com.thinkaurelius.titan.diskstorage.util.time.TimestampProvider) Instant(java.time.Instant) TitanException(com.thinkaurelius.titan.core.TitanException) TitanManagement(com.thinkaurelius.titan.core.schema.TitanManagement) RelationTypeIndex(com.thinkaurelius.titan.core.schema.RelationTypeIndex) TitanGraphIndex(com.thinkaurelius.titan.core.schema.TitanGraphIndex) PropertyKey(com.thinkaurelius.titan.core.PropertyKey)

Example 23 with Instant

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;
    });
}
Also used : MemberHeartbeatData(com.torodb.mongodb.commands.pojos.MemberHeartbeatData) MemberState(com.torodb.mongodb.commands.pojos.MemberState) OpTime(com.eightkdata.mongowp.OpTime) MemberHeartbeatData(com.torodb.mongodb.commands.pojos.MemberHeartbeatData) Nonnegative(javax.annotation.Nonnegative) UnauthorizedException(com.eightkdata.mongowp.exceptions.UnauthorizedException) InvalidOptionsException(com.eightkdata.mongowp.exceptions.InvalidOptionsException) MemberConfig(com.torodb.mongodb.commands.pojos.MemberConfig) ReplSetHeartbeatArgument(com.torodb.mongodb.commands.signatures.internal.ReplSetHeartbeatCommand.ReplSetHeartbeatArgument) HashMap(java.util.HashMap) ReplSetHeartbeatReply(com.torodb.mongodb.commands.signatures.internal.ReplSetHeartbeatReply) ShutdownInProgressException(com.eightkdata.mongowp.exceptions.ShutdownInProgressException) ReplicaSetConfig(com.torodb.mongodb.commands.pojos.ReplicaSetConfig) OptionalInt(java.util.OptionalInt) ArrayList(java.util.ArrayList) ReplSetProtocolVersion(com.torodb.mongodb.commands.pojos.ReplSetProtocolVersion) ReplSetSyncFromReply(com.torodb.mongodb.commands.signatures.repl.ReplSetSyncFromCommand.ReplSetSyncFromReply) UnsignedInteger(com.google.common.primitives.UnsignedInteger) Duration(java.time.Duration) Map(java.util.Map) RemoteCommandResponse(com.eightkdata.mongowp.client.core.MongoConnection.RemoteCommandResponse) MongoException(com.eightkdata.mongowp.exceptions.MongoException) ErrorCode(com.eightkdata.mongowp.ErrorCode) Nonnull(javax.annotation.Nonnull) WeakHashMap(java.util.WeakHashMap) Nullable(javax.annotation.Nullable) NodeNotFoundException(com.eightkdata.mongowp.exceptions.NodeNotFoundException) Set(java.util.Set) Health(com.torodb.mongodb.commands.pojos.MemberHeartbeatData.Health) Instant(java.time.Instant) HostAndPort(com.google.common.net.HostAndPort) List(java.util.List) Logger(org.apache.logging.log4j.Logger) Stream(java.util.stream.Stream) Entry(java.util.Map.Entry) Optional(java.util.Optional) Preconditions(com.google.common.base.Preconditions) LogManager(org.apache.logging.log4j.LogManager) Collections(java.util.Collections) HostUnreachableException(com.eightkdata.mongowp.exceptions.HostUnreachableException) NotThreadSafe(javax.annotation.concurrent.NotThreadSafe) OpTime(com.eightkdata.mongowp.OpTime) MemberConfig(com.torodb.mongodb.commands.pojos.MemberConfig)

Example 24 with Instant

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);
}
Also used : Instant(java.time.Instant) Tuple3(akka.japi.tuple.Tuple3)

Example 25 with Instant

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());
}
Also used : ReplSetHeartbeatReply(com.torodb.mongodb.commands.signatures.internal.ReplSetHeartbeatReply) Instant(java.time.Instant) Duration(java.time.Duration) GuardedBy(javax.annotation.concurrent.GuardedBy)

Aggregations

Instant (java.time.Instant)463 Test (org.testng.annotations.Test)143 Test (org.junit.Test)85 ZonedDateTime (java.time.ZonedDateTime)39 Duration (java.time.Duration)30 Clock (java.time.Clock)26 Lifetime (org.apache.cxf.sts.request.Lifetime)26 OffsetDateTime (java.time.OffsetDateTime)23 LocalDateTime (java.time.LocalDateTime)20 ArrayList (java.util.ArrayList)18 Element (org.w3c.dom.Element)18 LocalDate (java.time.LocalDate)17 IOException (java.io.IOException)14 Date (java.util.Date)14 LocalTime (java.time.LocalTime)12 DateTimeFormatter (java.time.format.DateTimeFormatter)12 STSException (org.apache.cxf.ws.security.sts.provider.STSException)12 SecurityToken (org.apache.cxf.ws.security.tokenstore.SecurityToken)12 Timestamp (java.sql.Timestamp)11 DefaultConditionsProvider (org.apache.cxf.sts.token.provider.DefaultConditionsProvider)10