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);
}
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);
}
}
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);
}
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;
}
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);
}
Aggregations