Search in sources :

Example 81 with StaticBuffer

use of org.janusgraph.diskstorage.StaticBuffer in project janusgraph by JanusGraph.

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(org.janusgraph.graphdb.database.serialize.DataOutput) Instant(java.time.Instant) StaticBuffer(org.janusgraph.diskstorage.StaticBuffer) StaticArrayEntry(org.janusgraph.diskstorage.util.StaticArrayEntry)

Example 82 with StaticBuffer

use of org.janusgraph.diskstorage.StaticBuffer in project janusgraph by JanusGraph.

the class KCVSLog method readSetting.

private long readSetting(String identifier, final StaticBuffer column, long defaultValue) {
    final StaticBuffer key = getSettingKey(identifier);
    StaticBuffer value = BackendOperation.execute(new BackendOperation.Transactional<StaticBuffer>() {

        @Override
        public StaticBuffer call(StoreTransaction txh) throws BackendException {
            return KCVSUtil.get(store, key, column, txh);
        }

        @Override
        public String toString() {
            return "readingLogSetting";
        }
    }, this, times, maxReadTime);
    if (value == null)
        return defaultValue;
    else {
        Preconditions.checkArgument(value.length() == 8);
        return value.getLong(0);
    }
}
Also used : StoreTransaction(org.janusgraph.diskstorage.keycolumnvalue.StoreTransaction) StaticBuffer(org.janusgraph.diskstorage.StaticBuffer) BackendOperation(org.janusgraph.diskstorage.util.BackendOperation) BackendException(org.janusgraph.diskstorage.BackendException) PermanentBackendException(org.janusgraph.diskstorage.PermanentBackendException)

Example 83 with StaticBuffer

use of org.janusgraph.diskstorage.StaticBuffer in project janusgraph by JanusGraph.

the class KCVSLog method writeSetting.

private void writeSetting(String identifier, final StaticBuffer column, long value) {
    final StaticBuffer key = getSettingKey(identifier);
    final Entry add = StaticArrayEntry.of(column, BufferUtil.getLongBuffer(value));
    Boolean status = BackendOperation.execute(new BackendOperation.Transactional<Boolean>() {

        @Override
        public Boolean call(StoreTransaction txh) throws BackendException {
            store.mutate(key, Collections.singletonList(add), KeyColumnValueStore.NO_DELETIONS, txh);
            return Boolean.TRUE;
        }

        @Override
        public String toString() {
            return "writingLogSetting";
        }
    }, this, times, maxWriteTime);
    Preconditions.checkState(status);
}
Also used : Entry(org.janusgraph.diskstorage.Entry) StaticArrayEntry(org.janusgraph.diskstorage.util.StaticArrayEntry) StoreTransaction(org.janusgraph.diskstorage.keycolumnvalue.StoreTransaction) StaticBuffer(org.janusgraph.diskstorage.StaticBuffer) BackendOperation(org.janusgraph.diskstorage.util.BackendOperation) BackendException(org.janusgraph.diskstorage.BackendException) PermanentBackendException(org.janusgraph.diskstorage.PermanentBackendException)

Example 84 with StaticBuffer

use of org.janusgraph.diskstorage.StaticBuffer in project janusgraph by JanusGraph.

the class KCVSLog method add.

/**
 * Adds the given message (content) to the timeslice for the partition identified by the provided partitionId.
 * If a persistor is specified, this persistor is used to add the message otherwise the internal delivery systems are used.
 *
 * @param content
 * @param partitionId
 * @param persistor
 * @return
 */
