Search in sources :

Example 1 with Timer

use of com.thinkaurelius.titan.diskstorage.util.time.Timer in project titan by thinkaurelius.

the class ConsistentKeyLocker method tryDeleteLockOnce.

private WriteResult tryDeleteLockOnce(StaticBuffer key, StaticBuffer col, StoreTransaction txh) {
    Throwable t = null;
    final Timer delTimer = times.getTimer().start();
    try {
        StoreTransaction newTx = overrideTimestamp(txh, delTimer.getStartTime());
        store.mutate(key, ImmutableList.<Entry>of(), Arrays.asList(col), newTx);
    } catch (BackendException e) {
        t = e;
    }
    delTimer.stop();
    return new WriteResult(delTimer.elapsed(), delTimer.getStartTime(), null, t);
}
Also used : Timer(com.thinkaurelius.titan.diskstorage.util.time.Timer)

Example 2 with Timer

use of com.thinkaurelius.titan.diskstorage.util.time.Timer in project titan by thinkaurelius.

the class CombinerLock method lock.

@Override
public void lock(Duration timeout) {
    Timer t = times.getTimer().start();
    first.lock(timeout);
    Duration remainingTimeout = timeout.minus(t.elapsed());
    try {
        second.lock(remainingTimeout);
    } catch (RuntimeException e) {
        first.unlock();
        throw e;
    }
}
Also used : Timer(com.thinkaurelius.titan.diskstorage.util.time.Timer) Duration(java.time.Duration)

Example 3 with Timer

use of com.thinkaurelius.titan.diskstorage.util.time.Timer in project titan by thinkaurelius.

the class GraphIndexStatusWatcher method call.

@Override
public GraphIndexStatusReport call() throws InterruptedException {
    Preconditions.checkNotNull(g, "Graph instance must not be null");
    Preconditions.checkNotNull(graphIndexName, "Index name must not be null");
    Preconditions.checkNotNull(status, "Target status must not be null");
    Map<String, SchemaStatus> notConverged = new HashMap<>();
    Map<String, SchemaStatus> converged = new HashMap<>();
    TitanGraphIndex idx;
    Timer t = new Timer(TimestampProviders.MILLI).start();
    boolean timedOut;
    while (true) {
        TitanManagement mgmt = null;
        try {
            mgmt = g.openManagement();
            idx = mgmt.getGraphIndex(graphIndexName);
            for (PropertyKey pk : idx.getFieldKeys()) {
                SchemaStatus s = idx.getIndexStatus(pk);
                LOGGER.debug("Key {} has status {}", pk, s);
                if (!status.equals(s))
                    notConverged.put(pk.toString(), s);
                else
                    converged.put(pk.toString(), s);
            }
        } finally {
            if (null != mgmt)
                // Let an exception here propagate up the stack
                mgmt.rollback();
        }
        String waitingOn = Joiner.on(",").withKeyValueSeparator("=").join(notConverged);
        if (!notConverged.isEmpty()) {
            LOGGER.info("Some key(s) on index {} do not currently have status {}: {}", graphIndexName, status, waitingOn);
        } else {
            LOGGER.info("All {} key(s) on index {} have status {}", converged.size(), graphIndexName, status);
            return new GraphIndexStatusReport(true, graphIndexName, status, notConverged, converged, t.elapsed());
        }
        timedOut = null != timeout && 0 < t.elapsed().compareTo(timeout);
        if (timedOut) {
            LOGGER.info("Timed out ({}) while waiting for index {} to converge on status {}", timeout, graphIndexName, status);
            return new GraphIndexStatusReport(false, graphIndexName, status, notConverged, converged, t.elapsed());
        }
        notConverged.clear();
        converged.clear();
        Thread.sleep(poll.toMillis());
    }
}
Also used : Timer(com.thinkaurelius.titan.diskstorage.util.time.Timer) HashMap(java.util.HashMap) SchemaStatus(com.thinkaurelius.titan.core.schema.SchemaStatus) TitanGraphIndex(com.thinkaurelius.titan.core.schema.TitanGraphIndex) TitanManagement(com.thinkaurelius.titan.core.schema.TitanManagement) PropertyKey(com.thinkaurelius.titan.core.PropertyKey)