private Future<Message> add(StaticBuffer content, int partitionId, ExternalPersistor persistor) {
    ResourceUnavailableException.verifyOpen(isOpen, "Log", name);
    Preconditions.checkArgument(content != null && content.length() > 0, "Content is empty");
    Preconditions.checkArgument(partitionId >= 0 && partitionId < (1 << manager.partitionBitWidth), "Invalid partition id: %s", partitionId);
    final Instant timestamp = times.getTime();
    KCVSMessage msg = new KCVSMessage(content, timestamp, manager.senderId);
    FutureMessage futureMessage = new FutureMessage(msg);
    StaticBuffer key = getLogKey(partitionId, (int) (numBucketCounter.incrementAndGet() % numBuckets), getTimeSlice(timestamp));
    MessageEnvelope envelope = new MessageEnvelope(futureMessage, key, writeMessage(msg));
    if (persistor != null) {
        try {
            persistor.add(envelope.key, envelope.entry);
            envelope.message.delivered();
        } catch (JanusGraphException e) {
            envelope.message.failed(e);
            throw e;
        }
    } else if (outgoingMsg == null) {
        sendMessages(Collections.singletonList(envelope));
    } else {
        try {
            // Produces back pressure when full
            outgoingMsg.put(envelope);
            log.debug("Enqueued {} for partition {}", envelope, partitionId);
        } catch (InterruptedException e) {
            throw new JanusGraphException("Got interrupted waiting to send message", e);
        }
    }
    return futureMessage;
}
Also used : Instant(java.time.Instant) JanusGraphException(org.janusgraph.core.JanusGraphException) StaticBuffer(org.janusgraph.diskstorage.StaticBuffer) FutureMessage(org.janusgraph.diskstorage.log.util.FutureMessage)

Example 85 with StaticBuffer

use of org.janusgraph.diskstorage.StaticBuffer in project janusgraph by JanusGraph.

the class ConsistentKeyLockerSerializer method fromLockColumn.

public TimestampRid fromLockColumn(StaticBuffer lockKey, TimestampProvider provider) {
    ReadBuffer r = lockKey.asReadBuffer();
    int len = r.length();
    long tsNS = r.getLong();
    len -= 8;
    byte[] curRid = new byte[len];
    for (int i = 0; r.hasRemaining(); i++) {
        curRid[i] = r.getByte();
    }
    StaticBuffer rid = new StaticArrayBuffer(curRid);
    Instant time = provider.getTime(tsNS);
    return new TimestampRid(time, rid);
}
Also used : ReadBuffer(org.janusgraph.diskstorage.ReadBuffer) Instant(java.time.Instant) StaticArrayBuffer(org.janusgraph.diskstorage.util.StaticArrayBuffer) StaticBuffer(org.janusgraph.diskstorage.StaticBuffer)

Aggregations

StaticBuffer (org.janusgraph.diskstorage.StaticBuffer)101 Entry (org.janusgraph.diskstorage.Entry)36 Test (org.junit.jupiter.api.Test)36 ArrayList (java.util.ArrayList)27 HashMap (java.util.HashMap)20 Map (java.util.Map)19 StoreTransaction (org.janusgraph.diskstorage.keycolumnvalue.StoreTransaction)17 KeySliceQuery (org.janusgraph.diskstorage.keycolumnvalue.KeySliceQuery)16 StaticArrayEntry (org.janusgraph.diskstorage.util.StaticArrayEntry)16 BackendException (org.janusgraph.diskstorage.BackendException)15 List (java.util.List)14 EntryList (org.janusgraph.diskstorage.EntryList)14 TemporaryBackendException (org.janusgraph.diskstorage.TemporaryBackendException)14 KCVMutation (org.janusgraph.diskstorage.keycolumnvalue.KCVMutation)13 PermanentBackendException (org.janusgraph.diskstorage.PermanentBackendException)12 Instant (java.time.Instant)11 DataOutput (org.janusgraph.graphdb.database.serialize.DataOutput)10 ReadBuffer (org.janusgraph.diskstorage.ReadBuffer)8 ConsistentKeyLockStatus (org.janusgraph.diskstorage.locking.consistentkey.ConsistentKeyLockStatus)7 BackendOperation (org.janusgraph.diskstorage.util.BackendOperation)7