Example 4 with Timer

use of com.thinkaurelius.titan.diskstorage.util.time.Timer in project titan by thinkaurelius.

the class RelationIndexStatusWatcher method call.

/**
     * Poll a relation index until it has a certain {@link SchemaStatus},
     * or until a configurable timeout is exceeded.
     *
     * @return a report with information about schema state, execution duration, and the index
     */
@Override
public RelationIndexStatusReport call() throws InterruptedException {
    Preconditions.checkNotNull(g, "Graph instance must not be null");
    Preconditions.checkNotNull(relationIndexName, "Index name must not be null");
    Preconditions.checkNotNull(status, "Target status must not be null");
    RelationTypeIndex idx;
    Timer t = new Timer(TimestampProviders.MILLI).start();
    boolean timedOut;
    while (true) {
        SchemaStatus actualStatus = null;
        TitanManagement mgmt = null;
        try {
            mgmt = g.openManagement();
            idx = mgmt.getRelationIndex(mgmt.getRelationType(relationTypeName), relationIndexName);
            actualStatus = idx.getIndexStatus();
            LOGGER.info("Index {} (relation type {}) has status {}", relationIndexName, relationTypeName, actualStatus);
            if (status.equals(actualStatus)) {
                return new RelationIndexStatusReport(true, relationIndexName, relationTypeName, actualStatus, status, t.elapsed());
            }
        } finally {
            if (null != mgmt)
                // Let an exception here propagate up the stack
                mgmt.rollback();
        }
        timedOut = null != timeout && 0 < t.elapsed().compareTo(timeout);
        if (timedOut) {
            LOGGER.info("Timed out ({}) while waiting for index {} (relation type {}) to reach status {}", timeout, relationIndexName, relationTypeName, status);
            return new RelationIndexStatusReport(false, relationIndexName, relationTypeName, actualStatus, status, t.elapsed());
        }
        Thread.sleep(poll.toMillis());
    }
}
Also used : Timer(com.thinkaurelius.titan.diskstorage.util.time.Timer) RelationTypeIndex(com.thinkaurelius.titan.core.schema.RelationTypeIndex) SchemaStatus(com.thinkaurelius.titan.core.schema.SchemaStatus) TitanManagement(com.thinkaurelius.titan.core.schema.TitanManagement)

Example 5 with Timer

use of com.thinkaurelius.titan.diskstorage.util.time.Timer in project titan by thinkaurelius.

the class ConsistentKeyLocker method tryWriteLockOnce.

private WriteResult tryWriteLockOnce(StaticBuffer key, StaticBuffer del, StoreTransaction txh) {
    Throwable t = null;
    final Timer writeTimer = times.getTimer().start();
    StaticBuffer newLockCol = serializer.toLockCol(writeTimer.getStartTime(), rid, times);
    Entry newLockEntry = StaticArrayEntry.of(newLockCol, zeroBuf);
    try {
        StoreTransaction newTx = overrideTimestamp(txh, writeTimer.getStartTime());
        store.mutate(key, Arrays.asList(newLockEntry), null == del ? KeyColumnValueStore.NO_DELETIONS : Arrays.asList(del), newTx);
    } catch (BackendException e) {
        log.debug("Lock write attempt failed with exception", e);
        t = e;
    }
    writeTimer.stop();
    return new WriteResult(writeTimer.elapsed(), writeTimer.getStartTime(), newLockCol, t);
}
Also used : Timer(com.thinkaurelius.titan.diskstorage.util.time.Timer)

Aggregations

Timer (com.thinkaurelius.titan.diskstorage.util.time.Timer)5 SchemaStatus (com.thinkaurelius.titan.core.schema.SchemaStatus)2 TitanManagement (com.thinkaurelius.titan.core.schema.TitanManagement)2 PropertyKey (com.thinkaurelius.titan.core.PropertyKey)1 RelationTypeIndex (com.thinkaurelius.titan.core.schema.RelationTypeIndex)1 TitanGraphIndex (com.thinkaurelius.titan.core.schema.TitanGraphIndex)1 Duration (java.time.Duration)1 HashMap (java.util.HashMap)1